telegram-inline-keyboard-builder 1.0.0__py3-none-any.whl

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.
adapters/__init__.py ADDED
File without changes
@@ -0,0 +1,16 @@
1
+ from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
2
+
3
+
4
+ class AiogramInlineAdapter:
5
+ def create_callback(self, text, data, hide=False):
6
+ return InlineKeyboardButton(text=text, callback_data=data)
7
+
8
+ def create_url(self, text, url, hide=False):
9
+ return InlineKeyboardButton(text=text, url=url)
10
+
11
+ def create_pay(self, text, hide=False):
12
+ return InlineKeyboardButton(text=text, pay=True)
13
+
14
+ def build_keyboard(self, rows):
15
+ keyboard = InlineKeyboardMarkup(inline_keyboard=rows)
16
+ return keyboard
@@ -0,0 +1,15 @@
1
+ from telegram import InlineKeyboardButton, InlineKeyboardMarkup
2
+
3
+
4
+ class PTBInlineAdapter:
5
+ def create_callback(self, text, data, hide=False):
6
+ return InlineKeyboardButton(text=text, callback_data=data)
7
+
8
+ def create_url(self, text, url, hide=False):
9
+ return InlineKeyboardButton(text=text, url=url)
10
+
11
+ def create_pay(self, text, hide=False):
12
+ return InlineKeyboardButton(text=text, pay=True)
13
+
14
+ def build_keyboard(self, rows):
15
+ return InlineKeyboardMarkup(rows)
@@ -0,0 +1,15 @@
1
+ from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
2
+
3
+
4
+ class PyrogramInlineAdapter:
5
+ def create_callback(self, text, data, hide=False):
6
+ return InlineKeyboardButton(text=text, callback_data=data)
7
+
8
+ def create_url(self, text, url, hide=False):
9
+ return InlineKeyboardButton(text=text, url=url)
10
+
11
+ def create_pay(self, text, hide=False):
12
+ return InlineKeyboardButton(text=text, pay=True)
13
+
14
+ def build_keyboard(self, rows):
15
+ return InlineKeyboardMarkup(rows)
builders/__init__.py ADDED
File without changes
@@ -0,0 +1,11 @@
1
+ from core.inline_keyboard_builder import InlineKeyboardBuilder
2
+ from adapters.aiogram_adapter import AiogramInlineAdapter
3
+
4
+
5
+ class InlineKeyboardAiogram(InlineKeyboardBuilder):
6
+ def __init__(self, buttons_per_row=2, auto_wrap_max_chars=0):
7
+ super().__init__(
8
+ AiogramInlineAdapter(),
9
+ buttons_per_row,
10
+ auto_wrap_max_chars
11
+ )
@@ -0,0 +1,11 @@
1
+ from core.inline_keyboard_builder import InlineKeyboardBuilder
2
+ from adapters.ptb_adapter import PTBInlineAdapter
3
+
4
+
5
+ class InlineKeyboardPTB(InlineKeyboardBuilder):
6
+ def __init__(self, buttons_per_row=2, auto_wrap_max_chars=0):
7
+ super().__init__(
8
+ PTBInlineAdapter(),
9
+ buttons_per_row,
10
+ auto_wrap_max_chars
11
+ )
@@ -0,0 +1,10 @@
1
+ from core.inline_keyboard_builder import InlineKeyboardBuilder
2
+ from adapters.pyrogram_adapter import PyrogramInlineAdapter
3
+
4
+
5
+ class InlineKeyboardPyrogram(InlineKeyboardBuilder):
6
+ def __init__(self, buttons_per_row=2, auto_wrap_max_chars=0):
7
+ super().__init__(PyrogramInlineAdapter(), buttons_per_row, auto_wrap_max_chars)
8
+ ow,
9
+ auto_wrap_max_chars
10
+ )
@@ -0,0 +1,69 @@
1
+ class InlineKeyboardBuilder:
2
+ def __init__(self, adapter, buttons_per_row=2, auto_wrap_max_chars=0):
3
+ if adapter is None:
4
+ raise ValueError("Adapter is required")
5
+
6
+ self.adapter = adapter
7
+ self.buttons_per_row = buttons_per_row
8
+ self.auto_wrap_max_chars = auto_wrap_max_chars
9
+ self._buttons = []
10
+
11
+ def _push(self, btn):
12
+ self._buttons.append(btn)
13
+ return self
14
+
15
+ def add_callback_button(self, text, data, hide=False):
16
+ return self._push(self.adapter.create_callback(text, data, hide))
17
+
18
+ def add_url_button(self, text, url, hide=False):
19
+ return self._push(self.adapter.create_url(text, url, hide))
20
+
21
+ def add_pay_button(self, text, hide=False):
22
+ return self._push(self.adapter.create_pay(text, hide))
23
+
24
+ def add_custom_button(self, btn):
25
+ return self._push(btn)
26
+
27
+ def new_row(self):
28
+ self._buttons.append({"__new_row": True})
29
+ return self
30
+
31
+ def _layout(self):
32
+ rows = []
33
+ row = []
34
+ row_chars = 0
35
+
36
+ def push_row():
37
+ nonlocal row, row_chars
38
+ if row:
39
+ rows.append(row)
40
+ row = []
41
+ row_chars = 0
42
+
43
+ for btn in self._buttons:
44
+ if isinstance(btn, dict) and btn.get("__new_row"):
45
+ push_row()
46
+ continue
47
+
48
+ text = getattr(btn, "text", "") or btn.get("text", "")
49
+ length = len(str(text))
50
+
51
+ if (
52
+ self.auto_wrap_max_chars > 0
53
+ and row
54
+ and row_chars + length > self.auto_wrap_max_chars
55
+ ):
56
+ push_row()
57
+
58
+ if len(row) >= self.buttons_per_row:
59
+ push_row()
60
+
61
+ row.append(btn)
62
+ row_chars += length
63
+
64
+ push_row()
65
+ return rows
66
+
67
+ def build(self):
68
+ rows = self._layout()
69
+ return self.adapter.build_keyboard(rows)
core/__init__.py ADDED
File without changes
@@ -0,0 +1,28 @@
1
+ Metadata-Version: 2.4
2
+ Name: telegram-inline-keyboard-builder
3
+ Version: 1.0.0
4
+ Summary: Library-agnostic inline keyboard builder for Telegram bots (Aiogram, Pyrogram, python-telegram-bot).
5
+ Author-email: neoncraftx <neoncraftx@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/neoncraftx/telegram-inline-keyboard-builder
8
+ Project-URL: Repository, https://github.com/neoncraftx/telegram-inline-keyboard-builder
9
+ Project-URL: Issues, https://github.com/neoncraftx/telegram-inline-keyboard-builder/issues
10
+ Keywords: telegram,telegram-bot,inline-keyboard,aiogram,pyrogram,python-telegram-bot,builder,adapter
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Topic :: Software Development :: Libraries
16
+ Classifier: Topic :: Communications :: Chat
17
+ Requires-Python: >=3.8
18
+ Description-Content-Type: text/markdown
19
+ Provides-Extra: aiogram
20
+ Requires-Dist: aiogram>=3.0; extra == "aiogram"
21
+ Provides-Extra: pyrogram
22
+ Requires-Dist: pyrogram>=2.0; extra == "pyrogram"
23
+ Provides-Extra: ptb
24
+ Requires-Dist: python-telegram-bot>=20.0; extra == "ptb"
25
+ Provides-Extra: all
26
+ Requires-Dist: aiogram>=3.0; extra == "all"
27
+ Requires-Dist: pyrogram>=2.0; extra == "all"
28
+ Requires-Dist: python-telegram-bot>=20.0; extra == "all"
@@ -0,0 +1,14 @@
1
+ adapters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ adapters/aiogram_adapter.py,sha256=VZDCJhMzOF4IT7ZihJgf4740gxB5e1uIi6c078oWLGM,551
3
+ adapters/ptb_adapter.py,sha256=KKp5VuUU5srVGFQt_b8WuHNwLHpofS3SdCKD0V4k-7I,498
4
+ adapters/pyrogram_adapter.py,sha256=ZlQjMaArkAc63_SwY48x3o6fh_EJ0C9zd6hBdD4Dd-w,510
5
+ builders/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ builders/inline_keyboard_aiogram.py,sha256=6igGXEr5fNtwtJbHlNQ4tID-TDmkI2G9Li4n2MnkBmk,373
7
+ builders/inline_keyboard_ptb.py,sha256=vjmT9VfD7FLT1L_x0DHkL69Xe3ScRGyYraS4PIN7mU4,357
8
+ builders/inline_keyboard_pyrogram.py,sha256=oTLIMMcMQDS6RVxeTk4MqUMrG9T3uFVyJeIYm6A_l-w,377
9
+ core/InlineKeyboardBuilder.py,sha256=e-r7_iX6l9fjXPjjn1RkYLDvIUEqcG8nfWA0r3hRCZg,1935
10
+ core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ telegram_inline_keyboard_builder-1.0.0.dist-info/METADATA,sha256=EqCT6AMMkrXZfvYmI1sBP-LmwrpEGM95dX7LSvXwVjA,1367
12
+ telegram_inline_keyboard_builder-1.0.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
13
+ telegram_inline_keyboard_builder-1.0.0.dist-info/top_level.txt,sha256=LD4IrvpounC3LzXgWttOJB879WpmTOvXqYY8YZjxzjU,23
14
+ telegram_inline_keyboard_builder-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.10.2)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,3 @@
1
+ adapters
2
+ builders
3
+ core