Skip to content

Commit b986395

Browse files
committed
Only permacache attachments from mods
1 parent df92f9f commit b986395

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

core/models.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def type(self):
149149

150150

151151
class Attachment:
152-
def __init__(self, data):
152+
def __init__(self, data, author):
153153
if isinstance(data, str): # Backwards compatibility
154154
self.id = 0
155155
self.filename = "attachment"
@@ -159,7 +159,9 @@ def __init__(self, data):
159159
else:
160160
self.id = int(data["id"])
161161
self.filename = data["filename"]
162-
self.url = data["url"].replace('cdn.discordapp.com/', os.environ['PERMACACHE_LOCATION'])
162+
self.url = data["url"]
163+
if author.mod:
164+
self.url = self.url.replace('cdn.discordapp.com/', os.environ['PERMACACHE_LOCATION'])
163165
self.is_image = data["is_image"]
164166
self.size = data["size"]
165167

@@ -172,17 +174,17 @@ def __init__(self, data):
172174
class Message:
173175
def __init__(self, data):
174176
self.id = int(data["message_id"])
177+
self.type = data.get("type", "thread_message")
178+
self.author = User(data["author"])
175179
self.created_at = dateutil.parser.parse(data["timestamp"]).replace(tzinfo=None)
176180
self.human_created_at = duration(self.created_at, now=datetime.now())
177181
self.raw_content = data["content"]
178182
self.content = self.format_html_content(self.raw_content)
179-
self.attachments = [Attachment(a) for a in data["attachments"]]
183+
self.attachments = [Attachment(a, self.author) for a in data["attachments"]]
180184
if "stickers" in data:
181185
self.stickers = [Sticker(a) for a in data["stickers"]]
182186
else:
183187
self.stickers = []
184-
self.author = User(data["author"])
185-
self.type = data.get("type", "thread_message")
186188
self.edited = data.get("edited", False)
187189

188190
def is_different_from(self, other):

0 commit comments

Comments
 (0)