Reformatted modmail embed

Uploading file like bytes object instead of saving to the directory
pull/8/head
sgoudham 4 years ago
parent 7c282cb6ea
commit 7750c5092e

@ -1,6 +1,6 @@
import asyncio import asyncio
import datetime import datetime
import os import io
import random import random
import aiomysql import aiomysql
@ -154,6 +154,12 @@ class Guild(Cog):
"""Printing out that Cog is ready on startup""" """Printing out that Cog is ready on startup"""
print(f"{self.__class__.__name__} Cog has been loaded\n-----") print(f"{self.__class__.__name__} Cog has been loaded\n-----")
@group(invoke_without_command=True, usage="`[argument...]`")
@has_permissions(manage_guild=True)
@bot_has_permissions(administrator=True)
async def roles_persist(self, ctx):
pass
@group(invoke_without_command=True, usage="`[argument...]`") @group(invoke_without_command=True, usage="`[argument...]`")
@has_permissions(manage_guild=True) @has_permissions(manage_guild=True)
@bot_has_permissions(administrator=True) @bot_has_permissions(administrator=True)
@ -366,8 +372,8 @@ class Guild(Cog):
desc = "React to this message if you want to send a message to the Staff Team!" \ desc = "React to this message if you want to send a message to the Staff Team!" \
"\n\n**React with ✅**" \ "\n\n**React with ✅**" \
"\n\nWe encourage all suggestions/thoughts and opinions on the server!" \ "\n\nWe encourage all suggestions/thoughts and opinions on the server!" \
"\nAs long as it is **valid** criticism" \ "\nAs long as it is **valid** criticism." \
"\n\n**Purely negative feedback will not be considered**" "\n\n\n**Purely negative feedback will not be considered.**"
# Set up embed to let the user how to start sending modmail # Set up embed to let the user how to start sending modmail
ModMail = Embed(title="**Welcome to Modmail!**", ModMail = Embed(title="**Welcome to Modmail!**",
@ -479,7 +485,6 @@ class Guild(Cog):
# Send error message if the channel ID is not recognised # Send error message if the channel ID is not recognised
text = "**Invalid ChannelID Detected... Aborting Process**" text = "**Invalid ChannelID Detected... Aborting Process**"
await generate_embed(ctx, text) await generate_embed(ctx, text)
return
@modmail.command(name="delete") @modmail.command(name="delete")
@has_permissions(manage_guild=True) @has_permissions(manage_guild=True)
@ -587,10 +592,10 @@ class Guild(Cog):
} }
# Saving this for later within when discord.py 1.4 comes out # Saving this for later within when discord.py 1.4 comes out
# cat = await guild.create_category_channel(member.name, overwrites=overwrites, position=0) # user_channel = await guild.create_category_channel("Member", overwrites=overwrites, position=7)
# Create the text channel # Create the text channel
user_channel = await guild.create_text_channel(member.name, overwrites=overwrites, user_channel = await guild.create_text_channel("Member", overwrites=overwrites,
position=0) position=0)
# Mention the user to make sure that they get pinged # Mention the user to make sure that they get pinged
@ -617,6 +622,11 @@ class Guild(Cog):
print(ex) print(ex)
return return
else: else:
# Making sure that the reply is from the author
def check(m):
return m.author == payload.member and user_channel.id == instructions.channel.id
if str(reaction.emoji) == "": if str(reaction.emoji) == "":
self.anon = True self.anon = True
@ -626,10 +636,6 @@ class Guild(Cog):
# Tell the user to type their mail into the chat # Tell the user to type their mail into the chat
instructions = await user_channel.send(embed=send_instructions(member)) instructions = await user_channel.send(embed=send_instructions(member))
# Making sure that the reply is from the author
def check(m):
return m.author == payload.member and user_channel.id == instructions.channel.id
# Wait for the message from the author # Wait for the message from the author
msg = await self.bot.wait_for('message', check=check) msg = await self.bot.wait_for('message', check=check)
@ -645,22 +651,17 @@ class Guild(Cog):
# Delete the previous embed # Delete the previous embed
await instructions.delete() await instructions.delete()
# Determine a path for the message logs to be stored # Store all text in the channel in a bytesio object
path = "cogs/Anon.txt" text = ""
with open(path, 'a+') as f:
# Store the date and content of every message in the text file
async for message in user_channel.history(limit=300): async for message in user_channel.history(limit=300):
print(f"{message.created_at} : {message.content}", file=f) text = "".join(f"{message.created_at} : {message.content}\n")
text_bytes = str.encode(text)
file = io.BytesIO(text_bytes)
# Send the message to the modmail channel # Send the message to the modmail channel
await modmail_channel.send(embed=send_modmail(self, msg, member), await modmail_channel.send(embed=send_modmail(self, msg, member),
file=File(fp=path)) file=File(file, 'Anon.txt'))
# Removing file from the directory after it has been sent
if os.path.exists(path):
os.remove(path)
else:
print("The file does not exist")
# Make sure the user knows that their message has been sent # Make sure the user knows that their message has been sent
await user_channel.send(embed=message_sent_confirmation(member)) await user_channel.send(embed=message_sent_confirmation(member))
@ -670,7 +671,6 @@ class Guild(Cog):
# Delete the channel and then stop the function # Delete the channel and then stop the function
await user_channel.delete() await user_channel.delete()
return
# If the user types anywhere else, delete the channel # If the user types anywhere else, delete the channel
else: else:
@ -686,10 +686,6 @@ class Guild(Cog):
# Tell the user to type their mail into the chat # Tell the user to type their mail into the chat
instructions = await user_channel.send(embed=send_instructions(member)) instructions = await user_channel.send(embed=send_instructions(member))
# Making sure that the reply is from the author
def check(m):
return m.author == payload.member and user_channel.id == instructions.channel.id
# Wait for the message from the author # Wait for the message from the author
msg = await self.bot.wait_for('message', check=check, timeout=300) msg = await self.bot.wait_for('message', check=check, timeout=300)
@ -704,22 +700,17 @@ class Guild(Cog):
# Delete the previous embed # Delete the previous embed
await instructions.delete() await instructions.delete()
# Determine a path for the message logs to be stored # Store all text in the channel in a bytesio object
path = "cogs/{}.txt".format(payload.member.name) text = ""
with open(path, 'a+') as f:
# Store the date and content of every message in the text file
async for message in user_channel.history(limit=300): async for message in user_channel.history(limit=300):
print(f"{message.created_at} : {message.content}", file=f) text = "".join(f"{message.created_at} : {message.content}\n")
text_bytes = str.encode(text)
file = io.BytesIO(text_bytes)
# Send the message to the modmail channel # Send the message to the modmail channel
await modmail_channel.send(embed=send_modmail(self, msg, member), await modmail_channel.send(embed=send_modmail(self, msg, member),
file=File(fp=path)) file=File(file, f'{member.name}.txt'))
# Removing file from the directory after it has been sent
if os.path.exists(path):
os.remove(path)
else:
print("The file does not exist")
# Make sure the user knows that their message has been sent # Make sure the user knows that their message has been sent
await user_channel.send(embed=message_sent_confirmation(member)) await user_channel.send(embed=message_sent_confirmation(member))
@ -727,24 +718,16 @@ class Guild(Cog):
# Let the user read the message for 5 seconds # Let the user read the message for 5 seconds
await asyncio.sleep(5) await asyncio.sleep(5)
# Delete the channel and then stop the function # Delete the channel
await user_channel.delete() await user_channel.delete()
return
# If the user types anywhere else, delete the channel # If the user types anywhere else, delete the channel
else: else:
await user_channel.delete() await user_channel.delete()
return
except Exception as ex: except Exception as ex:
print(ex) print(ex)
# Removing file from the directory after it has been sent
if os.path.exists(path):
os.remove(path)
else:
print("The file does not exist")
# Send out an error message if the user waited too long # Send out an error message if the user waited too long
await user_channel.send( await user_channel.send(
"Sorry! Something seems to have gone wrong and the modmail will be aborting." "Sorry! Something seems to have gone wrong and the modmail will be aborting."

Loading…
Cancel
Save