No project description provided
Project description
OrigamiBot - A Pythonic telegram bot API library
This is WORK IN PROGRESS
Library for creating bots for telegram with Python.
TODO
- implement methods for sending messages, media, etc.
Usage example
Here goes a simple example of a bot:
from sys import argv
from time import sleep
from origamibot import OrigamiBot as Bot
class BotsCommands:
def __init__(self, bot: Bot): # Can initialize however you like
self.bot = bot
def start(self, message): # /start command
self.bot.send_message(
message.chat.id,
'Hello user!\nThis is an example bot.')
def echo(self, message, value: str): # /echo [value: str] command
self.bot.send_message(
message.chat.id,
value)
def add(self, message, a: float, b: float): # /add [a: float] [b: float] command
self.bot.send_message(
message.chat.id,
str(a + b))
if __name__ == '__main__':
token = (argv[1]
if len(argv) > 1 else
input('Enter bot token: '))
bot = Bot(token)
bot.add_commands(BotsCommands(bot))
bot.start() # start bot's threads
while True:
sleep(1)
# Can also do some useful work i main thread
# Like autoposting to channels for example
Commands are added as methods of an object(be it class or instance of it), if their names don't start with _
which makes it possible to also contain some utility functions inside command container.
For the command to be called two conditions must be met:
- command name must match with method name
- command's arguments must match signature of a method
Method signature supports any number of arguments with simple typing(str
, int
, float
, bool
) or without a typing(in this case all arguments are strings by default), as well as variable number of arguments *args
. More complex types(as lists, tuples, custom object classes) are not supported, as bot does not know how to parse them, and I don't want to enforce my own parsing algorithm, but bot will still attempt to convert it like cls(argument)
, but a correct result is not guaranteed.
Boolean values are considered True if their string representation is in
{'True', 'true', '1'}
, and False if in{'False', 'false', '0'}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for origamibot-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5573e508948910349288a6876dfad03bf52a34391ffa17327ddbe118b7b6453 |
|
MD5 | 060ebb523d89b5521996eff61ee6f121 |
|
BLAKE2b-256 | 8cdde9cca7ebdd6750734a7ca45e4c37bc94db16eece01a2919f4efc9c92399b |