mirror of
https://gitlab.com/octospacc/WinDog.git
synced 2025-06-05 22:09:20 +02:00
More API refactoring, add HTML text for Telegram, start work on /config
This commit is contained in:
@@ -17,14 +17,16 @@ def cSource(context:EventContext, data:InputMessageData) -> None:
|
||||
def cGdpr(context:EventContext, data:InputMessageData) -> None:
|
||||
pass
|
||||
|
||||
# Module: Config
|
||||
# ...
|
||||
#def cConfig(update:telegram.Update, context:CallbackContext) -> None:
|
||||
# Cmd = TelegramHandleCmd(update)
|
||||
# if not Cmd: return
|
||||
# # ... area: eu, us, ...
|
||||
# # ... language: en, it, ...
|
||||
# # ... userdata: import, export, delete
|
||||
def cConfig(context:EventContext, data:InputMessageData) -> None:
|
||||
if not (settings := GetUserSettings(data.user.id)):
|
||||
User.update(settings=EntitySettings.create()).where(User.id == data.user.id).execute()
|
||||
if (get := ObjGet(data, "command.arguments.get")):
|
||||
SendMessage(context, OutputMessageData(text_plain=str(ObjGet(data.user.settings, get))))
|
||||
#Cmd = TelegramHandleCmd(update)
|
||||
#if not Cmd: return
|
||||
# ... area: eu, us, ...
|
||||
# ... language: en, it, ...
|
||||
# ... userdata: import, export, delete
|
||||
|
||||
def cPing(context:EventContext, data:InputMessageData) -> None:
|
||||
SendMessage(context, {"Text": "*Pong!*"})
|
||||
@@ -54,6 +56,9 @@ def cExec(context:EventContext, data:InputMessageData) -> None:
|
||||
RegisterModule(name="Misc", endpoints=[
|
||||
SafeNamespace(names=["start"], summary="Salutes the user, hinting that the bot is working and providing basic quick help.", handler=cStart),
|
||||
SafeNamespace(names=["source"], summary="Provides a copy of the bot source codes and/or instructions on how to get it.", 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=["eval"], summary="Execute a Python command (or safe literal operation) in the current context. Currently not implemented.", handler=cEval),
|
||||
|
@@ -7,7 +7,7 @@ from json import dumps as json_dumps
|
||||
|
||||
def cDump(context:EventContext, data:InputMessageData):
|
||||
if not (message := ObjGet(data, "quoted")):
|
||||
pass
|
||||
pass # TODO send error message
|
||||
SendMessage(context, {"TextPlain": json_dumps(message, default=(lambda obj: obj.__dict__), indent=" ")})
|
||||
|
||||
RegisterModule(name="Dumper", group="Geek", endpoints=[
|
||||
|
@@ -17,9 +17,9 @@ def cEcho(context:EventContext, data:InputMessageData) -> None:
|
||||
if nonascii:
|
||||
# text is not ascii, probably an emoji (altough not necessarily), so just pass as is (useful for Telegram emojis)
|
||||
prefix = ''
|
||||
SendMessage(context, {"Text": (prefix + text)})
|
||||
SendMessage(context, OutputMessageData(text=(prefix + text)))
|
||||
else:
|
||||
SendMessage(context, {"Text": choice(Locale.__('echo.empty'))}) #context.endpoint.get_string('empty')
|
||||
SendMessage(context, OutputMessageData(text_html=context.endpoint.get_string('empty')))
|
||||
|
||||
RegisterModule(name="Echo", endpoints=[
|
||||
SafeNamespace(names=["echo"], handler=cEcho),
|
||||
|
@@ -92,6 +92,7 @@ def cTranslate(context:EventContext, data:InputMessageData) -> None:
|
||||
except Exception:
|
||||
raise
|
||||
|
||||
# unsplash source appears to be deprecated! <https://old.reddit.com/r/unsplash/comments/s13x4h/what_happened_to_sourceunsplashcom/l65epl8/>
|
||||
def cUnsplash(context:EventContext, data:InputMessageData) -> None:
|
||||
try:
|
||||
Req = HttpReq(f'https://source.unsplash.com/random/?{UrlParse.quote(data.Body)}')
|
||||
@@ -144,7 +145,7 @@ RegisterModule(name="Internet", summary="Tools and toys related to the Internet.
|
||||
"language_to": True,
|
||||
"language_from": False,
|
||||
}),
|
||||
SafeNamespace(names=["unsplash"], summary="Sends a picture sourced from Unsplash.", handler=cUnsplash),
|
||||
#SafeNamespace(names=["unsplash"], summary="Sends a picture sourced from Unsplash.", handler=cUnsplash),
|
||||
SafeNamespace(names=["safebooru"], summary="Sends a picture sourced from Safebooru.", handler=cSafebooru),
|
||||
])
|
||||
|
||||
|
@@ -123,6 +123,6 @@ def cCraiyonSelenium(context:EventContext, data:InputMessageData) -> None:
|
||||
|
||||
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"], summary="Sends an AI-generated picture from Craiyon.com.", handler=cCraiyonSelenium),
|
||||
SafeNamespace(names=["craiyon", "crayion"], summary="Sends an AI-generated picture from Craiyon.com.", handler=cCraiyonSelenium),
|
||||
])
|
||||
|
||||
|
Reference in New Issue
Block a user