only run commands in pubmsg if the bot has been addressed
This commit is contained in:
parent
d1d54ca35c
commit
f6319244c8
14
dr.botzo.py
14
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)
|
||||
|
|
Loading…
Reference in New Issue