diff options
Diffstat (limited to 'modules/m_say.sh')
-rw-r--r-- | modules/m_say.sh | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/modules/m_say.sh b/modules/m_say.sh new file mode 100644 index 0000000..104b30c --- /dev/null +++ b/modules/m_say.sh @@ -0,0 +1,98 @@ +#!/bin/bash +# -*- coding: utf-8 -*- +########################################################################### +# # +# envbot - an IRC bot in bash # +# Copyright (C) 2007-2008 Arvid Norlander # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see <http://www.gnu.org/licenses/>. # +# # +########################################################################### +#--------------------------------------------------------------------- +## Allow owners to make to bot say something +#--------------------------------------------------------------------- + +module_say_INIT() { + modinit_API='2' + modinit_HOOKS='' + commands_register "$1" 'say' || return 1 + commands_register "$1" 'act' || return 1 + helpentry_module_say_description="Provides say and act commands." + + helpentry_say_act_syntax='<target> <message>' + helpentry_say_act_description='Send a <message> to <target> (nick or channel).' + + helpentry_say_act_syntax='<target> <message>' + helpentry_say_act_description='Peform the <message> as a /me to <target> (nick or channel).' +} + +module_say_UNLOAD() { + return 0 +} + +module_say_REHASH() { + return 0 +} + +module_say_handler_say() { + local sender="$1" + local parameters="$3" + if [[ "$parameters" =~ ^([^ ]+)\ (.+) ]]; then + local target="${BASH_REMATCH[1]}" + local message="${BASH_REMATCH[2]}" + local scope + # Is it a channel? + if [[ $target =~ ^# ]]; then + scope="$target" + else + scope="MSG" + fi + if access_check_capab "say" "$sender" "$scope"; then + access_log_action "$sender" "made the bot say \"$message\" in/to \"$target\"" + send_msg "$target" "$message" + else + access_fail "$sender" "make the bot talk with say" "say" + fi + else + local sendernick + parse_hostmask_nick "$sender" 'sendernick' + feedback_bad_syntax "$sendernick" "say" "<target> <message> # Where target is a nick or channel" + fi +} + +module_say_handler_act() { + local sender="$1" + local parameters="$3" + if [[ "$parameters" =~ ^([^ ]+)\ (.+) ]]; then + local target="${BASH_REMATCH[1]}" + local message="${BASH_REMATCH[2]}" + local scope + # Is it a channel? + if [[ $target =~ ^# ]]; then + scope="$target" + else + scope="MSG" + fi + if access_check_capab "say" "$sender" "$scope"; then + access_log_action "$sender" "made the bot act \"$message\" in/to \"$target\"" + send_ctcp "$target" "ACTION ${message}" + else + access_fail "$sender" "make the bot act" "say" + fi + else + local sendernick + parse_hostmask_nick "$sender" 'sendernick' + feedback_bad_syntax "$sendernick" "act" "<target> <message> # Where target is a nick or channel" + fi +} |