diff --git a/LICENSE b/LICENSE index 1a99936..909d321 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,21 @@ -MIT License - -Copyright (c) 2020 PyMaster - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +MIT License + +Copyright (c) 2020 PyMaster + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the 'Software'), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 089ec1d..8c8901f 100644 --- a/README.md +++ b/README.md @@ -1 +1,221 @@ -# pykeyboard \ No newline at end of file +

+Pykeyboard +

+ +## Installation + +```shell +pip install pykeyboard +``` + +## Documentation + +### Inline Keyboard + +```python +from pykeyboard import InlineKeyboard +``` + +#### Inline Keyboard add buttons + +##### Code + +```python +from pykeyboard import InlineKeyboard +from pyrogram import InlineKeyboardButton + + +keyboard = InlineKeyboard(row_width=3) +keyboard.add( + InlineKeyboardButton('1', 'inline_keyboard#1'), + InlineKeyboardButton('2', 'inline_keyboard#2'), + InlineKeyboardButton('3', 'inline_keyboard#3'), + InlineKeyboardButton('4', 'inline_keyboard#4'), + InlineKeyboardButton('5', 'inline_keyboard#5'), + InlineKeyboardButton('6', 'inline_keyboard#6'), + InlineKeyboardButton('7', 'inline_keyboard#7') +) +``` + +##### Result + +

add_inline_button

+ +#### Inline Keyboard row buttons + +##### Code + +```python +from pykeyboard import InlineKeyboard +from pyrogram import InlineKeyboardButton + + +keyboard = InlineKeyboard() +keyboard.row(InlineKeyboardButton('1', 'inline_keyboard#1')) +keyboard.row( + InlineKeyboardButton('2', 'inline_keyboard#2'), + InlineKeyboardButton('3', 'inline_keyboard#3') +) +keyboard.row(InlineKeyboardButton('4', 'inline_keyboard#4')) +keyboard.row( + InlineKeyboardButton('5', 'inline_keyboard#5'), + InlineKeyboardButton('6', 'inline_keyboard#6') +) +``` + +##### Result + +

row_inline_button

+ +### Reply Keyboard + +```python +from pykeyboard import ReplyKeyboard +``` + +#### Reply Keyboard add buttons + +##### Code + +```python +from pykeyboard import ReplyKeyboard +from pyrogram import KeyboardButton + + +keyboard = ReplyKeyboard(row_width=3) +keyboard.add( + KeyboardButton('1', 'reply_keyboard#1'), + KeyboardButton('2', 'reply_keyboard#2'), + KeyboardButton('3', 'reply_keyboard#3'), + KeyboardButton('4', 'reply_keyboard#4'), + KeyboardButton('5', 'reply_keyboard#5'), +) +``` + +##### Result + +

add_reply_button

+ +#### Reply Keyboard row buttons + +##### Code + +```python +from pykeyboard import ReplyKeyboard +from pyrogram import KeyboardButton + + +keyboard = ReplyKeyboard() +keyboard.row(KeyboardButton('1', 'reply_keyboard#1')) +keyboard.row( + KeyboardButton('2', 'reply_keyboard#2'), + KeyboardButton('3', 'reply_keyboard#3') +) +keyboard.row(KeyboardButton('4', 'reply_keyboard#4')) +keyboard.row(KeyboardButton('5', 'reply_keyboard#5')) +``` + +##### Result + +

row_reply_button

+ +### Pagination inline keyboard + +```python +from pykeyboard import InlinePaginationKeyboard +``` + +#### Pagination 3 pages + +##### Code + +```python +from pykeyboard import InlinePaginationKeyboard + + +keyboard = InlinePaginationKeyboard(3, 3, 'pagination_keyboard#{number}') +``` + +##### Result + +

pagination_keyboard_3

+ +#### Pagination 5 pages + +##### Code + +```python +from pykeyboard import InlinePaginationKeyboard + + +keyboard = InlinePaginationKeyboard(5, 3, 'pagination_keyboard#{number}') +``` + +##### Result + +

pagination_keyboard_5

