-
Notifications
You must be signed in to change notification settings - Fork 0
/
module_confessions.py
91 lines (67 loc) · 3.2 KB
/
module_confessions.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import json
import time
from datetime import datetime
from pathlib import Path
import nextcord
from nextcord.ext import commands
class ListenerConfession(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.latest_sender = None
@commands.Cog.listener()
async def on_message(self, message):
if int(message.channel.id) == int(788839489216315433):
confessions_file = Path("confessions.txt")
if not confessions_file.exists():
confessions_file.touch()
now_timestamp = time.time()
offset = datetime.fromtimestamp(now_timestamp) - datetime.utcfromtimestamp(now_timestamp)
message_time = message.created_at
message_time = message_time + offset
jump_url = message.id
time_string = "[" + message_time.strftime("%b %d, %Y %H:%M:%S.%f") + "]"
author_string = message.author.name
prefix = f"{time_string} {author_string}: "
empty_prefix = " " * len(prefix)
attachment_list = message.attachments
if len(attachment_list) > 0:
attachment_url_list = []
for attachment in attachment_list:
attachment_url = attachment.url
attachment_url_list.append(attachment_url)
serialized_attachments = json.dumps(attachment_url_list)
empty_prefix = " " * len(prefix)
with confessions_file.open("a") as f:
f.write(f"{prefix}{message.content}\n")
# if len(embed_list) > 0:
# f.write(f"{empty_prefix}{serialized_embeds}\n")
if len(attachment_list) > 0:
f.write(f"{empty_prefix}{serialized_attachments}\n")
private_confessions_channel = self.bot.get_channel(819972744221163603)
if len(message.content) > 0:
content_to_send = "> " + message.content
else:
content_to_send = ""
if len(attachment_list) > 0:
if len(message.content) > 0:
content_to_send = content_to_send + "\n" + serialized_attachments
else:
content_to_send = serialized_attachments
new_author = False
if self.latest_sender is None or self.latest_sender != message.author:
author_string = f"**{author_string}:** `{jump_url}`\n"
new_author = True
else:
author_string = f"`{jump_url}`\n"
if len(message.content) > 0 and new_author:
content_to_send = f"{author_string}" + content_to_send
elif len(message.content) > 0 and not new_author:
content_to_send = author_string + content_to_send
else:
content_to_send = author_string + content_to_send
self.latest_sender = message.author
if len(message.embeds) > 0:
embed_to_send = message.embeds[0]
await private_confessions_channel.send(content = content_to_send, embed = embed_to_send)
else:
await private_confessions_channel.send(content = content_to_send)