def test_addGamePoolAmount(self):
        original: GamblingGame = GamblingUtil.create_game(
            123, "new_game", 5, ["hello", "hi"], 123)
        GamblingUtil.add_game_pool_amount(original, 300)
        original = GamblingUtil.get_game(original.id)

        assert original.pool == 300
    def test_getActiveGameInChannel(self):
        original: GamblingGame = GamblingUtil.create_game(
            123, "new_game", 5, ["hello", "hi"], 123)
        GamblingUtil.update_game_status(original, Util.GamblingStatus.ready,
                                        123, 456)

        game = GamblingUtil.get_active_game_in_channel(123, 456)
        assert len(game) == 0
        game = GamblingUtil.get_active_game_in_channel(123, 123)
        assert game == [original]

        another = GamblingUtil.create_game(123, "new_game", 5, ["hello", "hi"],
                                           123)
        GamblingUtil.update_game_status(another, Util.GamblingStatus.ready,
                                        123, 456)
        game = GamblingUtil.get_active_game_in_channel(123, 123)
        assert len(game) == 2
    def test_updateGameStatus(self):
        game: GamblingGame = GamblingUtil.create_game(123, "new_game", 5,
                                                      ["hello", "hi"], 123)
        GamblingUtil.update_game_status(game, Util.GamblingStatus.ready, 123,
                                        456)
        result_game = GamblingUtil.get_game(game.id)

        assert game == result_game
    def test_getBets(self):
        original: GamblingGame = GamblingUtil.create_game(
            123, "new_game", 5, ["hello", "hi"], 123)
        GamblingUtil.update_game_status(original, Util.GamblingStatus.ready,
                                        123, 456)
        assert GamblingUtil.add_bet(original, 123, 10, 1)

        bets = GamblingUtil.get_bets(original)
        assert len(bets) == 1
    def test_getActiveGameList(self):
        game1: GamblingGame = GamblingUtil.create_game(123, "new_game1", 5,
                                                       ["hello", "hi"], 123)
        game2: GamblingGame = GamblingUtil.create_game(123, "new_game2", 5,
                                                       ["hello", "hi"], 123)
        gameList = GamblingUtil.get_active_games(123)
        assert len(gameList) == 0

        GamblingUtil.update_game_status(game1, Util.GamblingStatus.ready, 123,
                                        321)
        gameList = GamblingUtil.get_active_games(123)
        assert len(gameList) == 1

        GamblingUtil.update_game_status(game2, Util.GamblingStatus.ready, 123,
                                        321)
        gameList = GamblingUtil.get_active_games(123)
        assert len(gameList) == 2
        assert gameList == [game1, game2]
    def test_gameCreation(self):
        game: GamblingGame = GamblingUtil.create_game(123, "new_game", 5,
                                                      ["hello", "hi"], 123)

        assert game.guild_id == 123
        assert game.name == "new_game"
        assert game.base == 5
        assert game.pool == 0
        assert game.item_list == ["hello", "hi"]
        assert game.creater_id == 123
        assert game.status == Util.GamblingStatus.init
    def test_addBetSuccess(self):
        original: GamblingGame = GamblingUtil.create_game(
            123, "new_game", 5, ["hello", "hi"], 123)
        GamblingUtil.update_game_status(original, Util.GamblingStatus.ready,
                                        123, 456)
        assert GamblingUtil.add_bet(original, 123, 10, 1)

        original: GamblingGame = GamblingUtil.get_game(original.id)
        assert original.pool == 10

        assert GamblingUtil.add_bet(original, 123, 10, 1)
        assert original.pool == 20
Пример #8
0
    async def betting_create_command(self, ctx: commands.Context, *argv):

        descript_base = '請<@{}>跟著指示完成創建\n'.format(ctx.author.id)
        embed = Embed()
        embed.title = '創建賭盤: 創建者<@!{}>'.format(ctx.author.id)
        embed.description = descript_base
        embed.add_field(name='設定賭盤名稱', value='請直接回覆賭局名稱', inline=False)
        embed.add_field(name='設定賭注單位', value='請先回覆賭局名稱', inline=False)
        main_message = await ctx.channel.send(embed=embed)

        def reaction_check(reaction, user):
            if user == ctx.author and reaction.message == main_message:
                return str(reaction.emoji) == '⭕' or '❌'
            else:
                return False

        betting_count = 0
        bet_item_offset = 2

        if not await GamblingUtil.create_loop(embed, main_message, ctx,
                                              type(str()), '賭盤名稱', 0):
            return
        embed.set_field_at(1, name='設定賭注單位', value='請直接回覆每注單位', inline=False)
        await main_message.edit(embed=embed)
        if not await GamblingUtil.create_loop(embed, main_message, ctx,
                                              type(int()), '賭注單位', 1):
            return
        add_flag = True
        while add_flag or betting_count < 2:
            embed.add_field(name='設定賭注項目-第{}項'.format(betting_count),
                            value='請先回覆賭注項目-第{}項'.format(betting_count),
                            inline=False)
            await main_message.edit(embed=embed)
            if not await GamblingUtil.create_loop(
                    embed, main_message, ctx, type(
                        str()), '賭品-第{}項'.format(betting_count),
                    betting_count + bet_item_offset):
                return
            if betting_count > 0:
                embed.add_field(name='完成設定?',
                                value='完成設定⭕️繼續設定❌',
                                inline=False)
                await main_message.edit(embed=embed)
                await main_message.add_reaction('⭕')
                await main_message.add_reaction('❌')
                try:
                    get_reaction = await self.bot.wait_for(
                        'reaction_add', timeout=30.0, check=reaction_check)
                except asyncio.TimeoutError:
                    embed.set_field_at(betting_count + bet_item_offset + 1,
                                       name='完成設定?-等待反應超時',
                                       value='error')
                    await main_message.clear_reactions()
                    await main_message.edit(embed=embed)
                    return False
                else:
                    if get_reaction[0].emoji == '⭕':
                        tem_list = []
                        for i in embed.fields[2:-1]:
                            tem_list.append(i.value)
                        game: GamblingGame = GamblingUtil.create_game(
                            ctx.guild.id, embed.fields[0].value,
                            int(embed.fields[1].value), tem_list,
                            ctx.author.id)
                        embed.set_field_at(
                            betting_count + bet_item_offset + 1,
                            name='完成設定!!!',
                            value=
                            '設定完成!!!\n請<@{}> 到想要的頻道輸入\n`!betting start {}`\n開啟賭局!'
                            .format(ctx.author.id, game.id),
                            inline=False)
                        add_flag = False
                    else:
                        embed.remove_field(betting_count + bet_item_offset + 1)
                    await main_message.clear_reactions()
                    await main_message.edit(embed=embed)

            betting_count += 1
 def test_addBetFailedNotReady(self):
     original: GamblingGame = GamblingUtil.create_game(
         123, "new_game", 5, ["hello", "hi"], 123)
     assert not GamblingUtil.add_bet(original, 123, 2, 1)