mirror of
https://gitlab.com/octospacc/WinDog.git
synced 2025-06-05 22:09:20 +02:00
Remove rest of legacy code, fix bridges, complete Codings module
This commit is contained in:
@@ -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,
|
||||
}),
|
||||
])
|
||||
|
||||
|
20
ModWinDog/Codings/Codings.yaml
Normal file
20
ModWinDog/Codings/Codings.yaml
Normal file
@@ -0,0 +1,20 @@
|
||||
summary:
|
||||
en: Functions for encoding content.
|
||||
it: Funzioni per codificare contenuti.
|
||||
endpoints:
|
||||
encode:
|
||||
body:
|
||||
en: Text to encode
|
||||
it: Testo da codificare
|
||||
decode:
|
||||
body:
|
||||
en: Text to decode
|
||||
it: Testo da decodificare
|
||||
algorithms:
|
||||
en: Available algorithms
|
||||
it: Algoritmi disponibili
|
||||
arguments:
|
||||
algorithm:
|
||||
en: Algorithm
|
||||
it: Algoritmo
|
||||
|
Reference in New Issue
Block a user