• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.send_async函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中utils.send_async函数的典型用法代码示例。如果您正苦于以下问题:Python send_async函数的具体用法?Python send_async怎么用?Python send_async使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: new_game

def new_game(bot, update):
    """Handler for the /new command"""
    chat_id = update.message.chat_id

    if update.message.chat.type == 'private':
        help(bot, update)

    else:

        if update.message.chat_id in gm.remind_dict:
            for user in gm.remind_dict[update.message.chat_id]:
                send_async(bot,
                           user,
                           text=_("A new game has been started in {title}").format(
                                title=update.message.chat.title))

            del gm.remind_dict[update.message.chat_id]

        game = gm.new_game(update.message.chat)
        game.owner = update.message.from_user
        send_async(bot, chat_id,
                   text=_("Created a new game! Join the game with /join "
                          "and start the game with /start"))

        if botan:
            botan.track(update.message, 'New games')
开发者ID:bay122,项目名称:mau_mau_bot,代码行数:26,代码来源:bot.py


示例2: stats

def stats(bot, update):
    user = update.message.from_user
    us = UserSetting.get(id=user.id)
    if not us or not us.stats:
        send_async(bot, update.message.chat_id,
                   text=_("You did not enable statistics. Use /settings in "
                          "a private chat with the bot to enable them."))
    else:
        stats_text = list()

        n = us.games_played
        stats_text.append(
            _("{number} game played",
              "{number} games played",
              n).format(number=n)
        )

        n = us.first_places
        stats_text.append(
            _("{number} first place",
              "{number} first places",
              n).format(number=n)
        )

        n = us.cards_played
        stats_text.append(
            _("{number} card played",
              "{number} cards played",
              n).format(number=n)
        )

        send_async(bot, update.message.chat_id,
                   text='\n'.join(stats_text))
开发者ID:jh0ker,项目名称:mau_mau_bot,代码行数:33,代码来源:simple_commands.py


示例3: skip_player

def skip_player(bot, update):
    """Handler for the /skip command"""
    chat = update.message.chat
    user = update.message.from_user

    player = gm.player_for_user_in_chat(user, chat)
    if not player:
        send_async(bot, chat.id,
                   text=_("You are not playing in a game in this chat."))
        return

    game = player.game
    skipped_player = game.current_player
    next_player = game.current_player.next

    started = skipped_player.turn_started
    now = datetime.now()
    delta = (now - started).seconds

    if delta < skipped_player.waiting_time:
        send_async(bot, chat.id,
                   text=_("Please wait {time} seconds")
                   .format(time=(skipped_player.waiting_time - delta)),
                   reply_to_message_id=update.message.message_id)

    elif skipped_player.waiting_time > 0:
        skipped_player.anti_cheat += 1
        skipped_player.waiting_time -= 30
        try:
            skipped_player.draw()
        except DeckEmptyError:
            pass

        send_async(bot, chat.id,
                   text=__("Waiting time to skip this player has "
                           "been reduced to {time} seconds.\n"
                           "Next player: {name}", game.translate)
                   .format(time=skipped_player.waiting_time,
                           name=display_name(next_player.user)))
        game.turn()

    else:
        try:
            gm.leave_game(skipped_player.user, chat)
            send_async(bot, chat.id,
                       text=__("{name1} was skipped four times in a row "
                               "and has been removed from the game.\n"
                               "Next player: {name2}", game.translate)
                       .format(name1=display_name(skipped_player.user),
                               name2=display_name(next_player.user)))

        except NotEnoughPlayersError:
            send_async(bot, chat.id,
                       text=__("{name} was skipped four times in a row "
                               "and has been removed from the game.\n"
                               "The game ended.", game.translate)
                       .format(name=display_name(skipped_player.user)))

            gm.end_game(chat.id, skipped_player.user)
开发者ID:imlonghao,项目名称:unocn_bot,代码行数:59,代码来源:bot.py


示例4: reset_waiting_time

