async def parse_token(self, ctx, token): token_part = token.split(".") if len(token_part) != 3: return await ctx.maybe_reply("Invalid token") def decode_user(user): user_bytes = user.encode() user_id_decoded = base64.b64decode(user_bytes) return user_id_decoded.decode("ascii") str_id = call(decode_user, token_part[0]) if not str_id or not str_id.isdigit(): return await ctx.maybe_reply("Invalid user") user_id = int(str_id) coro_user = functools.partial(try_call, self.bot.fetch_user, user_id, exception=discord.NotFound) member = ctx.guild.get_member(user_id) or self.bot.get_user( user_id) or await coro_user() if not member: return await ctx.maybe_reply("Invalid user") timestamp = call(self.parse_date, token_part[1]) or "Invalid date" embed = discord.Embed(title=f"{member.display_name}'s token", description=f"**User:** `{member}`\n" f"**ID:** `{member.id}`\n" f"**Bot:** `{member.bot}`\n" f"**Created:** `{member.created_at}`\n" f"**Token Created:** `{timestamp}`") embed.set_thumbnail(url=member.avatar.url) await ctx.embed(embed=embed)
def loading_cog(self): """Loads the cog""" cogs = ("error_handler", "find_bot", "useful", "helpful", "myself", "eros", "jishaku") for cog in cogs: ext = "cogs." if cog != "jishaku" else "" if error := call(self.load_extension, f"{ext}{cog}", ret=True): print_exception( 'Ignoring exception while loading up {}:'.format(cog), error) else: print(f"cog {cog} is loaded")
def loading_cog(self): """Loads the cog""" cogs = () for file in os.listdir("cogs"): if file.endswith(".py"): cogs += (file[:-3],) cogs += ("jishaku",) for cog in cogs: ext = "cogs." if cog != "jishaku" else "" if error := call(self.load_extension, f"{ext}{cog}", ret=True): print_exception('Ignoring exception while loading up {}:'.format(cog), error) else: print(f"cog {cog} is loaded")
async def generate_signature_error(self, ctx, error): command = ctx.command argument = "" found = False def check_converter(_error): if isinstance(_error, commands.BadArgument): frames = [*traceback.walk_tb(_error.__traceback__)] last_trace = frames[-1] frame = last_trace[0] converter = frame.f_locals.get("self") if converter is not None: return getattr( discord, converter.__class__.__name__.replace("Converter", ""), None) if _class := getattr(error, "converter", call(check_converter, error)): signature = inspect.signature(command.callback).parameters for typing in signature.values(): if typing_inspect.is_union_type(typing): checking = typing.annotation.__args__ else: checking = (typing.annotation, ) for convert in checking: if convert is _class: found = True argument = typing.name break
async def cogs_handler(self, ctx, method, extensions): def do_cog(exts): func = getattr(self.bot, f"{method}_extension") return func(f"cogs.{exts}") outputs = [ call(do_cog, ext, ret=True) or f"cogs.{ext} is {method}ed" for ext in extensions ] await ctx.maybe_reply(embed=BaseEmbed.default( ctx, description="\n".join(str(x) for x in outputs)))
async def cogs_handler(self, ctx, extensions): method = ctx.command.name def do_cog(exts): func = getattr(self.bot, f"{method}_extension") return func(f"cogs.{exts}") outputs = [ call(do_cog, ext, ret=True) or f"cogs.{ext} is {method}ed" for ext in extensions ] await ctx.embed(description="\n".join(str(x) for x in outputs))