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(' [] {{hash.help.generate}}') async def _(msg: Bot.MessageSession): algorithm = msg.parsed_msg[''] string = msg.parsed_msg[''] encoding = msg.parsed_msg.get('', '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)))