This repository has been archived by the owner on Oct 16, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathticket_log.py
44 lines (38 loc) · 1.84 KB
/
ticket_log.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import discord
import os
from discord.ext import commands
from config import *
import asyncio
async def ticketlog(channel,user,bot):
#Channel must be a discord.TextChannel
#User must be a discord.User of the theead
"""Create the logs"""
LOGS = []
async for message in channel.history(limit=10000000):
if message.author == bot.user:
time = f"{message.created_at.year}-{message.created_at.month}-{message.created_at.day} {message.created_at.hour}:{message.created_at.minute}:{message.created_at.second} UTC"
### Have to do time to get message time
LOGS.append(f"\n[{time}] {message.content}")
else:
### Have to do the get message time
time = f"{message.created_at.year}-{message.created_at.month}-{message.created_at.day} {message.created_at.hour}:{message.created_at.minute}:{message.created_at.second} UTC"
LOGS.append(f"\n[{time}] {message.author.name}#{message.author.discriminator} : {message.content}")
### Add topic of thread
###SAME HAVE TO DO TIME time is channel creation date
LOGS.append(f"THREADS FOR {user.name}#{user.discriminator} ({str(user.id)}) on {channel.created_at} UTC")
LOGS = LOGS[::-1]
#Determine the filename to save logs as
log_no = 1
for file in os.listdir("tickets"):
if file.startswith(f"{str(user.id)}"):
log_no = log_no+1
file = open(f"tickets/{str(user.id)}-{str(log_no)}.txt","w")
for item in LOGS:
try:
file.write(item)
except:
pass
file.close()
channel = bot.get_channel(DiscordModmailLogChannel)
file = open(f"tickets/{str(user.id)}-{str(log_no)}.txt","rb")
await channel.send(content=f"New Thread with {user.name}#{user.discriminator} closed.",file=discord.File(fp=file))