Add files via upload
This commit is contained in:
parent
98558a3bb4
commit
4c38456016
42
LICENSE
42
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.
|
||||
|
222
README.md
222
README.md
@ -1 +1,221 @@
|
||||
# pykeyboard
|
||||
<p align="center">
|
||||
<img src="https://raw.githubusercontent.com/pystorage/pykeyboard/master/docs/source/images/logo.png" alt="Pykeyboard">
|
||||
</p>
|
||||
|
||||
## 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
|
||||
|
||||
<p><img src="https://raw.githubusercontent.com/pystorage/pykeyboard/master/docs/source/images/add_inline_button.png" alt="add_inline_button"></p>
|
||||
|
||||
#### 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
|
||||
|
||||
<p><img src="https://raw.githubusercontent.com/pystorage/pykeyboard/master/docs/source/images/row_inline_button.png" alt="row_inline_button"></p>
|
||||
|
||||
### 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
|
||||
|
||||
<p><img src="https://raw.githubusercontent.com/pystorage/pykeyboard/master/docs/source/images/add_reply_button.png" alt="add_reply_button"></p>
|
||||
|
||||
#### 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
|
||||
|
||||
<p><img src="https://raw.githubusercontent.com/pystorage/pykeyboard/master/docs/source/images/row_reply_button.png" alt="row_reply_button"></p>
|
||||
|
||||
### 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
|
||||
|
||||
<p><img src="https://raw.githubusercontent.com/pystorage/pykeyboard/master/docs/source/images/pagination_keyboard_3.png" alt="pagination_keyboard_3"></p>
|
||||
|
||||
#### Pagination 5 pages
|
||||
|
||||
##### Code
|
||||
|
||||
```python
|
||||
from pykeyboard import InlinePaginationKeyboard
|
||||
|
||||
|
||||
keyboard = InlinePaginationKeyboard(5, 3, 'pagination_keyboard#{number}')
|
||||
```
|
||||
|
||||
##### Result
|
||||
|
||||
<p><img src="https://raw.githubusercontent.com/pystorage/pykeyboard/master/docs/source/images/pagination_keyboard_5.png" alt="pagination_keyboard_5"></p>
|
||||
|
||||
#### Pagination 9 pages
|
||||
|
||||
##### Code
|
||||
|
||||
```python
|
||||
from pykeyboard import InlinePaginationKeyboard
|
||||
|
||||
|
||||
keyboard = InlinePaginationKeyboard(9, 5, 'pagination_keyboard#{number}')
|
||||
```
|
||||
|
||||
##### Result
|
||||
|
||||
<p><img src="https://raw.githubusercontent.com/pystorage/pykeyboard/master/docs/source/images/pagination_keyboard_9.png" alt="pagination_keyboard_9"></p>
|
||||
|
||||
#### Pagination 25 pages
|
||||
|
||||
##### Code
|
||||
|
||||
```python
|
||||
from pykeyboard import InlinePaginationKeyboard
|
||||
|
||||
|
||||
keyboard = InlinePaginationKeyboard(25, 14, 'pagination_keyboard#{number}')
|
||||
```
|
||||
|
||||
##### Result
|
||||
|
||||
<p><img src="https://raw.githubusercontent.com/pystorage/pykeyboard/master/docs/source/images/pagination_keyboard_25.png" alt="pagination_keyboard_25"></p>
|
||||
|
||||
#### Pagination 100 pages
|
||||
|
||||
##### Code
|
||||
|
||||
```python
|
||||
from pykeyboard import InlinePaginationKeyboard
|
||||
|
||||
|
||||
keyboard = InlinePaginationKeyboard(100, 100, 'pagination_keyboard#{number}')
|
||||
```
|
||||
|
||||
##### Result
|
||||
|
||||
<p><img src="https://raw.githubusercontent.com/pystorage/pykeyboard/master/docs/source/images/pagination_keyboard_100.png" alt="pagination_keyboard_100"></p>
|
||||
|
||||
#### 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
|
||||
|
||||
<p><img src="https://raw.githubusercontent.com/pystorage/pykeyboard/master/docs/source/images/pagination_keyboard_150.png" alt="pagination_keyboard_150"></p>
|
||||
|
21
examples/LICENSE
Normal file
21
examples/LICENSE
Normal file
@ -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.
|
1
examples/README.md
Normal file
1
examples/README.md
Normal file
@ -0,0 +1 @@
|
||||
# Example: Telegram Pyrogram bot
|
20
examples/bot/__init__.py
Normal file
20
examples/bot/__init__.py
Normal file
@ -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()
|
5
examples/bot/__main__.py
Normal file
5
examples/bot/__main__.py
Normal file
@ -0,0 +1,5 @@
|
||||
from . import App
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
App().run()
|
5
examples/bot/config.py
Normal file
5
examples/bot/config.py
Normal file
@ -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'
|
70
examples/bot/modules/inline_keyboard.py
Normal file
70
examples/bot/modules/inline_keyboard.py
Normal file
@ -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(
|
||||
'<b>Inline keyboard:</b>\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(
|
||||
'<b>Add buttons:</b>\n\n'
|
||||
'<code>keyboard = InlineKeyboard(row_width=3)</code>\n'
|
||||
'<code>keyboard.add(</code>\n'
|
||||
"<code> InlineKeyboardButton('1', 'inline_keyboard#1'),</code>\n"
|
||||
"<code> InlineKeyboardButton('2', 'inline_keyboard#2'),</code>\n"
|
||||
"<code> InlineKeyboardButton('3', 'inline_keyboard#3'),</code>\n"
|
||||
"<code> InlineKeyboardButton('4', 'inline_keyboard#4'),</code>\n"
|
||||
"<code> InlineKeyboardButton('5', 'inline_keyboard#5'),</code>\n"
|
||||
"<code> InlineKeyboardButton('6', 'inline_keyboard#6'),</code>\n"
|
||||
"<code> InlineKeyboardButton('7', 'inline_keyboard#7')</code>\n"
|
||||
'<code>)</code>\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(
|
||||
'<b>Add button row:</b>\n\n'
|
||||
"<code>keyboard = InlineKeyboard()</code>\n"
|
||||
"<code>keyboard.row(InlineKeyboardButton('1', 'inline_keyboard#1'))</code>\n"
|
||||
"<code>keyboard.row(</code>\n"
|
||||
"<code> InlineKeyboardButton('2', 'inline_keyboard#2'),</code>\n"
|
||||
"<code> InlineKeyboardButton('3', 'inline_keyboard#3')</code>\n"
|
||||
"<code>)</code>\n"
|
||||
"<code>keyboard.row(InlineKeyboardButton('4', 'inline_keyboard#4'))</code>\n"
|
||||
"<code>keyboard.row(</code>\n"
|
||||
"<code> InlineKeyboardButton('5', 'inline_keyboard#5'),</code>\n"
|
||||
"<code> InlineKeyboardButton('6', 'inline_keyboard#6')</code>\n"
|
||||
"<code>)</code>\n",
|
||||
reply_markup=keyboard
|
||||
)
|
10
examples/bot/modules/install.py
Normal file
10
examples/bot/modules/install.py
Normal file
@ -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(
|
||||
'<b>Installation:</b>\n\n'
|
||||
'<code>pip install -U pykeyboard</code>'
|
||||
)
|
86
examples/bot/modules/pagination_keyboard.py
Normal file
86
examples/bot/modules/pagination_keyboard.py
Normal file
@ -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(
|
||||
'<b>Pagination inline keyboard:</b>\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'<b>3 page pagination:</b>\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'<b>5 page pagination:</b>\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'<b>9 page pagination:</b>\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'<b>25 page pagination:</b>\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'<b>100 page pagination:</b>\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'<b>150 page pagination and buttons:</b>\n\n {TEXT}',
|
||||
reply_markup=keyboard
|
||||
)
|
60
examples/bot/modules/reply_keyboard.py
Normal file
60
examples/bot/modules/reply_keyboard.py
Normal file
@ -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(
|
||||
'<b>Reply keyboard:</b>\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(
|
||||
'<b>Add buttons:</b>\n\n'
|
||||
'<code>keyboard = ReplyKeyboard(row_width=3)</code>\n'
|
||||
'<code>keyboard.add(</code>\n'
|
||||
"<code> KeyboardButton('1', 'reply_keyboard#1'),</code>\n"
|
||||
"<code> KeyboardButton('2', 'reply_keyboard#2'),</code>\n"
|
||||
"<code> KeyboardButton('3', 'reply_keyboard#3'),</code>\n"
|
||||
"<code> KeyboardButton('4', 'reply_keyboard#4'),</code>\n"
|
||||
"<code> KeyboardButton('5', 'reply_keyboard#5'),</code>\n"
|
||||
'<code>)</code>\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(
|
||||
'<b>Add button row:</b>\n\n'
|
||||
"<code>keyboard = ReplyKeyboard()</code>\n"
|
||||
"<code>keyboard.row(KeyboardButton('1', 'reply_keyboard#1'))</code>\n"
|
||||
"<code>keyboard.row(</code>\n"
|
||||
"<code> KeyboardButton('2', 'reply_keyboard#2'),</code>\n"
|
||||
"<code> KeyboardButton('3', 'reply_keyboard#3')</code>\n"
|
||||
"<code>)</code>\n"
|
||||
"<code>keyboard.row(KeyboardButton('4', 'reply_keyboard#4'))</code>\n"
|
||||
"<code>keyboard.row(KeyboardButton('5', 'reply_keyboard#5'))</code>\n",
|
||||
reply_markup=keyboard
|
||||
)
|
15
examples/bot/modules/start.py
Normal file
15
examples/bot/modules/start.py
Normal file
@ -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 <b>{message.from_user.first_name}</b>!\n\n'
|
||||
'I will help you learn how to wrk with the <b>pykeyboard</b> library.\n\n'
|
||||
'<b>Library features:</b>\n\n'
|
||||
'/install - library installation\n'
|
||||
'/inline_keyboard - inline keyboard\n'
|
||||
'/pagination_keyboard - pagination inline keyboard\n'
|
||||
'/reply_keyboard - reply keyboard'
|
||||
)
|
3
pykeyboard/__init__.py
Normal file
3
pykeyboard/__init__.py
Normal file
@ -0,0 +1,3 @@
|
||||
from .inline_keyboard import InlineKeyboard
|
||||
from .inline_pagination_keyboard import InlinePaginationKeyboard
|
||||
from .reply_keyboard import ReplyKeyboard
|
17
pykeyboard/inline_keyboard.py
Normal file
17
pykeyboard/inline_keyboard.py
Normal file
@ -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])
|
101
pykeyboard/inline_pagination_keyboard.py
Normal file
101
pykeyboard/inline_pagination_keyboard.py
Normal file
@ -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)
|
23
pykeyboard/reply_keyboard.py
Normal file
23
pykeyboard/reply_keyboard.py
Normal file
@ -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])
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
pyrogram
|
||||
tgcrypto
|
35
setup.py
Normal file
35
setup.py
Normal file
@ -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',
|
||||
)
|
Reference in New Issue
Block a user