def reset_waiting_time(bot, player):
    """Resets waiting time for a player and sends a notice to the group"""
    chat = player.game.chat

    if player.waiting_time < 90:
        player.waiting_time = 90
        send_async(bot, chat.id,
                   text=__("Waiting time for {name} has been reset to 90 "
                           "seconds", multi=player.game.translate)
                   .format(name=display_name(player.user)))
开发者ID:bay122,项目名称:mau_mau_bot,代码行数:10,代码来源:bot.py


示例5: locale_select

def locale_select(bot, update, groups):
    chat = update.message.chat
    user = update.message.from_user
    option = groups[0]

    if option in available_locales:
        us = UserSetting.get(id=user.id)
        us.lang = option
        _.push(option)
        send_async(bot, chat.id, text=_("Set locale!"))
        _.pop()
开发者ID:LoonCode,项目名称:mau_mau_bot,代码行数:11,代码来源:settings.py


示例6: notify_me

def notify_me(bot, update):
    """Handler for /notify_me command, pm people for next game"""
    chat_id = update.message.chat_id
    if update.message.chat.type == 'private':
        send_async(bot,
                   chat_id,
                   text=_("Send this command in a group to be notified "
                          "when a new game is started there."))
    else:
        try:
            gm.remind_dict[chat_id].add(update.message.from_user.id)
        except KeyError:
            gm.remind_dict[chat_id] = {update.message.from_user.id}
开发者ID:bay122,项目名称:mau_mau_bot,代码行数:13,代码来源:bot.py


示例7: leave_game

def leave_game(bot, update):
    """Handler for the /leave command"""
    chat = update.message.chat
    user = update.message.from_user

    player = gm.player_for_user_in_chat(user, chat)

    if player is None:
        send_async(bot, chat.id, text=_("You are not playing in a game in "
                                        "this group."),
                   reply_to_message_id=update.message.message_id)
        return

    game = player.game
    user = update.message.from_user

    try:
        gm.leave_game(user, chat)

    except NoGameInChatError:
        send_async(bot, chat.id, text=_("You are not playing in a game in "
                                        "this group."),
                   reply_to_message_id=update.message.message_id)

    except NotEnoughPlayersError:
        gm.end_game(chat, user)
        send_async(bot, chat.id, text=__("Game ended!", multi=game.translate))

    else:
        send_async(bot, chat.id,
                   text=__("Okay. Next Player: {name}",
                           multi=game.translate).format(
                       name=display_name(game.current_player.user)),
                   reply_to_message_id=update.message.message_id)
开发者ID:bay122,项目名称:mau_mau_bot,代码行数:34,代码来源:bot.py


示例8: do_call_bluff

def do_call_bluff(bot, player):
    """Handles the bluff calling"""
    game = player.game
    chat = game.chat

    if player.prev.bluffing:
        send_async(bot, chat.id,
                   text=__("Bluff called! Giving 4 cards to {name}",
                           multi=game.translate)
                   .format(name=player.prev.user.first_name))

        try:
            player.prev.draw()
        except DeckEmptyError:
            send_async(bot, player.game.chat.id,
                       text=__("There are no more cards in the deck.",
                               multi=game.translate))

    else:
        game.draw_counter += 2
        send_async(bot, chat.id,
                   text=__("{name1} didn't bluff! Giving 6 cards to {name2}",
                           multi=game.translate)
                   .format(name1=player.prev.user.first_name,
                           name2=player.user.first_name))
        try:
            player.draw()
        except DeckEmptyError:
            send_async(bot, player.game.chat.id,
                       text=__("There are no more cards in the deck.",
                               multi=game.translate))

    game.turn()
开发者ID:bay122,项目名称:mau_mau_bot,代码行数:33,代码来源:bot.py


示例9: new_game

def new_game(bot, update):
    """Handler for the /new command"""
    chat_id = update.message.chat_id

    if update.message.chat.type == 'private':
        help(bot, update)

    else:
        game = gm.new_game(update.message.chat)
        game.owner = update.message.from_user
        send_async(bot, chat_id,
                   text=_("Created a new game! Join the game with /join "
                          "and start the game with /start"))

        if botan:
            botan.track(update.message, 'New games')
