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
810 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
h = module('hash', alias={'rand': 'random', 'rng': 'random'},
developers=['Dianliang233'], desc='{hash.help.desc}', )
@h.handle('<algorithm> <str> [<encoding>] {{hash.help.generate}}')
async def _(msg: Bot.MessageSession):
algorithm = msg.parsed_msg['<algorithm>']
string = msg.parsed_msg['<str>']
encoding = msg.parsed_msg.get('<encoding>', 'utf-8')
hash_ = hashlib.new(algorithm, string.encode(encoding))
await msg.finish(msg.locale.t('hash.output', algorithm=hash_.name, digest=hash_.hexdigest()))
@h.handle('algorithms {{hash.help.algorithms}}')
async def _(msg: Bot.MessageSession):
await msg.finish(msg.locale.t('hash.algorithms', algorithms=', '.join(hashlib.algorithms_available)))