Browse Source

improved code quality in image cog.

tags/v2.0.0
Roxie Gibson 6 years ago
parent
commit
d32814e9d6
1 changed files with 28 additions and 112 deletions
  1. +28
    -112
      roxbot/cogs/image.py

+ 28
- 112
roxbot/cogs/image.py View File

file = discord.File(f) file = discord.File(f)
return file return file


async def image_logging(self, ctx, output):
"""Logging function for all image commands to avoid shit loads or repeating code.
Required because image has outputs that are user decided and therefore could need logging for."""
logging = roxbot.guild_settings.get(ctx.guild).logging
log_channel = self.bot.get_channel(logging["channel"])
await roxbot.log(
ctx.guild,
log_channel,
"image",
User=ctx.author,
User_ID=ctx.author.id,
Output_Message_ID=output.id,
Channel=ctx.channel,
Channel_Mention=ctx.channel.mention,
Time="{:%a %Y/%m/%d %H:%M:%S} UTC".format(ctx.message.created_at)
)

@commands.group(case_insensitive=True) @commands.group(case_insensitive=True)
async def pride(self, ctx): async def pride(self, ctx):
"""A collection of filters that show simple LGBT pride flags over the image provided. """A collection of filters that show simple LGBT pride flags over the image provided.
The filters work with either your pfp, someone elses', or an image provided either by attachment or URL.""" The filters work with either your pfp, someone elses', or an image provided either by attachment or URL."""
logging = roxbot.guild_settings.get(ctx.guild).logging
self.log_channel = self.bot.get_channel(logging["channel"])
pass


@pride.command() @pride.command()
async def lgbt(self, ctx, image: roxbot.converters.AvatarURL=None): async def lgbt(self, ctx, image: roxbot.converters.AvatarURL=None):
file = await self.flag_filter("lgbt", flag, image) file = await self.flag_filter("lgbt", flag, image)
output = await ctx.send(file=file) output = await ctx.send(file=file)
os.remove(file.filename) os.remove(file.filename)
await roxbot.log(
ctx.guild,
self.log_channel,
"pride",
User=ctx.author,
User_ID=ctx.author.id,
Output_Message_ID=output.id,
Channel=ctx.channel,
Channel_Mention=ctx.channel.mention,
Time="{:%a %Y/%m/%d %H:%M:%S} UTC".format(ctx.message.created_at)
)



@pride.command(aliases=["trans"]) @pride.command(aliases=["trans"])
async def transgender(self, ctx, image: roxbot.converters.AvatarURL=None): async def transgender(self, ctx, image: roxbot.converters.AvatarURL=None):
file = await self.flag_filter("trans", flag, image) file = await self.flag_filter("trans", flag, image)
output = await ctx.send(file=file) output = await ctx.send(file=file)
os.remove(file.filename) os.remove(file.filename)
await roxbot.log(
ctx.guild,
self.log_channel,
"pride",
User=ctx.author,
User_ID=ctx.author.id,
Output_Message_ID=output.id,
Channel=ctx.channel,
Channel_Mention=ctx.channel.mention,
Time="{:%a %Y/%m/%d %H:%M:%S} UTC".format(ctx.message.created_at)
)
await self.image_logging(ctx, output)


@pride.command(aliases=["nb", "enby"]) @pride.command(aliases=["nb", "enby"])
async def nonbinary(self, ctx, image: roxbot.converters.AvatarURL=None): async def nonbinary(self, ctx, image: roxbot.converters.AvatarURL=None):
file = await self.flag_filter("nb", flag, image) file = await self.flag_filter("nb", flag, image)
output = await ctx.send(file=file) output = await ctx.send(file=file)
os.remove(file.filename) os.remove(file.filename)
await roxbot.log(
ctx.guild,
self.log_channel,
"pride",
User=ctx.author,
User_ID=ctx.author.id,
Output_Message_ID=output.id,
Channel=ctx.channel,
Channel_Mention=ctx.channel.mention,
Time="{:%a %Y/%m/%d %H:%M:%S} UTC".format(ctx.message.created_at)
)
await self.image_logging(ctx, output)


@pride.command(aliases=["bi"]) @pride.command(aliases=["bi"])
async def bisexual(self, ctx, image: roxbot.converters.AvatarURL=None): async def bisexual(self, ctx, image: roxbot.converters.AvatarURL=None):
file = await self.flag_filter("bi", flag, image) file = await self.flag_filter("bi", flag, image)
output = await ctx.send(file=file) output = await ctx.send(file=file)
os.remove(file.filename) os.remove(file.filename)
await roxbot.log(
ctx.guild,
self.log_channel,
"pride",
User=ctx.author,
User_ID=ctx.author.id,
Output_Message_ID=output.id,
Channel=ctx.channel,
Channel_Mention=ctx.channel.mention,
Time="{:%a %Y/%m/%d %H:%M:%S} UTC".format(ctx.message.created_at)
)
await self.image_logging(ctx, output)


@pride.command(aliases=["gq"]) @pride.command(aliases=["gq"])
async def genderqueer(self, ctx, image: roxbot.converters.AvatarURL=None): async def genderqueer(self, ctx, image: roxbot.converters.AvatarURL=None):
file = await self.flag_filter("gq", flag, image) file = await self.flag_filter("gq", flag, image)
output = await ctx.send(file=file) output = await ctx.send(file=file)
os.remove(file.filename) os.remove(file.filename)
await roxbot.log(
ctx.guild,
self.log_channel,
"pride",
User=ctx.author,
User_ID=ctx.author.id,
Output_Message_ID=output.id,
Channel=ctx.channel,
Channel_Mention=ctx.channel.mention,
Time="{:%a %Y/%m/%d %H:%M:%S} UTC".format(ctx.message.created_at)
)
await self.image_logging(ctx, output)


@pride.command(aliases=["pan"]) @pride.command(aliases=["pan"])
async def pansexual(self, ctx, image: roxbot.converters.AvatarURL=None): async def pansexual(self, ctx, image: roxbot.converters.AvatarURL=None):
file = await self.flag_filter("pan", flag, image) file = await self.flag_filter("pan", flag, image)
output = await ctx.send(file=file) output = await ctx.send(file=file)
os.remove(file.filename) os.remove(file.filename)
await roxbot.log(
ctx.guild,
self.log_channel,
"pride",
User=ctx.author,
User_ID=ctx.author.id,
Output_Message_ID=output.id,
Channel=ctx.channel,
Channel_Mention=ctx.channel.mention,
Time="{:%a %Y/%m/%d %H:%M:%S} UTC".format(ctx.message.created_at)
)
await self.image_logging(ctx, output)


@pride.command(aliases=["ace"]) @pride.command(aliases=["ace"])
async def asexual(self, ctx, image: roxbot.converters.AvatarURL=None): async def asexual(self, ctx, image: roxbot.converters.AvatarURL=None):
file = await self.flag_filter("ace", flag, image) file = await self.flag_filter("ace", flag, image)
output = await ctx.send(file=file) output = await ctx.send(file=file)
os.remove(file.filename) os.remove(file.filename)
await roxbot.log(
ctx.guild,
self.log_channel,
"pride",
User=ctx.author,
User_ID=ctx.author.id,
Output_Message_ID=output.id,
Channel=ctx.channel,
Channel_Mention=ctx.channel.mention,
Time="{:%a %Y/%m/%d %H:%M:%S} UTC".format(ctx.message.created_at)
)
await self.image_logging(ctx, output)


@pride.command(aliases=["gf"]) @pride.command(aliases=["gf"])
async def genderfluid(self, ctx, image: roxbot.converters.AvatarURL = None): async def genderfluid(self, ctx, image: roxbot.converters.AvatarURL = None):
file = await self.flag_filter("pan", flag, image) file = await self.flag_filter("pan", flag, image)
output = await ctx.send(file=file) output = await ctx.send(file=file)
os.remove(file.filename) os.remove(file.filename)
await roxbot.log(
ctx.guild,
self.log_channel,
"pride",
User=ctx.author,
User_ID=ctx.author.id,
Output_Message_ID=output.id,
Channel=ctx.channel,
Channel_Mention=ctx.channel.mention,
Time="{:%a %Y/%m/%d %H:%M:%S} UTC".format(ctx.message.created_at)
)
await self.image_logging(ctx, output)


@pride.command() @pride.command()
async def agender(self, ctx, image: roxbot.converters.AvatarURL = None): async def agender(self, ctx, image: roxbot.converters.AvatarURL = None):
file = await self.flag_filter("gf", flag, image) file = await self.flag_filter("gf", flag, image)
output = await ctx.send(file=file) output = await ctx.send(file=file)
os.remove(file.filename) os.remove(file.filename)
await roxbot.log(
ctx.guild,
self.log_channel,
"pride",
User=ctx.author,
User_ID=ctx.author.id,
Output_Message_ID=output.id,
Channel=ctx.channel,
Channel_Mention=ctx.channel.mention,
Time="{:%a %Y/%m/%d %H:%M:%S} UTC".format(ctx.message.created_at)
)
await self.image_logging(ctx, output)


@commands.command(aliases=["df"]) @commands.command(aliases=["df"])
async def deepfry(self, ctx, image: roxbot.converters.AvatarURL=None): async def deepfry(self, ctx, image: roxbot.converters.AvatarURL=None):


output = await ctx.send(file=discord.File(jpg_name)) output = await ctx.send(file=discord.File(jpg_name))
os.remove(jpg_name) os.remove(jpg_name)
await roxbot.log(
ctx.guild,
log_channel,
"deepfry",
User=ctx.author,
User_ID=ctx.author.id,
Output_Message_ID=output.id,
Channel=ctx.channel,
Channel_Mention=ctx.channel.mention,
Time="{:%a %Y/%m/%d %H:%M:%S} UTC".format(ctx.message.created_at)
)
await self.image_logging(ctx, output)




def setup(bot_client): def setup(bot_client):

Loading…
Cancel
Save