开发者ID:imlonghao,项目名称:unocn_bot,代码行数:16,代码来源:bot.py


示例10: do_draw

def do_draw(bot, player):
    """Does the drawing"""
    game = player.game
    draw_counter_before = game.draw_counter

    try:
        player.draw()
    except DeckEmptyError:
        send_async(bot, player.game.chat.id,
                   text=__("There are no more cards in the deck.",
                           multi=game.translate))

    if (game.last_card.value == c.DRAW_TWO or
        game.last_card.special == c.DRAW_FOUR) and \
            draw_counter_before > 0:
        game.turn()
开发者ID:bay122,项目名称:mau_mau_bot,代码行数:16,代码来源:bot.py


示例11: process_result

def process_result(bot, update):
    """
    Handler for chosen inline results.
    Checks the players actions and acts accordingly.
    """
    try:
        user = update.chosen_inline_result.from_user
        player = gm.userid_current[user.id]
        game = player.game
        result_id = update.chosen_inline_result.result_id
        chat = game.chat
    except (KeyError, AttributeError):
        return

    logger.debug("Selected result: " + result_id)

    result_id, anti_cheat = result_id.split(':')
    last_anti_cheat = player.anti_cheat
    player.anti_cheat += 1

    if result_id in ('hand', 'gameinfo', 'nogame'):
        return
    elif len(result_id) == 36:  # UUID result
        return
    elif int(anti_cheat) != last_anti_cheat:
        send_async(bot, chat.id,
                   text=__("Cheat attempt by {name}", multi=game.translate)
                   .format(name=display_name(player.user)))
        return
    elif result_id == 'call_bluff':
        reset_waiting_time(bot, player)
        do_call_bluff(bot, player)
    elif result_id == 'draw':
        reset_waiting_time(bot, player)
        do_draw(bot, player)
    elif result_id == 'pass':
        game.turn()
    elif result_id in c.COLORS:
        game.choose_color(result_id)
    else:
        reset_waiting_time(bot, player)
        do_play_card(bot, player, result_id)

    if game in gm.chatid_games.get(chat.id, list()):
        send_async(bot, chat.id,
                   text=__("Next player: {name}", multi=game.translate)
                   .format(name=display_name(game.current_player.user)))
开发者ID:bay122,项目名称:mau_mau_bot,代码行数:47,代码来源:bot.py


示例12: status_update

def status_update(bot, update):
    """Remove player from game if user leaves the group"""
    chat = update.message.chat

    if update.message.left_chat_member:
        user = update.message.left_chat_member

        try:
            gm.leave_game(user, chat)
            game = gm.player_for_user_in_chat(user, chat).game

        except NoGameInChatError:
            pass
        except NotEnoughPlayersError:
            gm.end_game(chat, user)
            send_async(bot, chat.id, text=__("Game ended!", game.translate))
        else:
            send_async(bot, chat.id, text=__("Removing {name} from the game",
                                             game.translate)
                       .format(name=display_name(user)))
开发者ID:imlonghao,项目名称:unocn_bot,代码行数:20,代码来源:bot.py


示例13: manageSubscribe

def manageSubscribe(bot, update):
    chat_id = update.message.chat.id
    subscribes = r.table('users').get(chat_id).run(db)
    if subscribes is None:
        send_async(bot, chat_id, '您什么也没有订阅',
                   reply_markup=ReplyKeyboardMarkup(keyboard=KB, one_time_keyboard=True))
        return
    kb = []
    for sub in subscribes['value']:
        q = r.table('traces').get(sub).run(db)
        kb.append(['[{0}] {1} ({2})'.format(
            q['com'],
            q['id'],
            STATES[q['state']]
        )])
    kb.append([
        '%s 查询/订阅快件' % Emoji.EYES,
        '%s 管理订阅' % Emoji.CLIPBOARD,
    ])
    send_async(bot, chat_id, '以下的是您的订阅',
               reply_markup=ReplyKeyboardMarkup(keyboard=kb, one_time_keyboard=True))
