Package silbot
This is a simple framework for telegram bot API.
Expand source code
"""
[](https://pypi.python.org/pypi/silbot)
[](https://t.me/SilverOSp)
This is a simple framework for [telegram bot API](https://core.telegram.org/bots/api).
- [__Examples__](https://github.com/SilverOS/Silbot-Py/tree/master/examples)
- [__Github__](https://github.com/SilverOS/Silbot-Py)
- [__Download__](https://github.com/SilverOS/Silbot-Py/archive/1.4.2.zip)
"""
from silbot import botapi, update
def GetUpdatesLoop(bot: botapi.BotApi, handlefunc, onUpdate=None, on_getUpdates=None):
""" This is a builtin function to handle updates with getUpdates
**Args:**
- bot (`botApi`): botApi object
- handlefunc (`function`): function **defined by the user**, that function has to accept there arguments:
- `update` (`silbot.types.update`) : The object that rapresents the update
- `bot` (`silbot.botapi.BotApi`) : The botApi object for that bot,
- onUpdate (`function`, optional): a function that is called every update (non async)
- on_getUpdates (`function`, optional): a function that is called everytime a getUpdates call is done (non async)
If this is not clear, check the examples
"""
offset = -1
while True:
response = bot.getUpdates(offset)[1]
if on_getUpdates is not None:
on_getUpdates()
js = response.decoded
if js["ok"]:
if len(js["result"]) > 0:
for up in js["result"]:
if onUpdate is not None:
onUpdate()
offset = up["update_id"] + 1
thread = update.update(up, bot, handlefunc)
thread.start()
else:
continue
Sub-modules
silbot.botapi
-
In this module there is the botApi class, whose purpose is to send requests
silbot.database
-
This module should manage the database of the bot You are supposed to write your own DatabaseManager class that extends this, you can find some …
silbot.helper
-
Here there are some functions that can be useful
silbot.objects
-
Here there are some extra methods for types objects
silbot.response
-
This module's purpose is to handle botApi responses
silbot.types
silbot.update
-
This module's purpose is to handle botApi updates with multithreading
Functions
def GetUpdatesLoop(bot: BotApi, handlefunc, onUpdate=None, on_getUpdates=None)
-
This is a builtin function to handle updates with getUpdates
Args:
- bot (
botApi
): botApi object - handlefunc (
function
): function defined by the user, that function has to accept there arguments:silbot.update
(silbot.types.update
) : The object that rapresents the updatebot
(BotApi
) : The botApi object for that bot,
- onUpdate (
function
, optional): a function that is called every update (non async) - on_getUpdates (
function
, optional): a function that is called everytime a getUpdates call is done (non async) If this is not clear, check the examples
Expand source code
def GetUpdatesLoop(bot: botapi.BotApi, handlefunc, onUpdate=None, on_getUpdates=None): """ This is a builtin function to handle updates with getUpdates **Args:** - bot (`botApi`): botApi object - handlefunc (`function`): function **defined by the user**, that function has to accept there arguments: - `update` (`silbot.types.update`) : The object that rapresents the update - `bot` (`silbot.botapi.BotApi`) : The botApi object for that bot, - onUpdate (`function`, optional): a function that is called every update (non async) - on_getUpdates (`function`, optional): a function that is called everytime a getUpdates call is done (non async) If this is not clear, check the examples """ offset = -1 while True: response = bot.getUpdates(offset)[1] if on_getUpdates is not None: on_getUpdates() js = response.decoded if js["ok"]: if len(js["result"]) > 0: for up in js["result"]: if onUpdate is not None: onUpdate() offset = up["update_id"] + 1 thread = update.update(up, bot, handlefunc) thread.start() else: continue
- bot (