Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/modules/hash/__init__.py
2023-06-04 21:03:24 +08:00

21 lines
940 B
Python

import hashlib
from core.builtins import Bot
from core.component import module
h = module('hash', developers=['Dianliang233'], desc='{hash.help}', )
@h.handle('<algorithm> <string> [<encoding>] {{hash.help}}')
async def _(msg: Bot.MessageSession, algorithm: str, string: str, encoding: str = 'utf-8'):
try:
hash_ = hashlib.new(algorithm, string.encode(encoding))
await msg.finish(msg.locale.t('hash.message.output', algorithm=hash_.name, digest=hash_.hexdigest()))
except ValueError:
await msg.finish(f"{msg.locale.t('hash.message.unsupported_algorithm', algorithm=algorithm)}\n"
f"{msg.locale.t('hash.message.algorithms_list', algorithms=', '.join(hashlib.algorithms_available))}")
@h.handle('list {{hash.help.list}}')
async def _(msg: Bot.MessageSession):
await msg.finish(msg.locale.t('hash.message.algorithms_list', algorithms=', '.join(hashlib.algorithms_available)))