开发者ID:imlonghao,项目名称:ExpressCN_bot,代码行数:21,代码来源:bot.py


示例14: disable_translations

def disable_translations(bot, update):
    """Handler for the /disable_translations command"""
    chat = update.message.chat
    user = update.message.from_user
    games = gm.chatid_games.get(chat.id)

    if not games:
        send_async(bot, chat.id,
                   text=_("There is no running game in this chat."))
        return

    game = games[-1]

    if game.owner.id == user.id:
        game.translate = False
        send_async(bot, chat.id, text=_("Disabled multi-translations. "
                                        "Enable them again with "
                                        "/enable_translations"))
        return

    else:
        send_async(bot, chat.id,
                   text=_("Only the game creator ({name}) can do that")
                   .format(name=game.owner.first_name),
                   reply_to_message_id=update.message.message_id)
        return
开发者ID:bay122,项目名称:mau_mau_bot,代码行数:26,代码来源:bot.py


示例15: help

def help(bot, update):
    chat_id = update.message.chat.id
    if user_action.get(chat_id) == 1:
        express_id = update.message.text
        user_action[chat_id] = express_id
        result = getDetail(express_id)
        if result == '快递单号不正确':
            send_async(bot, chat_id, result,
                       reply_markup=ReplyKeyboardMarkup(keyboard=KB, one_time_keyboard=True))
            return
        subscribes = r.table('users').get(chat_id).run(db)
        if subscribes is not None and express_id in subscribes['value']:
            kb = [
                ['%s 取消对该快件的订阅' % Emoji.BELL_WITH_CANCELLATION_STROKE],
                [
                    '%s 查询/订阅快件' % Emoji.EYES,
                    '%s 管理订阅' % Emoji.CLIPBOARD,
                ]
            ]
        else:
            kb = [
                ['%s 订阅该快件' % Emoji.BELL],
                [
                    '%s 查询/订阅快件' % Emoji.EYES,
                    '%s 管理订阅' % Emoji.CLIPBOARD,
                ]
            ]
        send_async(bot, chat_id, result, parse_mode='html',
                   reply_markup=ReplyKeyboardMarkup(
                       keyboard=kb,
                       one_time_keyboard=True))
        return
    send_async(bot, chat_id, '请按照下面的提示进行操作~',
               reply_markup=ReplyKeyboardMarkup(keyboard=KB, one_time_keyboard=True))
开发者ID:imlonghao,项目名称:ExpressCN_bot,代码行数:34,代码来源:bot.py


示例16: do_play_card

def do_play_card(bot, player, result_id):
    """Plays the selected card and sends an update to the group if needed"""
    card = c.from_str(result_id)
    player.play(card)
    game = player.game
    chat = game.chat
    user = player.user

    us = UserSetting.get(id=user.id)
    if not us:
        us = UserSetting(id=user.id)

    if us.stats:
        us.cards_played += 1

    if game.choosing_color:
        send_async(bot, chat.id, text=_("Please choose a color"))

    if len(player.cards) == 1:
        send_async(bot, chat.id, text="UNO!")

    if len(player.cards) == 0:
        send_async(bot, chat.id,
                   text=__("{name} won!", multi=game.translate)
                   .format(name=user.first_name))

        if us.stats:
            us.games_played += 1

            if game.players_won is 0:
                us.first_places += 1

        game.players_won += 1

        try:
            gm.leave_game(user, chat)
        except NotEnoughPlayersError:
            send_async(bot, chat.id,
                       text=__("Game ended!", multi=game.translate))

            us2 = UserSetting.get(id=game.current_player.user.id)
            if us2 and us2.stats:
                us2.games_played += 1

            gm.end_game(chat, user)

    if botan:
        botan.track(Message(randint(1, 1000000000), user, datetime.now(),
                            Chat(chat.id, 'group')),
                    'Played cards')
开发者ID:bay122,项目名称:mau_mau_bot,代码行数:50,代码来源:bot.py


示例17: kb_select