+ +#### Pagination 9 pages + +##### Code + +```python +from pykeyboard import InlinePaginationKeyboard + + +keyboard = InlinePaginationKeyboard(9, 5, 'pagination_keyboard#{number}') +``` + +##### Result + +

pagination_keyboard_9

+ +#### Pagination 25 pages + +##### Code + +```python +from pykeyboard import InlinePaginationKeyboard + + +keyboard = InlinePaginationKeyboard(25, 14, 'pagination_keyboard#{number}') +``` + +##### Result + +

pagination_keyboard_25

+ +#### Pagination 100 pages + +##### Code + +```python +from pykeyboard import InlinePaginationKeyboard + + +keyboard = InlinePaginationKeyboard(100, 100, 'pagination_keyboard#{number}') +``` + +##### Result + +

pagination_keyboard_100

+ +#### Pagination 150 pages and buttons + +##### Code + +```python +from pykeyboard import InlinePaginationKeyboard +from pyrogram import InlineKeyboardButton + + +keyboard = InlinePaginationKeyboard(150, 123, 'pagination_keyboard#{number}') +keyboard.row( + InlineKeyboardButton('Back', 'pagination_keyboard#back'), + InlineKeyboardButton('Close', 'pagination_keyboard#close') +) +``` + +##### Result + +

pagination_keyboard_150

