class FunSlash(commands.Cog): """The description for FunSlash goes here.""" def __init__(self, bot): self.bot = bot @slash_command(name="who", description=_("cmds.who.desc"), options=[ Option("member", _("cmds.who.options.member"), OptionType.USER, required=True) ]) async def get_user_info(self, ctx, member=None): """ Get info about a user. """ member = member or ctx.author embed = discord.Embed(color=member.color, description=f"{member.mention}") embed.set_author(name=str(member), icon_url=member.avatar) embed.set_thumbnail(url=member.avatar) embed.add_field(name="Join date", value=f"{member.joined_at}"[0:10]) embed.add_field(name="Creation date", value=f"{member.created_at}"[0:10]) embed.add_field(name="Roles", value=", ".join([r.mention for r in member.roles[1:]]), inline=False) embed.set_footer(text="ID: " + str(member.id)) await ctx.send(embed=embed)
async def get_xkcd(self, ctx, *, comic: int = None): if comic: try: json = await default.fetch_xkcd_comic(comic=comic) except Exception: await ctx.reply(_("cmds.xkcd.could_not_find_comic")) return else: json = await default.fetch_xkcd_comic() embed = default.branded_embed( title=f"{json['safe_title']}", description=f"{json['alt']}", color=0x909090, title_url=f"https://xkcd.com/{json['num']}") embed.set_image(url=f"{json['img']}") embed.set_footer(text=_("cmds.xkcd.posted_on", m=json['month'], d=json['day'], y=json['year'])) if comic: embed.set_author(name=f"xkcd comic #{comic}", url=f"https://xkcd.com/{comic}") else: embed.set_author(name=f"The latest xkcd comic", url=f"https://xkcd.com") await ctx.reply(embed=embed, mention_author=False)
async def mass_delete(self, ctx, amount: int): try: await ctx.channel.purge(limit=amount + 1) except discord.HTTPException: sent = await ctx.reply(_("events.missing_permission")) return await sent.delete(delay=3) sent = await ctx.send( _("cmds.purge.res", ctx=ctx.author.mention, amount=amount)) await sent.delete(delay=3)
async def ip(self, inter, mention): embed = default.branded_embed(title=_("interactives.ip.desc"), description=_("interactives.ip.res")) if mention: await inter.respond(f"{mention.mention}", embed=embed, ephemeral=False) else: await inter.respond(embed=embed, ephemeral=True)
class Mod(commands.Cog): """Commands for moderators""" def __init__(self, bot): self.bot = bot @commands.command(name="kick", description=_("cmds.kick.desc")) @commands.has_guild_permissions(kick_members=True) @commands.guild_only() async def kick_user(self, ctx, member: discord.Member, *, reason=None) -> None: if await perms.check_priv(ctx, member=member): return try: await member.kick(reason=default.responsible(ctx.author, reason)) except discord.HTTPException: return await ctx.reply(_("events.missing_permission")) sent = await ctx.reply( _("cmds.kick.res_noreason", member=str(member)) if reason is None else _("cmds.kick.res_reason", member=str(member), reason=reason)) await sent.delete(delay=3) @commands.command(name="ban", description=_("cmds.ban.desc")) @commands.has_guild_permissions(ban_members=True) @commands.guild_only() async def ban_user(self, ctx, member: discord.Member, *, reason=None) -> None: if await perms.check_priv(ctx, member=member): return try: await member.ban(reason=default.responsible(ctx.author, reason)) except discord.errors.HTTPException: sent = await ctx.reply(_("events.missing_permission")) return await sent.delete(delay=3) sent = await ctx.reply( _("cmds.ban.res_noreason", member=str(member)) if reason is None else _("cmds.ban.res_reason", member=str(member), reason=reason)) await sent.delete(delay=3) @commands.command(name="purge", description=_("cmds.purge.desc")) @commands.has_guild_permissions(manage_messages=True) @commands.guild_only() async def mass_delete(self, ctx, amount: int): try: await ctx.channel.purge(limit=amount + 1) except discord.HTTPException: sent = await ctx.reply(_("events.missing_permission")) return await sent.delete(delay=3) sent = await ctx.send( _("cmds.purge.res", ctx=ctx.author.mention, amount=amount)) await sent.delete(delay=3)
async def kick_user(self, ctx, member: discord.Member, *, reason=None) -> None: if await perms.check_priv(ctx, member=member): return try: await member.kick(reason=default.responsible(ctx.author, reason)) except discord.HTTPException: return await ctx.reply(_("events.missing_permission")) sent = await ctx.reply( _("cmds.kick.res_noreason", member=str(member)) if reason is None else _("cmds.kick.res_reason", member=str(member), reason=reason)) await sent.delete(delay=3)
class Interactives(commands.Cog): """The description for Interactives goes here.""" def __init__(self, bot): self.bot = bot @slash_command(name="ip", description=_("interactives.ip.desc"), options=[ Option("mention", "Mention a user and make the message public", OptionType.USER) ]) @dislash.has_guild_permissions(manage_messages=True) async def ip(self, inter, mention): embed = default.branded_embed(title=_("interactives.ip.desc"), description=_("interactives.ip.res")) if mention: await inter.respond(f"{mention.mention}", embed=embed, ephemeral=False) else: await inter.respond(embed=embed, ephemeral=True) @ip.error async def on_slash_command_error(self, inter, error): if isinstance(error, discord.errors.NotFound): pass # Ignore exception. embed = default.branded_embed(title=_("interactives.ip.desc"), description=_("interactives.ip.res")) await inter.respond(embed=embed, ephemeral=True)
async def get_last_deleted_message(self, ctx): try: embed = default.branded_embed(description=str( events.Events.snipes["message"]), color="green", inline=True) embed.set_author(name=str(events.Events.snipes["author"]) + " said...", icon_url=events.Events.snipes["author_icon_url"]) embed.set_footer(text="Sent at " + str(events.Events.snipes["date"])) except Exception as e: return # This will be logged either way if events.Events.snipes["message"] is None: return await ctx.reply(_("cmds.snipe.failed"), mention_author=False) await ctx.reply(embed=embed, mention_author=False)
async def on_slash_command_error(self, inter, error): if isinstance(error, discord.errors.NotFound): pass # Ignore exception. embed = default.branded_embed(title=_("interactives.ip.desc"), description=_("interactives.ip.res")) await inter.respond(embed=embed, ephemeral=True)
class Fun(commands.Cog): """The description for Fun goes here.""" def __init__(self, bot): self.bot = bot @commands.command(name="who", description=_("cmds.who.desc")) async def get_user_info(self, ctx, member: discord.Member = None): member = member or ctx.author embed = discord.Embed(colour=member.color, description=f"{member.mention}") embed.set_author(name=str(member), icon_url=member.avatar) embed.set_thumbnail(url=member.avatar) embed.add_field(name="Join date", value=f"{member.joined_at}"[0:10]) embed.add_field(name="Creation date", value=f"{member.created_at}"[0:10]) embed.add_field(name="Roles", value=", ".join([r.mention for r in member.roles[1:]]), inline=False) embed.set_footer(text="ID: " + str(member.id)) await ctx.reply(embed=embed, mention_author=False) @commands.command(name="xkcd", description=_("cmds.xkcd.desc")) async def get_xkcd(self, ctx, *, comic: int = None): if comic: try: json = await default.fetch_xkcd_comic(comic=comic) except Exception: await ctx.reply(_("cmds.xkcd.could_not_find_comic")) return else: json = await default.fetch_xkcd_comic() embed = default.branded_embed( title=f"{json['safe_title']}", description=f"{json['alt']}", color=0x909090, title_url=f"https://xkcd.com/{json['num']}") embed.set_image(url=f"{json['img']}") embed.set_footer(text=_("cmds.xkcd.posted_on", m=json['month'], d=json['day'], y=json['year'])) if comic: embed.set_author(name=f"xkcd comic #{comic}", url=f"https://xkcd.com/{comic}") else: embed.set_author(name=f"The latest xkcd comic", url=f"https://xkcd.com") await ctx.reply(embed=embed, mention_author=False) @commands.command(name="8ball", description=_("cmds.8ball.desc")) async def random_response_generator(self, ctx): # i know, lame name pass @commands.command(name="avatar") async def get_user_avatar(self, ctx): try: await ctx.send(ctx.guild.icon.with_format("png").with_size(2048)) except Exception as e: await ctx.send(default.traceback_maker(err=e)) @commands.command(name="snipe") async def get_last_deleted_message(self, ctx): try: embed = default.branded_embed(description=str( events.Events.snipes["message"]), color="green", inline=True) embed.set_author(name=str(events.Events.snipes["author"]) + " said...", icon_url=events.Events.snipes["author_icon_url"]) embed.set_footer(text="Sent at " + str(events.Events.snipes["date"])) except Exception as e: return # This will be logged either way if events.Events.snipes["message"] is None: return await ctx.reply(_("cmds.snipe.failed"), mention_author=False) await ctx.reply(embed=embed, mention_author=False)