More code cleanup on the main bot and its supporting functions.
This commit is contained in:
parent
c5f5c41a7d
commit
0eccf775da
16
bot.sh
16
bot.sh
@ -4,8 +4,16 @@ if [ "$(whoami)" = "root" ]; then
|
||||
echo "This bot should not be ran as root."
|
||||
exit 1
|
||||
fi
|
||||
[ -f functions.sh ] && source functions.sh
|
||||
[ -f bot.cfg ] && source bot.cfg
|
||||
|
||||
# Load required files.
|
||||
for i in "bot.cfg" "functions.sh" ; do
|
||||
if [[ -f "$i" ]]; then
|
||||
source "$i"
|
||||
else
|
||||
echo "Could not find required file \"${i}\"."
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
# Variables important to modules need to be exported here.
|
||||
export allowList
|
||||
@ -14,19 +22,23 @@ export input
|
||||
export ignoreList
|
||||
export quitMessage
|
||||
|
||||
# Function called on exit to remove the temporary input file.
|
||||
rm_input() {
|
||||
if [[ -f "$input" ]]; then
|
||||
rm -f "$input"
|
||||
fi
|
||||
}
|
||||
|
||||
# Trap exiting ffrom the program to remove the temporary input file.
|
||||
trap rm_input EXIT
|
||||
|
||||
# Set up the connection.
|
||||
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"
|
||||
|
||||
# The main loop of the program where we watch for output from irc.
|
||||
tail -f "$input" | telnet "$server" "$port" | while read -r result ; do
|
||||
# log the session
|
||||
echo "$(date "+[$dateFormat]") $result" >> "$log"
|
||||
|
12
functions.sh
12
functions.sh
@ -8,29 +8,25 @@ close_bot() {
|
||||
echo -en "QUIT :${quitMessage}\r\n" >> "$input"
|
||||
}
|
||||
|
||||
msg()
|
||||
{
|
||||
msg() {
|
||||
local msg="PRIVMSG $1 :"
|
||||
shift
|
||||
echo -en "${msg}$@\r\n" | tee -a "$input"
|
||||
}
|
||||
|
||||
nick()
|
||||
{
|
||||
nick() {
|
||||
local msg="NICK $1"
|
||||
shift
|
||||
echo -en "${msg}\r\n" | tee -a "$input"
|
||||
}
|
||||
|
||||
reply()
|
||||
{
|
||||
reply() {
|
||||
shift
|
||||
local msg="PRIVMSG $1 :"
|
||||
echo -en "${msg}$@\r\n" | tee -a "$input"
|
||||
}
|
||||
|
||||
act()
|
||||
{
|
||||
act() {
|
||||
local msg="PRIVMSG $1 :\x01ACTION"
|
||||
shift
|
||||
echo -en "$msg $@\x01\r\n" | tee -a "$input"
|
||||
|
Loading…
Reference in New Issue
Block a user