async def disable(self, ctx, command, *args): user = ctx.author date_args_start_index = 0 if len(args) > 0: try: user = await commands.MemberConverter().convert(ctx, args[0]) date_args_start_index = 1 except (commands.CommandError, IndexError): date_args_start_index = 0 if user != ctx.author and not permChecks.check_full_access(ctx.author): raise commands.MissingAnyRole(Config().FULL_ACCESS_ROLES) until = utils.analyze_time_input(*args[date_args_start_index:]) result = self.bot.ignoring.add_user_command(user, command, until) if result == IgnoreEditResult.Success: await ctx.message.add_reaction(Lang.CMDSUCCESS) elif result == IgnoreEditResult.Already_in_list: await ctx.message.add_reaction(Lang.CMDERROR) await ctx.send(Lang.lang(self, 'user_cmd_already_blocked', command, utils.get_best_username(user))) elif result == IgnoreEditResult.Until_in_past: await ctx.message.add_reaction(Lang.CMDERROR) await ctx.send(Lang.lang(self, 'no_time_machine')) await utils.log_to_admin_channel(ctx)
async def update(self, ctx, check=None): # Argument parsing if not permChecks.check_full_access(ctx.author) or check == "check": release = self.check_release() await ctx.message.add_reaction(Lang.CMDSUCCESS) if release is None: await ctx.message.channel.send(lang["no_new_version"]) else: await ctx.message.channel.send( lang["new_version"].format(release)) return # Check state and send error messages if necessary if self.state == State.CHECKING or self.state == State.CONFIRMED or self.state == State.UPDATING: await ctx.message.channel.send(lang["err_already_updating"]) return if self.state == State.WAITINGFORCONFIRM: if not self.waiting_for_confirm.channel == ctx.message.channel: await ctx.message.channel.send(lang["err_different_channel"]) elif not self.waiting_for_confirm.author == ctx.message.author: await ctx.message.channel.send(lang["err_different_user"]) return assert self.state == State.IDLE # Check for new version self.state = State.CHECKING release = self.check_release() if release is None: await ctx.message.channel.send(lang["wont_update"]) self.state = State.IDLE return await ctx.message.add_reaction(Lang.CMDSUCCESS) await ctx.message.channel.send( lang["new_version_update"].format(release)) # Ask for confirmation self.state = State.WAITINGFORCONFIRM self.waiting_for_confirm = ctx.message self.to_log = ctx await asyncio.sleep( CONFIRMTIMEOUT ) # This means that the bot doesn't react immediately on confirmation # No confirmation, cancel if self.state == State.WAITINGFORCONFIRM: self.state = State.IDLE await ctx.message.channel.send(lang["update_timeout"]) return # Confirmation came in elif self.state == State.CONFIRMED: await self.do_update(ctx.message.channel, release) return else: logging.getLogger(__name__).error( "{}: PANIC! I am on {}, this should not happen!".format( self.get_name(), self.state)) self.state = State.IDLE self.waiting_for_confirm = None
async def dsc_set(self, ctx): if (not permChecks.check_full_access(ctx.author) and Config.get(self)['songmaster_role_id'] != 0 and Config.get(self)['songmaster_role_id'] not in [role.id for role in ctx.author.roles]): raise commands.BotMissingAnyRole([*Config().FULL_ACCESS_ROLES, Config.get(self)['songmaster_role_id']]) if Config.get(self)['channel_id'] != 0 and Config.get(self)['channel_id'] != ctx.channel.id: raise commands.CheckFailure() if ctx.invoked_subcommand is None: await ctx.send_help(self.dsc_set)
async def enable(self, ctx, command, user: discord.Member = None): if user is None: user = ctx.author if user != ctx.author and not permChecks.check_full_access(ctx.author): raise commands.MissingAnyRole(*Config().FULL_ACCESS_ROLES) result = self.bot.ignoring.remove_user_command(user, command) if result == IgnoreEditResult.Success: await ctx.message.add_reaction(Lang.CMDSUCCESS) elif result == IgnoreEditResult.Not_in_list: await ctx.message.add_reaction(Lang.CMDERROR) await ctx.send(Lang.lang(self, 'user_cmd_not_blocked', command, utils.get_best_username(user))) await utils.log_to_admin_channel(ctx)
async def cmd_del(self, ctx, cmd_name, text_id: int = None): cmd_name = cmd_name.lower() if cmd_name not in self.commands: await ctx.message.add_reaction(Lang.CMDERROR) await ctx.send(Lang.lang(self, "del_doesnt_exists", cmd_name)) return cmd = self.commands[cmd_name] if not permChecks.check_full_access( ctx.author) and ctx.author.id != cmd.creator_id: await ctx.send(Lang.lang(self, 'del_perm_missing')) return if text_id is not None and text_id < 0: await ctx.message.add_reaction(Lang.CMDERROR) await ctx.send(Lang.lang(self, 'text_id_not_positive')) return if text_id is not None and text_id >= len(cmd.texts): await ctx.message.add_reaction(Lang.CMDERROR) await ctx.send(Lang.lang(self, 'text_id_not_exists')) if text_id == 0 and len(cmd.texts) == 1: text_id = None if text_id is None: # Remove command cmd_raw = cmd.get_raw_texts() del (self.commands[cmd_name]) await utils.write_debug_channel( self.bot, Lang.lang(self, 'cmd_removed', cmd_raw)) else: # remove text cmd_raw = cmd.get_raw_text(text_id) del (cmd.texts[text_id]) await utils.write_debug_channel( self.bot, Lang.lang(self, 'cmd_text_removed', cmd_name, cmd_raw)) self.save() # await utils.log_to_admin_channel(ctx) await ctx.message.add_reaction(Lang.CMDSUCCESS)
async def cmd_prefix(self, ctx, new_prefix=None): # get current prefix if new_prefix is None: example = random.choice(list(self.commands.keys())) await ctx.send( Lang.lang(self, 'current_prefix', Config.get(self)['prefix'], example)) return # set new prefix if not permChecks.check_full_access(ctx.author): await ctx.message.add_reaction(Lang.CMDERROR) raise commands.BotMissingAnyRole(Config().FULL_ACCESS_ROLES) if new_prefix == ctx.prefix: await ctx.message.add_reaction(Lang.CMDERROR) await ctx.send(Lang.lang(self, 'invalid_prefix')) else: Config.get(self)['prefix'] = new_prefix self.save() await ctx.message.add_reaction(Lang.CMDSUCCESS)
async def cmd_del(self, ctx, *args): if len(args) != 2: await ctx.message.add_reaction(Lang.CMDERROR) return if not permChecks.check_full_access(ctx.message.author): await ctx.message.add_reaction(Lang.CMDERROR) return try: user = await commands.MemberConverter().convert(ctx, args[1]) except (commands.CommandError, IndexError): await ctx.message.add_reaction(Lang.CMDERROR) return ladder = Storage().get(self)["ladder"] if user.id in ladder: del ladder[user.id] Storage().save(self) await ctx.message.add_reaction(Lang.CMDSUCCESS) else: await ctx.message.add_reaction(Lang.CMDNOCHANGE)
async def role(self, ctx, user: discord.Member, action, role: discord.Role): if not permChecks.check_full_access(ctx.author): if role.id not in self.rc(): raise commands.CheckFailure( message=Lang.lang(self, 'role_user_not_configured')) need_mod_role_id = self.rc()[role.id]['modrole'] if need_mod_role_id is None or need_mod_role_id == 0: raise commands.CheckFailure( message=Lang.lang(self, 'role_user_no_modrole', role.name)) if need_mod_role_id not in [r.id for r in ctx.author.roles]: raise commands.MissingRole(need_mod_role_id) if action.lower() == "add": if role in user.roles: await ctx.send( Lang.lang(self, 'role_user_already', utils.get_best_username(user), role)) return await add_user_role(user, role) await ctx.send( Lang.lang(self, 'role_user_added', role, utils.get_best_username(user))) elif action.lower() == "del": if role not in user.roles: await ctx.send( Lang.lang(self, 'role_user_doesnt_have', utils.get_best_username(user), role)) return await remove_user_role(user, role) await ctx.send( Lang.lang(self, 'role_user_removed', role, utils.get_best_username(user))) else: raise commands.BadArgument(Lang.lang(self, 'role_user_bad_arg')) await utils.log_to_admin_channel(ctx)
async def kwiss(self, ctx, *args): """ !kwiss command """ self.logger.debug("Caught kwiss cmd") channel = ctx.channel try: controller_class, args = self.parse_args(channel, args) except QuizInitError as e: # Parse Error await ctx.send(str(e)) return # Subcommand except SubCommandEncountered as subcmd: self.logger.debug("Calling subcommand: {}, {}".format( subcmd.callback, subcmd.args)) await subcmd.callback(ctx, *subcmd.args) return err = self.args_combination_check(controller_class, args) if err is not None: args = [] if err == "ranked_playercount": args = (self.config["ranked_min_participants"], ) if err == "ranked_questioncount": args = (self.config["ranked_min_questions"], ) await ctx.message.add_reaction(Lang.CMDERROR) await ctx.send(Lang.lang(self, err, *args)) return # Look for existing quiz method = args["method"] modifying = method == Methods.STOP \ or method == Methods.PAUSE \ or method == Methods.RESUME \ or method == Methods.SCORE \ or method == Methods.STATUS if method == Methods.START and self.get_controller(channel): await ctx.message.add_reaction(Lang.CMDERROR) raise QuizInitError(self, "existing_quiz") if modifying and self.get_controller(channel) is None: if method == Methods.STATUS: await ctx.send(Lang.lang(self, "status_no_quiz")) return # Not starting a new quiz if modifying: quiz_controller = self.get_controller(channel) if method == Methods.PAUSE: await quiz_controller.pause(ctx.message) elif method == Methods.RESUME: await quiz_controller.resume(ctx.message) elif method == Methods.SCORE: await ctx.send(embed=quiz_controller.score.embed()) elif method == Methods.STOP: if permChecks.check_full_access( ctx.message.author ) or quiz_controller.requester == ctx.message.author: await self.abort_quiz(channel, ctx.message) elif method == Methods.STATUS: await quiz_controller.status(ctx.message) else: assert False return # Starting a new quiz assert method == Methods.START await ctx.message.add_reaction(Lang.EMOJI["success"]) quiz_controller = controller_class(self, self.config, args["quizapi"], ctx.channel, ctx.message.author, category=args["category"], question_count=args["questions"], difficulty=args["difficulty"], debug=args["debug"], ranked=args["ranked"], gecki=args["gecki"]) self.controllers[channel] = quiz_controller self.logger.debug("Registered quiz controller {} in channel {}".format( quiz_controller, ctx.channel)) await ctx.send( Lang.lang(self, "quiz_start", args["questions"], quiz_controller.quizapi.category_name(args["category"]), Difficulty.human_readable(quiz_controller.difficulty), self.controller_mapping[controller_class][0])) await quiz_controller.start(ctx.message)