当前位置: 首页>>代码示例>>Python>>正文


Python Bot.answerCallbackQuery方法代码示例

本文整理汇总了Python中telegram.Bot.answerCallbackQuery方法的典型用法代码示例。如果您正苦于以下问题:Python Bot.answerCallbackQuery方法的具体用法?Python Bot.answerCallbackQuery怎么用?Python Bot.answerCallbackQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在telegram.Bot的用法示例。


在下文中一共展示了Bot.answerCallbackQuery方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: inlinekeyboard

# 需要导入模块: from telegram import Bot [as 别名]
# 或者: from telegram.Bot import answerCallbackQuery [as 别名]
def inlinekeyboard(bot: Bot, update):
    """Seleziona un preset dalla tastiera."""
    game = findgamebyid(update.callback_query.message.chat.id)
    if game is None:
        bot.answerCallbackQuery(callback_query_id=update.callback_query.id, text=s.error_no_games_found, show_alert=True)
        return
    if game.phase is 'Preset':
        if update.callback_query.from_user.id != game.admin.tid:
            bot.answerCallbackQuery(callback_query_id=update.callback_query.id, text=s.error_not_admin, show_alert=True)
            return
        game.loadpreset(update.callback_query.data)
        bot.answerCallbackQuery(callback_query_id=update.callback_query.id, text=s.preset_selected.format(selected=update.callback_query.data))
    elif game.phase is 'Voting':
        # Controlla che non sia il primo giorno
        if game.day <= 1:
            bot.answerCallbackQuery(callback_query_id=update.callback_query.id, text=s.error_no_votes_on_first_day, show_alert=True)
            return
        # Trova il giocatore
        player = game.findplayerbyid(update.callback_query.from_user.id)
        if player is None:
            bot.answerCallbackQuery(callback_query_id=update.callback_query.id, text=s.error_not_in_game, show_alert=True)
            return
        # Controlla che sia vivo
        if not player.alive:
            bot.answerCallbackQuery(callback_query_id=update.callback_query.id, text=s.error_dead, show_alert=True)
            return
        if update.callback_query.data == "-":
            # Annulla il voto
            player.votingfor = None
            game.message(s.vote_none.format(player=player))
            bot.answerCallbackQuery(callback_query_id=update.callback_query.id, text=s.vote_none_fp)
        else:
            # Cambia il voto
            target = game.findplayerbyusername(update.callback_query.data)
            player.votingfor = target
            game.message(s.vote.format(voting=player.tusername, voted=target.tusername))
            bot.answerCallbackQuery(callback_query_id=update.callback_query.id, text=s.vote_fp.format(voted=target.tusername))
        # Aggiorna i voti
        game.updatevotes()
        mostvoted = game.mostvotedplayers()
        # Aggiorna la tastiera
        table = list()
        for player in game.players:
            if not player.alive:
                continue
            if player in mostvoted:
                status_icon = s.status_most_voted
            else:
                status_icon = s.status_normal_voted
            row = list()
            row.append(InlineKeyboardButton(s.vote_keyboard_line.format(status=status_icon, player=player, votes=player.votes),
                                            callback_data=player.tusername))
            table.append(row)
        row = list()
        row.append(InlineKeyboardButton(s.vote_keyboard_nobody, callback_data="-"))
        table.append(row)
        keyboard = InlineKeyboardMarkup(table)
        # Manda la tastiera
        bot.editMessageReplyMarkup(game.groupid, game.votemsg.message_id, reply_markup=keyboard)
开发者ID:Steffo99,项目名称:royal-mifia,代码行数:61,代码来源:main.py


注:本文中的telegram.Bot.answerCallbackQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。