def command(cls, irc_c, msg, cmd): cmd.expandargs(["add a", "remove r", "list l"]) if len(cmd.args['root']) > 0: nick = cmd.args['root'][0] else: nick = msg.sender # 1. Check if this is the right nick # get the user ID user_id = DB.get_user_id(nick) if user_id is None: msg.reply("I don't know anyone called '{}'.".format(nick)) return # 2. Add new aliases if 'add' in cmd: if nick.lower() != msg.sender.lower() and not defer.controller(cmd): raise CommandError("You can't add an alias for someone else.") aliases = cmd['add'] # db has add_alias, but that needs user ID for alias in aliases: if alias.lower() == msg.sender.lower(): continue if DB.add_alias(user_id, alias, 1): msg.reply("{} already has the alias {}!".format(nick,alias)) msg.reply("Added aliases to {}: {}".format(nick, ", ".join(aliases))) irc_c.PRIVMSG(CONFIG.home, "{} added alias {}".format(nick,alias)) if 'remove' in cmd: if nick.lower() != msg.sender.lower() and not defer.controller(cmd): raise CommandError("You can't remove an alias from someone else.") aliases = cmd['remove'] # db has add_alias, but that needs user ID for alias in aliases: if not DB.remove_alias(user_id, alias, 1): msg.reply("{} didn't have the alias {}!".format(nick,alias)) msg.reply("Removed aliases from {}: {}".format(nick, ", ".join(aliases))) if 'list' in cmd: # get all aliases associated with the user aliases = DB.get_aliases(user_id) msg.reply("I've seen {} go by the names: {}" .format(nick if nick != msg.sender else "you", ", ".join(aliases))) if not any(['add' in cmd,'remove' in cmd,'list' in cmd]): raise CommandError("Add or remove aliases to a nick with --add " "and --remove. See all nicks with --list")
def command(cls, irc_c, msg, cmd): cmd.expandargs(["obfuscate o", "colour color c"]) if not defer.controller(cmd): raise CommandError("I'm afriad I can't let you do that.") return if len(cmd.args['root']) == 0: raise CommandError("Must specify a recipient and message") if len(cmd.args['root']) == 1: raise CommandError("Must specify a message") if cmd.args['root'][0][0] == '/' or cmd.args['root'][1][0] == '/': # This is an IRC command say.issue_raw(irc_c, msg, cmd) else: message = " ".join(cmd.args['root'][1:]) if 'obfuscate' in cmd and msg.raw_channel is not None: message = gib.obfuscate(message, DB.get_aliases(None) + ["ops"]) if 'colour' in cmd: print(nickColor(message)) msg.reply("Printed that to console") irc_c.PRIVMSG(cmd.args['root'][0], message) if not cmd.args['root'][0] == msg.raw_channel: msg.reply("Saying that to {}".format(cmd.args['root'][0]))
def command(cls, irc_c, msg, cmd): cmd.expandargs(["table tables t", "user users u"]) # No argument given - show the db structure if len(cmd.args) == 1: msg.reply("https://raw.githubusercontent.com/" "rossjrw/tars/master/database.png") return # Table - print a list of tables, or a given table if 'table' in cmd: if len(cmd['table']) > 0: # print a specific table msg.reply("Printing contents of table {} to console." .format(cmd['table'][0])) DB.print_one_table(cmd['table'][0]) else: # print a list of all tables tables = DB.get_all_tables() msg.reply("Printed a list of tables to console. {} total." .format(len(tables))) print(" ".join(tables)) # Users - print a list of users, or from a given channel if 'user' in cmd: users = DB.get_all_users() if len(users) == 0: msg.reply("There are no users.") else: msg.reply("Printed a list of users to console. {} total." .format(len(users))) print(" ".join([nickColor(u) for u in users])) if 'id' in cmd: # we want to find the id of something if len(cmd.args['root']) != 2: search = msg.sender else: search = cmd.args['root'][1] id, type = DB.get_generic_id(search) if id: if type == 'user' and search == msg.sender: msg.reply("{}, your ID is {}.".format(msg.sender, id)) elif search == "TARS": msg.reply("My ID is {}.".format(id)) else: msg.reply("{}'s ID is {}.".format(search, id)) else: if type == 'channel': msg.reply("I don't know the channel '{}'." .format(search)) else: msg.reply("I don't know anything called '{}'." .format(search)) if 'alias' in cmd: search = cmd.args['root'][1] if len(cmd.args['root']) > 1 \ else msg.sender aliases = DB.get_aliases(search) # should be None or a list of lists if aliases is None: msg.reply("I don't know anyone with the alias '{}'." .format(search)) else: msg.reply("I know {} users with the alias '{}'." .format(len(aliases), search)) for i,group in enumerate(aliases): msg.reply("\x02{}.\x0F {}" .format(i+1, ", ".join(group))) if 'occ' in cmd: if len(cmd.args['root']) < 2: raise CommandError("Specify a channel to get the occupants of") msg.reply("Printing occupants of {} to console" .format(cmd.args['root'][1])) users = DB.get_occupants(cmd.args['root'][1], True) if isinstance(users[0], int): pprint(users) else: pprint([nickColor(user) for user in users]) if 'sql' in cmd: if not defer.controller(cmd): raise CommandError("I'm afriad I can't let you do that.") try: DB.print_selection(" ".join(cmd['sql']), 'str' in cmd) msg.reply("Printing that selection to console") except: msg.reply("There was a problem with the selection") raise