the bot can now exit gracefully.
This commit is contained in:
parent
cce7ef88dc
commit
45447d2e77
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,5 +1,5 @@
|
||||
/response/error.txt
|
||||
response/error.txt
|
||||
log.txt
|
||||
.botinput
|
||||
.*
|
||||
bot.cfg
|
||||
bot.cfg
|
||||
|
24
bot.sh
24
bot.sh
@ -6,19 +6,22 @@ if [ "$(whoami)" = "root" ]; then
|
||||
fi
|
||||
[ -f functions.sh ] && source functions.sh
|
||||
[ -f bot.cfg ] && source bot.cfg
|
||||
export allowList
|
||||
export ignoreList
|
||||
input=".botinput"
|
||||
|
||||
close_bot() {
|
||||
echo -en "QUIT :${quitMessage}\r\n" | telnet "$server" "$port"
|
||||
rm "$input"
|
||||
exit 0
|
||||
# Variables important to modules need to be exported here.
|
||||
export allowList
|
||||
export input
|
||||
export ignoreList
|
||||
export quitMessage
|
||||
|
||||
rm_input() {
|
||||
if [[ -f "$input" ]]; then
|
||||
rm "$input"
|
||||
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 "USER $user" >> "$input"
|
||||
echo "JOIN #$channel" >> "$input"
|
||||
@ -149,3 +152,6 @@ tail -f "$input" | telnet "$server" "$port" | while read -r result ; do
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
rm_input
|
||||
exit 0
|
||||
|
@ -1,9 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ -z "$input" ]; then
|
||||
input=".botinput"
|
||||
if [[ -z "$input" ]]; then
|
||||
input="$(mktemp .XXXXXX)"
|
||||
fi
|
||||
|
||||
close_bot() {
|
||||
echo -en "QUIT :${quitMessage}\r\n" >> "$input"
|
||||
}
|
||||
|
||||
msg()
|
||||
{
|
||||
local msg="PRIVMSG $1 :"
|
||||
|
8
modules/exit/exit.sh
Executable file
8
modules/exit/exit.sh
Executable file
@ -0,0 +1,8 @@
|
||||
[ -f functions.sh ] && source functions.sh
|
||||
|
||||
user=$1
|
||||
shift
|
||||
shift
|
||||
if [[ "$user" =~ $allowList ]]; then
|
||||
close_bot
|
||||
fi
|
Loading…
Reference in New Issue
Block a user