|
4 | 4 | from telegram import Chat, InlineQueryResultArticle, InputTextMessageContent, ParseMode
|
5 | 5 | from telegram.ext import Dispatcher, InlineQueryHandler, CommandHandler
|
6 | 6 |
|
| 7 | +from bot.const import DEFAULT_TRUNCATION_LIMIT |
7 | 8 | from bot.github import github_api
|
8 | 9 | from bot.menu import Button, Menu, BackButton, reply_menu, MenuHandler, ToggleButton, SetButton
|
9 | 10 | from bot.repo import Repo
|
@@ -56,8 +57,9 @@ def settings_buttons(update, context):
|
56 | 57 | else:
|
57 | 58 | buttons.append(Button('🔑 Login', menu='login'))
|
58 | 59 | else:
|
59 |
| - buttons.append(Button('👤 User settings', url=f'https://telegram.me/{context.bot.username}?start=settings')) |
| 60 | + buttons.append(Button('👤 Go to User settings', url=f'https://telegram.me/{context.bot.username}?start=settings')) |
60 | 61 |
|
| 62 | + buttons.append(Button('👥 Chat settings', menu='chat')) |
61 | 63 | buttons.append(Button('🗃️ Repositories', menu='repos'))
|
62 | 64 |
|
63 | 65 | return [[button] for button in buttons]
|
@@ -172,6 +174,39 @@ def repo_set_data(update, context):
|
172 | 174 | )
|
173 | 175 |
|
174 | 176 |
|
| 177 | +def chat_text(update, context): |
| 178 | + if update.effective_chat.title: |
| 179 | + chat = update.effective_chat.title |
| 180 | + elif update.effective_chat.first_name: |
| 181 | + chat = f'this chat with {update.effective_chat.first_name}' |
| 182 | + else: |
| 183 | + chat = 'this chat' |
| 184 | + return f'⚙ Settings for {context.bot.name} for {chat}\n\n' |
| 185 | + |
| 186 | + |
| 187 | +def chat_buttons(update, context): |
| 188 | + truncation_limit = context.chat_data.get('truncation_limit', DEFAULT_TRUNCATION_LIMIT) |
| 189 | + truncation_limits = [256, 512, 1024, 2048, 4096] |
| 190 | + truncation_limit_states = [(limit, f'Max notification message length: {limit}') for limit in truncation_limits] |
| 191 | + |
| 192 | + return [ |
| 193 | + [ToggleButton('truncation_limit', truncation_limit, states=truncation_limit_states)], |
| 194 | + [BackButton(BACK)] |
| 195 | + ] |
| 196 | + |
| 197 | + |
| 198 | +def chat_set_data(update, context): |
| 199 | + context.chat_data[context.key] = context.value |
| 200 | + |
| 201 | + |
| 202 | +chat_settings_menu = Menu( |
| 203 | + name='chat', |
| 204 | + text=chat_text, |
| 205 | + buttons=chat_buttons, |
| 206 | + set_data=chat_set_data |
| 207 | +) |
| 208 | + |
| 209 | + |
175 | 210 | def settings_command(update, context):
|
176 | 211 | if context.args:
|
177 | 212 | context.menu_stack = context.args
|
@@ -265,7 +300,8 @@ def add_handlers(dp: Dispatcher):
|
265 | 300 | dp.add_handler(MenuHandler(settings_menu, [
|
266 | 301 | repos_menu,
|
267 | 302 | repo_menu,
|
268 |
| - login_menu |
| 303 | + login_menu, |
| 304 | + chat_settings_menu |
269 | 305 | ]))
|
270 | 306 |
|
271 | 307 | dp.add_handler(InlineQueryHandler(inline_add_repo, pattern=InlineQueries.add_repo + r'(.*)'))
|
|
0 commit comments