async def demote(self, args, pmsg): reason = "" lock = False if args[1].lower() == "lock": lock = True reason = common.strip_mentions(" ".join(args[2:])) else: reason = common.strip_mentions(" ".join(args[1:])) text = "Are you sure you want to demote " first = True for m in pmsg.mentions: if first: first = False text = "{}{}".format(text, m.mention) else: text = "{}, {}".format(text, m.mention) text = "{}?".format(text) await self.send(pmsg.channel, text) reply = (await self.getreply(60, pmsg.author, pmsg.channel)).content if reply.lower() == "y" or reply.lower() == "yes": msg = await self.send(pmsg.channel, "Plugging potato into battery terminals...") for m in pmsg.mentions: p = common.User.from_discord_id(self.client, self.db, m.id) await self.edit(msg, "Demoting {}".format(m.mention)) await p.setrank(p.previous_rank(), reason, lock) await self.edit(msg, "Demotion complete.")
async def title(self, args, message): title = common.strip_mentions(" ".join(args[1:])) self.db.run( "UPDATE `accounts` SET `title`=%s WHERE `did`={}".format( message.mentions[0].id), [title]) await self.send( message.channel, "{}'s new title is: {}".format(message.mentions[0].mention, title))
async def clear(self, args, pmsg): nargs = common.strip_mentions(" ".join(args[1:])).split(" ") if len(nargs) == 0 or nargs[0] == "": await self.logiter(pmsg.channel, mentions=pmsg.mentions) elif len(nargs) == 1: await self.logiter(pmsg.channel, limit=nargs[0], mentions=pmsg.mentions) else: await self.send(pmsg.channel, "Too many arguments")
async def on_message(message): args = message.content.split(" ") cmd = args[0].lower() handled = False for n in modules: module = modules[n] if not module.has_command(cmd): continue if module.permissible(cmd, common.getrank(db, message.author.id), message.channel.is_private): t = int(time.time()) handled = module.receive(cmd, args, message) break else: s = "{} attempted to use a command in ".format(message.author.id) if message.channel.is_private: s = "{}a chat by the name of ".format(s) else: s = "{}#".format(s) logger.warn( "{}{}, but did not have the rank or permissions to do so.". format(s, message.channel.name)) if hasattr(module, 'on_message') and callable( getattr(module, 'on_message')): await module.on_message(message) if not handled: t = int(time.time()) show_help = False show_modhelp = None args = common.strip_mentions(message.content.lower()).split(" ") if message.channel.is_private: if args[0] == "help": show_help = True if len(args) > 1: show_modhelp = args[1:] elif client.user in message.mentions: if args[0] == "help": show_help = True if len(args) > 1: show_modhelp = args[1:] logger.debug("Selected modules: {}".format(", ".join( args[1:]))) handled = show_help s = "Displayed help for {} module{} (" if handled and show_modhelp == None: s = s.format("all", "s") await help.show(message.channel) elif handled: s.format("selected", " or modules") await help.show_modules(message.channel, show_modhelp) diff = int(time.time()) - t if handled: logger.info("{}{}s)".format(s, diff))
async def flink(self, args, message): if not len(message.mentions) == 1: await self.send( message.channel, "Please mention some poor f**k to link to this Steam ID.") return nargs = common.strip_mentions(" ".join(args[1:])).split(" ") self.logger.debug(" ".join(nargs)) if not len(nargs) == 1: await self.send(message.channel, "Learn to use the damn commands.") return try: sid = int(nargs[0]) except ValueError: await self.send(message.channel, "Are you a moron? Steam IDs are integers...") return except: await self.send( message.channel, "I think I'm stupid or broken. I don't know which. Either way I was unable to convert the arg you provided to an integer." ) return query = self.db.query( "SELECT * FROM `accounts` WHERE `sid`={} OR `did`={}".format( sid, message.mentions[0].id)) if len(query) > 0: await self.send(message.channel, "This account is already linked ijiot") return self.db.run("DELETE FROM `link` WHERE `id`={}".format( message.mentions[0].id)) self.db.run( "INSERT INTO `accounts` (`sid`,`did`) VALUES ({},{})".format( sid, message.mentions[0].id)) await self.send( message.channel, "{} you have been forcefully linked to the Steam profile with url https://steamcommunity.com/profiles/{}" .format(message.mentions[0].mention, sid))
async def ignore(self, args, pmsg): nargs = common.strip_mentions(" ".join(args[1:])).split(" ") if len(nargs) > 1: await self.send(pmsg.channel, "Uh... that's a few too many arguments mate.") return if nargs[0] == "" or nargs[0] == "on": val = "TRUE" ret = True elif nargs[0] == "off": val = "FALSE" ret = False else: await self.send(pmsg.channel, "Uh... I only support on or off.") return for person in pmsg.mentions: sql = "INSERT INTO `antispam` (`id`,`ignore`) VALUES ({0},{1}) ON DUPLICATE KEY UPDATE `ignore`={1}".format( person.id, val) self.db.run(sql) await self.send( pmsg.channel, "Anti-Spam scanning is now set to **{}** messages from the mentioned people." .format("IGNORE" if ret else "SCAN"))