def kb_select(bot, update, groups):
    chat = update.message.chat
    user = update.message.from_user
    option = groups[0]

    if option == Emoji.BAR_CHART:
        us = UserSetting.get(id=user.id)
        us.stats = True
        send_async(bot, chat.id, text=_("Enabled statistics!"))

    elif option == Emoji.EARTH_GLOBE_EUROPE_AFRICA:
        kb = [[locale + ' - ' + descr]
              for locale, descr
              in sorted(available_locales.items())]
        send_async(bot, chat.id, text=_("Select locale"),
                   reply_markup=ReplyKeyboardMarkup(keyboard=kb,
                                                    one_time_keyboard=True))

    elif option == Emoji.CROSS_MARK:
        us = UserSetting.get(id=user.id)
        us.stats = False
        us.first_places = 0
        us.games_played = 0
        us.cards_played = 0
        send_async(bot, chat.id, text=_("Deleted and disabled statistics!"))
开发者ID:LoonCode,项目名称:mau_mau_bot,代码行数:25,代码来源:settings.py


示例18: close_game

def close_game(bot, update):
    """Handler for the /close command"""
    chat = update.message.chat
    user = update.message.from_user
    games = gm.chatid_games.get(chat.id)

    if not games:
        send_async(bot, chat.id,
                   text=_("There is no running game in this chat."))
        return

    game = games[-1]

    if game.owner.id == user.id:
        game.open = False
        send_async(bot, chat.id, text=_("Closed the lobby. "
                                        "No more players can join this game."))
        return

    else:
        send_async(bot, chat.id,
                   text=_("Only the game creator ({name}) can do that.")
                   .format(name=game.owner.first_name),
                   reply_to_message_id=update.message.message_id)
        return
开发者ID:bay122,项目名称:mau_mau_bot,代码行数:25,代码来源:bot.py


示例19: show_settings

def show_settings(bot, update):
    chat = update.message.chat

    if update.message.chat.type != 'private':
        send_async(bot, chat.id,
                   text=_("Please edit your settings in a private chat with "
                          "the bot."))
        return

    us = UserSetting.get(id=update.message.from_user.id)

    if not us:
        us = UserSetting(id=update.message.from_user.id)

    if not us.stats:
        stats = Emoji.BAR_CHART + ' ' + _("Enable statistics")
    else:
        stats = Emoji.CROSS_MARK + ' ' + _("Delete all statistics")

    kb = [[stats], [Emoji.EARTH_GLOBE_EUROPE_AFRICA + ' ' + _("Language")]]
    send_async(bot, chat.id, text=Emoji.WRENCH + ' ' + _("Settings"),
               reply_markup=ReplyKeyboardMarkup(keyboard=kb,
                                                one_time_keyboard=True))
开发者ID:LoonCode,项目名称:mau_mau_bot,代码行数:23,代码来源:settings.py


示例20: join_game

def join_game(bot, update):
    """Handler for the /join command"""
    chat = update.message.chat

    if update.message.chat.type == 'private':
        help(bot, update)
        return

    try:
        gm.join_game(update.message.from_user, chat)

    except LobbyClosedError:
            send_async(bot, chat.id, text=_("The lobby is closed"))

    except NoGameInChatError:
        send_async(bot, chat.id,
                   text=_("No game is running at the moment. "
                          "Create a new game with /new"),
                   reply_to_message_id=update.message.message_id)

    except AlreadyJoinedError:
        send_async(bot, chat.id,
                   text=_("You already joined the game. Start the game "
                          "with /start"),
                   reply_to_message_id=update.message.message_id)

    except DeckEmptyError:
        send_async(bot, chat.id,
                   text=_("There are not enough cards left in the deck for "
                          "new players to join."),
                   reply_to_message_id=update.message.message_id)

    else:
        send_async(bot, chat.id,
                   text=_("Joined the game"),
                   reply_to_message_id=update.message.message_id)
开发者ID:bay122,项目名称:mau_mau_bot,代码行数:36,代码来源:bot.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.send_email函数代码示例发布时间:2022-05-26
下一篇:
Python utils.sendLog函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap