Beispiel #1
0
    def start(chat_id):
        # TODO: change tokens multi.
        try:
            token = Metrika_tokens.select().order_by(Metrika_tokens.id.desc()).where(Metrika_tokens.chat_id == chat_id).get()
            buttons = Handler.get_counters(token, "start")

            send_object_to_chat("Теперь выберите сайт, статистику которого хотите получать.\n", json.dumps({
                'inline_keyboard': buttons
            }), chat_id)

        except Metrika_tokens.DoesNotExist:
            send_to_chat("Для подключения счетчика, вам нужно авторизовать бота. " \
                         "Для этого, пройдите по ссылке и подтвердите доступ к счетчику. \n\n" \
                         "https://oauth.yandex.ru/authorize?response_type=code&client_id=%s&state=%s\n" %
                         (CConfig.MODULES['metrika']['ID'], chat_id),
                         chat_id)
            return
Beispiel #2
0
    def github_stop(self, chat_id):

        repositories = Github_repositories.select().where(Github_repositories.chat_id == chat_id)

        if not len(repositories):
            send_to_chat("У вас не подключено ни одного репозитория.", chat_id)
        else:
            buttons = [
                {
                    'text': repository.repository_name,
                    'callback_data': "/github_delete%s" % str(repository.repository_id)
                } for repository in repositories
            ]
            print(buttons)
            send_object_to_chat("Выберите репозиторий, который хотите отключить.\n", json.dumps({
                'inline_keyboard': [
                    buttons
                ]
            }), chat_id)
Beispiel #3
0
    def metrika_stop(self, chat_id):
        try:
            token = Metrika_tokens.get(Metrika_tokens.chat_id == chat_id)
            counters = Metrika.select().where(Metrika.chat_id == chat_id)
            if len(counters):
                buttons = []
                buttons_row = []
                for counter in counters:
                    buttons_row.append(
                        {'text': counter.counter_name, 'callback_data': "/metrika_%s%s#%s" % ("stop", token.id, counter.counter_id)})
                    CConfig.CACHE['metrika_%s_%s' % (token.id, counter.counter_id)] = counter.counter_name
                    if len(buttons_row) == 2:
                        buttons.append(buttons_row[:])
                        buttons_row = []
                if len(buttons_row):
                    buttons.append(buttons_row[:])

                send_object_to_chat("Выберите сайт, который хотите отключить.\n", json.dumps({
                    'inline_keyboard': buttons
                }), chat_id)
            else:
                send_to_chat("Подключенных счетчиков не найдено.", chat_id)
        except Metrika_tokens.DoesNotExist:
            send_to_chat("Токен не найден.", chat_id)