diff --git a/examples/LICENSE b/examples/LICENSE new file mode 100644 index 0000000..909d321 --- /dev/null +++ b/examples/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 PyMaster + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the 'Software'), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..1c55c04 --- /dev/null +++ b/examples/README.md @@ -0,0 +1 @@ +# Example: Telegram Pyrogram bot \ No newline at end of file diff --git a/examples/bot/__init__.py b/examples/bot/__init__.py new file mode 100644 index 0000000..4b4da42 --- /dev/null +++ b/examples/bot/__init__.py @@ -0,0 +1,20 @@ +from .config import (SESSION_NAME, API_ID, API_HASH, + BOT_TOKEN, APP_PLUGINS) +from pyrogram import Client + + +class App(Client): + def __init__(self): + super().__init__( + session_name=SESSION_NAME, + api_id=API_ID, + api_hash=API_HASH, + bot_token=BOT_TOKEN, + plugins=dict(root=APP_PLUGINS) + ) + + def start(self, *args): + super().start() + + def stop(self, *args): + super().stop() diff --git a/examples/bot/__main__.py b/examples/bot/__main__.py new file mode 100644 index 0000000..630467e --- /dev/null +++ b/examples/bot/__main__.py @@ -0,0 +1,5 @@ +from . import App + + +if __name__ == '__main__': + App().run() diff --git a/examples/bot/config.py b/examples/bot/config.py new file mode 100644 index 0000000..170d1ce --- /dev/null +++ b/examples/bot/config.py @@ -0,0 +1,5 @@ +SESSION_NAME = 'bot' +API_ID = '' # https://my.telegram.org/ +API_HASH = '' # https://my.telegram.org/ +BOT_TOKEN = '' # @BotFather +APP_PLUGINS = 'bot/modules' diff --git a/examples/bot/modules/inline_keyboard.py b/examples/bot/modules/inline_keyboard.py new file mode 100644 index 0000000..e6feb66 --- /dev/null +++ b/examples/bot/modules/inline_keyboard.py @@ -0,0 +1,70 @@ +from .. import App +from pykeyboard import InlineKeyboard +from pyrogram import Filters, InlineKeyboardButton + + +@App.on_message(Filters.command('inline_keyboard')) +def inline_keyboard_command(client, message): + message.reply_text( + 'Inline keyboard:\n\n' + '/add_inline_button - add buttons\n' + '/row_inline_button - add button row\n' + ) + + +@App.on_message(Filters.command('add_inline_button')) +def add_inline_button_command(client, message): + keyboard = InlineKeyboard(row_width=3) + keyboard.add( + InlineKeyboardButton('1', 'inline_keyboard#1'), + InlineKeyboardButton('2', 'inline_keyboard#2'), + InlineKeyboardButton('3', 'inline_keyboard#3'), + InlineKeyboardButton('4', 'inline_keyboard#4'), + InlineKeyboardButton('5', 'inline_keyboard#5'), + InlineKeyboardButton('6', 'inline_keyboard#6'), + InlineKeyboardButton('7', 'inline_keyboard#7') + ) + message.reply_text( + 'Add buttons:\n\n' + 'keyboard = InlineKeyboard(row_width=3)\n' + 'keyboard.add(\n' + " InlineKeyboardButton('1', 'inline_keyboard#1'),\n" + " InlineKeyboardButton('2', 'inline_keyboard#2'),\n" + " InlineKeyboardButton('3', 'inline_keyboard#3'),\n" + " InlineKeyboardButton('4', 'inline_keyboard#4'),\n" + " InlineKeyboardButton('5', 'inline_keyboard#5'),\n" + " InlineKeyboardButton('6', 'inline_keyboard#6'),\n" + " InlineKeyboardButton('7', 'inline_keyboard#7')\n" + ')\n', + reply_markup=keyboard + ) + + +@App.on_message(Filters.command('row_inline_button')) +def row_inline_button_command(client, message): + keyboard = InlineKeyboard() + keyboard.row(InlineKeyboardButton('1', 'inline_keyboard#1')) + keyboard.row( + InlineKeyboardButton('2', 'inline_keyboard#2'), + InlineKeyboardButton('3', 'inline_keyboard#3') + ) + keyboard.row(InlineKeyboardButton('4', 'inline_keyboard#4')) + keyboard.row( + InlineKeyboardButton('5', 'inline_keyboard#5'), + InlineKeyboardButton('6', 'inline_keyboard#6') + ) + message.reply_text( + 'Add button row:\n\n' + "keyboard = InlineKeyboard()\n" + "keyboard.row(InlineKeyboardButton('1', 'inline_keyboard#1'))\n" + "keyboard.row(\n" + " InlineKeyboardButton('2', 'inline_keyboard#2'),\n" + " InlineKeyboardButton('3', 'inline_keyboard#3')\n" + ")\n" + "keyboard.row(InlineKeyboardButton('4', 'inline_keyboard#4'))\n" + "keyboard.row(\n" + " InlineKeyboardButton('5', 'inline_keyboard#5'),\n" + " InlineKeyboardButton('6', 'inline_keyboard#6')\n" + ")\n", + reply_markup=keyboard + ) diff --git a/examples/bot/modules/install.py b/examples/bot/modules/install.py new file mode 100644 index 0000000..17d6f5e --- /dev/null +++ b/examples/bot/modules/install.py @@ -0,0 +1,10 @@ +from .. import App +from pyrogram import Filters + + +@App.on_message(Filters.command('install')) +def install_command(client, message): + message.reply_text( + 'Installation:\n\n' + 'pip install -U pykeyboard' + ) diff --git a/examples/bot/modules/pagination_keyboard.py b/examples/bot/modules/pagination_keyboard.py new file mode 100644 index 0000000..24a0686 --- /dev/null +++ b/examples/bot/modules/pagination_keyboard.py @@ -0,0 +1,86 @@ +from .. import App +from pyrogram import Filters, InlineKeyboardButton +from pykeyboard import InlinePaginationKeyboard + + +TEXT = 'sed risus pretium quam vulputate dignissim suspendisse in est ante in nibh mauris cursus mattis molestie a iaculis at erat pellentesque adipiscing commodo elit at imperdiet dui accumsan sit amet nulla facilisi morbi tempus iaculis urna id volutpat lacus laoreet non curabitur gravida arcu ac tortor dignissim convallis aenean et' + + +@App.on_message(Filters.command('pagination_keyboard')) +def pagination_keyboard_command(client, message): + message.reply_text( + 'Pagination inline keyboard:\n\n' + '/pagination_keyboard_3 - 3 pages\n' + '/pagination_keyboard_5 - 5 pages\n' + '/pagination_keyboard_9 - 9 pages\n' + '/pagination_keyboard_25 - 25 pages\n' + '/pagination_keyboard_100 - 100 pages\n' + '/pagination_keyboard_150 - 150 page and buttons' + ) + + +@App.on_message(Filters.command('pagination_keyboard_3')) +def pagination_keyboard_3_command(client, message): + keyboard = InlinePaginationKeyboard(3, 3, 'pagination_keyboard#{number}') + + message.reply_text( + f'3 page pagination:\n\n {TEXT}', + reply_markup=keyboard + ) + + +@App.on_message(Filters.command('pagination_keyboard_5')) +def pagination_keyboard_5_command(client, message): + keyboard = InlinePaginationKeyboard(5, 3, 'pagination_keyboard#{number}') + + message.reply_text( + f'5 page pagination:\n\n {TEXT}', + reply_markup=keyboard + ) + + +@App.on_message(Filters.command('pagination_keyboard_9')) +def pagination_keyboard_9_command(client, message): + keyboard = InlinePaginationKeyboard(9, 5, 'pagination_keyboard#{number}') + + message.reply_text( + f'9 page pagination:\n\n {TEXT}', + reply_markup=keyboard + ) + + +@App.on_message(Filters.command('pagination_keyboard_25')) +def pagination_keyboard_25_command(client, message): + keyboard = InlinePaginationKeyboard( + 25, 14, 'pagination_keyboard#{number}') + + message.reply_text( + f'25 page pagination:\n\n {TEXT}', + reply_markup=keyboard + ) + + +@App.on_message(Filters.command('pagination_keyboard_100')) +def pagination_keyboard_100_command(client, message): + keyboard = InlinePaginationKeyboard( + 100, 100, 'pagination_keyboard#{number}') + + message.reply_text( + f'100 page pagination:\n\n {TEXT}', + reply_markup=keyboard + ) + + +@App.on_message(Filters.command('pagination_keyboard_150')) +def pagination_keyboard_150_command(client, message): + keyboard = InlinePaginationKeyboard( + 150, 123, 'pagination_keyboard#{number}') + keyboard.row( + InlineKeyboardButton('Back', 'pagination_keyboard#back'), + InlineKeyboardButton('Close', 'pagination_keyboard#close') + ) + + message.reply_text( + f'150 page pagination and buttons:\n\n {TEXT}', + reply_markup=keyboard + ) diff --git a/examples/bot/modules/reply_keyboard.py b/examples/bot/modules/reply_keyboard.py new file mode 100644 index 0000000..c253af8 --- /dev/null +++ b/examples/bot/modules/reply_keyboard.py @@ -0,0 +1,60 @@ +from .. import App +from pykeyboard import ReplyKeyboard +from pyrogram import Filters, KeyboardButton + + +@App.on_message(Filters.command('reply_keyboard')) +def reply_keyboard_command(client, message): + message.reply_text( + 'Reply keyboard:\n\n' + '/add_reply_button - add buttons\n' + '/row_reply_button - add button row\n' + ) + + +@App.on_message(Filters.command('add_reply_button')) +def add_reply_button_command(client, message): + keyboard = ReplyKeyboard(row_width=3) + keyboard.add( + KeyboardButton('1', 'reply_keyboard#1'), + KeyboardButton('2', 'reply_keyboard#2'), + KeyboardButton('3', 'reply_keyboard#3'), + KeyboardButton('4', 'reply_keyboard#4'), + KeyboardButton('5', 'reply_keyboard#5'), + ) + message.reply_text( + 'Add buttons:\n\n' + 'keyboard = ReplyKeyboard(row_width=3)\n' + 'keyboard.add(\n' + " KeyboardButton('1', 'reply_keyboard#1'),\n" + " KeyboardButton('2', 'reply_keyboard#2'),\n" + " KeyboardButton('3', 'reply_keyboard#3'),\n" + " KeyboardButton('4', 'reply_keyboard#4'),\n" + " KeyboardButton('5', 'reply_keyboard#5'),\n" + ')\n', + reply_markup=keyboard + ) + + +@App.on_message(Filters.command('row_reply_button')) +def row_reply_button_command(client, message): + keyboard = ReplyKeyboard() + keyboard.row(KeyboardButton('1', 'reply_keyboard#1')) + keyboard.row( + KeyboardButton('2', 'reply_keyboard#2'), + KeyboardButton('3', 'reply_keyboard#3') + ) + keyboard.row(KeyboardButton('4', 'reply_keyboard#4')) + keyboard.row(KeyboardButton('5', 'reply_keyboard#5')) + message.reply_text( + 'Add button row:\n\n' + "keyboard = ReplyKeyboard()\n" + "keyboard.row(KeyboardButton('1', 'reply_keyboard#1'))\n" + "keyboard.row(\n" + " KeyboardButton('2', 'reply_keyboard#2'),\n" + " KeyboardButton('3', 'reply_keyboard#3')\n" + ")\n" + "keyboard.row(KeyboardButton('4', 'reply_keyboard#4'))\n" + "keyboard.row(KeyboardButton('5', 'reply_keyboard#5'))\n", + reply_markup=keyboard + ) diff --git a/examples/bot/modules/start.py b/examples/bot/modules/start.py new file mode 100644 index 0000000..06bb914 --- /dev/null +++ b/examples/bot/modules/start.py @@ -0,0 +1,15 @@ +from .. import App +from pyrogram import Filters + + +@App.on_message(Filters.command(['start', 'help'])) +def start_command(client, message): + message.reply_text( + f'Welcome {message.from_user.first_name}!\n\n' + 'I will help you learn how to wrk with the pykeyboard library.\n\n' + 'Library features:\n\n' + '/install - library installation\n' + '/inline_keyboard - inline keyboard\n' + '/pagination_keyboard - pagination inline keyboard\n' + '/reply_keyboard - reply keyboard' + ) \ No newline at end of file diff --git a/pykeyboard/__init__.py b/pykeyboard/__init__.py new file mode 100644 index 0000000..40b561f --- /dev/null +++ b/pykeyboard/__init__.py @@ -0,0 +1,3 @@ +from .inline_keyboard import InlineKeyboard +from .inline_pagination_keyboard import InlinePaginationKeyboard +from .reply_keyboard import ReplyKeyboard diff --git a/pykeyboard/inline_keyboard.py b/pykeyboard/inline_keyboard.py new file mode 100644 index 0000000..b17b68c --- /dev/null +++ b/pykeyboard/inline_keyboard.py @@ -0,0 +1,17 @@ +from pyrogram import InlineKeyboardMarkup + + +class InlineKeyboard(InlineKeyboardMarkup): + def __init__(self, row_width=3): + self.inline_keyboard = list() + super().__init__(inline_keyboard=self.inline_keyboard) + self.row_width = row_width + + def add(self, *args): + self.inline_keyboard = [ + args[i:i + self.row_width] + for i in range(0, len(args), self.row_width) + ] + + def row(self, *args): + self.inline_keyboard.append([button for button in args]) diff --git a/pykeyboard/inline_pagination_keyboard.py b/pykeyboard/inline_pagination_keyboard.py new file mode 100644 index 0000000..bf2f11e --- /dev/null +++ b/pykeyboard/inline_pagination_keyboard.py @@ -0,0 +1,101 @@ +from pyrogram import InlineKeyboardMarkup, InlineKeyboardButton + + +class InlinePaginationKeyboard(InlineKeyboardMarkup): + SYMBOL_FIRST_PAGE = '« {}' + SYMBOL_PREVIOUS_PAGE = '‹ {}' + SYMBOL_CURRENT_PAGE = '· {} ·' + SYMBOL_NEXT_PAGE = '{} ›' + SYMBOL_LAST_PAGE = '{} »' + + def __init__(self, count_pages: int, current_page: int, + callback_pattern: str): + self.inline_keyboard = list() + super().__init__(inline_keyboard=self.inline_keyboard) + self.count_pages = count_pages + self.current_page = current_page + self.callback_pattern = callback_pattern + self.markup + + def add_button(self, text, callback_data): + return InlineKeyboardButton( + text=text, + callback_data=self.callback_pattern.format( + number=callback_data) + ) + + @property + def left_pagination(self): + return [ + self.add_button( + self.SYMBOL_CURRENT_PAGE.format(number), number) + if number == self.current_page else self.add_button( + self.SYMBOL_NEXT_PAGE.format(number), number) + if number == 4 else self.add_button( + self.SYMBOL_LAST_PAGE.format(self.count_pages), + self.count_pages) + if number == 5 else self.add_button(number, number) + for number in range(1, 6) + ] + + @property + def middle__pagination(self): + return [ + self.add_button( + self.SYMBOL_FIRST_PAGE.format(1), 1), + self.add_button( + self.SYMBOL_PREVIOUS_PAGE.format(self.current_page - 1), + self.current_page - 1), + self.add_button( + self.SYMBOL_CURRENT_PAGE.format(self.current_page), + self.current_page), + self.add_button( + self.SYMBOL_NEXT_PAGE.format(self.current_page + 1), + self.current_page + 1), + self.add_button( + self.SYMBOL_LAST_PAGE.format(self.count_pages), + self.count_pages), + ] + + @property + def right_pagination(self): + return [ + self.add_button( + self.SYMBOL_FIRST_PAGE.format(1), 1), + self.add_button( + self.SYMBOL_PREVIOUS_PAGE.format(self.count_pages - 3), + self.count_pages - 3) + ] + [ + self.add_button( + self.SYMBOL_CURRENT_PAGE.format(number), number) + if number == self.current_page else self.add_button(number, number) + for number in range(self.count_pages - 2, self.count_pages + 1) + ] + + @property + def full_pagination(self): + return [ + self.add_button(number, number) + if number != self.current_page else self.add_button( + self.SYMBOL_CURRENT_PAGE.format(number), number) + for number in range(1, self.count_pages + 1) + ] + + @property + def build_pagination(self): + if self.count_pages <= 5: + return self.full_pagination + else: + if self.current_page <= 3: + return self.left_pagination + elif self.current_page > self.count_pages - 3: + return self.right_pagination + else: + return self.middle__pagination + + def row(self, *args): + self.inline_keyboard.append([button for button in args]) + + @property + def markup(self): + self.inline_keyboard.append(self.build_pagination) diff --git a/pykeyboard/reply_keyboard.py b/pykeyboard/reply_keyboard.py new file mode 100644 index 0000000..a24dcb5 --- /dev/null +++ b/pykeyboard/reply_keyboard.py @@ -0,0 +1,23 @@ +from pyrogram import ReplyKeyboardMarkup + + +class ReplyKeyboard(ReplyKeyboardMarkup): + def __init__(self, resize_keyboard=None, one_time_keyboard=None, + selective=None, row_width=3): + self.keyboard = list() + super().__init__( + keyboard=self.keyboard, + resize_keyboard=resize_keyboard, + one_time_keyboard=one_time_keyboard, + selective=selective + ) + self.row_width = row_width + + def add(self, *args): + self.keyboard = [ + args[i:i + self.row_width] + for i in range(0, len(args), self.row_width) + ] + + def row(self, *args): + self.keyboard.append([button for button in args]) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..5076161 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +pyrogram +tgcrypto \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..b1c0769 --- /dev/null +++ b/setup.py @@ -0,0 +1,35 @@ +from os import path +from setuptools import setup + + +this_directory = path.abspath(path.dirname(__file__)) +with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f: + long_description = f.read() + +setup( + name='pykeyboard', + version='0.1.0', + author='PyMaster', + author_email='', + description='Best Keyboard and Pagination for the Pyrogram Library.', + license='MIT', + classifiers=[ + 'Programming Language :: Python', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Topic :: Internet', + 'Topic :: Communications', + 'Topic :: Communications :: Chat', + 'Topic :: Software Development :: Libraries', + 'Topic :: Software Development :: Libraries :: Python Modules' + ], + keywords='telegram pyrogram keyboard bot userbot', + url='https://github.com/pystorage/pykeyboard', + packages=['pykeyboard'], + install_requires=['pyrogram', 'tgcrypto'], + long_description=long_description, + long_description_content_type='text/markdown', +)