Skip to content

Commit 23162c8

Browse files
author
bspkrs
committed
added ability to define basic text info commands in the config file
1 parent 1982c44 commit 23162c8

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

Diff for: BotBase.py

+36-6
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ def __init__(self, configfile=None, nspass=None, backupcfg=False):
118118
self.logerrorsmaxbytes = self.config.geti('BOT', 'LOGERRORSMAXBYTES', str(1024*1024), "The log will be rotated when its size reaches this many bytes.")
119119
self.help_url = self.config.get('BOT', 'HELP_URL', '')
120120
self.primary_channels = set(self.config.get('BOT','PRIMARY_CHANNELS', '', 'Important bot messages will be sent to Ops in these channels.').split(';') if self.config.get('BOT','PRIMARY_CHANNELS', "").strip() else [])
121-
self.about_msg = self.config.get('BOT', 'ABOUT_MSG', '', 'A message with info about the bot (owners, authors, more info, etc).')
122121

123122
self.allowunregistered = self.config.getb('AUTH', 'ALLOWUNREGISTERED', "true", 'Can users without a registered nick emit commands?')
124123
self.authtimeout = self.config.geti('AUTH', 'TIMEOUT', "60", 'User authentication refresh delay in seconds. User auth will be considered valid for this period.')
@@ -150,6 +149,7 @@ def __init__(self, configfile=None, nspass=None, backupcfg=False):
150149

151150
self.logger.info("Users : %s"%self.authUsers)
152151
self.logger.info("Groups : %s"%self.groups)
152+
self.txtcmds = {}
153153

154154
self.updateConfig()
155155

@@ -196,8 +196,13 @@ def __init__(self, configfile=None, nspass=None, backupcfg=False):
196196
self.registerCommand('shutdown', self.killSelf, ['admin'], 0, 0, "", "Kills the bot.")
197197

198198
self.registerCommand('help', self.helpcmd, ['any'], 0, 1, "[<command>|*]", "Lists available commands or help about a specific command.", allowpub=True)
199-
if self.about_msg and self.about_msg != '':
200-
self.registerCommand('about', self.aboutcmd, ['any'], 0, 0, '', 'About this bot.', allowpub=True)
199+
200+
# We collect the list of simple text commands)
201+
for option in self.config.options('TEXTCOMMANDS'):
202+
self.addtxtcmd(option, json.loads(self.config.get('TEXTCOMMANDS',option)))
203+
204+
if 'about' not in self.txtcmds.keys():
205+
self.addtxtcmd('about', {})
201206

202207
def clone(self):
203208
return BotBase(self.configfile, self.nspass, self.backupcfg)
@@ -406,6 +411,31 @@ def groupmeta(self, bot, sender, dest, cmd, args):
406411
bot.sendNotice(sender.nick, "Done")
407412
self.updateConfig()
408413

414+
def addtxtcmd(self, cmd, data):
415+
if cmd.lower() not in self.txtcmds.keys() and cmd.lower() not in self.cmdHandler.commands.keys():
416+
data = self.addmissingkeys(data)
417+
self.txtcmds[cmd.lower()] = data
418+
if data['text'] and data['text'] != '':
419+
self.registerCommand(cmd.lower(), self.txtcmd, data.get('groups'), 0, 0, '', data.get('helpdesc', ''), showhelp=data.get('showhelp', True), allowpub=data.get('allowpub', True))
420+
else:
421+
self.logger.warning('Attempted to register duplicate command %s' % cmd)
422+
423+
def addmissingkeys(self, data):
424+
if 'groups' not in data.keys():
425+
data['groups'] = ['any']
426+
if 'helpdesc' not in data.keys():
427+
data['helpdesc'] = ''
428+
if 'showhelp' not in data.keys():
429+
data['showhelp'] = True
430+
if 'allowpub' not in data.keys():
431+
data['allowpub'] = True
432+
if 'text' not in data.keys():
433+
data['text'] = ''
434+
return data
435+
436+
def txtcmd(self, bot, sender, dest, cmd, args):
437+
bot.sendOutput(dest, self.txtcmds[cmd['command']]['text'])
438+
409439
# Default help command
410440
def helpcmd(self, bot, sender, dest, cmd, args):
411441
if len(args) == 0 or args[0] == '*':
@@ -459,9 +489,6 @@ def helpcmd(self, bot, sender, dest, cmd, args):
459489
else:
460490
bot.sendNotice(sender.nick, "§B*** Invalid command specified ***")
461491

462-
def aboutcmd(self, bot, sender, dest, cmd, args):
463-
self.sendOutput(dest, self.about_msg)
464-
465492
# DCC Request command, in by default
466493
def requestDCC(self, bot, sender, dest, cmd, args):
467494
if self.dccActive:
@@ -570,6 +597,9 @@ def updateConfig(self):
570597
for user, bans in self.banList.items():
571598
self.config.set('BANLIST',user, ';'.join(bans))
572599

600+
for command, data in self.txtcmds.items():
601+
self.config.set('TEXTCOMMANDS', command, json.dumps(data))
602+
573603
self.config.write(fp)
574604

575605
#IRC COMMANDS QUICK ACCESS

0 commit comments

Comments
 (0)