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

@@ -38,12 +38,12 @@ def cPing(context:EventContext, data:InputMessageData) -> None:
# CharEscape(choice(Locale.__('time')).format(time.ctime().replace(' ', ' ')), 'MARKDOWN_SPEECH'),
# reply_to_message_id=update.message.message_id)
def cEval(context:EventContext, data:InputMessageData) -> None:
SendMessage(context, {"Text": choice(Locale.__('eval'))})
#def cEval(context:EventContext, data:InputMessageData) -> None:
# SendMessage(context, {"Text": choice(Locale.__('eval'))})
RegisterModule(name="Base", endpoints=[
SafeNamespace(names=["source"], handler=cSource),
SafeNamespace(names=["config"], handler=cConfig, arguments={
SafeNamespace(names=["config"], handler=cConfig, body=False, arguments={
"get": True,
}),
#SafeNamespace(names=["gdpr"], summary="Operations for european citizens regarding your personal data.", handler=cGdpr),

0
ModWinDog/Base/Base.yaml Normal file → Executable file
View File

View File

@@ -5,7 +5,7 @@
def cBroadcast(context:EventContext, data:InputMessageData) -> None:
if (data.user.id not in AdminIds) and (data.user.tag not in AdminIds):
return SendMessage(context, {"Text": choice(Locale.__('eval'))})
return SendMessage(context, {"Text": "Permission denied."})
destination = data.command.arguments["destination"]
text = data.command.body
if not (destination and text):
@@ -14,7 +14,7 @@ def cBroadcast(context:EventContext, data:InputMessageData) -> None:
SendMessage(context, OutputMessageData(text_plain="Executed."))
RegisterModule(name="Broadcast", endpoints=[
SafeNamespace(names=["broadcast"], handler=cBroadcast, arguments={
SafeNamespace(names=["broadcast"], handler=cBroadcast, body=True, arguments={
"destination": True,
}),
])

0
ModWinDog/Broadcast/Broadcast.yaml Normal file → Executable file
View File

View File

@@ -6,11 +6,12 @@
from json import dumps as json_dumps
def cDump(context:EventContext, data:InputMessageData):
if not (message := ObjGet(data, "quoted")):
pass # TODO send error message
SendMessage(context, {"TextPlain": json_dumps(message, default=(lambda obj: obj.__dict__), indent=" ")})
SendMessage(context, {
"text_html": (f'<pre>{json_dumps(message, default=(lambda obj: obj.__dict__), indent=" ")}</pre>'
if (message := ObjGet(data, "quoted"))
else context.endpoint.help_text(data.user.settings.language))})
RegisterModule(name="Dumper", group="Geek", endpoints=[
SafeNamespace(names=["dump"], handler=cDump),
SafeNamespace(names=["dump"], handler=cDump, quoted=True),
])

View File

@@ -1,6 +1,9 @@
summary:
en: Functions for dumping of various data.
dump:
summary:
en: Dumps the data for a quoted message and returns the JSON representation.
endpoints:
dump:
summary:
en: Dumps the data for a quoted message and returns the JSON representation.
body:
en: Target message

View File

@@ -5,21 +5,22 @@
def cEcho(context:EventContext, data:InputMessageData) -> None:
if not (text := ObjGet(data, "command.body")):
return SendMessage(context, {"text_html": context.endpoint.get_string("empty", data.user.settings.language)})
return SendMessage(context, {
"text_html": context.endpoint.get_string("empty", data.user.settings.language)})
prefix = f'<a href="{data.message_url}">🗣️</a> '
#prefix = f"[🗣️]({context.linker(data).message}) "
if len(data.command.tokens) == 2:
if len(data.command.tokens) == 2: # text is a single word
nonascii = True
for char in data.command.tokens[1]:
if ord(char) < 256:
nonascii = False
break
if nonascii:
# text is not ascii, probably an emoji (altough not necessarily), so just pass as is (useful for Telegram emojis)
# word is not ascii, probably an emoji (altough not necessarily)
# so just pass it as is (useful for Telegram emojis)
prefix = ''
SendMessage(context, {"text_html": (prefix + html_escape(text))})
RegisterModule(name="Echo", endpoints=[
SafeNamespace(names=["echo"], handler=cEcho),
SafeNamespace(names=["echo"], handler=cEcho, body=True),
])

View File

@@ -18,6 +18,6 @@ def cGpt(context:EventContext, data:InputMessageData) -> None:
return SendMessage(context, {"TextPlain": f"[🤖️ GPT]\n\n{output}"})
RegisterModule(name="GPT", endpoints=[
SafeNamespace(names=["gpt", "chatgpt"], handler=cGpt),
SafeNamespace(names=["gpt", "chatgpt"], handler=cGpt, body=True),
])

0
ModWinDog/GPT/GPT.yaml Normal file → Executable file
View File

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,
}),
])

View File

@@ -4,12 +4,15 @@ summary:
endpoints:
hash:
summary:
en: Responds with the hash-sum of the received message.
en: Responds with the hash-sum of the included or quoted text.
algorithms:
en: Available algorithms
it: Algoritmi disponibili
arguments:
algorithm:
en: Algorithm
it: Algoritmo
body:
en: Text to hash
it: Testo da hashare
body:
en: Text to hash
it: Testo da hashare

View File

@@ -5,16 +5,16 @@
# TODO: implement /help <commandname> feature
def cHelp(context:EventContext, data:InputMessageData) -> None:
module_list = ''
text = (context.endpoint.get_string(lang=data.user.settings.language) or '')
language = data.user.settings.language
for module in Modules:
summary = Modules[module].get_string("summary", language)
endpoints = Modules[module].endpoints
module_list += (f"\n\n{module}" + (f": {summary}" if summary else ''))
text += (f"\n\n{module}" + (f": {summary}" if summary else ''))
for endpoint in endpoints:
summary = Modules[module].get_string(f"endpoints.{endpoint.names[0]}.summary", language)
module_list += (f"\n* /{', /'.join(endpoint.names)}" + (f": {summary}" if summary else ''))
SendMessage(context, OutputMessageData(text=module_list))
text += (f"\n* /{', /'.join(endpoint.names)}" + (f": {summary}" if summary else ''))
SendMessage(context, {"text_html": text})
RegisterModule(name="Help", group="Basic", endpoints=[
SafeNamespace(names=["help"], handler=cHelp),

5
ModWinDog/Help/Help.yaml Normal file → Executable file
View File

@@ -2,4 +2,9 @@ endpoints:
help:
summary:
en: Provides help for the bot. For now, it just lists the commands.
help:
en: >
<b>There's no one around to help.</b> However, you can have the commands list:
it: >
<b>Non c'è nessuno qui ad aiutarti.</b> Tuttavia, puoi avere la lista dei comandi:

View File

@@ -137,13 +137,13 @@ def cSafebooru(context:EventContext, data:InputMessageData) -> None:
raise
RegisterModule(name="Internet", endpoints=[
SafeNamespace(names=["embedded"], handler=cEmbedded),
SafeNamespace(names=["web"], handler=cWeb),
SafeNamespace(names=["translate"], handler=cTranslate, arguments={
SafeNamespace(names=["embedded"], handler=cEmbedded, body=False, quoted=False),
SafeNamespace(names=["web"], handler=cWeb, body=True),
SafeNamespace(names=["translate"], handler=cTranslate, body=False, quoted=False, arguments={
"language_to": True,
"language_from": False,
}),
#SafeNamespace(names=["unsplash"], summary="Sends a picture sourced from Unsplash.", handler=cUnsplash),
SafeNamespace(names=["safebooru"], handler=cSafebooru),
SafeNamespace(names=["safebooru"], handler=cSafebooru, body=False),
])

0
ModWinDog/Internet/Internet.yaml Normal file → Executable file
View File

View File

@@ -4,23 +4,22 @@
# ================================== #
def mMultifun(context:EventContext, data:InputMessageData) -> None:
cmdkey = data.command.name
replyToId = None
reply_to = None
fun_strings = {}
for key in ("empty", "bot", "self", "others"):
fun_strings[key] = context.endpoint.get_string(key, data.user.settings.language)
if data.quoted:
replyFromUid = data.quoted.user.id
# TODO work on all platforms for the bot id
if replyFromUid.split(':')[1] == TelegramToken.split(':')[0] and 'bot' in Locale.__(cmdkey):
Text = choice(Locale.__(f'{cmdkey}.bot'))
elif replyFromUid == data.user.id and 'self' in Locale.__(cmdkey):
Text = choice(Locale.__(f'{cmdkey}.self')).format(data.user.name)
else:
if 'others' in Locale.__(cmdkey):
Text = choice(Locale.__(f'{cmdkey}.others')).format(data.user.name, data.quoted.user.name)
replyToId = data.quoted.message_id
if fun_strings["bot"] and (data.quoted.user.id == Platforms[context.platform].agent_info.id):
text = choice(fun_strings["bot"])
elif fun_strings["self"] and (data.quoted.user.id == data.user.id):
text = choice(fun_strings["self"]).format(data.user.name)
elif fun_strings["others"]:
text = choice(fun_strings["others"]).format(data.user.name, data.quoted.user.name)
reply_to = data.quoted.message_id
else:
if 'empty' in Locale.__(cmdkey):
Text = choice(Locale.__(f'{cmdkey}.empty'))
SendMessage(context, {"Text": Text, "ReplyTo": replyToId})
if fun_strings["empty"]:
text = choice(fun_strings["empty"])
SendMessage(context, {"text_html": text, "ReplyTo": reply_to})
RegisterModule(name="Multifun", endpoints=[
SafeNamespace(names=["hug", "pat", "poke", "cuddle", "hands", "floor", "sessocto"], handler=mMultifun),

116
ModWinDog/Multifun/Multifun.yaml Normal file → Executable file
View File

@@ -1,3 +1,119 @@
summary:
en: Provides fun trough preprogrammed text-based toys.
endpoints:
hug:
empty:
en:
- <b>Hug? You haven't replied to anyone...</b>
it:
- <b>Chi vuoi abbracciare? Rispondi a qualcuno.</b>
- <b>Un abbraccio a chi? Non hai risposto a nessuno...</b>
bot:
it:
- <b>...Grazie uwu <3</b>
- <b>Non puoi abbracciarmi ☁️ :/</b>
self:
it:
- <b>{0} allunga le braccia attorno a sè, si stringe forte, e si sente ora meno triste.</b>
others:
en:
- <b>{0} hugs {1} tightly... :3</b>
it:
- <b>{0} abbraccia {1} forte forte... :3</b>
- <b>{0} ti ha dato un abbraccio!</b>
pat:
empty:
it:
- <b>Chi vuoi accarezzare? Rispondi a qualcuno.</b>
- <b>Una carezza a chi? Non hai risposto a nessuno...</b>
bot:
it:
- <b>Rawrrr xDDdd</b>
- <b>Come vuoi accarezzarmi? Vivo nel cloud... :(</b>
self:
it:
- <b>{0} allunga goffamente la mano dietro di sè per accarezzarsi in testa 🙃</b>
others:
it:
- <b>{0} fa patpat a {1} ^.^</b>
- <b>{0} ti accarezza con dolcezza.</b>
poke:
empty:
it:
- <b>Chi vuoi punzecchiare? Rispondi a qualcuno.</b>
- <b>Punzecchiare chi? Non hai risposto a nessuno...</b>
bot:
it:
- <b>&gt;_&lt; perché?</b>
- <b>heh ☁️😌</b>
self:
it:
- <b>{0} si punzecchia :o</b>
others:
it:
- <b>{0} punzecchia {1} 👀*</b>
- <b>{0} ti punzecchia con impertinenza 👉</b>
cuddle:
empty:
it:
- <b>A chi vuoi fare le coccole? Rispondi a qualcuno.</b>
- <b>Le coccole? A chi? Non hai risposto a nessuno...</b>
bot:
it:
- <b>Aww.. grazie :3</b>
- <b>Vorrei anche io le coccole ma... ☁️😔</b>
self:
it:
- <b>{0} si stende sul letto e prova a farsi le coccole, per sentirsi meglio.</b>
others:
it:
- <b>{0} fa le coccole a {1} 🥰</b>
- <b>{0} ti fa le coccole! 🤗️</b>
floor:
empty:
it:
- <b>Il pavimento?</b>
- <b>Il pavimentowo?</b>
- <b>Vuoi mettere qualcuno sul pavimento? Rispondi ad un suo messaggio.</b>
bot:
it:
- <b>Sono già sul pavimento.. sono sempre sul pavimento.</b>
self:
it:
- <b>{0} si mette sul pavimento.</b>
others:
it:
- <b>{0} solleva {1} dal pavimento.</b>
- <b>{0} ti prende in braccio e ti appoggia con delicatezza sul pavimento.</b>
hands:
empty:
it:
- <b>Le t.me/manineuwu? 😳️</b>
- <b>A chi vuoi dare le manine? Rispondi a qualcuno.</b>
bot:
it:
- <b>Io non le ho le manine,.,. 😭️</b>
self:
it:
- <b>{0} fa handholding in solitudine... 😶️</b>
- <b>{0} non ha nessuno a cui dare la mano 😐️</b>
others:
it:
- <b>{0} prende le mani di {1} 😳️❤️</b>
- <b>{0} vuole darti la sua manina 🥺👉️👈️</b>
sessocto:
empty:
it:
- <b>Sessocto?!?! 😳️</b>
- <b>Vuoi fare sessocto con qualcuno? Rispondi ad un suo messaggio.</b>
bot:
it:
- <b>Vorrei anche io sessocto ma non ho un corpo... 😥️</b>
self:
it:
- <b>{0} fa sessocto in singleplayer 😳️</b>
others:
it:
- <b>{0} vuole fare sessocto con te... 👀️</b>
- <b>{0} e {1} fanno sessocto insieme 💑️</b>

View File

@@ -4,10 +4,13 @@
# ==================================== #
def mPercenter(context:EventContext, data:InputMessageData) -> None:
SendMessage(context, {"Text": choice(Locale.__(f'{data.command.name}.{"done" if data.command.body else "empty"}')).format(
Cmd=data.command.tokens[0], Percent=RandPercent(), Thing=data.command.body)})
SendMessage(context, {"text_html": (context.endpoint.get_string(
("done" if data.command.body else "empty"),
data.user.settings.language
) or context.endpoint.help_text(data.user.settings.language)
).format(RandPercent(), data.command.body)})
RegisterModule(name="Percenter", endpoints=[
SafeNamespace(names=["wish", "level"], handler=mPercenter),
SafeNamespace(names=["wish", "level"], handler=mPercenter, body=True),
])

27
ModWinDog/Percenter/Percenter.yaml Normal file → Executable file
View File

@@ -1,3 +1,30 @@
summary:
en: Provides fun trough percentage-based toys.
endpoints:
wish:
empty:
en: |
<b>You wished for nothing! ✨</b>
<i>Nothing happens...</i>
it: |
<b>Non hai desiderato nulla! ✨</b>
<i>Non succede niente...</i>
done:
en: |
<b>Your wish has been cast! ✨</b>
<i>Chance of success: <b>{0}%</b>.</i>
it: |
<b>Il tuo desiderio è stato espresso! ✨</b>
<i>Probabilità che si avveri: <b>{0}%</b>.</i>
level:
summary:
en: Check what's your level of something.
it: Controlla il tuo livello di qualcosa.
done:
en: <i>Your level of <b>{1}</b> is... <b>{0}%</b>.</i>
it: <i>Il tuo livello di <b>{1}</b> è... <b>{0}%</b>.</i>

View File

@@ -119,7 +119,7 @@ def cCraiyonSelenium(context:EventContext, data:InputMessageData) -> None:
closeSelenium(driver_index, driver)
RegisterModule(name="Scrapers", endpoints=[
SafeNamespace(names=["dalle"], handler=cDalleSelenium),
SafeNamespace(names=["craiyon", "crayion"], handler=cCraiyonSelenium),
SafeNamespace(names=["dalle"], handler=cDalleSelenium, body=True),
SafeNamespace(names=["craiyon", "crayion"], handler=cCraiyonSelenium, body=True),
])

0
ModWinDog/Scrapers/Scrapers.yaml Normal file → Executable file
View File

View File

@@ -53,6 +53,6 @@ end)()"""))
SendMessage(context, {"TextPlain": textOutput})
RegisterModule(name="Scripting", group="Geek", endpoints=[
SafeNamespace(names=["lua"], handler=cLua),
SafeNamespace(names=["lua"], handler=cLua, body=False, quoted=False),
])

0
ModWinDog/Scripting/Scripting.yaml Normal file → Executable file
View File

0
ModWinDog/Start/Start.py Normal file → Executable file
View File

0
ModWinDog/Start/Start.yaml Normal file → Executable file
View File

4
ModWinDog/System/System.py Normal file → Executable file
View File

@@ -15,7 +15,7 @@ from re import compile as re_compile
def cExec(context:EventContext, data:InputMessageData) -> None:
if not (len(data.command.tokens) >= 2 and data.command.tokens[1].lower() in ExecAllowed):
return SendMessage(context, {"Text": choice(Locale.__('eval'))})
return SendMessage(context, {"Text": "This feature is not implemented [Security Issue]."})
command = data.command.tokens[1].lower()
output = subprocess.run(
("sh", "-c", f"export PATH=$PATH:/usr/games; {command}"),
@@ -26,6 +26,6 @@ def cExec(context:EventContext, data:InputMessageData) -> None:
text_plain=text, text_html=f"<pre>{html_escape(text)}</pre>"))
RegisterModule(name="System", endpoints=[
SafeNamespace(names=["exec"], handler=cExec),
SafeNamespace(names=["exec"], handler=cExec, body=True),
])

0
ModWinDog/System/System.yaml Normal file → Executable file
View File