Reorganization to hopefully prevent git conflicts.
This commit is contained in:
48
bot.sh
48
bot.sh
@@ -18,6 +18,47 @@ if [[ ! -f "bot.cfg" ]]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check and initialize customizable configuration files
|
||||
check_config_files() {
|
||||
local configFiles=(
|
||||
"response/error.txt:response/error.txt.example"
|
||||
"response/exit.txt:response/exit.txt.example"
|
||||
"triggers/greet/greetings.txt:triggers/greet/greetings.txt.example"
|
||||
"triggers/keywords/keywords.cfg:triggers/keywords/keywords.cfg.example"
|
||||
)
|
||||
|
||||
for entry in "${configFiles[@]}"; do
|
||||
local target="${entry%:*}"
|
||||
local example="${entry#*:}"
|
||||
|
||||
if [[ ! -f "$target" ]]; then
|
||||
if [[ -f "$example" ]]; then
|
||||
cp "$example" "$target"
|
||||
echo "Created $target from $example"
|
||||
else
|
||||
# Hardcoded fallback for critical files if example is missing
|
||||
case "$target" in
|
||||
"response/error.txt")
|
||||
mkdir -p "$(dirname "$target")"
|
||||
printf "I don't understand\nI'm not sure how to help you with that.\n" > "$target"
|
||||
echo "Warning: $example not found. Created $target with default content."
|
||||
;;
|
||||
"response/exit.txt")
|
||||
mkdir -p "$(dirname "$target")"
|
||||
printf "Ta ta for now.\nbye.\n" > "$target"
|
||||
echo "Warning: $example not found. Created $target with default content."
|
||||
;;
|
||||
*)
|
||||
echo "Warning: Missing $example and no hardcoded fallback available."
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
check_config_files
|
||||
|
||||
# Load required files.
|
||||
for i in "bot.cfg" "functions.sh" ; do
|
||||
if [[ -f "$i" ]]; then
|
||||
@@ -231,6 +272,13 @@ while true; do
|
||||
from="${result#*#}"
|
||||
from="${from%% *}"
|
||||
from="#${from:-${channels[0]}}"
|
||||
|
||||
# Validate channel name format (IRC RFC 2812: must start with #, contain only valid chars)
|
||||
if [[ ! "$from" =~ ^#[a-zA-Z0-9_-]+$ ]]; then
|
||||
# Invalid channel, use default
|
||||
from="#${channels[0]}"
|
||||
fi
|
||||
|
||||
# Trigger stuff happens here.
|
||||
# Call link trigger if msg contains a link:
|
||||
if [[ "$result" =~ .*http://|https://|www\..* ]]; then
|
||||
|
||||
Reference in New Issue
Block a user