Commit 98b05b51 authored by Dmitry Shelepnev's avatar Dmitry Shelepnev
Browse files

Telebot update: Add cmdtrans decorator

parent ee4de82c
Loading
Loading
Loading
Loading
+71 −54
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-04-03 22:20+0300\n"
"POT-Creation-Date: 2018-04-07 16:38+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -259,6 +259,76 @@ msgstr "секция"
msgid "subsection"
msgstr "подсекция"

#: .\opds_catalog\management\commands\sopds_telebot.py:45
#, python-format
msgid ""
"Hello %s!\n"
"Unfortunately you do not have access to information. Please contact the bot "
"administrator."
msgstr ""
"Здравствуйте %s!\n"
"К сожалению у Вас отсутствует доступ к информации. Обратитесь к "
"администратору бота."

#: .\opds_catalog\management\commands\sopds_telebot.py:46
#, python-format
msgid "Denied access for user: %s"
msgstr "Отказ в доступе для пользователя: %s"

#: .\opds_catalog\management\commands\sopds_telebot.py:65
#, python-format
msgid ""
"%(subtitle)s\n"
"Hello %(username)s! To search for a book, enter part of her title or author:"
msgstr ""
"%(subtitle)s\n"
"Здравствуйте %(username)s! Для поиска книги, введите часть ее наименования "
"или автора:"

#: .\opds_catalog\management\commands\sopds_telebot.py:168
#, python-format
msgid "(doubles:%s) "
msgstr "(дубликатов:%s) "

#: .\opds_catalog\management\commands\sopds_telebot.py:187
msgid "Too short for search, please try again."
msgstr "Слишком короткая строка для поиска, попробуйте еще раз."

#: .\opds_catalog\management\commands\sopds_telebot.py:189
#, python-format
msgid "I'm searching for the book: %s"
msgstr "Выполняю поиск книги: %s"

#: .\opds_catalog\management\commands\sopds_telebot.py:201
msgid "No results were found for your query, please try again."
msgstr "По Вашему запросу ничего не найдено, попробуйте еще раз."

#: .\opds_catalog\management\commands\sopds_telebot.py:206
#, python-format
msgid ""
"Found %s books.\n"
"I create list, after a few seconds, select the file to download:"
msgstr ""
"Найдено %s книг(и). \n"
"Формирую список, через несколько секунд выберите нужную для скачивания:"

#: .\opds_catalog\management\commands\sopds_telebot.py:244
#: .\opds_catalog\management\commands\sopds_telebot.py:281
msgid ""
"The book on the link you specified is not found, try to repeat the book "
"search first."
msgstr ""
"Книга по указанной Вами ссылке не найдена, попробуйте повторить поиск книги "
"сначала."

#: .\opds_catalog\management\commands\sopds_telebot.py:250
msgid "Annotation:"
msgstr "Аннотация:"

#: .\opds_catalog\management\commands\sopds_telebot.py:313
msgid "There was a technical error, please contact the Bot administrator."
msgstr "Возникла техническая ошибка, обратитесь к администратору Бота."

#: .\opds_catalog\sopdscan.py:233
msgid "Unknown author"
msgstr "Неизвестный автор"
@@ -268,59 +338,6 @@ msgstr "Неизвестный автор"
msgid "All books by %(full_name)s"
msgstr "Все книги автора %(full_name)s"

#~ msgid ""
#~ "Hello %s!\n"
#~ "Unfortunately you do not have access to information. Please contact the "
#~ "bot administrator."
#~ msgstr ""
#~ "Здравствуйте %s!\n"
#~ "К сожалению у Вас отсутствует доступ к информации. Обратитесь к "
#~ "администратору бота."

#~ msgid "Denied access for user: %s"
#~ msgstr "Отказ в доступе для пользователя: %s"

#~ msgid ""
#~ "%(subtitle)s\n"
#~ "Hello %(username)s! To search for a book, enter part of her title or "
#~ "author:"
#~ msgstr ""
#~ "%(subtitle)s\n"
#~ "Здравствуйте %(username)s! Для поиска книги, введите часть ее "
#~ "наименования или автора:"

#~ msgid "(doubles:%s) "
#~ msgstr "(дубликатов:%s) "

#~ msgid "Too short for search, please try again."
#~ msgstr "Слишком короткая строка для поиска, попробуйте еще раз."

#~ msgid "I'm searching for the book: %s"
#~ msgstr "Выполняю поиск книги: %s"

#~ msgid "No results were found for your query, please try again."
#~ msgstr "По Вашему запросу ничего не найдено, попробуйте еще раз."

#~ msgid ""
#~ "Found %s books.\n"
#~ "I create list, after a few seconds, select the file to download:"
#~ msgstr ""
#~ "Найдено %s книг(и). \n"
#~ "Формирую список, через несколько секунд выберите нужную для скачивания:"

#~ msgid ""
#~ "The book on the link you specified is not found, try to repeat the book "
#~ "search first."
#~ msgstr ""
#~ "Книга по указанной Вами ссылке не найдена, попробуйте повторить поиск "
#~ "книги сначала."

#~ msgid "Annotation:"
#~ msgstr "Аннотация:"

#~ msgid "There was a technical error, please contact the Bot administrator."
#~ msgstr "Возникла техническая ошибка, обратитесь к администратору Бота."

#~ msgid "Book name:"
#~ msgstr "Название:"

+15 −2
Original line number Diff line number Diff line
@@ -24,10 +24,18 @@ from telegram.error import InvalidToken

