telekit 0.0.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.
- telekit-0.0.1/PKG-INFO +219 -0
- telekit-0.0.1/README.md +191 -0
- telekit-0.0.1/setup.cfg +7 -0
- telekit-0.0.1/setup.py +28 -0
- telekit-0.0.1/telekit/__init__.py +14 -0
- telekit-0.0.1/telekit/callback_query_handler.py +58 -0
- telekit-0.0.1/telekit/chain.py +248 -0
- telekit-0.0.1/telekit/example/__init__.py +1 -0
- telekit-0.0.1/telekit/example/example_handlers/__init__.py +4 -0
- telekit-0.0.1/telekit/example/example_handlers/entry.py +125 -0
- telekit-0.0.1/telekit/example/example_handlers/help.py +42 -0
- telekit-0.0.1/telekit/example/example_handlers/start.py +49 -0
- telekit-0.0.1/telekit/example/example_server.py +9 -0
- telekit-0.0.1/telekit/handler.py +59 -0
- telekit-0.0.1/telekit/init.py +18 -0
- telekit-0.0.1/telekit/input_handler.py +79 -0
- telekit-0.0.1/telekit/senders.py +471 -0
- telekit-0.0.1/telekit/server.py +42 -0
- telekit-0.0.1/telekit/user.py +46 -0
- telekit-0.0.1/telekit.egg-info/PKG-INFO +219 -0
- telekit-0.0.1/telekit.egg-info/SOURCES.txt +23 -0
- telekit-0.0.1/telekit.egg-info/dependency_links.txt +1 -0
- telekit-0.0.1/telekit.egg-info/requires.txt +1 -0
- telekit-0.0.1/telekit.egg-info/top_level.txt +1 -0
telekit-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: telekit
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: This is the simplest module for making Telegram Bots.
|
|
5
|
+
Home-page: https://t.me/TeleKitLib
|
|
6
|
+
Author: romashka
|
|
7
|
+
Author-email: comfy6011@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Telegram, https://t.me/TeleKitLib
|
|
10
|
+
Keywords: files speedfiles
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Requires-Python: >=3.12
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
Requires-Dist: pyTelegramBotAPI>=4.27.0
|
|
17
|
+
Dynamic: author
|
|
18
|
+
Dynamic: author-email
|
|
19
|
+
Dynamic: classifier
|
|
20
|
+
Dynamic: description
|
|
21
|
+
Dynamic: description-content-type
|
|
22
|
+
Dynamic: home-page
|
|
23
|
+
Dynamic: keywords
|
|
24
|
+
Dynamic: project-url
|
|
25
|
+
Dynamic: requires-dist
|
|
26
|
+
Dynamic: requires-python
|
|
27
|
+
Dynamic: summary
|
|
28
|
+
|
|
29
|
+
# TeleKit Library
|
|
30
|
+
|
|
31
|
+
## Overview
|
|
32
|
+
|
|
33
|
+
**TeleKit** is a Python library designed to simplify common tasks for developers working with Telegram bots or Python projects in general.
|
|
34
|
+
It provides tools for:
|
|
35
|
+
|
|
36
|
+
- Managing data with `Vault`, a lightweight interface for SQLite databases.
|
|
37
|
+
- Organizing and processing text data using `chapters`, which allows converting `.txt` files into Python dictionaries for easy access.
|
|
38
|
+
- Creating modular, reusable handlers and chains for structured code.
|
|
39
|
+
|
|
40
|
+
The library is designed to reduce boilerplate code and make Python development more efficient.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Quick Guide
|
|
45
|
+
|
|
46
|
+
Here is an example of defining a handler using TeleKit:
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import telebot.types
|
|
50
|
+
import telekit
|
|
51
|
+
import typing
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class StartHandler(telekit.Handler):
|
|
55
|
+
|
|
56
|
+
# ------------------------------------------
|
|
57
|
+
# Initialization
|
|
58
|
+
# ------------------------------------------
|
|
59
|
+
|
|
60
|
+
@classmethod
|
|
61
|
+
def init_handler(cls, bot: telebot.TeleBot) -> None:
|
|
62
|
+
"""
|
|
63
|
+
Initializes the message handler for the '/start' command.
|
|
64
|
+
"""
|
|
65
|
+
@bot.message_handler(commands=['start'])
|
|
66
|
+
def handler(message: telebot.types.Message) -> None:
|
|
67
|
+
cls(message).handle()
|
|
68
|
+
|
|
69
|
+
# ------------------------------------------
|
|
70
|
+
# Handling Logic
|
|
71
|
+
# ------------------------------------------
|
|
72
|
+
|
|
73
|
+
def handle(self) -> None:
|
|
74
|
+
chain: telekit.Chain = self.get_chain()
|
|
75
|
+
|
|
76
|
+
chain.sender.set_title("Hello")
|
|
77
|
+
chain.sender.set_message("Welcome to the bot! Click the button below to start interacting.")
|
|
78
|
+
chain.sender.set_photo("https://static.wikia.nocookie.net/ssb-tourney/images/d/db/Bot_CG_Art.jpg/revision/latest?cb=20151224123450")
|
|
79
|
+
chain.sender.set_effect(chain.sender.Effect.PARTY)
|
|
80
|
+
|
|
81
|
+
def counter_factory() -> typing.Callable[[int], int]:
|
|
82
|
+
count = 0
|
|
83
|
+
def counter(value: int=1) -> int:
|
|
84
|
+
nonlocal count
|
|
85
|
+
count += value
|
|
86
|
+
return count
|
|
87
|
+
return counter
|
|
88
|
+
|
|
89
|
+
click_counter = counter_factory()
|
|
90
|
+
|
|
91
|
+
@chain.inline_keyboard({"⊕": 1, "⊖": -1}, row_width=2)
|
|
92
|
+
def _(message: telebot.types.Message, value: int) -> None:
|
|
93
|
+
chain.sender.set_message(f"You clicked {click_counter(value)} times")
|
|
94
|
+
chain.edit_previous_message()
|
|
95
|
+
chain.send()
|
|
96
|
+
|
|
97
|
+
chain.send()
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Chapters Example
|
|
103
|
+
|
|
104
|
+
TeleKit allows you to store large texts or structured information in `.txt` files and access them as Python dictionaries:
|
|
105
|
+
|
|
106
|
+
**`help.txt`**:
|
|
107
|
+
|
|
108
|
+
```txt
|
|
109
|
+
# intro
|
|
110
|
+
Welcome to TeleKit library. Here are the available commands:
|
|
111
|
+
|
|
112
|
+
# entry
|
|
113
|
+
/entry — Example command for handling input
|
|
114
|
+
|
|
115
|
+
# about
|
|
116
|
+
TeleKit is a general-purpose library for Python projects.
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Usage in Python:
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
import telekit
|
|
123
|
+
|
|
124
|
+
chapters: dict[str, str] = telekit.chapters.read("help.txt")
|
|
125
|
+
|
|
126
|
+
print(chapters["intro"])
|
|
127
|
+
# Output: "Welcome to TeleKit library. Here are the available commands:"
|
|
128
|
+
|
|
129
|
+
print(chapters["entry"])
|
|
130
|
+
# Output: "/entry — Example command for handling input"
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
This approach allows separating content from code and accessing text sections programmatically.
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Features
|
|
138
|
+
|
|
139
|
+
- Easy-to-use modular handlers and chains for structured project code.
|
|
140
|
+
- `Vault` for persistent storage of Python data structures in SQLite.
|
|
141
|
+
- `Chapters` for converting `.txt` files into Python dictionaries.
|
|
142
|
+
- Lightweight and minimal dependencies, fully compatible with Python 3.12 and higher.
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Getting Started With Server / Main.py
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
|
|
150
|
+
# Your server.py or main.py
|
|
151
|
+
|
|
152
|
+
import telebot
|
|
153
|
+
import telekit
|
|
154
|
+
|
|
155
|
+
from . import handlers # All your handlers
|
|
156
|
+
|
|
157
|
+
bot = telebot.TeleBot("TOKEN")
|
|
158
|
+
telekit.Server(bot).polling()
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
# Getting Started With Handlers
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
|
|
165
|
+
# handlers/start.py
|
|
166
|
+
|
|
167
|
+
import telebot.types
|
|
168
|
+
import telekit
|
|
169
|
+
import typing
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
class StartHandler(telekit.Handler):
|
|
173
|
+
|
|
174
|
+
# ------------------------------------------
|
|
175
|
+
# Initialization
|
|
176
|
+
# ------------------------------------------
|
|
177
|
+
|
|
178
|
+
@classmethod
|
|
179
|
+
def init_handler(cls, bot: telebot.TeleBot) -> None:
|
|
180
|
+
"""
|
|
181
|
+
Initializes the message handler for the '/start' command.
|
|
182
|
+
"""
|
|
183
|
+
@bot.message_handler(commands=['start'])
|
|
184
|
+
def handler(message: telebot.types.Message) -> None:
|
|
185
|
+
cls(message).handle()
|
|
186
|
+
|
|
187
|
+
# ------------------------------------------
|
|
188
|
+
# Handling Logic
|
|
189
|
+
# ------------------------------------------
|
|
190
|
+
|
|
191
|
+
def handle(self) -> None:
|
|
192
|
+
chain: telekit.Chain = self.get_chain()
|
|
193
|
+
|
|
194
|
+
chain.sender.set_title("Hello")
|
|
195
|
+
chain.sender.set_message("Welcome to the bot! Click the button below to start interacting.")
|
|
196
|
+
chain.sender.set_photo("https://static.wikia.nocookie.net/ssb-tourney/images/d/db/Bot_CG_Art.jpg/revision/latest?cb=20151224123450")
|
|
197
|
+
chain.sender.set_effect(chain.sender.Effect.PARTY)
|
|
198
|
+
|
|
199
|
+
def counter_factory() -> typing.Callable[[int], int]:
|
|
200
|
+
count = 0
|
|
201
|
+
def counter(value: int=1) -> int:
|
|
202
|
+
nonlocal count
|
|
203
|
+
count += value
|
|
204
|
+
return count
|
|
205
|
+
return counter
|
|
206
|
+
|
|
207
|
+
click_counter = counter_factory()
|
|
208
|
+
|
|
209
|
+
@chain.inline_keyboard({"⊕": 1, "⊖": -1}, row_width=2)
|
|
210
|
+
def _(message: telebot.types.Message, value: int) -> None:
|
|
211
|
+
chain.sender.set_message(f"You clicked {click_counter(value)} times")
|
|
212
|
+
chain.edit_previous_message()
|
|
213
|
+
chain.send()
|
|
214
|
+
|
|
215
|
+
chain.send()
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Developer ##
|
|
219
|
+
Telegram: [@TeleKitLib](https://t.me/TeleKitLib)
|
telekit-0.0.1/README.md
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# TeleKit Library
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
**TeleKit** is a Python library designed to simplify common tasks for developers working with Telegram bots or Python projects in general.
|
|
6
|
+
It provides tools for:
|
|
7
|
+
|
|
8
|
+
- Managing data with `Vault`, a lightweight interface for SQLite databases.
|
|
9
|
+
- Organizing and processing text data using `chapters`, which allows converting `.txt` files into Python dictionaries for easy access.
|
|
10
|
+
- Creating modular, reusable handlers and chains for structured code.
|
|
11
|
+
|
|
12
|
+
The library is designed to reduce boilerplate code and make Python development more efficient.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Quick Guide
|
|
17
|
+
|
|
18
|
+
Here is an example of defining a handler using TeleKit:
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
import telebot.types
|
|
22
|
+
import telekit
|
|
23
|
+
import typing
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class StartHandler(telekit.Handler):
|
|
27
|
+
|
|
28
|
+
# ------------------------------------------
|
|
29
|
+
# Initialization
|
|
30
|
+
# ------------------------------------------
|
|
31
|
+
|
|
32
|
+
@classmethod
|
|
33
|
+
def init_handler(cls, bot: telebot.TeleBot) -> None:
|
|
34
|
+
"""
|
|
35
|
+
Initializes the message handler for the '/start' command.
|
|
36
|
+
"""
|
|
37
|
+
@bot.message_handler(commands=['start'])
|
|
38
|
+
def handler(message: telebot.types.Message) -> None:
|
|
39
|
+
cls(message).handle()
|
|
40
|
+
|
|
41
|
+
# ------------------------------------------
|
|
42
|
+
# Handling Logic
|
|
43
|
+
# ------------------------------------------
|
|
44
|
+
|
|
45
|
+
def handle(self) -> None:
|
|
46
|
+
chain: telekit.Chain = self.get_chain()
|
|
47
|
+
|
|
48
|
+
chain.sender.set_title("Hello")
|
|
49
|
+
chain.sender.set_message("Welcome to the bot! Click the button below to start interacting.")
|
|
50
|
+
chain.sender.set_photo("https://static.wikia.nocookie.net/ssb-tourney/images/d/db/Bot_CG_Art.jpg/revision/latest?cb=20151224123450")
|
|
51
|
+
chain.sender.set_effect(chain.sender.Effect.PARTY)
|
|
52
|
+
|
|
53
|
+
def counter_factory() -> typing.Callable[[int], int]:
|
|
54
|
+
count = 0
|
|
55
|
+
def counter(value: int=1) -> int:
|
|
56
|
+
nonlocal count
|
|
57
|
+
count += value
|
|
58
|
+
return count
|
|
59
|
+
return counter
|
|
60
|
+
|
|
61
|
+
click_counter = counter_factory()
|
|
62
|
+
|
|
63
|
+
@chain.inline_keyboard({"⊕": 1, "⊖": -1}, row_width=2)
|
|
64
|
+
def _(message: telebot.types.Message, value: int) -> None:
|
|
65
|
+
chain.sender.set_message(f"You clicked {click_counter(value)} times")
|
|
66
|
+
chain.edit_previous_message()
|
|
67
|
+
chain.send()
|
|
68
|
+
|
|
69
|
+
chain.send()
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Chapters Example
|
|
75
|
+
|
|
76
|
+
TeleKit allows you to store large texts or structured information in `.txt` files and access them as Python dictionaries:
|
|
77
|
+
|
|
78
|
+
**`help.txt`**:
|
|
79
|
+
|
|
80
|
+
```txt
|
|
81
|
+
# intro
|
|
82
|
+
Welcome to TeleKit library. Here are the available commands:
|
|
83
|
+
|
|
84
|
+
# entry
|
|
85
|
+
/entry — Example command for handling input
|
|
86
|
+
|
|
87
|
+
# about
|
|
88
|
+
TeleKit is a general-purpose library for Python projects.
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Usage in Python:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
import telekit
|
|
95
|
+
|
|
96
|
+
chapters: dict[str, str] = telekit.chapters.read("help.txt")
|
|
97
|
+
|
|
98
|
+
print(chapters["intro"])
|
|
99
|
+
# Output: "Welcome to TeleKit library. Here are the available commands:"
|
|
100
|
+
|
|
101
|
+
print(chapters["entry"])
|
|
102
|
+
# Output: "/entry — Example command for handling input"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
This approach allows separating content from code and accessing text sections programmatically.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Features
|
|
110
|
+
|
|
111
|
+
- Easy-to-use modular handlers and chains for structured project code.
|
|
112
|
+
- `Vault` for persistent storage of Python data structures in SQLite.
|
|
113
|
+
- `Chapters` for converting `.txt` files into Python dictionaries.
|
|
114
|
+
- Lightweight and minimal dependencies, fully compatible with Python 3.12 and higher.
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## Getting Started With Server / Main.py
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
|
|
122
|
+
# Your server.py or main.py
|
|
123
|
+
|
|
124
|
+
import telebot
|
|
125
|
+
import telekit
|
|
126
|
+
|
|
127
|
+
from . import handlers # All your handlers
|
|
128
|
+
|
|
129
|
+
bot = telebot.TeleBot("TOKEN")
|
|
130
|
+
telekit.Server(bot).polling()
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
# Getting Started With Handlers
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
|
|
137
|
+
# handlers/start.py
|
|
138
|
+
|
|
139
|
+
import telebot.types
|
|
140
|
+
import telekit
|
|
141
|
+
import typing
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
class StartHandler(telekit.Handler):
|
|
145
|
+
|
|
146
|
+
# ------------------------------------------
|
|
147
|
+
# Initialization
|
|
148
|
+
# ------------------------------------------
|
|
149
|
+
|
|
150
|
+
@classmethod
|
|
151
|
+
def init_handler(cls, bot: telebot.TeleBot) -> None:
|
|
152
|
+
"""
|
|
153
|
+
Initializes the message handler for the '/start' command.
|
|
154
|
+
"""
|
|
155
|
+
@bot.message_handler(commands=['start'])
|
|
156
|
+
def handler(message: telebot.types.Message) -> None:
|
|
157
|
+
cls(message).handle()
|
|
158
|
+
|
|
159
|
+
# ------------------------------------------
|
|
160
|
+
# Handling Logic
|
|
161
|
+
# ------------------------------------------
|
|
162
|
+
|
|
163
|
+
def handle(self) -> None:
|
|
164
|
+
chain: telekit.Chain = self.get_chain()
|
|
165
|
+
|
|
166
|
+
chain.sender.set_title("Hello")
|
|
167
|
+
chain.sender.set_message("Welcome to the bot! Click the button below to start interacting.")
|
|
168
|
+
chain.sender.set_photo("https://static.wikia.nocookie.net/ssb-tourney/images/d/db/Bot_CG_Art.jpg/revision/latest?cb=20151224123450")
|
|
169
|
+
chain.sender.set_effect(chain.sender.Effect.PARTY)
|
|
170
|
+
|
|
171
|
+
def counter_factory() -> typing.Callable[[int], int]:
|
|
172
|
+
count = 0
|
|
173
|
+
def counter(value: int=1) -> int:
|
|
174
|
+
nonlocal count
|
|
175
|
+
count += value
|
|
176
|
+
return count
|
|
177
|
+
return counter
|
|
178
|
+
|
|
179
|
+
click_counter = counter_factory()
|
|
180
|
+
|
|
181
|
+
@chain.inline_keyboard({"⊕": 1, "⊖": -1}, row_width=2)
|
|
182
|
+
def _(message: telebot.types.Message, value: int) -> None:
|
|
183
|
+
chain.sender.set_message(f"You clicked {click_counter(value)} times")
|
|
184
|
+
chain.edit_previous_message()
|
|
185
|
+
chain.send()
|
|
186
|
+
|
|
187
|
+
chain.send()
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Developer ##
|
|
191
|
+
Telegram: [@TeleKitLib](https://t.me/TeleKitLib)
|
telekit-0.0.1/setup.cfg
ADDED
telekit-0.0.1/setup.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
def readme():
|
|
4
|
+
with open('README.md', 'r') as f:
|
|
5
|
+
return f.read()
|
|
6
|
+
|
|
7
|
+
setup(
|
|
8
|
+
name='telekit',
|
|
9
|
+
version='0.0.1',
|
|
10
|
+
author='romashka',
|
|
11
|
+
author_email='comfy6011@gmail.com',
|
|
12
|
+
description='This is the simplest module for making Telegram Bots.',
|
|
13
|
+
long_description=readme(),
|
|
14
|
+
long_description_content_type='text/markdown',
|
|
15
|
+
url='https://t.me/TeleKitLib',
|
|
16
|
+
packages=find_packages(),
|
|
17
|
+
install_requires=['pyTelegramBotAPI>=4.27.0'],
|
|
18
|
+
classifiers=[
|
|
19
|
+
'Programming Language :: Python :: 3.11',
|
|
20
|
+
'License :: OSI Approved :: MIT License',
|
|
21
|
+
'Operating System :: OS Independent'
|
|
22
|
+
],
|
|
23
|
+
keywords='files speedfiles ',
|
|
24
|
+
project_urls={
|
|
25
|
+
"Telegram": "https://t.me/TeleKitLib"
|
|
26
|
+
},
|
|
27
|
+
python_requires='>=3.12'
|
|
28
|
+
)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Copyright (c) 2025 Ving Studio, Romashka
|
|
2
|
+
# Licensed under the MIT License. See LICENSE file for full terms.
|
|
3
|
+
|
|
4
|
+
# engine/__init__.py
|
|
5
|
+
from .handler import Handler
|
|
6
|
+
from .chain import Chain
|
|
7
|
+
from .callback_query_handler import CallbackQueryHandler
|
|
8
|
+
from .server import Server, example
|
|
9
|
+
from .snapvault.snapvault import Vault # type: ignore
|
|
10
|
+
from .chapters import chapters
|
|
11
|
+
from .user import User
|
|
12
|
+
from . import senders
|
|
13
|
+
|
|
14
|
+
__all__ = ["senders", "Chain", "Handler", "CallbackQueryHandler", "Server", "Vault", "User", "chapters", "example"]
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
import telebot # type: ignore
|
|
4
|
+
from telebot.types import ( # type: ignore
|
|
5
|
+
Message,
|
|
6
|
+
InaccessibleMessage,
|
|
7
|
+
CallbackQuery
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class CallbackQueryHandler:
|
|
12
|
+
|
|
13
|
+
bot: telebot.TeleBot
|
|
14
|
+
|
|
15
|
+
@classmethod
|
|
16
|
+
def init(cls, bot: telebot.TeleBot):
|
|
17
|
+
"""
|
|
18
|
+
Initializes the bot instance for the class.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
bot (TeleBot): The Telegram bot instance to be used for sending messages.
|
|
22
|
+
"""
|
|
23
|
+
cls.bot = bot
|
|
24
|
+
|
|
25
|
+
@bot.callback_query_handler(func=lambda call: True) # type: ignore
|
|
26
|
+
def handle_callback(call: telebot.types.CallbackQuery) -> None: # type: ignore
|
|
27
|
+
CallbackQueryHandler().handle(call)
|
|
28
|
+
|
|
29
|
+
def handle(self, call: CallbackQuery):
|
|
30
|
+
self._simulate(call.message, str(call.data), from_user=call.from_user)
|
|
31
|
+
|
|
32
|
+
def _simulate(self, message: Message | InaccessibleMessage, text: str, from_user: Any=None) -> None:
|
|
33
|
+
args = {}
|
|
34
|
+
|
|
35
|
+
is_bot: bool = getattr(getattr(message, "from_user", from_user), "is_bot", False)
|
|
36
|
+
|
|
37
|
+
args["message_id"] = getattr(message, "message_id", None)
|
|
38
|
+
args["from_user"] = from_user if from_user else getattr(message, "from_user", None)
|
|
39
|
+
args["date"] = getattr(message, "date", None)
|
|
40
|
+
args["chat"] = getattr(message, "chat", None)
|
|
41
|
+
args["json_string"] = getattr(message, "json", None)
|
|
42
|
+
|
|
43
|
+
args["content_type"] = "text"
|
|
44
|
+
args["options"] = {}
|
|
45
|
+
|
|
46
|
+
if any(value is None for value in args.values()): # type: ignore
|
|
47
|
+
return print("Error: Missing required fields in message simulation.")
|
|
48
|
+
|
|
49
|
+
original_message = message
|
|
50
|
+
|
|
51
|
+
message = Message(**args) # type: ignore
|
|
52
|
+
message.message_thread_id = getattr(original_message, "message_thread_id", None)
|
|
53
|
+
message.text = text
|
|
54
|
+
|
|
55
|
+
if message.from_user:
|
|
56
|
+
message.from_user.is_bot = is_bot
|
|
57
|
+
|
|
58
|
+
self.bot.process_new_messages([message]) # type: ignore
|