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

22 lines
940 B
Python
Raw Normal View History

2023-04-30 11:14:19 +00:00
import hashlib
from core.builtins import Bot
from core.component import module
2023-05-02 14:53:51 +00:00
h = module('hash', developers=['Dianliang233'], desc='{hash.help}', )
2023-04-30 11:14:19 +00:00
2023-06-04 13:03:24 +00:00
@h.handle('<algorithm> <string> [<encoding>] {{hash.help}}')
async def _(msg: Bot.MessageSession, algorithm: str, string: str, encoding: str = 'utf-8'):
2023-04-30 11:27:53 +00:00
try:
hash_ = hashlib.new(algorithm, string.encode(encoding))
2023-06-04 13:03:24 +00:00
await msg.finish(msg.locale.t('hash.message.output', algorithm=hash_.name, digest=hash_.hexdigest()))
2023-04-30 11:27:53 +00:00
except ValueError:
2023-05-02 14:53:51 +00:00
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))}")
2023-04-30 11:14:19 +00:00
2023-05-02 14:53:51 +00:00
@h.handle('list {{hash.help.list}}')
2023-04-30 11:14:19 +00:00
async def _(msg: Bot.MessageSession):
2023-05-02 14:53:51 +00:00
await msg.finish(msg.locale.t('hash.message.algorithms_list', algorithms=', '.join(hashlib.algorithms_available)))