Move all new strings to YAML, basic working Matrix backend with text messages

This commit is contained in:
2024-06-29 01:52:53 +02:00
parent 4afb5f3275
commit 6d2f51f02c
23 changed files with 153 additions and 81 deletions

View File

@@ -1,7 +1,7 @@
# ==================================== #
# WinDog multi-purpose chatbot #
# Licensed under AGPLv3 by OctoSpacc #
# ==================================== #
# ================================== #
# WinDog multi-purpose chatbot #
# Licensed under AGPLv3 by OctoSpacc #
# ================================== #
def cSource(context:EventContext, data:InputMessageData) -> None:
SendMessage(context, {"TextPlain": ("""\
@@ -28,7 +28,10 @@ def cConfig(context:EventContext, data:InputMessageData) -> None:
# ... userdata: import, export, delete
def cPing(context:EventContext, data:InputMessageData) -> None:
SendMessage(context, {"Text": "*Pong!*"})
# nice experiment, but it won't work with Telegram since time is not to milliseconds (?)
#time_diff = (time_now := int(time.time())) - (time_sent := data.datetime)
#SendMessage(context, OutputMessageData(text_html=f"<b>Pong!</b>\n\n{time_sent} → {time_now} = {time_diff}"))
SendMessage(context, OutputMessageData(text_html="<b>Pong!</b>"))
#def cTime(update:Update, context:CallbackContext) -> None:
# update.message.reply_markdown_v2(
@@ -39,12 +42,12 @@ def cEval(context:EventContext, data:InputMessageData) -> None:
SendMessage(context, {"Text": choice(Locale.__('eval'))})
RegisterModule(name="Base", endpoints=[
SafeNamespace(names=["source"], summary="Provides a copy of the bot source codes and/or instructions on how to get it.", handler=cSource),
SafeNamespace(names=["source"], handler=cSource),
SafeNamespace(names=["config"], handler=cConfig, arguments={
"get": True,
}),
#SafeNamespace(names=["gdpr"], summary="Operations for european citizens regarding your personal data.", handler=cGdpr),
SafeNamespace(names=["ping"], summary="Responds pong, useful for testing messaging latency.", handler=cPing),
SafeNamespace(names=["ping"], handler=cPing),
#SafeNamespace(names=["eval"], summary="Execute a Python command (or safe literal operation) in the current context. Currently not implemented.", handler=cEval),
#SafeNamespace(names=["format"], summary="Reformat text using an handful of rules. Not yet implemented.", handler=cFormat),
#SafeNamespace(names=["frame"], summary="Frame someone's message into a platform-styled image. Not yet implemented.", handler=cFrame),

8
ModWinDog/Base/Base.yaml Normal file
View File

@@ -0,0 +1,8 @@
endpoints:
source:
summary:
en: Provides a copy of the bot source codes and/or instructions on how to get it.
ping:
summary:
en: Responds pong, useful for testing messaging latency.

View File

@@ -13,7 +13,7 @@ def cBroadcast(context:EventContext, data:InputMessageData) -> None:
SendMessage(context, {"TextPlain": "Executed."})
RegisterModule(name="Broadcast", endpoints=[
SafeNamespace(names=["broadcast"], summary="Sends an admin message over to any chat destination.", handler=cBroadcast, arguments={
SafeNamespace(names=["broadcast"], handler=cBroadcast, arguments={
"destination": True,
}),
])

View File

@@ -0,0 +1,5 @@
endpoints:
broadcast:
summary:
en: Sends an admin message over to any chat destination.

View File

@@ -17,7 +17,7 @@ def cGpt(context:EventContext, data:InputMessageData) -> None:
output += (completion.choices[0].delta.content or "")
return SendMessage(context, {"TextPlain": f"[🤖️ GPT]\n\n{output}"})
RegisterModule(name="ChatGPT", endpoints=[
SafeNamespace(names=["gpt", "chatgpt"], summary="Sends a message to GPT to get back a response. Note: conversations are not yet supported, and this is more standard GPT than ChatGPT, and in general there are many bugs!", handler=cGpt),
RegisterModule(name="GPT", endpoints=[
SafeNamespace(names=["gpt", "chatgpt"], handler=cGpt),
])

6
ModWinDog/GPT/GPT.yaml Normal file
View File

@@ -0,0 +1,6 @@
endpoints:
gpt:
summary:
en: >
Sends a message to GPT to get back a response. Note: conversations are not yet supported, and this is more standard GPT than ChatGPT, and in general there are many bugs!

View File

@@ -8,7 +8,7 @@ def cHelp(context:EventContext, data:InputMessageData) -> None:
module_list = ''
language = data.user.settings.language
for module in Modules:
summary = Modules[module].get_string("summary", language)#summary
summary = Modules[module].get_string("summary", language)
endpoints = Modules[module].endpoints
module_list += (f"\n\n{module}" + (f": {summary}" if summary else ''))
for endpoint in endpoints:

View File

@@ -136,14 +136,14 @@ def cSafebooru(context:EventContext, data:InputMessageData) -> None:
except Exception as error:
raise
RegisterModule(name="Internet", summary="Tools and toys related to the Internet.", endpoints=[
SafeNamespace(names=["embedded"], summary="Rewrites a link, trying to bypass embed view protection.", handler=cEmbedded),
SafeNamespace(names=["web"], summary="Provides results of a DuckDuckGo search.", handler=cWeb),
SafeNamespace(names=["translate"], summary="Returns the received message after translating it in another language.", handler=cTranslate, arguments={
RegisterModule(name="Internet", endpoints=[
SafeNamespace(names=["embedded"], handler=cEmbedded),
SafeNamespace(names=["web"], handler=cWeb),
SafeNamespace(names=["translate"], handler=cTranslate, arguments={
"language_to": True,
"language_from": False,
}),
#SafeNamespace(names=["unsplash"], summary="Sends a picture sourced from Unsplash.", handler=cUnsplash),
SafeNamespace(names=["safebooru"], summary="Sends a picture sourced from Safebooru.", handler=cSafebooru),
SafeNamespace(names=["safebooru"], handler=cSafebooru),
])

View File

@@ -0,0 +1,16 @@
summary:
en: Tools and toys related to the Internet.
endpoints:
embedded:
summary:
en: Rewrite a link, bypassing embed view protections for known sites.
web:
summary:
en: Provides results of a DuckDuckGo search.
translate:
summary:
en: Returns the received message after translating it in another language.
safebooru:
summary:
en: Sends a picture sourced from Safebooru.

View File

@@ -1,7 +1,7 @@
# ==================================== #
# WinDog multi-purpose chatbot #
# Licensed under AGPLv3 by OctoSpacc #
# ==================================== #
# ================================== #
# WinDog multi-purpose chatbot #
# Licensed under AGPLv3 by OctoSpacc #
# ================================== #
def mMultifun(context:EventContext, data:InputMessageData) -> None:
cmdkey = data.command.name
@@ -23,6 +23,6 @@ def mMultifun(context:EventContext, data:InputMessageData) -> None:
SendMessage(context, {"Text": Text, "ReplyTo": replyToId})
RegisterModule(name="Multifun", endpoints=[
SafeNamespace(names=["hug", "pat", "poke", "cuddle", "hands", "floor", "sessocto"], summary="Provides fun trough preprogrammed-text-based toys.", handler=mMultifun),
SafeNamespace(names=["hug", "pat", "poke", "cuddle", "hands", "floor", "sessocto"], handler=mMultifun),
])

View File

@@ -0,0 +1,3 @@
summary:
en: Provides fun trough preprogrammed text-based toys.

View File

@@ -8,6 +8,6 @@ def mPercenter(context:EventContext, data:InputMessageData) -> None:
Cmd=data.command.tokens[0], Percent=RandPercent(), Thing=data.command.body)})
RegisterModule(name="Percenter", endpoints=[
SafeNamespace(names=["wish", "level"], summary="Provides fun trough percentage-based toys.", handler=mPercenter),
SafeNamespace(names=["wish", "level"], handler=mPercenter),
])

View File

@@ -0,0 +1,3 @@
summary:
en: Provides fun trough percentage-based toys.

View File

@@ -119,7 +119,7 @@ def cCraiyonSelenium(context:EventContext, data:InputMessageData) -> None:
closeSelenium(driver_index, driver)
RegisterModule(name="Scrapers", endpoints=[
SafeNamespace(names=["dalle"], summary="Sends an AI-generated picture from DALL-E 3 via Microsoft Bing.", handler=cDalleSelenium),
SafeNamespace(names=["craiyon", "crayion"], summary="Sends an AI-generated picture from Craiyon.com.", handler=cCraiyonSelenium),
SafeNamespace(names=["dalle"], handler=cDalleSelenium),
SafeNamespace(names=["craiyon", "crayion"], handler=cCraiyonSelenium),
])

View File

@@ -0,0 +1,8 @@
endpoints:
dalle:
summary:
en: Sends an AI-generated picture from DALL-E 3 via Microsoft Bing.
craiyon:
summary:
en: Sends an AI-generated picture from Craiyon.com.

View File

@@ -52,7 +52,7 @@ end)()"""))
Log(textOutput := ("Lua Error: " + str(error)))
SendMessage(context, {"TextPlain": textOutput})
RegisterModule(name="Scripting", group="Geek", summary="Tools for programming the bot and expanding its features.", endpoints=[
SafeNamespace(names=["lua"], summary="Execute a Lua snippet and get its output.", handler=cLua),
RegisterModule(name="Scripting", group="Geek", endpoints=[
SafeNamespace(names=["lua"], handler=cLua),
])

View File

@@ -0,0 +1,7 @@
summary:
en: Tools for programming the bot and expanding its features.
endpoints:
lua:
summary:
en: Execute a Lua snippet and get its output.