query_delimiter = "####"

def cmdtrans(func):
    def wrapper(self, bot, update):
        translation.activate(config.SOPDS_LANGUAGE)
        result =  func(self, bot, update)
        translation.deactivate()
        return result

    return wrapper


def CheckAuthDecorator(func):
    def wrapper(self, bot, update):

        if not config.SOPDS_TELEBOT_AUTH:
            return func(self, bot, update)

@@ -60,7 +68,6 @@ class Command(BaseCommand):
        parser.add_argument('--daemon',action='store_true', dest='daemonize', default=False, help='Daemonize server')
        
    def handle(self, *args, **options):
        translation.activate(config.SOPDS_LANGUAGE)
        self.pidfile = os.path.join(main_settings.BASE_DIR, config.SOPDS_TELEBOT_PID)
        action = options['command']            
        self.logger = logging.getLogger('')
@@ -96,6 +103,7 @@ class Command(BaseCommand):
            pid = open(self.pidfile, "r").read()
            self.restart(pid)

    @cmdtrans
    @CheckAuthDecorator
    def startCommand(self, bot, update):
        bot.sendMessage(chat_id=update.message.chat_id, text=_("%(subtitle)s\nHello %(username)s! To search for a book, enter part of her title or author:")%
@@ -176,6 +184,7 @@ class Command(BaseCommand):

        return {'message':response, 'buttons':markup}

    @cmdtrans
    @CheckAuthDecorator
    def getBooks(self, bot, update):
        query=update.message.text
@@ -208,6 +217,7 @@ class Command(BaseCommand):
        response = self.BookPager(books, 1, query)
        bot.send_message(chat_id=update.message.chat_id, text=response['message'], parse_mode='HTML', reply_markup=response['buttons'])

    @cmdtrans
    @CheckAuthDecorator
    def getBooksPage(self, bot, update):
        callback_query = update.callback_query
@@ -224,6 +234,7 @@ class Command(BaseCommand):
        bot.edit_message_text(chat_id=callback_query.message.chat_id, message_id=callback_query.message.message_id, text=response['message'], parse_mode='HTML', reply_markup=response['buttons'])
        return

    @cmdtrans
    @CheckAuthDecorator
    def downloadBooks(self, bot, update):
        book_id_set=re.findall(r'\d+$',update.message.text)
@@ -260,6 +271,7 @@ class Command(BaseCommand):
        self.logger.info("Send download buttons.")
        return

    @cmdtrans
    @CheckAuthDecorator
    def getBookFile(self, bot, update):
        callback_query = update.callback_query
@@ -315,6 +327,7 @@ class Command(BaseCommand):

        return

    @cmdtrans
    @CheckAuthDecorator
    def botCallback(self, bot, update):
        query = update.callback_query
−2.47 KiB

File deleted.

+0 −79
Original line number Diff line number Diff line
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-04-03 22:20+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || (n"
"%100>=11 && n%100<=14)? 2 : 3);\n"
#: .\opds_catalog\management\commands\sopds_telebot.py:45
#, python-format
msgid ""
"Hello %s!\n"
"Unfortunately you do not have access to information. Please contact the bot "
"administrator."
msgstr "Здравствуйте %s!\nК сожалению у Вас отсутствует доступ к информации. Обратитесь к администратору бота."

#: .\opds_catalog\management\commands\sopds_telebot.py:46
#, python-format
msgid "Denied access for user: %s"
msgstr "Отказ в доступе для пользователя: %s"

#: .\opds_catalog\management\commands\sopds_telebot.py:99
#, python-format
msgid ""
"%(subtitle)s\n"
"Hello %(username)s! To search for a book, enter part of her title or author:"
msgstr "%(subtitle)s\nЗдравствуйте %(username)s! Для поиска книги, введите часть ее наименования или автора:"

#: .\opds_catalog\management\commands\sopds_telebot.py:164
#, python-format
msgid "(doubles:%s) "
msgstr "(дубликатов:%s) "

#: .\opds_catalog\management\commands\sopds_telebot.py:183
msgid "Too short for search, please try again."
msgstr "Слишком короткая строка для поиска, попробуйте еще раз."

#: .\opds_catalog\management\commands\sopds_telebot.py:185
#, python-format
msgid "I'm searching for the book: %s"
msgstr "Выполняю поиск книги: %s"

#: .\opds_catalog\management\commands\sopds_telebot.py:197
msgid "No results were found for your query, please try again."
msgstr "По Вашему запросу ничего не найдено, попробуйте еще раз."

#: .\opds_catalog\management\commands\sopds_telebot.py:202
#, python-format
msgid ""
"Found %s books.\n"
"I create list, after a few seconds, select the file to download:"
msgstr "Найдено %s книг(и). \nФормирую список, через несколько секунд выберите нужную для скачивания:"

#: .\opds_catalog\management\commands\sopds_telebot.py:240
#: .\opds_catalog\management\commands\sopds_telebot.py:277
msgid ""
"The book on the link you specified is not found, try to repeat the book "
"search first."
msgstr "Книга по указанной Вами ссылке не найдена, попробуйте повторить поиск книги сначала."

#: .\opds_catalog\management\commands\sopds_telebot.py:246
msgid "Annotation:"
msgstr "Аннотация:"

#: .\opds_catalog\management\commands\sopds_telebot.py:309
msgid "There was a technical error, please contact the Bot administrator."
msgstr "Возникла техническая ошибка, обратитесь к администратору Бота."
Loading