From da1e7abd099c1a4b646bfacaf35bb4fba56fd9ca Mon Sep 17 00:00:00 2001 From: io mintz Date: Tue, 6 Apr 2021 04:31:47 +0000 Subject: [PATCH] fix 3.8 md5() compat --- bot.py | 4 ++-- utils/__init__.py | 1 + utils/compat.py | 9 +++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 utils/compat.py diff --git a/bot.py b/bot.py index fb79485..54165dc 100755 --- a/bot.py +++ b/bot.py @@ -16,13 +16,13 @@ # along with Emote Manager. If not, see . import base64 -import hashlib import logging import traceback import discord from bot_bin.bot import Bot from discord.ext import commands +from utils.compat import md5 logging.basicConfig(level=logging.WARNING) logging.getLogger('discord').setLevel(logging.INFO) @@ -61,7 +61,7 @@ class Bot(Bot): # Metrics async def on_command(self, ctx): - user_id_md5 = hashlib.md5(ctx.author.id.to_bytes(8, byteorder='big'), usedforsecurity=False).digest() + user_id_md5 = md5(ctx.author.id.to_bytes(8, byteorder='big')).digest() await self.pool.execute( 'INSERT INTO invokes (guild_id, user_id_md5, command) VALUES ($1, $2, $3)', getattr(ctx.guild, 'id', None), user_id_md5, ctx.command.qualified_name, diff --git a/utils/__init__.py b/utils/__init__.py index d26896f..f2be9b2 100644 --- a/utils/__init__.py +++ b/utils/__init__.py @@ -5,5 +5,6 @@ from . import archive from . import emote from . import errors from . import paginator +from . import compat # note: do not import .image in case the user doesn't want it # since importing image can take a long time. diff --git a/utils/compat.py b/utils/compat.py new file mode 100644 index 0000000..f333c17 --- /dev/null +++ b/utils/compat.py @@ -0,0 +1,9 @@ +import hashlib + +try: + hashlib.md5(usedforsecurity=False) +except TypeError: + md5 = hashlib.md5 +else: + def md5(*args): + return hashlib.md5(*args, usedforsecurity=False)