From f5368ce7d7ade57a96eef5ceabc07ae816f0826a Mon Sep 17 00:00:00 2001 From: sgoudham Date: Thu, 16 Jul 2020 20:45:45 +0100 Subject: [PATCH] Creating txt log file for the modmail Sending it to the modmail channel Removing it from the directory --- cogs/modmail/modmail.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/cogs/modmail/modmail.py b/cogs/modmail/modmail.py index 202e0a32..2ab17170 100644 --- a/cogs/modmail/modmail.py +++ b/cogs/modmail/modmail.py @@ -1,16 +1,18 @@ -# Method to ask the user if they want to be anonymous or not import asyncio import datetime +import os import random import discord from discord import Embed +from discord import File from discord.ext import commands import db from settings import enso_embedmod_colours, blank_space, hammyMention +# Method to ask the user if they want to be anonymous or not def AnonOrNot(author): # Set up embed to let the user how to start sending modmail AnonModMailEmbed = Embed(title="**Want to send it Anonymously?**", @@ -256,8 +258,23 @@ class Modmail(commands.Cog): if len(msg.content) > 50 and msg.channel == user_channel: # Delete the previous embed await instructions.delete() + + # Determine a path for the message logs to be stored + path = "cogs/modmail/{}.txt".format(payload.member.name) + 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): + print(f"{message.created_at} : {message.content}", file=f) + # Send the message to the modmail channel - await modmail_channel.send(embed=SendMsgToModMail(self, msg, member)) + await modmail_channel.send(embed=SendMsgToModMail(self, msg, member), + file=File(fp=path)) + + # 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 await user_channel.send(embed=MessageSentConfirmation(member)) @@ -266,8 +283,7 @@ class Modmail(commands.Cog): await asyncio.sleep(5) await user_channel.delete() - # Log the message within the database - # logModMail(ctx, self.anon, msg) + else: await user_channel.delete()