python-zatolox-bot 0.1.0__tar.gz → 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_zatolox_bot-0.1.0 → python_zatolox_bot-0.1.1}/PKG-INFO +1 -1
- {python_zatolox_bot-0.1.0 → python_zatolox_bot-0.1.1}/python_zatolox_bot.egg-info/PKG-INFO +1 -1
- {python_zatolox_bot-0.1.0 → python_zatolox_bot-0.1.1}/setup.py +1 -1
- {python_zatolox_bot-0.1.0 → python_zatolox_bot-0.1.1}/zatolox/__init__.py +1 -1
- {python_zatolox_bot-0.1.0 → python_zatolox_bot-0.1.1}/zatolox/bot.py +39 -0
- {python_zatolox_bot-0.1.0 → python_zatolox_bot-0.1.1}/python_zatolox_bot.egg-info/SOURCES.txt +0 -0
- {python_zatolox_bot-0.1.0 → python_zatolox_bot-0.1.1}/python_zatolox_bot.egg-info/dependency_links.txt +0 -0
- {python_zatolox_bot-0.1.0 → python_zatolox_bot-0.1.1}/python_zatolox_bot.egg-info/requires.txt +0 -0
- {python_zatolox_bot-0.1.0 → python_zatolox_bot-0.1.1}/python_zatolox_bot.egg-info/top_level.txt +0 -0
- {python_zatolox_bot-0.1.0 → python_zatolox_bot-0.1.1}/setup.cfg +0 -0
- {python_zatolox_bot-0.1.0 → python_zatolox_bot-0.1.1}/zatolox/types.py +0 -0
|
@@ -5,7 +5,7 @@ from setuptools import setup, find_packages
|
|
|
5
5
|
# sono, meno se ne rompono.
|
|
6
6
|
setup(
|
|
7
7
|
name="python-zatolox-bot",
|
|
8
|
-
version="0.1.
|
|
8
|
+
version="0.1.1",
|
|
9
9
|
description="SDK ufficiale per costruire bot su Zatolox",
|
|
10
10
|
long_description=(
|
|
11
11
|
"Wrapper leggero attorno al gateway HTTP dei bot di Zatolox. "
|
|
@@ -91,6 +91,26 @@ class ZatoloxBot:
|
|
|
91
91
|
result = self._call("getUpdates", params, http="get") or []
|
|
92
92
|
return [Update.from_dict(u) for u in result]
|
|
93
93
|
|
|
94
|
+
def set_my_commands(self, commands: List[Any]) -> List[dict]:
|
|
95
|
+
"""
|
|
96
|
+
Registra i comandi del bot sul server (come setMyCommands di Telegram).
|
|
97
|
+
|
|
98
|
+
Il client Zatolox li mostra nel menu "/" della barra input: senza almeno un comando quel
|
|
99
|
+
menu non compare proprio. Da chiamare una volta all'avvio.
|
|
100
|
+
|
|
101
|
+
`commands` accetta forme diverse, per comodita':
|
|
102
|
+
- dict: {"command": "start", "description": "avvia il bot"}
|
|
103
|
+
- tupla: ("start", "avvia il bot")
|
|
104
|
+
Lo slash iniziale e' facoltativo: lo normalizza il server. Un array vuoto azzera i comandi.
|
|
105
|
+
"""
|
|
106
|
+
norm: List[dict] = []
|
|
107
|
+
for c in commands:
|
|
108
|
+
if isinstance(c, dict):
|
|
109
|
+
norm.append({"command": str(c.get("command", "")), "description": str(c.get("description", ""))})
|
|
110
|
+
elif isinstance(c, (tuple, list)) and len(c) >= 2:
|
|
111
|
+
norm.append({"command": str(c[0]), "description": str(c[1])})
|
|
112
|
+
return self._call("setMyCommands", {"commands": norm})
|
|
113
|
+
|
|
94
114
|
# ------------------------------------------------------------------ handler
|
|
95
115
|
|
|
96
116
|
def add_command_handler(self, command: str, callback: Callable[[Message], None]) -> None:
|
|
@@ -113,6 +133,25 @@ class ZatoloxBot:
|
|
|
113
133
|
return fn
|
|
114
134
|
return deco
|
|
115
135
|
|
|
136
|
+
def message_handler(self, fn: Optional[Callable[[Message], None]] = None):
|
|
137
|
+
"""
|
|
138
|
+
Decoratore per il fallback sul testo LIBERO (i messaggi che non sono comandi) — la base per
|
|
139
|
+
un bot conversazionale (es. inoltrare il testo a un'IA). Equivale ad add_message_handler.
|
|
140
|
+
|
|
141
|
+
Funziona sia nudo sia con le parentesi::
|
|
142
|
+
|
|
143
|
+
@bot.message_handler
|
|
144
|
+
def on_text(msg): ...
|
|
145
|
+
|
|
146
|
+
@bot.message_handler()
|
|
147
|
+
def on_text(msg): ...
|
|
148
|
+
"""
|
|
149
|
+
def register(f: Callable[[Message], None]) -> Callable[[Message], None]:
|
|
150
|
+
self.add_message_handler(f)
|
|
151
|
+
return f
|
|
152
|
+
# Uso nudo (@bot.message_handler): Python passa gia' la funzione qui.
|
|
153
|
+
return register(fn) if fn is not None else register
|
|
154
|
+
|
|
116
155
|
# ------------------------------------------------------------------ instradamento
|
|
117
156
|
|
|
118
157
|
def _dispatch(self, update: Update) -> None:
|
{python_zatolox_bot-0.1.0 → python_zatolox_bot-0.1.1}/python_zatolox_bot.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{python_zatolox_bot-0.1.0 → python_zatolox_bot-0.1.1}/python_zatolox_bot.egg-info/requires.txt
RENAMED
|
File without changes
|
{python_zatolox_bot-0.1.0 → python_zatolox_bot-0.1.1}/python_zatolox_bot.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|