diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/discord_image_bridge/utils.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/discord_image_bridge/utils.py b/src/discord_image_bridge/utils.py index 923e17f..e614e50 100644 --- a/src/discord_image_bridge/utils.py +++ b/src/discord_image_bridge/utils.py @@ -1,7 +1,7 @@ import os import cherrypy import requests -from hashlib import md5 as do_hash +from hashlib import sha256 as do_hash from .dbpool import DBPoolManager from . import discord @@ -13,7 +13,7 @@ def download_and_cache(url, filename): hash=do_hash(resp.content).hexdigest() try: os.mkdir(hash[:2]) - fname=hash[:2]+hash + fname=os.path.join(hash[:2],hash) with open(fname,'wb') as fd: fd.write(resp.content) return hash, fname @@ -21,6 +21,13 @@ def download_and_cache(url, filename): cherrypy.log("Error writing "+filename+" to disk: "+repr(e)) return None, None +def download_uncached(channel, msgid, attachmentid): + status,data=discord.channel_message_get(channel_id=channel, message_id=msgid) + for attachment in data["attachments"]: + if attachment["id"]==str(attachmentid): + return download_and_cache(attachment["url"],attachment["filename"]) + return (None, None) + def on_ready(plugin:discord.DiscordWsManager, client:discord.DiscordWsClient): dbpool:DBPoolManager=plugin.dbpool @@ -32,7 +39,7 @@ def on_ready(plugin:discord.DiscordWsManager, client:discord.DiscordWsClient): "channel BIGINT UNSIGNED," "message BIGINT UNSIGNED," "id BIGINT UNSIGNED," - "hash CHAR(32)" + "hash CHAR(64)" ")" ) conn.commit() |
