From 16e6a1ba67699c3f762563c1624d49a9df9d3385 Mon Sep 17 00:00:00 2001 From: PyMaster <59120866+pystorage@users.noreply.github.com> Date: Sun, 9 Jan 2022 00:21:24 +0300 Subject: [PATCH] Add files via upload --- README.md | 76 +++++++++++------------- pykeyboard/__init__.py | 13 ++-- pykeyboard/inline_keyboard.py | 16 +++++ pykeyboard/inline_pagination_keyboard.py | 16 +++++ pykeyboard/reply_keyboard.py | 22 ++++++- setup.py | 3 +- 6 files changed, 97 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index c921ca9..6144bc2 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ # What's new? - Added a new method to InlineKeyboard for working with pagination. The InlinePaginationKeyboard class will be removed in a future version. +- Overriding the KeyboardButton, ReplyKeyboardRemove, ForceReply, InlineKeyboardButton methods in ReplyButton, ReplyKeyboardRemove, ForceReply, InlineButton. # Installation @@ -54,19 +55,18 @@ from pykeyboard import InlineKeyboard #### Code ```python -from pykeyboard import InlineKeyboard -from pyrogram.types import InlineKeyboardButton +from pykeyboard import InlineKeyboard, InlineButton 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') + InlineButton('1', 'inline_keyboard:1'), + InlineButton('2', 'inline_keyboard:2'), + InlineButton('3', 'inline_keyboard:3'), + InlineButton('4', 'inline_keyboard:4'), + InlineButton('5', 'inline_keyboard:5'), + InlineButton('6', 'inline_keyboard:6'), + InlineButton('7', 'inline_keyboard:7') ) ``` @@ -79,20 +79,19 @@ keyboard.add( #### Code ```python -from pykeyboard import InlineKeyboard -from pyrogram.types import InlineKeyboardButton +from pykeyboard import InlineKeyboard, InlineButton keyboard = InlineKeyboard() -keyboard.row(InlineKeyboardButton('1', 'inline_keyboard#1')) +keyboard.row(InlineButton('1', 'inline_keyboard:1')) keyboard.row( - InlineKeyboardButton('2', 'inline_keyboard#2'), - InlineKeyboardButton('3', 'inline_keyboard#3') + InlineButton('2', 'inline_keyboard:2'), + InlineButton('3', 'inline_keyboard:3') ) -keyboard.row(InlineKeyboardButton('4', 'inline_keyboard#4')) +keyboard.row(InlineButton('4', 'inline_keyboard:4')) keyboard.row( - InlineKeyboardButton('5', 'inline_keyboard#5'), - InlineKeyboardButton('6', 'inline_keyboard#6') + InlineButton('5', 'inline_keyboard:5'), + InlineButton('6', 'inline_keyboard:6') ) ``` @@ -120,7 +119,7 @@ from pykeyboard import InlineKeyboard from pykeyboard import InlineKeyboard keyboard = InlineKeyboard() -keyboard.paginate(3, 3, 'pagination_keyboard#{number}') +keyboard.paginate(3, 3, 'pagination_keyboard:{number}') ``` #### Result @@ -135,7 +134,7 @@ keyboard.paginate(3, 3, 'pagination_keyboard#{number}') from pykeyboard import InlineKeyboard keyboard = InlineKeyboard() -keyboard.paginate(5, 3, 'pagination_keyboard#{number}') +keyboard.paginate(5, 3, 'pagination_keyboard:{number}') ``` #### Result @@ -150,7 +149,7 @@ keyboard.paginate(5, 3, 'pagination_keyboard#{number}') from pykeyboard import InlineKeyboard keyboard = InlineKeyboard() -keyboard.paginate(9, 5, 'pagination_keyboard#{number}') +keyboard.paginate(9, 5, 'pagination_keyboard:{number}') ``` #### Result @@ -165,7 +164,7 @@ keyboard.paginate(9, 5, 'pagination_keyboard#{number}') from pykeyboard import InlineKeyboard keyboard = InlineKeyboard() -keyboard.paginate(100, 100, 'pagination_keyboard#{number}') +keyboard.paginate(100, 100, 'pagination_keyboard:{number}') ``` #### Result @@ -177,14 +176,13 @@ keyboard.paginate(100, 100, 'pagination_keyboard#{number}') #### Code ```python -from pykeyboard import InlineKeyboard -from pyrogram.types import InlineKeyboardButton +from pykeyboard import InlineKeyboard, InlineButton keyboard = InlineKeyboard() -keyboard.paginate(150, 123, 'pagination_keyboard#{number}') +keyboard.paginate(150, 123, 'pagination_keyboard:{number}') keyboard.row( - InlineKeyboardButton('Back', 'pagination_keyboard#back'), - InlineKeyboardButton('Close', 'pagination_keyboard#close') + InlineButton('Back', 'pagination_keyboard:back'), + InlineButton('Close', 'pagination_keyboard:close') ) ``` @@ -210,17 +208,16 @@ from pykeyboard import ReplyKeyboard #### Code ```python -from pykeyboard import ReplyKeyboard -from pyrogram.types import KeyboardButton +from pykeyboard import ReplyKeyboard, ReplyButton 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'), + ReplyButton('Reply button 1'), + ReplyButton('Reply button 2'), + ReplyButton('Reply button 3'), + ReplyButton('Reply button 4'), + ReplyButton('Reply button 5') ) ``` @@ -233,18 +230,17 @@ keyboard.add( #### Code ```python -from pykeyboard import ReplyKeyboard -from pyrogram.types import KeyboardButton +from pykeyboard import ReplyKeyboard, ReplyButton keyboard = ReplyKeyboard() -keyboard.row(KeyboardButton('1', 'reply_keyboard#1')) +keyboard.row(ReplyButton('Reply button 1')) keyboard.row( - KeyboardButton('2', 'reply_keyboard#2'), - KeyboardButton('3', 'reply_keyboard#3') + ReplyButton('Reply button 2'), + ReplyButton('Reply button 3') ) -keyboard.row(KeyboardButton('4', 'reply_keyboard#4')) -keyboard.row(KeyboardButton('5', 'reply_keyboard#5')) +keyboard.row(ReplyButton('Reply button 4')) +keyboard.row(ReplyButton('Reply button 5')) ``` #### Result diff --git a/pykeyboard/__init__.py b/pykeyboard/__init__.py index 8e96f0c..0eb7c21 100644 --- a/pykeyboard/__init__.py +++ b/pykeyboard/__init__.py @@ -1,11 +1,10 @@ __title__ = 'pykeyboard' -__version__ = '0.1.2' +__version__ = '0.1.3' __author__ = 'PyMaster' __license__ = 'MIT License' -__copyright__ = 'Copyright 2020 PyMaster' - -from .inline_keyboard import InlineKeyboard -from .inline_pagination_keyboard import InlinePaginationKeyboard -from .reply_keyboard import ReplyKeyboard -from .inline_query_results import InlineQueryResults +__copyright__ = 'Copyright 2020-2022 PyMaster' +from .inline_keyboard import InlineKeyboard, InlineButton +from .inline_pagination_keyboard import InlinePaginationKeyboard, InlineButton +from .reply_keyboard import ( + ReplyKeyboard, ReplyButton, ReplyKeyboardRemove, ForceReply) diff --git a/pykeyboard/inline_keyboard.py b/pykeyboard/inline_keyboard.py index b8b1fd0..0a872b7 100644 --- a/pykeyboard/inline_keyboard.py +++ b/pykeyboard/inline_keyboard.py @@ -105,3 +105,19 @@ class InlineKeyboard(InlineKeyboardMarkup): self.callback_pattern = callback_pattern return self.inline_keyboard.append(self._build_pagination) + + +class InlineButton(InlineKeyboardButton): + def __init__(self, text=None, callback_data=None, url=None, + login_url=None, user_id=None, switch_inline_query=None, + switch_inline_query_current_chat=None, callback_game=None): + super().__init__( + text=text, + callback_data=callback_data, + url=url, + login_url=login_url, + user_id=user_id, + switch_inline_query=switch_inline_query, + switch_inline_query_current_chat=switch_inline_query_current_chat, + callback_game=callback_game + ) diff --git a/pykeyboard/inline_pagination_keyboard.py b/pykeyboard/inline_pagination_keyboard.py index 3a07672..cf3f202 100644 --- a/pykeyboard/inline_pagination_keyboard.py +++ b/pykeyboard/inline_pagination_keyboard.py @@ -99,3 +99,19 @@ class InlinePaginationKeyboard(InlineKeyboardMarkup): @property def markup(self): self.inline_keyboard.append(self.build_pagination) + + +class InlineButton(InlineKeyboardButton): + def __init__(self, text=None, callback_data=None, url=None, + login_url=None, user_id=None, switch_inline_query=None, + switch_inline_query_current_chat=None, callback_game=None): + super().__init__( + text=text, + callback_data=callback_data, + url=url, + login_url=login_url, + user_id=user_id, + switch_inline_query=switch_inline_query, + switch_inline_query_current_chat=switch_inline_query_current_chat, + callback_game=callback_game + ) diff --git a/pykeyboard/reply_keyboard.py b/pykeyboard/reply_keyboard.py index 5fd4042..4ec8732 100644 --- a/pykeyboard/reply_keyboard.py +++ b/pykeyboard/reply_keyboard.py @@ -1,4 +1,5 @@ -from pyrogram.types import ReplyKeyboardMarkup +from pyrogram.types import ( + ReplyKeyboardMarkup, KeyboardButton, ReplyKeyboardRemove, ForceReply) class ReplyKeyboard(ReplyKeyboardMarkup): @@ -21,3 +22,22 @@ class ReplyKeyboard(ReplyKeyboardMarkup): def row(self, *args): self.keyboard.append([button for button in args]) + + +class ReplyButton(KeyboardButton): + def __init__(self, text=None, request_contact=None, request_location=None): + super().__init__( + text=text, + request_contact=request_contact, + request_location=request_location + ) + + +class ReplyKeyboardRemove(ReplyKeyboardRemove): + def __init__(self, selective=None): + super().__init__(selective=selective) + + +class ForceReply(ForceReply): + def __init__(self, selective=None): + super().__init__(selective=selective) diff --git a/setup.py b/setup.py index 88a662b..ba5a42e 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f: setup( name='pykeyboard', - version='0.1.2', + version='0.1.3', author='PyMaster', author_email='', description='Best Keyboard and Pagination for the Pyrogram Library.', @@ -20,6 +20,7 @@ setup( 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', 'Topic :: Internet', 'Topic :: Communications', 'Topic :: Communications :: Chat',