Cleanup.
This commit is contained in:
29
bot.sh
29
bot.sh
@@ -30,7 +30,7 @@ done
|
||||
|
||||
# Variables important to modules need to be exported here.
|
||||
export allowList
|
||||
export channel
|
||||
export channels
|
||||
export input
|
||||
export ignoreList
|
||||
export nick
|
||||
@@ -90,7 +90,10 @@ while true; do
|
||||
echo -e "Session started $(date "+%I:%M%p%n %A, %B %d, %Y").\n\nTo gracefully exit, make sure you are in the allow list and send the command exit to the bot.\n\n" | tee -a "$log"
|
||||
echo "NICK $nick" > "$input"
|
||||
echo "USER $user" >> "$input"
|
||||
echo "JOIN #$channel" >> "$input"
|
||||
# Join all configured channels
|
||||
for channelName in "${channels[@]}"; do
|
||||
echo "JOIN #$channelName" >> "$input"
|
||||
done
|
||||
|
||||
# The main loop of the program where we watch for output from irc.
|
||||
# Use SSL if enabled, otherwise plain TCP
|
||||
@@ -136,12 +139,17 @@ while true; do
|
||||
;;
|
||||
# for pings on nick/user
|
||||
*"You have not"*)
|
||||
echo "JOIN #$channel" | tee -a "$input"
|
||||
for channelName in "${channels[@]}"; do
|
||||
echo "JOIN #$channelName" | tee -a "$input"
|
||||
done
|
||||
;;
|
||||
# Run on kick
|
||||
:*!*@*" KICK "*" $nick :"*)
|
||||
if [ "$autoRejoinChannel" = "true" ]; then
|
||||
echo "JOIN #$channel" | tee -a "$input"
|
||||
# Extract channel name from kick message and rejoin that specific channel
|
||||
kickedChannel="${result##*#}"
|
||||
kickedChannel="#${kickedChannel%% *}"
|
||||
echo "JOIN $kickedChannel" | tee -a "$input"
|
||||
fi
|
||||
if [ "$curseKicker" = "true" ]; then
|
||||
kickerName="${result%!*}"
|
||||
@@ -197,7 +205,8 @@ while true; do
|
||||
echo "Calling module ./modules/${command% *}/${command% *}/${command% *}.sh \"$who\" \"$from\" $willSanitized" >> "$log"
|
||||
# Disable wildcards
|
||||
set -f
|
||||
"./modules/${command% *}/${command% *}.sh" "$who" "#$channel" "$will"
|
||||
# For PMs, respond directly to the user, not to a channel
|
||||
"./modules/${command% *}/${command% *}.sh" "$who" "$from" "$will"
|
||||
# Enable wildcards
|
||||
set +f
|
||||
else
|
||||
@@ -213,7 +222,7 @@ while true; do
|
||||
who="${who:1}"
|
||||
from="${result#*#}"
|
||||
from="${from%% *}"
|
||||
from="#${from:-$channel}"
|
||||
from="#${from:-${channels[0]}}"
|
||||
# Trigger stuff happens here.
|
||||
# Call link trigger if msg contains a link:
|
||||
if [[ "$result" =~ .*http://|https://|www\..* ]]; then
|
||||
@@ -229,6 +238,8 @@ while true; do
|
||||
command="${command//# /}"
|
||||
will="${command#* }"
|
||||
command="${command%% *}"
|
||||
# If will equals command, there were no arguments
|
||||
[[ "$will" == "$command" ]] && will=""
|
||||
willSanitized="${will//[$'\001'-$'\037'$'\177']/}"
|
||||
echo "DEBUG: command='$command' will='$willSanitized'" >> "$log"
|
||||
if command -v "./modules/${command% *}/${command% *}.sh" &>/dev/null ; then
|
||||
@@ -245,6 +256,12 @@ while true; do
|
||||
if ! [[ "$who" =~ ^($ignoreList)$ ]]; then
|
||||
set -f
|
||||
./triggers/keywords/keywords.sh "$who" "$from" "$result"
|
||||
# Only call wordtrack for valid channel messages
|
||||
if [[ "$from" =~ ^#[a-zA-Z0-9_-]+$ ]]; then
|
||||
# Extract just the message text for wordtrack
|
||||
messageText="${result#*PRIVMSG*:}"
|
||||
./triggers/wordtrack/wordtrack.sh "$who" "$from" "$messageText"
|
||||
fi
|
||||
set +f
|
||||
fi
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user