Queer European MD passionate about IT
Browse Source

Consider user_record in /talk related function

Thus, user-selected language will be applied in get_message method calls
Davte 5 years ago
parent
commit
d60637a3b7
1 changed files with 36 additions and 36 deletions
  1. 36 36
      davtelepot/administration_tools.py

+ 36 - 36
davtelepot/administration_tools.py

@@ -159,7 +159,7 @@ async def _forward_to(update, bot, sender, addressee, is_admin=False):
     return
     return
 
 
 
 
-def get_talk_panel(update, bot, text=''):
+def get_talk_panel(bot, update, user_record=None, text=''):
     """Return text and reply markup of talk panel.
     """Return text and reply markup of talk panel.
 
 
     `text` may be:
     `text` may be:
@@ -177,32 +177,29 @@ def get_talk_panel(update, bot, text=''):
             else:
             else:
                 users = list(
                 users = list(
                     db.query(
                     db.query(
-                        """SELECT *
-                        FROM users
-                        WHERE COALESCE(
-                            first_name || last_name || username,
-                            last_name || username,
-                            first_name || username,
-                            username,
-                            first_name || last_name,
-                            last_name,
-                            first_name
-                        ) LIKE '%{username}%'
-                        ORDER BY LOWER(
-                            COALESCE(
-                                first_name || last_name || username,
-                                last_name || username,
-                                first_name || username,
-                                username,
-                                first_name || last_name,
-                                last_name,
-                                first_name
-                            )
-                        )
-                        LIMIT 26
-                        """.format(
-                            username=text
-                        )
+                        "SELECT * "
+                        "FROM users "
+                        "WHERE COALESCE( "
+                        "    first_name || last_name || username, "
+                        "    last_name || username, "
+                        "    first_name || username, "
+                        "    username, "
+                        "    first_name || last_name, "
+                        "    last_name, "
+                        "    first_name "
+                        f") LIKE '%{text}%' "
+                        "ORDER BY LOWER( "
+                        "    COALESCE( "
+                        "        first_name || last_name || username, "
+                        "        last_name || username, "
+                        "        first_name || username, "
+                        "        username, "
+                        "        first_name || last_name, "
+                        "        last_name, "
+                        "        first_name "
+                        "    ) "
+                        ") "
+                        "LIMIT 26"
                     )
                     )
                 )
                 )
     if len(text) == 0:
     if len(text) == 0:
@@ -211,6 +208,7 @@ def get_talk_panel(update, bot, text=''):
                 'talk',
                 'talk',
                 'help_text',
                 'help_text',
                 update=update,
                 update=update,
+                user_record=user_record,
                 q=escape_html_chars(
                 q=escape_html_chars(
                     remove_html_tags(text)
                     remove_html_tags(text)
                 )
                 )
@@ -221,7 +219,7 @@ def get_talk_panel(update, bot, text=''):
                 make_button(
                 make_button(
                     bot.get_message(
                     bot.get_message(
                         'talk', 'search_button',
                         'talk', 'search_button',
-                        update=update
+                        update=update, user_record=user_record
                     ),
                     ),
                     prefix='talk:///',
                     prefix='talk:///',
                     data=['search']
                     data=['search']
@@ -235,6 +233,7 @@ def get_talk_panel(update, bot, text=''):
                 'talk',
                 'talk',
                 'user_not_found',
                 'user_not_found',
                 update=update,
                 update=update,
+                user_record=user_record,
                 q=escape_html_chars(
                 q=escape_html_chars(
                     remove_html_tags(text)
                     remove_html_tags(text)
                 )
                 )
@@ -245,7 +244,7 @@ def get_talk_panel(update, bot, text=''):
                 make_button(
                 make_button(
                     bot.get_message(
                     bot.get_message(
                         'talk', 'search_button',
                         'talk', 'search_button',
-                        update=update
+                        update=update, user_record=user_record
                     ),
                     ),
                     prefix='talk:///',
                     prefix='talk:///',
                     data=['search']
                     data=['search']
@@ -257,7 +256,7 @@ def get_talk_panel(update, bot, text=''):
         text = "{header}\n\n{u}{etc}".format(
         text = "{header}\n\n{u}{etc}".format(
             header=bot.get_message(
             header=bot.get_message(
                 'talk', 'select_user',
                 'talk', 'select_user',
-                update=update
+                update=update, user_record=user_record
             ),
             ),
             u=line_drawing_unordered_list(
             u=line_drawing_unordered_list(
                 [
                 [
@@ -300,13 +299,14 @@ def get_talk_panel(update, bot, text=''):
     return text, reply_markup
     return text, reply_markup
 
 
 
 
-async def _talk_command(update, bot):
+async def _talk_command(bot, update, user_record):
     text = get_cleaned_text(
     text = get_cleaned_text(
         update,
         update,
         bot,
         bot,
         ['talk']
         ['talk']
     )
     )
-    text, reply_markup = get_talk_panel(update, bot, text)
+    text, reply_markup = get_talk_panel(bot=bot, update=update,
+                                        user_record=user_record, text=text)
     return dict(
     return dict(
         text=text,
         text=text,
         parse_mode='HTML',
         parse_mode='HTML',
@@ -426,7 +426,7 @@ async def _talk_button(bot, update, user_record, data):
         )
         )
         text = bot.get_message(
         text = bot.get_message(
             'talk', 'instructions',
             'talk', 'instructions',
-            update=update
+            update=update, user_record=user_record
         )
         )
         reply_markup = None
         reply_markup = None
     elif command == 'select':
     elif command == 'select':
@@ -457,7 +457,7 @@ async def _talk_button(bot, update, user_record, data):
         elif not Confirmator.get('stop_bots').confirm(telegram_id):
         elif not Confirmator.get('stop_bots').confirm(telegram_id):
             result = bot.get_message(
             result = bot.get_message(
                 'talk', 'end_session',
                 'talk', 'end_session',
-                update=update,
+                update=update, user_record=user_record
             )
             )
         else:
         else:
             with bot.db as db:
             with bot.db as db:
@@ -753,8 +753,8 @@ def init(bot, talk_messages=None, admin_messages=None):
     @bot.command(command='/talk', aliases=[], show_in_keyboard=False,
     @bot.command(command='/talk', aliases=[], show_in_keyboard=False,
                  description=admin_messages['talk_command']['description'],
                  description=admin_messages['talk_command']['description'],
                  authorization_level='admin')
                  authorization_level='admin')
-    async def talk_command(update):
-        return await _talk_command(update, bot)
+    async def talk_command(bot, update, user_record):
+        return await _talk_command(bot, update, user_record)
 
 
     @bot.button(prefix='talk:///', separator='|', authorization_level='admin')
     @bot.button(prefix='talk:///', separator='|', authorization_level='admin')
     async def talk_button(bot, update, user_record, data):
     async def talk_button(bot, update, user_record, data):