Remove rest of legacy code, fix bridges, complete Codings module

This commit is contained in:
2024-08-08 00:58:07 +02:00
parent c9895a4bed
commit 183b8c60cd
15 changed files with 105 additions and 125 deletions

View File

@ -1,7 +1,28 @@
import base64
from binascii import Error as binascii_Error
#RegisterModule(name="Codings", group="Geek", endpoints={
# "Encode": CreateEndpoint(["encode"], summary="", handler=cEncode),
# "Decode": CreateEndpoint(["decode"], summary="", handler=cDecode),
#})
def mCodings(context:EventContext, data:InputMessageData):
algorithms = ["base64"]
methods = {
"encode_base64": base64.b64encode,
"decode_base64": base64.b64decode,
"encode_b64": base64.b64encode,
"decode_b64": base64.b64decode,
}
if (method := ObjGet(methods, f"{data.command.name}_{data.command.arguments.algorithm}")):
try:
result = method((data.command.body or (data.quoted and data.quoted.text_plain)).encode()).decode()
SendMessage(context, {"text_html": f"<pre>{html_escape(result)}</pre>"})
except binascii_Error:
SendMessage(context, {"text_plain": f"An error occurred."})
else:
language = data.user.settings.language
SendMessage(context, {
"text_html": f'{context.endpoint.help_text(language)}\n\n{context.module.get_string("algorithms", language)}: {algorithms}'})
RegisterModule(name="Codings", group="Geek", endpoints=[
SafeNamespace(names=["encode", "decode"], handler=mCodings, body=False, quoted=False, arguments={
"algorithm": True,
}),
])