@@ -77,53 +77,103 @@ Both decorators accept optional arguments:
7777Examples
7878~~~~~~~~~~~~
7979
80- Static layout :
80+ Static inline keyboard :
8181^^^^^^^^^^^^^^^^
8282
8383.. code-block :: python
8484
8585 from raito import rt
8686
87- @rt.keyboard.static (inline = True )
88- def faq_buttons ():
87+ @rt.keyboard.static ()
88+ def info_markup ():
8989 return [
90- ( " Terms of Service " , " tos " ) ,
91- ( " Privacy" , " privacy" ),
90+ [( " 💬 Support " , " support " )] ,
91+ [( " 🔒 Privacy" , " privacy" ), ( " 📄 TOS " , " terms_of_use " )]
9292 ]
9393
94- Dynamic layout:
94+ @router.message (... )
95+ async def handler (message : Message):
96+ await message.answer(" Buttons:" , reply_markup = info_markup())
97+
98+ Static reply keyboard:
99+ ^^^^^^^^^^^^^^^^
100+
101+ .. code-block :: python
102+
103+ from raito import rt
104+
105+ @rt.keyboard.static (inline = False )
106+ def info_markup ():
107+ return [
108+ [" 💬 Support" ],
109+ [[" 🔒 Privacy" ], [" 📄 TOS" ]]
110+ ]
111+
112+ @router.message (... )
113+ async def handler (message : Message):
114+ await message.answer(" Buttons:" , reply_markup = info_markup())
115+
116+ Dynamic inline keyboard:
95117^^^^^^^^^^^^^^^^
96118
97119.. code-block :: python
98120
99121 from aiogram.utils.keyboard import InlineKeyboardBuilder
100122 from raito import rt
101123
102- from ... import Player
124+ @rt.keyboard.dynamic (1 , 2 )
125+ def info_markup (builder : InlineKeyboardBuilder, privacy_url : str , tos_url : str ):
126+ builder.button(text = " 💬 Support" , callback_data = " support" )
127+ builder.button(text = " 🔒 Privacy" , url = privacy_url)
128+ builder.button(text = " 📄 TOS" , url = tos_url)
129+
130+ @router.message (... )
131+ async def handler (message : Message):
132+ await message.answer(" Buttons:" , reply_markup = info_markup(
133+ privacy_url = " https://example.com/privacy" ,
134+ tos_url = " https://example.com/tos" ,
135+ ))
103136
104- @rt. keyboard.dynamic ()
105- def leaderboard ( builder : InlineKeyboardBuilder, players : list[Player]):
106- for player in players:
107- builder.button( text = f " { player.name } " , callback_data = f " player: { player.id } " )
137+ Dynamic reply keyboard:
138+ ^^^^^^^^^^^^^^^^
139+
140+ .. code-block :: python
108141
109- builder.adjust(1 , 2 , 2 )
142+ from aiogram.utils.keyboard import ReplyKeyboardBuilder
143+ from raito import rt
110144
111- Dynamic pagination-like example:
112- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
145+ @rt.keyboard.dynamic (1 , 2 , inline = False )
146+ def info_markup (builder : ReplyKeyboardBuilder):
147+ builder.button(text = " 💬 Support" )
148+ builder.button(text = " 🔒 Privacy" )
149+ builder.button(text = " 📄 TOS" )
150+
151+ @router.message (... )
152+ async def handler (message : Message):
153+ await message.answer(" Buttons:" , reply_markup = info_markup())
154+
155+ Custom adjust:
156+ ^^^^^^^^^^^^^^^^
113157
114158.. code-block :: python
115159
116160 from aiogram.utils.keyboard import InlineKeyboardBuilder
117161 from raito import rt
118162
119- from ... import Player
120-
121163 @rt.keyboard.dynamic (adjust = False )
122- def leaderboard (builder : InlineKeyboardBuilder, players : list[Player]):
123- for i, player in enumerate (players, start = 1 ):
124- builder.button(text = f " # { i} { player.name} " , callback_data = f " player: { player.id} " )
164+ def admin_markup (builder : InlineKeyboardBuilder, show_balance_management : bool = False ):
165+ adjust = []
166+
167+ builder.button(text = " 👤 Users" , callback_data = " users" )
168+ adjust.append(1 )
169+
170+ if show_balance_management:
171+ builder.button(text = " 📤 Withdraw" , callback_data = " withdraw" )
172+ builder.button(text = " 📥 Deposit" , callback_data = " deposit" )
173+ adjust.append(2 )
125174
126- builder.button(text = " ◀️" , callback_data = " prev" )
127- builder.button(text = " ▶️" , callback_data = " next" )
175+ builder.adjust(* adjust)
128176
129- builder.adjust(3 )
177+ @router.message (... )
178+ async def handler (message : Message):
179+ await message.answer(" Buttons:" , reply_markup = admin_markup(True ))
0 commit comments