Skip to content

Commit

Permalink
Only permacache attachments from mods
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisa committed Aug 3, 2024
1 parent df92f9f commit b986395
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def type(self):


class Attachment:
def __init__(self, data):
def __init__(self, data, author):
if isinstance(data, str): # Backwards compatibility
self.id = 0
self.filename = "attachment"
Expand All @@ -159,7 +159,9 @@ def __init__(self, data):
else:
self.id = int(data["id"])
self.filename = data["filename"]
self.url = data["url"].replace('cdn.discordapp.com/', os.environ['PERMACACHE_LOCATION'])
self.url = data["url"]
if author.mod:
self.url = self.url.replace('cdn.discordapp.com/', os.environ['PERMACACHE_LOCATION'])
self.is_image = data["is_image"]
self.size = data["size"]

Expand All @@ -172,17 +174,17 @@ def __init__(self, data):
class Message:
def __init__(self, data):
self.id = int(data["message_id"])
self.type = data.get("type", "thread_message")
self.author = User(data["author"])
self.created_at = dateutil.parser.parse(data["timestamp"]).replace(tzinfo=None)
self.human_created_at = duration(self.created_at, now=datetime.now())
self.raw_content = data["content"]
self.content = self.format_html_content(self.raw_content)
self.attachments = [Attachment(a) for a in data["attachments"]]
self.attachments = [Attachment(a, self.author) for a in data["attachments"]]
if "stickers" in data:
self.stickers = [Sticker(a) for a in data["stickers"]]
else:
self.stickers = []
self.author = User(data["author"])
self.type = data.get("type", "thread_message")
self.edited = data.get("edited", False)

def is_different_from(self, other):
Expand Down

0 comments on commit b986395

Please sign in to comment.