import hashlib from core.builtins import Bot from core.component import module h = module('hash', developers=['Dianliang233'], desc='{hash.help}', ) @h.handle(' [] {{hash.help}}') async def _(msg: Bot.MessageSession): algorithm = msg.parsed_msg[''] string = msg.parsed_msg[''] encoding = msg.parsed_msg.get('', 'utf-8') try: hash_ = hashlib.new(algorithm, string.encode(encoding)) 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))}") await msg.finish(msg.locale.t('hash.message.output', algorithm=hash_.name, digest=hash_.hexdigest())) @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)))