the bot can now exit gracefully.

This commit is contained in:
Storm Dragon 2020-08-17 21:20:12 -04:00
parent cce7ef88dc
commit 45447d2e77
4 changed files with 31 additions and 13 deletions

4
.gitignore vendored
View File

@ -1,5 +1,5 @@
/response/error.txt response/error.txt
log.txt log.txt
.botinput .*
bot.cfg bot.cfg
bot.cfg bot.cfg

22
bot.sh
View File

@ -6,19 +6,22 @@ if [ "$(whoami)" = "root" ]; then
fi fi
[ -f functions.sh ] && source functions.sh [ -f functions.sh ] && source functions.sh
[ -f bot.cfg ] && source bot.cfg [ -f bot.cfg ] && source bot.cfg
export allowList
export ignoreList
input=".botinput"
close_bot() { # Variables important to modules need to be exported here.
echo -en "QUIT :${quitMessage}\r\n" | telnet "$server" "$port" export allowList
export input
export ignoreList
export quitMessage
rm_input() {
if [[ -f "$input" ]]; then
rm "$input" rm "$input"
exit 0 fi
} }
trap close_bot EXIT $? trap rm_input EXIT
echo "Session started $(date "+%I:%M%p%n %A, %B %d, %Y")" | tee "$log" 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 "$log"
echo "NICK $nick" > "$input" echo "NICK $nick" > "$input"
echo "USER $user" >> "$input" echo "USER $user" >> "$input"
echo "JOIN #$channel" >> "$input" echo "JOIN #$channel" >> "$input"
@ -149,3 +152,6 @@ tail -f "$input" | telnet "$server" "$port" | while read -r result ; do
;; ;;
esac esac
done done
rm_input
exit 0

View File

@ -1,9 +1,13 @@
#!/bin/bash #!/bin/bash
if [ -z "$input" ]; then if [[ -z "$input" ]]; then
input=".botinput" input="$(mktemp .XXXXXX)"
fi fi
close_bot() {
echo -en "QUIT :${quitMessage}\r\n" >> "$input"
}
msg() msg()
{ {
local msg="PRIVMSG $1 :" local msg="PRIVMSG $1 :"

8
modules/exit/exit.sh Executable file
View File

@ -0,0 +1,8 @@
[ -f functions.sh ] && source functions.sh
user=$1
shift
shift
if [[ "$user" =~ $allowList ]]; then
close_bot
fi