Skip to content

Commit 5f683e5

Browse files
fixed magic constants
1 parent 8f90bbb commit 5f683e5

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

helperBot/Client.py

-3
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ def keyboard_markup(self):
7878
if self.next_action == action.MESSAGE:
7979
return self.picked_keyboard()
8080
return [['/friends']] + [['/download']] + [['/files']]
81-
# + [['/pick ' + user.get_name()]
82-
# for user in self.interacted_with
83-
# if not user.should_fetch()]
8481

8582
def picked_keyboard(self):
8683
return [['/unpick ' + self.next_recepient.get_name()],

helperBot/Constants.py

+11
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,16 @@ def FIRST_PICK_USER():
9292
def PARTICIPANTS(participants):
9393
return '*In chat:* ' + participants
9494

95+
@constant
96+
def HELLO():
97+
return 'Hello! This is your helper bot, authenticate to start messaging or use /download command to get file by link'
98+
99+
@constant
100+
def ENTER_LINK():
101+
return 'Please, eneter the link'
102+
103+
@constant
104+
def CHOOSE_OPTION():
105+
return 'Choose from the following'
95106

96107
message = _Message()

helperBot/TelegramController.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(self, tg_bot_token, vk_client_id):
3838

3939
start_command_handler = CommandHandler('start', self.start_command_callback)
4040
dispatcher.add_handler(start_command_handler)
41-
start_command_handler = CommandHandler('auth', self.auth_command_callback)
41+
start_command_handler = CommandHandler('authenticate', self.auth_command_callback)
4242
dispatcher.add_handler(start_command_handler)
4343
start_command_handler = CommandHandler('downloadByLink', self.downloadByLink_callback)
4444
dispatcher.add_handler(start_command_handler)
@@ -69,20 +69,21 @@ def __init__(self, tg_bot_token, vk_client_id):
6969

7070
def button(self, update: Update, context: CallbackContext) -> None:
7171
"""Parses the CallbackQuery and updates the message text."""
72+
buttons_to_display = 16
7273
query = update.callback_query
7374
query.answer()
7475

7576
client = self.clients[query.message.chat_id]
7677
client.seen_now()
7778

7879
if query.data.startswith("<-Friends"):
79-
if client.offset_friends >= 16:
80+
if client.offset_friends >= buttons_to_display:
8081
client.prev_message_id_friends = query.message.message_id
81-
client.offset_friends -= 16
82+
client.offset_friends -= buttons_to_display
8283
self.friends_command_callback(update, context, client.chat_id)
8384
elif query.data.startswith("->Friends"):
8485
client.prev_message_id_friends = query.message.message_id
85-
client.offset_friends += 16
86+
client.offset_friends += buttons_to_display
8687
self.friends_command_callback(update, context, client.chat_id)
8788

8889
if query.data.startswith("['user id'"):
@@ -95,13 +96,13 @@ def button(self, update: Update, context: CallbackContext) -> None:
9596
reply_markup=TelegramController.keyboard(client.keyboard_markup()))
9697

9798
if query.data.startswith("<-Files"):
98-
if client.offset_files >= 16:
99+
if client.offset_files >= buttons_to_display:
99100
client.prev_message_id_files = query.message.message_id
100-
client.offset_files -= 16
101+
client.offset_files -= buttons_to_display
101102
self.list_files_callback(update, context, client.chat_id)
102103
elif query.data.startswith("->Files"):
103104
client.prev_message_id_files = query.message.message_id
104-
client.offset_files += 16
105+
client.offset_files += buttons_to_display
105106
self.list_files_callback(update, context, client.chat_id)
106107

107108
if query.data.startswith("['file id'"):
@@ -148,8 +149,8 @@ def restore(self):
148149
def start_command_callback(self, update, context: CallbackContext):
149150
chat_id = update.message.chat_id
150151
self.updater.bot.sendMessage(chat_id=chat_id,
151-
text="Hello! Can yoe choose button from th list?",
152-
reply_markup=TelegramController.keyboard([["/downloadByLink"]] + [["/auth"]])
152+
text=message.HELLO,
153+
reply_markup=TelegramController.keyboard([["/downloadByLink"]] + [["/authenticate"]])
153154
)
154155

155156
def auth_command_callback(self, update, context: CallbackContext):
@@ -187,7 +188,7 @@ def downloadByLink_callback(self, update, context: CallbackContext):
187188
chat_id = update.message.chat_id
188189
self.flagNotAuth = True
189190
self.updater.bot.sendMessage(chat_id=chat_id,
190-
text="Please, eneter the link")
191+
text=message.ENTER_LINK)
191192

192193
def download_file_callback(self, update, context: CallbackContext):
193194
"""
@@ -251,13 +252,13 @@ def friends_command_callback(self, update, context: CallbackContext, chatID=None
251252
reply_markup = InlineKeyboardMarkup(self.build_menu(button_list))
252253
if chatID is None:
253254
self.updater.bot.sendMessage(chat_id=chat_id,
254-
text='Choose from the following',
255+
text=message.CHOOSE_OPTION,
255256
parse_mode=ParseMode.MARKDOWN,
256257
reply_markup=reply_markup)
257258
else:
258259
self.updater.bot.edit_message_text(chat_id=chat_id,
259260
message_id=client.prev_message_id_friends,
260-
text='Choose from the following',
261+
text=message.CHOOSE_OPTION,
261262
parse_mode=ParseMode.MARKDOWN,
262263
reply_markup=reply_markup)
263264

0 commit comments

Comments
 (0)