示例#1
0
def help(bot, update):
    wrapper = TelegramBotResponseWrapper(update)
    lines = [
        '/new_lichess nickname - add your lichess nickname',
        '/elo - user information rating',
        '/link - get user lichess profile link',
        '/menu - bot menu for retrieve lichess users rating, etc',
    ]
    message = '\n'.join(lines)

    bot.send_message(chat_id=wrapper.get_chat_id(),
                     text=message,
                     parse_mode=telegram.ParseMode.HTML)
示例#2
0
def top_chat_lichess(bot, update):
    wrapper = TelegramBotResponseWrapper(update)
    type_game_name = 'blitz'
    # users_telegram_ids = core.get_all_telegram_ids_db()
    # users_ids = core.get_all_users_id_from_chat_without_bot(wrapper.get_chat_id())
    lichess_ids = core.get_all_lichess_ids_from_db()
    users = core.get_users_info_from_chess_api_by_nicknames(
        lichess, lichess_ids)
    sorted_users = core.sorting_user_by_game_type(type_game_name, users)
    message = core.rating_html(lichess.name, type_game_name, sorted_users)

    bot.send_message(chat_id=wrapper.get_chat_id(),
                     text=message,
                     parse_mode=telegram.ParseMode.HTML)
示例#3
0
def top_chat_rating(bot, update, chess_api, type_game_name):
    wrapper = TelegramBotResponseWrapper(update)
    chess_api_users_ids = core.get_all_chess_api_ids_from_db(chess_api.name)

    if chess_api_users_ids is None:
        message = '%s not found' % chess_api.name
    else:
        users = core.get_users_info_from_chess_api_by_nicknames(
            chess_api, chess_api_users_ids)
        sorted_users = core.sorting_user_by_game_type(type_game_name, users)
        message = core.rating_html(lichess.name, type_game_name, sorted_users)

    bot.send_message(chat_id=wrapper.get_chat_id(),
                     text=message,
                     parse_mode=telegram.ParseMode.HTML)
示例#4
0
def menu(bot, update):
    wrapper = TelegramBotResponseWrapper(update)
    permission = Permission(bot)
    keyboard = []

    if not wrapper.check_chat_name(config.chat_name):
        keyboard.append(
            [InlineKeyboardButton("Lichess rating", callback_data='lichess')])
    elif permission.check_user_in_administrators(wrapper.get_user_id(),
                                                 wrapper.get_chat_id()):
        keyboard.append(
            [InlineKeyboardButton("Lichess rating", callback_data='lichess')])
    else:
        pass

    keyboard += [[InlineKeyboardButton("Donate", callback_data='donate')],
                 [InlineKeyboardButton("Contact", callback_data='contact')]]
    reply_markup = InlineKeyboardMarkup(keyboard)

    update.message.reply_text('Please choose:', reply_markup=reply_markup)
示例#5
0
def button(bot, update):
    query = update.callback_query
    query_data = query.data
    permission = Permission(bot)
    wrapper = TelegramBotResponseWrapper(update)

    result = core.convert_string_to_list(query_data)

    if query_data == 'donate':
        bot.edit_message_text(text='<a href="%s">%s</a>' %
                              (config.donate, config.donate),
                              chat_id=query.message.chat_id,
                              message_id=query.message.message_id,
                              parse_mode=telegram.ParseMode.HTML)

    if query_data == 'contact':
        bot.edit_message_text(text='%s' % config.contact,
                              chat_id=query.message.chat_id,
                              message_id=query.message.message_id,
                              parse_mode=telegram.ParseMode.HTML)

    if isinstance(result, list):
        if result[0] == 'lichess':
            if not wrapper.check_chat_name(config.chat_name):
                top_chat_rating(bot, update, lichess, result[1])
            elif permission.check_user_in_administrators(
                    wrapper.get_user_id(), wrapper.get_chat_id()):
                top_chat_rating(bot, update, lichess, result[1])
    else:
        if query.data == ChessAPIEnum.LICHESS.value:
            keyboard = [[
                InlineKeyboardButton(game_type.name,
                                     callback_data="['lichess', '%s']" %
                                     game_type.value)
            ] for game_type in GameType]
            reply_markup = InlineKeyboardMarkup(keyboard)

            bot.edit_message_text(text="Choose game:".format(query.data),
                                  chat_id=query.message.chat_id,
                                  message_id=query.message.message_id,
                                  reply_markup=reply_markup)
示例#6
0
    def create_user(self, update):
        wrapper = TelegramBotResponseWrapper(update)
        user = self._data_access_layer.get_user(wrapper.get_user_id())

        if user is None:
            self._data_access_layer.insert_user(
                wrapper.get_user_id(), wrapper.get_telegram_fullname(),
                wrapper.get_telegram_username())
示例#7
0
def link(bot, update):
    wrapper = TelegramBotResponseWrapper(update)

    reply_message = wrapper.check_reply_message()

    if reply_message:
        user_id = wrapper.get_user_id_from_reply_message()
    else:
        user_id = wrapper.get_user_id()

    user = dal.get_user(user_id)

    if user and user.check_lichess_nickname():
        nickname = user.lichess_nickname
        info = core.get_info_by_nickname(nickname, lichess)
        message = info.get_link_html()
    else:
        message = 'User not register in bot'

    bot.send_message(chat_id=wrapper.get_chat_id(),
                     text=message,
                     parse_mode=telegram.ParseMode.HTML)
示例#8
0
def set_nickname_lichess(bot, update):
    wrapper = TelegramBotResponseWrapper(update)
    args = wrapper.get_command_args()
    nickname = core.get_nickname_from_command_args(args)

    if nickname:
        info = core.get_info_by_nickname(nickname, lichess)
        if isinstance(info, str):
            message = info
        else:
            if dal.get_user(wrapper.get_user_id()) is None:
                core.create_user(update)

            core.update_nickname_and_chess_api_id(wrapper.get_user_id(),
                                                  nickname, lichess,
                                                  info.user_id)
            message = info.get_total_info()
    else:
        message = 'You not sent nickname'

    bot.send_message(chat_id=wrapper.get_chat_id(),
                     text=message,
                     parse_mode=telegram.ParseMode.HTML)