async def roll_the_dice(self, ctx: commands.Context, start: int = 1, end: int = 6): if start > end: start, end = end, start if start < -128 or end > 127: return await ctx.send( embed=EmbedFactory.COMMAND_LOG_EMBED( title="주사위를 굴릴 수 없습니다!", description="숫자가 너무 큽니다! 범위는 -128 ~ 127 사이만 가능합니다.\n" "(과도하게 큰 수를 사용하는 몇몇 유저들을 위한 조치입니다.)", user=ctx.author ) ) import random result = random.randint(start, end) result_embed_factory = EmbedFactory( title="🎲 주사위를 던졌어요!", description=f"결과 : {result}", color=EmbedFactory.default_color, author={ "name": self.bot.user.display_name, "icon_url": self.bot.user.avatar_url }, footer={ "text": f"command executed by {EmbedFactory.get_user_info(user=ctx.author)}", "icon_url": ctx.author.avatar_url } ) await ctx.send(embed=await result_embed_factory.build())
async def ext_reload(self, ctx: commands.Context, *, params_raw: str): if params_raw.startswith("all"): self.bot.ext.reload_all(self.bot) return await ctx.send(embed=EmbedFactory.COMMAND_LOG_EMBED( title="[ Successfully Reloaded Extension ]", description=f"ext_args : {params_raw}", user=ctx.author)) params = await self.parse_params(params_raw) category: str = params.pop( "category") if "category" in params.keys() else '' name: str = params.pop("name") if "name" in params.keys() else '' dir: str = params.pop("dir") if "dir" in params.keys() else '' if (dir == '' and (category == '' or name == '')) or ((category == '' and name == '') and dir == ''): await ctx.send(embed=EmbedFactory.WARN_EMBED( title="Invalid usage!", description= "Module commands must be used with cli-style arguments to define module to load!\n" "usage: `ext reload -c (category) -n (name)` or `ext reload -d (dir)`" )) else: try: self.bot.ext.reload_ext(bot=self.bot, ext_category=category, ext_name=name, ext_dir=dir) except BadExtArguments as e: error_embed = EmbedFactory.ERROR_EMBED(e) await ctx.send(embed=error_embed) else: result_embed = EmbedFactory.COMMAND_LOG_EMBED( title="[ Successfully Reloaded Extension ]", description=f"ext_args : {params_raw}", user=ctx.author) await ctx.send(embed=result_embed) if category == "Utility" and name == "invites": # During reloading / loading module again, InvitesExt extension lose it`s trackin data. # So we need to call update() method and re-track invites data. # But, discord.Guild.invites() method is a coroutine, # it can`t be called in __init__ method while bot is running. # So, we need to call update() method manually right after reloading/loading extension again. await self.bot.get_cog(name).update()
async def restart(self, ctx: commands.Context): embed = EmbedFactory.COMMAND_LOG_EMBED(title="[ Command Result ]", description="봇을 재시작합니다!", user=ctx.author) await ctx.send(embed=embed) self.bot.get_logger().info( "[AdminExt] bot restart command detected. stopping bot...") self.bot.do_reboot = True await self.bot.close()
async def clearchat(self, ctx: commands.Context, amount: int = 5): if amount < 1: return await ctx.send(f"{amount} 는 너무 적습니다!") deleted: List[discord.Message] = await ctx.channel.purge( limit=amount + 1 ) # Add 1 to :param amout: to delete command message. return await ctx.send(embed=EmbedFactory.COMMAND_LOG_EMBED( title="메세지 청소 결과", description=f"{len(deleted)-1}개의 메세지를 청소했습니다!", user=ctx.author))
async def ext_unload(self, ctx: commands.Context, *, params_raw: str): if params_raw.startswith("all"): self.bot.ext.unload_all(self.bot) return await ctx.send(embed=EmbedFactory.COMMAND_LOG_EMBED( title="[ Successfully Unloaded Extension ]", description=f"ext_args : {params_raw}", user=ctx.author)) params = await self.parse_params(params_raw) category: str = params.pop( "category") if "category" in params.keys() else '' name: str = params.pop("name") if "name" in params.keys() else '' dir: str = params.pop("dir") if "dir" in params.keys() else '' if (dir == '' and (category == '' or name == '')) or ((category == '' and name == '') and dir == ''): await ctx.send(embed=EmbedFactory.WARN_EMBED( title="Invalid usage!", description= "Module commands must be used with cli-style arguments to define module to load!\n" "usage: `ext unload -c (category) -n (name)` or `ext unload -d (dir)`" )) else: try: self.bot.ext.unload_ext(bot=self.bot, ext_category=category, ext_name=name, ext_dir=dir) except BadExtArguments as e: error_embed = EmbedFactory.ERROR_EMBED(e) await ctx.send(embed=error_embed) else: result_embed = EmbedFactory.COMMAND_LOG_EMBED( title="[ Successfully Unloaded Extension ]", description=f"ext_args : {params_raw}", user=ctx.author) await ctx.send(embed=result_embed)
async def evaluate_code(self, ctx: commands.Context, *, code_raw: str): # Assume that code starts with ```py and endes with ``` (code block) if not code_raw.startswith("```py") or not code_raw.endswith("```"): raise ValueError( "Code to evaluate must starts with ```py and endswith ```") code_content: str = code_raw.replace("```", '')[2:] try: result = eval(code_content) except Exception as e: result = e await ctx.send(embed=EmbedFactory.COMMAND_LOG_EMBED( title="[ ADMIN COMMAND : EVAL ] 실행 결과", description=str(result), user=ctx.author))