if not aliasid: self.cursor.execute('''INSERT INTO Aliases Values (NULL,?,?),\ (NULL,?,?)''', (oldnickid, newnickid, newnickid, oldnickid)) self.connection.commit() @action(name='alias', rule=r'^\!alias (?P<nick>\S+).*$') def alias(self, bot, message, match, *args, **kwargs): """Return a list of known alternative usernames for nick. Usage: !alias nick""" nick = match.group('nick') self.cursor.execute('''SELECT id FROM Nicks WHERE nick=?''', (nick, )) nickid = self.cursor.fetchone() if not nickid: bot.say('No other known aliases for user {}.'.format(nick)) else: nickid = int(nickid[0]) self.cursor.execute('''SELECT n1.nick FROM Nicks n1, Aliases a WHERE a.nickid=? AND a.aliasid=n1.id''', (nickid, )) aliases = [i[0] for i in self.cursor.fetchall()] bot.say('User also seen as {}.'.format(', '.join(aliases)), message.channel) ircbot.register(Alias)
# Say the message bot.say(msg, channel) class ClassModuleExample(MultiAction): """An example MultiAction module class.""" def __init__(self, bot, *args, **kwargs): # Create a new bot public field bot.usersWhoSaidNi = [] # Run the superclass constructor super(ClassModuleExample, self).__init__(bot, *args, **kwargs) @action(name='grepNiSayers', rule=r'Ni!|ni!') def niSayersShallBeRemebered(self, bot, message, *args, **kwargs): """Remember users who said Ni! or ni!""" # Add the user who matched the rule to the list if not message.nick in bot.usersWhoSaidNi: bot.usersWhoSaidNi.append(message.nick) # Say something for fun bot.say('Ni sayer!', message.channel) # Register the module in the bot ircbot.register(ClassModuleExample)
if not hasattr(bot.config, 'IGNORES'): raise AttributeError('A IGNORES list required in the config file.') bot.ignores = bot.config.IGNORES super(Ignore, self).__init__(bot, *args, **kwargs) @action(name='ignore', rule=r'^\!ignore (?P<nick>\S+).*$') @admin_only def ignore(self, bot, message, match): """Ignore the given user. Usage: !ignore <nick>""" nick = match.group(1) if nick not in bot.ignores: bot.ignores.append(nick) bot.say('Ignoring {} from now on.'.format(nick), message.channel) @action(name='deignore', rule=r'^\!deignore (?P<nick>\S+).*$') @admin_only def deignore(self, bot, message, match): """Deignore the given user. Usage: !deignore <nick>""" nick = match.group(1) if nick in bot.ignores: bot.ignores.remove(nick) bot.say('Listening to {} again.'.format(nick), message.channel) ircbot.register(Ignore)
def __init__(self, bot, *args, **kwargs): self.seendb = {} super(Seen, self).__init__(bot, *args, **kwargs) @action(name='populate_seen', events=('PRIVMSG', 'JOIN')) def populate_seen(self, bot, message, match, *args, **kwargs): """Populates the seen database.""" user = message.nick msg = message._trailing date = datetime.now().strftime('%Y-%m-%d %H:%M:%S') self.seendb[user] = (msg, date) @action(name='seen', rule=r'^\!seen (?P<user>\S+).*$') @honor_ignores def seen(self, bot, message, match, *args, **kwargs): """Tells when the user was last seen on the channel. Usage: !seen user""" user = match.group('user') if user in self.seendb: msg = self.seendb[user][0] date = self.seendb[user][1] bot.say('{} last seen saying {} on {}.'.format(user, msg, date)) else: bot.say('I haven\'t seen {} around.'.format(user), message.channel) ircbot.register(Seen)
bot.userlists[msg[-1]] = [u for u in message._trailing.split()] @action(name='populate_userlist', events=('JOIN', )) def populate_userlists(self, bot, message, match, *args, **kwargs): """Populates the channel userlist.""" bot.userlists[message.channel].append(message.nick) @action(name='namechange_react', events=('NICK', )) def namechange_react(self, bot, message, match, *args, **kwargs): """React to a users name change.""" oldnick = message._prefix.split('!')[0] newnick = message._trailing for channel in bot.userlists.values(): if oldnick in channel: channel.remove(oldnick) channel.append(newnick) @action(name='depopulate_userlist', events=('PART', 'QUIT')) def depopulate_userlists(self, bot, message, match, *args, **kwargs): """Depopulates the channel userlist when someone quits.""" for c in bot.userlists.values(): if message.nick in c: c.remove(message.nick) ircbot.register(UserLists)
if what.startswith("/me "): what = what[4:] action = True if channel is not None: bot.say(what, "#" + channel, action=action) else: bot.say(what, action=action) @action(name="help", rule=r"^\!help(\ (?P<action>\S+))?$") @admin_only def help(self, bot, message, match, *args, **kwargs): """Returns the help for the given action or a list of actions. Usage: !help <action>""" action = match.group("action") if action is not None: for a in bot._actions: if a.name == action: bot.say(a.help, message.channel) break else: bot.say("No such command.", message.channel) else: actions = [ac.name for ac in bot._actions] bot.say(", ".join(actions), message.channel) ircbot.register(Utils)
channel = message.channel # Say the message bot.say(msg, channel) class ClassModuleExample(MultiAction): """An example MultiAction module class.""" def __init__(self, bot, *args, **kwargs): # Create a new bot public field bot.usersWhoSaidNi = [] # Run the superclass constructor super(ClassModuleExample, self).__init__(bot, *args, **kwargs) @action(name='grepNiSayers', rule=r'Ni!|ni!') def niSayersShallBeRemebered(self, bot, message, *args, **kwargs): """Remember users who said Ni! or ni!""" # Add the user who matched the rule to the list if not message.nick in bot.usersWhoSaidNi: bot.usersWhoSaidNi.append(message.nick) # Say something for fun bot.say('Ni sayer!', message.channel) # Register the module in the bot ircbot.register(ClassModuleExample)
if prob: self.throwprob = int(prob) bot.say( 'Changed the quote throw probability' ' to {}.'.format(self.throwprob), message.channel) else: bot.say('Current throw probability is {}.'.format(self.throwprob), message.channel) @action(name='gatherprobchange', rule=r'^\!gather(\ (?P<prob>\d+))?$') @admin_only def gatherprobchange(self, bot, message, match, *args, **kwargs): """Change the quote gather probability. Usage: !gather <prob>""" prob = match.group('prob') if prob: self.gatherprob = int(prob) bot.say( 'Changed the quote gather probability' ' to {}.'.format(self.gatherprob), message.channel) else: bot.say( 'Current gather probability is {}.'.format(self.gatherprob), message.channel) ircbot.register(RandQuote)
if what.startswith('/me '): what = what[4:] action = True if channel is not None: bot.say(what, '#'+channel, action=action) else: bot.say(what, action=action) @action(name='help', rule=r'^\!help(\ (?P<action>\S+))?$') @admin_only def help(self, bot, message, match, *args, **kwargs): """Returns the help for the given action or a list of actions. Usage: !help <action>""" action = match.group('action') if action is not None: for a in bot._actions: if a.name == action: bot.say(a.help, message.channel) break else: bot.say('No such command.', message.channel) else: actions = [ac.name for ac in bot._actions] bot.say(', '.join(actions), message.channel) ircbot.register(Utils)
@action(name='identify', rule=r'^\!identify\ (?P<password>\S+)$') def identify(self, bot, message, match, *args, **kwargs): """Log in an user as an admin. Usage: !identify <password>""" password = match.group(1) nick = message.nick if nick in bot.config.ADMINS \ and password == bot.config.ADMINS[nick]: bot.admins.append(nick) bot.say('Welcome {}!'.format(nick), message.nick) @action(name='logout', rule=r'^\!logout(\ (?P<user>\S+))?$') @admin_only def logout(self, bot, message, match, *args, **kwargs): """Log out the user. Usage: !logout <user>""" user = match.group('user') if user is None: user = message.nick if user in bot.admins: bot.admins.remove(user) bot.say('Goodbye {}!'.format(user), message.nick) ircbot.register(Admin)
self.cursor.execute( '''INSERT INTO Aliases Values (NULL,?,?),\ (NULL,?,?)''', (oldnickid, newnickid, newnickid, oldnickid)) self.connection.commit() @action(name='alias', rule=r'^\!alias (?P<nick>\S+).*$') def alias(self, bot, message, match, *args, **kwargs): """Return a list of known alternative usernames for nick. Usage: !alias nick""" nick = match.group('nick') self.cursor.execute('''SELECT id FROM Nicks WHERE nick=?''', (nick, )) nickid = self.cursor.fetchone() if not nickid: bot.say('No other known aliases for user {}.'.format(nick)) else: nickid = int(nickid[0]) self.cursor.execute( '''SELECT n1.nick FROM Nicks n1, Aliases a WHERE a.nickid=? AND a.aliasid=n1.id''', (nickid, )) aliases = [i[0] for i in self.cursor.fetchall()] bot.say('User also seen as {}.'.format(', '.join(aliases)), message.channel) ircbot.register(Alias)
Usage: !throw <prob>""" prob = match.group('prob') if prob: self.throwprob = int(prob) bot.say('Changed the quote throw probability' ' to {}.'.format(self.throwprob), message.channel) else: bot.say('Current throw probability is {}.'.format(self.throwprob), message.channel) @action(name='gatherprobchange', rule=r'^\!gather(\ (?P<prob>\d+))?$') @admin_only def gatherprobchange(self, bot, message, match, *args, **kwargs): """Change the quote gather probability. Usage: !gather <prob>""" prob = match.group('prob') if prob: self.gatherprob = int(prob) bot.say('Changed the quote gather probability' ' to {}.'.format(self.gatherprob), message.channel) else: bot.say('Current gather probability is {}.' .format(self.gatherprob), message.channel) ircbot.register(RandQuote)