Add months-old WIP code, add global get_linker(),get_message(),delete_message() update Telegram, add /getmessage, multi-type media handling, misc fixes

This commit is contained in:
2025-01-20 01:28:27 +01:00
parent 9220c95636
commit 9ccc1027f7
9 changed files with 176 additions and 74 deletions

48
LibWinDog/Utils.py Executable file
View File

@ -0,0 +1,48 @@
# ==================================== #
# WinDog multi-purpose chatbot #
# Licensed under AGPLv3 by OctoSpacc #
# ==================================== #
from LibWinDog.Types import *
def ObjectUnion(*objects:object, clazz:object=None):
dikt = {}
auto_clazz = objects[0].__class__
for obj in objects:
if not obj:
continue
if type(obj) == dict:
obj = (clazz or SafeNamespace)(**obj)
for key, value in tuple(obj.__dict__.items()):
dikt[key] = value
return (clazz or auto_clazz)(**dikt)
def ObjectClone(obj:object):
return ObjectUnion(obj, {});
def SureArray(array:any) -> list|tuple:
return (array if type(array) in [list, tuple] else [array])
def call_or_return(obj:any, *args) -> any:
return (obj(*args) if callable(obj) else obj)
def obj_get(node:object, query:str, /) -> any:
for key in query.split('.'):
if hasattr(node, "__getitem__") and node.__getitem__:
# dicts and such
method = "__getitem__"
exception = KeyError
else:
# namespaces and such
method = "__getattribute__"
exception = AttributeError
try:
node = node.__getattribute__(method)(key)
except exception:
return None
return node
def strip_url_scheme(url:str) -> str:
tokens = urlparse.urlparse(url)
return f"{tokens.netloc}{tokens.path}"