-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
223 lines (205 loc) · 7.23 KB
/
main.py
File metadata and controls
223 lines (205 loc) · 7.23 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import io
import discord
from discord.ext import commands
intents = discord.Intents.all()
client = commands.Bot(command_prefix='/', help_command=None, intents=intents)
TOKEN = ''
@client.event
async def on_ready():
print('Bot Is Ready')
@client.command()
async def transcript(ctx: discord.ext.commands.Context):
css = '''
body {
background-color: #36393e;
color: #dcddde;
}
a {
color: #0096cf;
}
.info {
display: flex;
max-width: 100%;
margin: 0 5px 10px;
}
.guild-icon-container {
flex: 0;
}
.guild-icon {
max-width: 88px;
max-height: 88px;
}
.metadata {
flex: 1;
margin-left: 10px;
}
.guild-name {
font-size: 1.4em;
}
.channel-name {
font-size: 1.2em;
}
.channel-topic {
margin-top: 2px;
}
.channel-message-count {
margin-top: 2px;
}
.chatlog {
max-width: 100%;
margin-bottom: 24px;
}
.message-group {
display: flex;
margin: 0 10px;
padding: 15px 0;
border-top: 1px solid;
}
.author-avatar-container {
flex: 0;
width: 40px;
height: 40px;
}
.author-avatar {
border-radius: 50%;
height: 40px;
width: 40px;
}
.messages {
flex: 1;
min-width: 50%;
margin-left: 20px;
}
.author-name {
font-size: 1em;
font-weight: 500;
}
.timestamp {
margin-left: 5px;
font-size: 0.75em;
}
.message {
padding: 2px 5px;
margin-right: -5px;
margin-left: -5px;
background-color: transparent;
transition: background-color 1s ease;
}
.content {
font-size: 0.9375em;
word-wrap: break-word;
}
.mention {
color: #7289da;
}
'''
def check_message_mention(msgs: discord.Message):
user_mentions: list = msgs.mentions
role_mentions: list = msgs.role_mentions
channel_mentions: list = msgs.channel_mentions
total_mentions: list = user_mentions + role_mentions + channel_mentions
m: str = msgs.content
for mentions in total_mentions:
if mentions in user_mentions:
for mention in user_mentions:
m = m.replace(str(f"<@{mention.id}>"),
f"<span class=\"mention\">@{mention.name}</span>")
m = m.replace(str(f"<@!{mention.id}>"),
f"<span class=\"mention\">@{mention.name}</span>")
elif mentions in role_mentions:
for mention in role_mentions:
m = m.replace(str(f"<@&{mention.id}>"),
f"<span class=\"mention\">@{mention.name}</span>")
elif mentions in channel_mentions:
for mention in channel_mentions:
m = m.replace(str(f"<#{mention.id}>"),
f"<span class=\"mention\">#{mention.name}</span>")
else:
pass
return m
messages: discord.TextChannel.history = await ctx.channel.history(limit=None, oldest_first=True).flatten()
f = f'''
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<meta name=viewport content="width=device-width">
<style>
{css}
</style>
</head>
<body>
<div class=info>
<div class=guild-icon-container><img class=guild-icon src={ctx.guild.icon_url}></div>
<div class=metadata>
<div class=guild-name>{ctx.guild.name}</div>
<div class=channel-name>{ctx.channel.name}</div>
<div class=channel-message-count>{len(messages)} messages</div>
</div>
</div>
'''
for message in messages:
if message.embeds:
content = 'Embed'
elif message.attachments:
# IS AN IMAGE:
if message.attachments[0].url.endswith(('jpg', 'png', 'gif', 'bmp')):
if message.content:
content = check_message_mention(message) + '<br>' + f"<img src=\"{message.attachments[0].url}\" width=\"200\" alt=\"Attachment\" \\>"
else:
content = f"<img src=\"{message.attachments[0].url}\" width=\"200\" alt=\"Attachment\" \\>"
# IS A VIDEO
elif message.attachments[0].url.endswith(('mp4', 'ogg', 'flv', 'mov', 'avi')):
if message.content:
content = check_message_mention(message) + '<br>' + f'''
<video width="320" height="240" controls>
<source src="{message.attachments[0].url}" type="video/{message.attachments[0].url[-3:]}">
Your browser does not support the video.
</video>
'''
else:
content = f'''
<video width="320" height="240" controls>
<source src="{message.attachments[0].url}" type="video/{message.attachments[0].url[-3:]}">
Your browser does not support the video.
</video>
'''
elif message.attachments[0].url.endswith(('mp3', 'boh')):
if message.content:
content = check_message_mention(message) + '<br>' + f'''
<audio controls>
<source src="{message.attachments[0].url}" type="audio/{message.attachments[0].url[-3:]}">
Your browser does not support the audio element.
</audio>
'''
else:
content = f'''
<audio controls>
<source src="{message.attachments[0].url}" type="audio/{message.attachments[0].url[-3:]}">
Your browser does not support the audio element.
</audio>
'''
# OTHER TYPE OF FILES
else:
# add things
pass
else:
content = check_message_mention(message)
f += f'''
<div class="message-group">
<div class="author-avatar-container"><img class=author-avatar src={message.author.avatar_url}></div>
<div class="messages">
<span class="author-name" >{message.author.name}</span><span class="timestamp">{message.created_at.strftime("%b %d, %Y %H:%M")}</span>
<div class="message">
<div class="content"><span class="markdown">{content}</span></div>
</div>
</div>
</div>
'''
f += '''
</div>
</body>
</html>
'''
await ctx.channel.send(file=discord.File(fp=io.StringIO(f), filename='file.html'))
client.run(TOKEN)