def stats(self, command, args, msg): """ Get command usage statistics.""" try: args = parse_args(args, (('cmd', ''), )) except ArgError as error: return error.msg if args.cmd: result = self.cmd_store.get(args.cmd) if result: return "%s: %s" % (args, result) else: return "No stats for command %s." % args results = self.cmd_store.get_all() cmd_stats = {} if not results is None: for stat in results: if cmd_stats.has_key(stat.cmd): cmd_stats[stat.cmd] += 1 else: cmd_stats[stat.cmd] = 1 cmd_list = [] for (key, val) in cmd_stats.iteritems(): cmd_list.append({'cmd': key, 'count': val}) cmd_stats = sorted(cmd_list, key=itemgetter('count'), reverse=True) response = "Command usage:\n" for stat in cmd_stats: response += "%s: %s\n" % (stat['count'], stat['cmd']) return response
def slap(self, command, args, msg): """Smack people with enormous iron bars and scary cellos.""" try: args = parse_args(args, (('nickname', str), )) except ArgError as error: return error.msg room = msg['mucroom'] roster = self.bot.plugin['xep_0045'].getRoster(room) for roster_nick in roster: if args.lower() == roster_nick.lower(): nick_real_jid = self.bot.mucnick_to_jid(room, roster_nick) if nick_real_jid != None: if nick_real_jid.bare in self.bot.acl.owners: return "I don't slap my owner!" # Do not slap the bot he will slap back if roster_nick == self.bot.plugin['xep_0045'].ourNicks[room]: roster_nick = msg['mucnick'] return "/me %(verb)s %(nick)s with %(size)s %(tool)s." % { 'verb': random.choice(self.slap_verbs), 'nick': roster_nick, 'size': random.choice(self.slap_size), 'tool': random.choice(self.slap_tools) } return "Unknown nickname %s." % args
def slap(self, command, args, msg): """Smack people with enormous iron bars and scary cellos.""" try: args = parse_args(args, (('nickname', str), )) except ArgError as error: return error.msg room = msg['mucroom'] roster = self.bot.plugin['xep_0045'].getRoster(room) for roster_nick in roster: if args.lower() == roster_nick.lower(): nick_real_jid = self.bot.mucnick_to_jid(room, roster_nick) if nick_real_jid != None: if nick_real_jid.bare in self.bot.acl.owners: return "I don't slap my owner!" # Do not slap the bot he will slap back if roster_nick == self.bot.plugin['xep_0045'].ourNicks[room]: roster_nick = msg['mucnick'] return "/me %(verb)s %(nick)s with %(size)s %(tool)s." % { 'verb': random.choice(self.slap_verbs), 'nick': roster_nick, 'size': random.choice(self.slap_size), 'tool': random.choice(self.slap_tools)} return "Unknown nickname %s." % args
def acl(self, command, args, msg): """ Access control list management """ try: args = parse_args(args, (('action', ('add', 'del', 'see', 'test')), ('jid', str), ('role', 'user'))) except ArgError as ex: return ex.msg return getattr(self, 'acl_' + args.action,)(command, args, msg)
def acl(self, command, args, msg): """ Administración de ACLs """ try: args = parse_args(args, (('action', ('add', 'del', 'see', 'test')), ('jid', str), ('role', 'user'))) except ArgError as ex: return ex.msg return getattr(self, 'acl_' + args.action,)(command, args, msg)
def alias(self, command, args, msg): """ Replace long commands (incl. options) with short words. """ try: args = parse_args(args, (('action', (str, 'add', 'del', 'list')), )) except ArgError as error: return error.msg args.parsed_ = False return getattr(self, 'alias_' + args.action,)(command, args, msg)
def alias(self, command, args, msg): """ Reemplaza comandos largos (incluyendo opciones) con palabras cortas. """ try: args = parse_args(args, (('action', (str, 'add', 'del', 'list')), )) except ArgError as error: return error.msg args.parsed_ = False return getattr(self, 'alias_' + args.action,)(command, args, msg)
def acl(self, command, args, msg): """ Access control list management """ try: args = parse_args(args, (('action', ('add', 'del', 'see', 'test')), ('jid', str), ('role', 'user'))) except ArgError as ex: return ex.msg return getattr( self, 'acl_' + args.action, )(command, args, msg)
def acl_del(self, command, args, msg): """Deletes a jid """ try: args = parse_args(args, (('jid', str), )) except ArgError as ex: return ex.msg present = args.jid in self.bot.acl if present: del self.bot.acl[args.jid] return '%s eliminado' % args.jid else: return '%s no se ha encontrado en la acl' % args.jid
def acl_del(self, command, args, msg): """Deletes a jid """ try: args = parse_args(args, (('jid', str), )) except ArgError as ex: return ex.msg present = args.jid in self.bot.acl if present: del self.bot.acl[args.jid] return '%s deleted' % args.jid else: return '%s was not found in acl' % args.jid
def alias(self, command, args, msg): """ Replace long commands (incl. options) with short words. """ try: args = parse_args(args, (('action', (str, 'add', 'del', 'list')), )) except ArgError as error: return error.msg args.parsed_ = False return getattr( self, 'alias_' + args.action, )(command, args, msg)
def alias_del(self, command, args, msg): """ Delete an alias. """ try: args = parse_args(args, (('action', (str, 'del')), ('alias', str))) except ArgError as error: return error.msg aliascmd = self.alias_store.get(AliasCmd(self.bot.get_real_jid(msg), args.alias)) if not aliascmd is None: self.alias_store.delete(AliasCmd(self.bot.get_real_jid(msg), args.alias)) return "Done." if args.alias in self.global_aliases: return "You can not delete a global alias." return "Unkown alias."
def random(self, command, args, msg): """Returns a random integer in range A - B or 1 - B.""" try: args = parse_args(args, (('first', int), ('second', 1))) except ArgError as error: return error.msg if args.first > args.second: args.first, args.second = args.second, args.first ran = random.randint(args.first, args.second) if msg['type'] == 'groupchat': return "%s rolls %d (%s - %s)" % \ (msg['mucnick'], ran, args.first, args.second) else: return "%d (%s - %s)" % (ran, args.first, args.second)
def alias_del(self, command, args, msg): """ Delete an alias. """ try: args = parse_args(args, (('action', (str, 'del')), ('alias', str))) except ArgError as error: return error.msg aliascmd = self.alias_store.get( AliasCmd(self.bot.get_real_jid(msg), args.alias)) if not aliascmd is None: self.alias_store.delete( AliasCmd(self.bot.get_real_jid(msg), args.alias)) return "Done." if args.alias in self.global_aliases: return "You can not delete a global alias." return "Unkown alias."
def alias_del(self, command, args, msg): """ Elimina un alias. """ try: args = parse_args(args, (('action', (str, 'del')), ('alias', str))) except ArgError as error: return error.msg aliascmd = self.alias_store.get(AliasCmd(self.bot.get_real_jid(msg), args.alias)) if not aliascmd is None: self.alias_store.delete(AliasCmd(self.bot.get_real_jid(msg), args.alias)) return "Alias eliminado." if args.alias in self.global_aliases: return "No se puede borrar un alias global." return "Alias desconocido."
def acl_see(self, command, args, msg): """See the role a jid """ try: args = parse_args(args, (('jid', str), )) except ArgError as ex: return ex.msg part = self.bot.acl.find_part(args.jid) if part: if part == args.jid: return '%s es %s' % \ (args.jid, self.bot.acl.ROLE[self.bot.acl[args.jid]]) else: return '%s a traves de %s es %s' % \ (args.jid, part, self.bot.acl.ROLE[self.bot.acl[part]]) else: return '%s no se ha encontrado en la acl' % args.jid
def acl_see(self, command, args, msg): """See the role a jid """ try: args = parse_args(args, (('jid', str), )) except ArgError as ex: return ex.msg part = self.bot.acl.find_part(args.jid) if part: if part == args.jid: return '%s is %s' % \ (args.jid, self.bot.acl.ROLE[self.bot.acl[args.jid]]) else: return '%s through %s is %s' % \ (args.jid, part, self.bot.acl.ROLE[self.bot.acl[part]]) else: return '%s was not found in acl' % args.jid
def acl_add(self, command, args, msg): """Add a jid with a given role If the user exists, modify the role. """ try: args = parse_args(args, (('jid', str), ('role', 'user'))) except ArgError as ex: return ex.msg try: rolen = getattr(self.bot.acl.ROLE, args.role) except AttributeError as ex: return '%s is not a valid role' % args.role present = args.jid in self.bot.acl self.bot.acl[args.jid] = rolen if present: return '%s updated as %s' % (args.jid, args.role) else: return '%s added as %s' % (args.jid, args.role)
def acl_test(self, command, args, msg): """Test if jid belongs to role """ try: args = parse_args(args, (('jid', str), ('role', 'user'))) except ArgError as ex: return ex.msg try: rolen = getattr(self.bot.acl.ROLE, args.role) except: return '%s no es un rol válido' % args.role present = args.jid in self.bot.acl if present: if self.bot.acl.check(args.jid, rolen): return '%s es %s' % (args.jid, args.role) else: return '%s no es %s' % (args.jid, args.role) else: return '%s no se ha encontrado en la acl' % args.jid
def acl_test(self, command, args, msg): """Test if jid belongs to role """ try: args = parse_args(args, (('jid', str), ('role', 'user'))) except ArgError as ex: return ex.msg try: rolen = getattr(self.bot.acl.ROLE, args.role) except: return '%s is not a valid role' % args.role present = args.jid in self.bot.acl if present: if self.bot.acl.check(args.jid, rolen): return '%s is %s' % (args.jid, args.role) else: return '%s is not %s' % (args.jid, args.role) else: return '%s was not found in acl' % args.jid
def handle_xep(self, command, args, msg): """Returns details of the specified XEP.""" self._ensure_cache_is_recent() try: args = parse_args(args, (('xep', int), )) except ArgError as ex: return ex.msg xepnumber = '%04i' % int(args.xep) if self._xeps == None: return self.RESPONSE_ERROR response = '' num_responses = 0 for xep in self._xeps.findall('xep'): if xep.find('number').text == xepnumber or \ xep.find('name').text.lower().find(args.lower()) >= 0: num_responses = num_responses + 1 if num_responses > 6: continue if response != '': response = response + "\n\n" response = response + self.RESPONSE_INFO texts = {} for prop in ('type', 'number', 'name', 'status', 'updated'): texts[prop] = xep.find(prop).text response = response % texts if num_responses > 6: response = response + self.RESPONSE_TOOMANY num_response_key = {} num_response_key['number'] = num_responses - 6 response = response % num_response_key if response == '': response = self.RESPONSE_NOTFOUND % args return response
def alias_add(self, command, args, msg): """ Añade un alias con el comando y opciones especificados. """ try: args = parse_args(args, (('action', (str, 'add')), ('alias', str), ('command', str))) except ArgError as error: return error.msg bot_commands = dict(self.bot.chat_commands.items() + self.bot.muc_commands.items()) if not args.alias in bot_commands: if not args.tail_ is None: command = args.command + ' ' + args.tail_ else: command = args.command self.alias_store.update(AliasCmd(self.bot.get_real_jid(msg), args.alias, command)) return "Alias guardado." else: return "%s es un comando del bot." % args.alias
def alias_add(self, command, args, msg): """ Add an alias with the given command and options. """ try: args = parse_args(args, (('action', (str, 'add')), ('alias', str), ('command', str))) except ArgError as error: return error.msg bot_commands = dict(self.bot.chat_commands.items() + self.bot.muc_commands.items()) if not args.alias in bot_commands: if not args.tail_ is None: command = args.command + ' ' + args.tail_ else: command = args.command self.alias_store.update( AliasCmd(self.bot.get_real_jid(msg), args.alias, command)) return "Done." else: return "%s is a bot command." % args.alias
def alias_add(self, command, args, msg): """ Add an alias with the given command and options. """ try: args = parse_args(args, (('action', (str, 'add')), ('alias', str), ('command', str))) except ArgError as error: return error.msg bot_commands = dict(self.bot.chat_commands.items() + self.bot.muc_commands.items()) if not args.alias in bot_commands: if not args.tail_ is None: command = args.command + ' ' + args.tail_ else: command = args.command self.alias_store.update(AliasCmd(self.bot.get_real_jid(msg), args.alias, command)) return "Done." else: return "%s is a bot command." % args.alias