only run commands in pubmsg if the bot has been addressed

This commit is contained in:
Brian S. Stephan 2010-07-25 08:52:48 -05:00
parent d1d54ca35c
commit f6319244c8
1 changed files with 13 additions and 1 deletions

View File

@ -2,6 +2,7 @@
from ConfigParser import ConfigParser, NoSectionError, NoOptionError
import os
import re
import sys
import irclib
@ -83,7 +84,7 @@ def on_connect(connection, event):
# user modes
try:
usermode = config.get('IRC', 'usermode')
connection.mode(nick, usermode)
connection.mode(botnick, usermode)
except NoOptionError: pass
# join the specified channels
@ -136,6 +137,17 @@ def on_pubmsg(connection, event):
admin_unlocked = True
except NoOptionError: pass
# only do commands if the bot has been addressed directly
addressed_pattern = '^' + botnick + '[:,]?\s+'
addressed_re = re.compile(addressed_pattern)
if not addressed_re.match(what):
return
else:
what = addressed_re.sub('', what)
print("could be a command: " + what)
# admin commands
sub_join_channel(connection, event, nick, userhost, replypath, what, admin_unlocked)
sub_part_channel(connection, event, nick, userhost, replypath, what, admin_unlocked)