establish a per-module option that specifies whether or not active commands to it need to be prefixed with the bot's name. doesn't help stuff like Seen's reimplementation of on_pubmsg, since it would want to do the tracking regardless of this option. also, work around this addition in the countdown module, so it doesn't show up in lists.

This commit is contained in:
Brian S. Stephan 2010-08-01 11:55:14 -05:00
parent 4d41314195
commit 1ec197be95
2 changed files with 14 additions and 3 deletions

View File

@ -16,6 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from ConfigParser import NoSectionError, NoOptionError
import inspect
import re
import sys
@ -101,7 +102,13 @@ class Module(object):
addressed_pattern = '^' + connection.get_nickname() + '[:,]?\s+'
addressed_re = re.compile(addressed_pattern)
if not addressed_re.match(what):
need_prefix = True
try:
need_prefix = self.config.getboolean(self.__class__.__name__, 'meta.pubmsg_needs_bot_prefix')
except NoOptionError: pass
except NoSectionError: pass
if not addressed_re.match(what) and need_prefix:
return
else:
what = addressed_re.sub('', what)

View File

@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from ConfigParser import NoOptionError
from ConfigParser import NoOptionError, NoSectionError
from datetime import datetime
from dateutil.parser import *
@ -50,7 +50,11 @@ class Countdown(Module):
try:
cdlist = self.config.options(self.__class__.__name__)
cdlist.remove('debug')
cdlist.remove('pubmsg_needs_bot_prefix')
# if this option has been provided, don't print it
try:
self.config.get(self.__class__.__name__, 'meta.pubmsg_needs_bot_prefix')
cdlist.remove('meta.pubmsg_needs_bot_prefix')
except NoOptionError: pass
cdlist.sort()
liststr = ', '.join(cdlist)
return self.reply(connection, replypath, liststr)