Cleanup Locale system, remove legacy Locale API, add command help handling, misc

This commit is contained in:
2024-08-07 02:27:17 +02:00
parent 6a1a21027c
commit c9895a4bed
37 changed files with 314 additions and 297 deletions

View File

@ -6,15 +6,17 @@
import hashlib
def cHash(context:EventContext, data:InputMessageData):
text_input = ObjGet(data, "command.body")
algorithm = ObjGet(data, "command.arguments.algorithm")
text_input = (data.command.body or (data.quoted and data.quoted.text_plain))
algorithm = data.command.arguments.algorithm
language = data.user.settings.language
if not (text_input and (algorithm in hashlib.algorithms_available)):
return SendMessage(context, {"Text": choice(Locale.__('hash.usage')).format(data.command.tokens[0], hashlib.algorithms_available)})
return SendMessage(context, {
"text_html": f'{context.endpoint.help_text(language)}\n\n{context.endpoint.get_string("algorithms", language)}: {hashlib.algorithms_available}'})
hashed = hashlib.new(algorithm, text_input.encode()).hexdigest()
return SendMessage(context, OutputMessageData(text_plain=hashed, text_html=f"<pre>{hashed}</pre>"))
return SendMessage(context, {"text_html": f"<pre>{hashed}</pre>"})
RegisterModule(name="Hashing", group="Geek", endpoints=[
SafeNamespace(names=["hash"], handler=cHash, arguments={
SafeNamespace(names=["hash"], handler=cHash, body=False, quoted=False, arguments={
"algorithm": True,
}),
])