Skip to main content

Description

Just base core for simple telegram bots.

How to create a bot

class AwesomeBot(Bot):

    def __init__(self, token: str):
        super().__init__(token)

    def init_controllers(self):
        UserController(self)

    def handle(self, e):
        self.send_message(12345, traceback.format_exc())
        return True

class UserController(Controller):

    def __init__(self, bot: Bot):
        super().__init__(bot)

    @message_handler(commands=["start"], chat_types=["private"])
    def start_handler(self, message: Message):
        self.bot.send_message(message.chat.id, "Hello!")

How to use database

db = DataBase("users.db", "structure.sql")
db.update("CREATE TABLE test (id INTEGER PRIMARY KEY, x TEXT)")
db.update("INSERT INTO test (id, x) VALUES (?, ?)", 0, "some text")
print(db.fetchall("SELECT * FROM test"))
print(db.fetchone("SELECT * FROM test WHERE id = ?", 0))

You can provide structure.sql to handle the case where the database doesn't exist. It should contain some scripts to define tables or any other what you need.

How to use service


database.update("CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT, money REAL)")

class UserInfo(ModelInfo):

    id: int
    username: str
    money: float

    @classmethod
    def table(cls):
        return "users"

    @classmethod    
    def fields(cls):
        return "id", "username", "money"

class UserDao(DAO):

    def __init__(self, database: DataBase):
        super().__init__(database, UserInfo)

    def find_by_username(self, username: str):
        return self.database.fetchone("SELECT * FROM users WHERE username = ?", username)

    def users_without_money():
        return self.database.fetchall("SELECT * FROM users WHERE money = 0")

class UserService(Service[UserInfo, UserDao]):

    def __init__(self, dao: UserDao):
        super().__init__(UserInfo, dao)

    def find_by_username(self, username: str):
        return self.to_object(self.dao.find_by_username(username))

    def users_without_money(self, user_id: int):
        return self.to_objects(self.dao.users_without_money())

service = UserService(UserDao(database))
user_id = service.create(username="some_username", money=10)
print(service.getall())
service.delete(user_id)

Release files for BotCore 1.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for BotCore 1.1.4
File Size Uploaded
BotCore-1.1.4.tar.gz 4.6 kB Details

Release files / BotCore-1.1.4.tar.gz

Download URL BotCore-1.1.4.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
9d16b536e3eae028ab1ee5e75ed23f914d15027908fd4ad597c4521f8afd75e8
BLAKE2b-256 checksum
How to use checksums
d32e593826ef21517d027c987380424aa5ba171ac3aff3e31ac893a608b4ad68
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Release history Release notifications | RSS feed

This release

1.1.4 This release

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.13

1 release file

1.0.12

1 release file

1.0.11

1 release file

1.0.10

1 release file

1.0.9

1 release file

1.0.8

1 release file

1.0.7

1 release file

1.0.6

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page