Creating txt log file for the modmail

Sending it to the modmail channel
Removing it from the directory
pull/8/head
sgoudham 5 years ago
parent f08a8a53cb
commit f5368ce7d7

@ -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()

Loading…
Cancel
Save