@commands.bot_has_permissions(manage_messages=True, read_message_history=True) | @commands.bot_has_permissions(manage_messages=True, read_message_history=True) | ||||
@commands.cooldown(1, 5) | @commands.cooldown(1, 5) | ||||
@commands.command() | @commands.command() | ||||
async def purge(self, ctx, limit=0, *, author: roxbot.converters.UserConverter=None): | |||||
async def purge(self, ctx, limit=0, *, author: roxbot.converters.User=None): | |||||
"""Purges messages from the text channel. | """Purges messages from the text channel. | ||||
Limit = Limit of messages to be deleted | Limit = Limit of messages to be deleted | ||||
Author (optional) = If given, roxbot will selectively only delete this user's messages.""" | Author (optional) = If given, roxbot will selectively only delete this user's messages.""" | ||||
return await ctx.send("Reported {}.".format(str(user))) | return await ctx.send("Reported {}.".format(str(user))) | ||||
@warn.command() | @warn.command() | ||||
async def list(self, ctx, *, user: roxbot.converters.UserConverter=None): | |||||
async def list(self, ctx, *, user: roxbot.converters.User=None): | |||||
"""Lists all or just the warnings for one user.""" | """Lists all or just the warnings for one user.""" | ||||
settings = gs.get(ctx.guild) | settings = gs.get(ctx.guild) | ||||
return await ctx.send(embed=em) | return await ctx.send(embed=em) | ||||
@warn.command() | @warn.command() | ||||
async def remove(self, ctx, user: roxbot.converters.UserConverter=None, index=None): | |||||
async def remove(self, ctx, user: roxbot.converters.User=None, index=None): | |||||
"""Removes one or all of the warnings for a user.""" | """Removes one or all of the warnings for a user.""" | ||||
user_id = str(user.id) | user_id = str(user.id) | ||||
settings = gs.get(ctx.guild) | settings = gs.get(ctx.guild) | ||||
@commands.has_permissions(ban_members=True) | @commands.has_permissions(ban_members=True) | ||||
@commands.bot_has_permissions(ban_members=True) | @commands.bot_has_permissions(ban_members=True) | ||||
@commands.command() | @commands.command() | ||||
async def unban(self, ctx, member: roxbot.converters.UserConverter, *, reason=""): | |||||
async def unban(self, ctx, member: roxbot.converters.User, *, reason=""): | |||||
"""Unbans user with given ID. Allows you to give a reason.""" | """Unbans user with given ID. Allows you to give a reason.""" | ||||
ban = await ctx.guild.get_ban(member) | ban = await ctx.guild.get_ban(member) | ||||
mem = ban.user | mem = ban.user |
return await ctx.send("File couldn't be uploaded.") | return await ctx.send("File couldn't be uploaded.") | ||||
@commands.command(aliases=["emoji"]) | @commands.command(aliases=["emoji"]) | ||||
async def emote(self, ctx, emote: roxbot.converters.EmojiConverter): | |||||
async def emote(self, ctx, emote: roxbot.converters.Emoji): | |||||
""" | """ | ||||
Uploads the emote given. Useful for downloading emotes. | Uploads the emote given. Useful for downloading emotes. | ||||
Usage: | Usage: | ||||
else: | else: | ||||
em = discord.Embed(title=emote.name, colour=roxbot.EmbedColours.blue) | em = discord.Embed(title=emote.name, colour=roxbot.EmbedColours.blue) | ||||
em.add_field(name="ID", value=str(emote.id), inline=False) | em.add_field(name="ID", value=str(emote.id), inline=False) | ||||
em.add_field(name="Guild", value=str(emote.guild), inline=False) | |||||
em.add_field(name="Created At", value="{:%a %Y/%m/%d %H:%M:%S} UTC".format(emote.created_at), inline=False) | |||||
if isinstance(emote, discord.Emoji): | |||||
em.add_field(name="Guild", value=str(emote.guild), inline=False) | |||||
em.add_field(name="Created At", value=roxbot.datetime_formatting.format(emote.created_at), inline=False) | |||||
em.set_image(url=emote.url) | em.set_image(url=emote.url) | ||||
return await ctx.send(embed=em) | return await ctx.send(embed=em) | ||||
except IndexError: | except IndexError: |
from discord.ext import commands | from discord.ext import commands | ||||
class UserConverter(commands.UserConverter): | |||||
class User(commands.UserConverter): | |||||
"""Overriding the discord version to add a slower global look up for when it is a requirement to return a user who has left the guild. | """Overriding the discord version to add a slower global look up for when it is a requirement to return a user who has left the guild. | ||||
Converts to a :class:`User`. | Converts to a :class:`User`. | ||||
return result | return result | ||||
class EmojiConverter(commands.EmojiConverter): | |||||
class Emoji(commands.EmojiConverter): | |||||
"""The Emoji conveter from discord.py but instead it returns the argument if an error is raised | """The Emoji conveter from discord.py but instead it returns the argument if an error is raised | ||||
It's messier than using the EmojiConverter proper but the issue is you can try converters.""" | It's messier than using the EmojiConverter proper but the issue is you can try converters.""" | ||||
async def convert(self, ctx, argument): | async def convert(self, ctx, argument): | ||||
try: | try: | ||||
return await super().convert(ctx, argument) | return await super().convert(ctx, argument) | ||||
except: # Same as above | |||||
return argument | |||||
except commands.errors.BadArgument: | |||||
return await commands.PartialEmojiConverter().convert(ctx, argument) | |||||
class AvatarURL(commands.UserConverter): | class AvatarURL(commands.UserConverter): |