-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
message.py
53 lines (51 loc) · 2.11 KB
/
message.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
from discord import Message
import re
from emoji.core import demojize
import requests
from objection_engine.beans.comment import Comment
class Message:
def __init__(self, update: Message):
try:
self.user = User(update.guild.get_member(update.author.id))
except Exception as e:
self.user = User(update.author)
print(e)
self.evidence = None
tmp = update.clean_content
tmp = re.sub(r'(https?)\S*', '(link)', tmp) # links
tmp = demojize(tmp)
tmp = re.sub(r'<[a]?:\w{2,32}:\d{18}>', '', tmp) # custom static and animated emojis
tmp = re.sub(r':\w{2,32}:', '', tmp) # stock emojis
tmp = re.sub(r'', '', tmp) # @everyone, @here
for file in update.attachments: # attachments
if file.filename.split('.')[-1] in {'jpg', 'jpeg', 'JPG', 'JPEG', 'png', 'PNG'}:
tmp += ' (image)'
name = str(file.id) + '.png'
response = requests.get(file.url)
with open(name, 'wb') as file:
file.write(response.content)
self.evidence = name
elif file.filename.split('.')[-1] in {'gif', 'gifv'}:
tmp += ' (gif)'
elif file.filename.split('.')[-1] in {'mp4', 'webm'}:
tmp += ' (video)'
elif file.filename.split('.')[-1] in {'mp3', 'wav', 'ogg'}:
tmp += ' (audio)'
else:
tmp += ' (file)'
for embed in update.embeds:
if embed.type == 'image':
tmp += ' (image)'
url = embed.thumbnail.proxy_url
name = url.split('/')[-1]
response = requests.get(url)
with open(name, 'wb') as file:
file.write(response.content)
self.evidence = name
self.text = tmp
def to_Comment(self):
return Comment(user_id=self.user.id, user_name=self.user.name, text_content=self.text, evidence_path=self.evidence)
class User:
def __init__(self, user):
self.name = user.display_name
self.id = user.id