From f6319244c8c0fe42a16c94f1f04e051a7a839b49 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sun, 25 Jul 2010 08:52:48 -0500 Subject: [PATCH] only run commands in pubmsg if the bot has been addressed --- dr.botzo.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/dr.botzo.py b/dr.botzo.py index 70d6fe3..ba8ce7b 100755 --- a/dr.botzo.py +++ b/dr.botzo.py @@ -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)