Skip to content

Commit

Permalink
Generate MD5 hash of content when adding to database
Browse files Browse the repository at this point in the history
  • Loading branch information
jb3 committed Sep 10, 2024
1 parent ff72d3e commit e507004
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions metricity/exts/event_listeners/_syncer_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import binascii
import hashlib

import discord
from pydis_core.utils import logging
from sqlalchemy import update
Expand Down Expand Up @@ -30,11 +33,17 @@ async def sync_message(message: discord.Message, sess: AsyncSession, *, from_thr
if await sess.get(models.Message, str(message.id)):
return

hash_ctx = hashlib.md5()
hash_ctx.update(message.content.encode())
digest = hash_ctx.digest()
digest_encoded = binascii.hexlify(digest).decode()

args = {
"id": str(message.id),
"channel_id": str(message.channel.id),
"author_id": str(message.author.id),
"created_at": message.created_at,
"content_hash": digest_encoded
}

if from_thread:
Expand Down

0 comments on commit e507004

Please sign in to comment.