From: Brett Parker Date: Tue, 17 Sep 2019 16:54:48 +0000 (+0100) Subject: Change a load of send_lines to use easier wrappers X-Git-Url: https://git.sommitrealweird.co.uk/bashbot.git/commitdiff_plain/2db6a6c04eb0acae2da79b6d4ad45844e3a96042 Change a load of send_lines to use easier wrappers --- diff --git a/bashbot.sh b/bashbot.sh index f692ddb..a47be46 100644 --- a/bashbot.sh +++ b/bashbot.sh @@ -18,7 +18,7 @@ keeprunning=1 declare -A reminders cleanup() { - echo "QUIT :Going back to hell" >&4 + send_line "QUIT :Going back to hell" keeprunning=0 sleep 0.2 if [[ $irc_process -gt 0 ]]; then @@ -127,7 +127,7 @@ EOF list_reminders $channel ;; *) - send_line "PRIVMSG $channel :Sorry, don't know how to $bot_command." + send_action $channel "is sorry, they don't know how to $bot_command." ;; esac fi @@ -139,21 +139,37 @@ send_line() { sleep 0.1 } +send_privmsg() { + channel="$1" + content="$2" + + send_line "PRIVMSG $channel :$content" +} + +send_action() { + channel="$1" + content="$2" + action_wrapper=$'\001' + + content="${action_wrapper}ACTION ${content}${action_wrapper}" + send_privmsg "$channel" "$content" +} + send_help_message() { channel=$1 echo "Sending help!" - send_line "PRIVMSG $channel :Help:" - send_line "PRIVMSG $channel : An IRC bot written in bash!" - send_line "PRIVMSG $channel : help - display this message" - send_line "PRIVMSG $channel : version - display version number" - send_line "PRIVMSG $channel : quit - make the bot quit IRC" - send_line "PRIVMSG $channel : add YYYY-mm-dd HH:MM reminder text" - send_line "PRIVMSG $channel : list - list reminders" + send_privmsg $channel "Help:" + send_privmsg $channel " An IRC bot written in bash!" + send_privmsg $channel " help - display this message" + send_privmsg $channel " version - display version number" + send_privmsg $channel " quit - make the bot quit IRC" + send_privmsg $channel " add YYYY-mm-dd HH:MM reminder text" + send_privmsg $channel " list - list reminders" } send_version() { channel=$1 - send_line "PRIVMSG $channel :Version: $version" + send_privmsg $channel "Version: $version" } add_reminder() { @@ -166,9 +182,9 @@ EOF # YYYY-mm-dd HH:MM the text of the reminder timestamp=$(date +"%s" --date="${dataparts[0]} ${dataparts[1]}") if [[ $? -ne 0 ]]; then - send_line "PRIVMSG $channel :Couldn't parse date/time ${dataparts[0]} ${dataparts[1]}" + send_privmsg $channel "Couldn't parse date/time ${dataparts[0]} ${dataparts[1]}" else - send_line "PRIVMSG $channel :Added reminder for ${dataparts[0]} ${dataparts[1]}: ${dataparts[@]:2}" + send_privmsg $channel "Added reminder for ${dataparts[0]} ${dataparts[1]}: ${dataparts[@]:2}" reminders[$timestamp]="${dataparts[@]:2}" fi } @@ -178,7 +194,7 @@ check_reminders() { # loop through the reminders keys to see if it's past and alert if so for ts in ${!reminders[@]}; do if [[ $ts -le $current_timestamp ]]; then - send_line "PRIVMSG $my_irc_channel :${reminders[$ts]}" + send_privmsg $my_irc_channel "${reminders[$ts]}" # we need to remove this from the array now unset "reminders[$ts]" fi @@ -189,7 +205,7 @@ list_reminders() { channel=$1 for ts in ${!reminders[@]}; do date_stamp="$(date --date="@$ts" +"%Y-%m-%d %H:%M")" - send_line "PRIVMSG $channel :$date_stamp ${reminders[$ts]}" + send_privmsg $channel "$date_stamp ${reminders[$ts]}" done }