async def restrictuser(context, *args, **kwargs): # need exactly one mentioned user (the order in the mentioned list is unreliable) if len(context["message"].mentions) != 1: return await koduck.sendmessage( context["message"], sendcontent=settings.message_nomentioneduser) userid = context["message"].mentions[0].id userlevel = koduck.getuserlevel(userid) # already restricted if userlevel == 0: return await koduck.sendmessage( context["message"], sendcontent=settings.message_restrict_failed) # don't restrict high level users elif userlevel >= 2: return await koduck.sendmessage( context["message"], sendcontent=settings.message_restrict_failed2.format( settings.botname)) else: koduck.updateuserlevel(userid, 0) return await koduck.sendmessage( context["message"], sendcontent=settings.message_restrict_success.format( userid, settings.botname))
async def commands(context, *args, **kwargs): #filter out the commands that the user doesn't have permission to run currentlevel = koduck.getuserlevel(context["message"].author.id) availablecommands = [] for commandname in koduck.commands.keys(): command = koduck.commands[commandname] if command[2] <= currentlevel and command[1] == "prefix": availablecommands.append(commandname) return await koduck.sendmessage(context["message"], sendcontent=", ".join(availablecommands))
async def removesetting(context, *args, **kwargs): if len(args) < 1: return await koduck.sendmessage( context["message"], sendcontent=settings.message_removesetting_noparam) result = koduck.removesetting( args[0], koduck.getuserlevel(context["message"].author.id)) if result is not None: return await koduck.sendmessage( context["message"], sendcontent=settings.message_removesetting_success) else: return await koduck.sendmessage( context["message"], sendcontent=settings.message_removesetting_failed)
async def addsetting(context, *args, **kwargs): if len(args) < 2: return await koduck.sendmessage( context["message"], sendcontent=settings.message_updatesetting_noparam) variable = args[0] value = context["paramline"][context["paramline"].index(settings.paramdelim ) + 1:].strip() result = koduck.addsetting( variable, value, koduck.getuserlevel(context["message"].author.id)) if result is not None: return await koduck.sendmessage( context["message"], sendcontent=settings.message_addsetting_success) else: return await koduck.sendmessage( context["message"], sendcontent=settings.message_addsetting_failed)
async def unrestrictuser(context, *args, **kwargs): # need exactly one mentioned user (the order in the mentioned list is unreliable) if len(context["message"].mentions) != 1: return await koduck.sendmessage( context["message"], sendcontent=settings.message_nomentioneduser) userid = context["message"].mentions[0].id userlevel = koduck.getuserlevel(userid) if userlevel != 0: return await koduck.sendmessage( context["message"], sendcontent=settings.message_unrestrict_failed) else: koduck.updateuserlevel(userid, 1) return await koduck.sendmessage( context["message"], sendcontent=settings.message_unrestrict_success.format( userid, settings.botname))
async def commands(context, *args, **kwargs): # filter out the commands that the user doesn't have permission to run currentlevel = koduck.getuserlevel(context["message"].author.id) availablecommands = commands_df[ commands_df["Permission"] <= currentlevel].sort_values( ["Function", "Command", "Permission"]) if context["message"].channel.type is discord.ChannelType.private: pass elif (context["message"].author.id == context["message"].guild.owner_id): availablecommands = availablecommands.append( commands_df[commands_df["Permission"] == 4]) availablecommands = availablecommands[~availablecommands["Hidden"]] cmd_groups = availablecommands.groupby(["Category"]) return_msgs = [ "**%s**\n*%s*" % (name, ", ".join(help_group["Command"].values)) for name, help_group in cmd_groups if name ] return await koduck.sendmessage(context["message"], sendcontent="\n\n".join(return_msgs))
async def admin(context, *args, **kwargs): # need exactly one mentioned user (the order in the mentioned list is unreliable) if len(context["message"].mentions) != 1: return await koduck.sendmessage( context["message"], sendcontent=settings.message_nomentioneduser) userid = context["message"].mentions[0].id userlevel = koduck.getuserlevel(userid) # already an admin if userlevel == 2: return await koduck.sendmessage( context["message"], sendcontent=settings.message_addadmin_failed.format( settings.botname)) else: koduck.updateuserlevel(userid, 2) return await koduck.sendmessage( context["message"], sendcontent=settings.message_addadmin_success.format( userid, settings.botname))