async def test_damage_weapon_only(bot, mocker):
    mocker.patch.object(dice, "roll_d6", return_value=2)

    dpytest.configure(bot)

    await dpytest.message("!damage Sword")
    dpytest.verify_embed(allow_text=True)
async def test_remove_team_from_twitch_alert_with_message(twitch_cog):
    test_custom_message = "We be live gamers!"

    # Creates guild and channels and adds user and bot
    guild = dpytest.backend.make_guild(name="TestGuild")
    channel = dpytest.backend.make_text_channel(name="TestChannel",
                                                guild=guild)
    dpytest.get_config().guilds.append(guild)
    dpytest.get_config().channels.append(channel)
    member = await dpytest.member_join(-1, name="TestUser", discrim=1)
    await dpytest.member_join(-1, dpytest.get_config().client.user)

    # Creates Twitch Alert
    await dpytest.message(
        f"{KoalaBot.COMMAND_PREFIX}add_team_to_twitch_alert {channel.id} faze {test_custom_message}",
        channel=-1,
        member=member)
    await dpytest.empty_queue()
    # Removes Twitch Alert
    await dpytest.message(
        f"{KoalaBot.COMMAND_PREFIX}remove_team_from_twitch_alert {channel.id} faze",
        channel=-1,
        member=member)
    new_embed = discord.Embed(title="Removed Team from Twitch Alert",
                              colour=KOALA_GREEN,
                              description=f"Channel: {channel.id}\n"
                              f"Team: faze")
    dpytest.verify_embed(new_embed)
    pass
async def test_damage_ignore_armor_no_armor(bot, mocker):
    mocker.patch.object(dice, "roll_d6", return_value=5)

    dpytest.configure(bot)

    await dpytest.message("!damage Maul")
    dpytest.verify_embed(allow_text=True)
async def test_damage_bonus(bot, mocker):
    mocker.patch.object(dice, "roll_d6", return_value=3)

    dpytest.configure(bot)

    await dpytest.message("!damage Maul +2")
    dpytest.verify_embed(allow_text=True)
Exemple #5
0
async def test_card_help():
    expected = discord.Embed(title="Liste des cartes \nSyntaxe : !poke <nom>",
                             description="azrod\nbane\nrun\nsergei\nxanatos\nphoe")  # noqa: E501
    expected.set_footer(text="Merci à Slyrax pour les cartes !")

    await dpytest.message('!poke help')
    dpytest.verify_embed(expected)
async def test_damage_armor(bot, mocker, armor, offset, damage):
    mocker.patch.object(dice, "roll_d6", return_value=3)

    dpytest.configure(bot)

    await dpytest.message(f"!damage Sword {armor}")
    dpytest.verify_embed(allow_text=True)
async def test_announce_db_first_creation(announce_cog):
    guild: discord.Guild = dpytest.get_config().guilds[0]
    author: discord.Member = guild.members[0]
    channel: discord.TextChannel = guild.channels[0]
    assert announce_cog.announce_database_manager.get_last_use_date(
        guild.id) is None
    msg_mock: discord.Message = dpytest.back.make_message(
        'testMessage', author, channel)
    with mock.patch('discord.client.Client.wait_for',
                    mock.AsyncMock(return_value=msg_mock)):
        await dpytest.message(KoalaBot.COMMAND_PREFIX + 'announce create',
                              channel=channel)
        dpytest.verify_message(
            "Please enter a message, I'll wait for 60 seconds, no rush.")
        dpytest.verify_message(
            f"An announcement has been created for guild {guild.name}")
        dpytest.verify_embed()
        dpytest.verify_message()
        assert announce_cog.has_active_msg(guild.id)
        assert announce_cog.announce_database_manager.get_last_use_date(
            guild.id) is None
        await dpytest.message(KoalaBot.COMMAND_PREFIX + 'announce send',
                              channel=channel)
        for _ in guild.members:
            dpytest.verify_embed()
        dpytest.verify_message("The announcement was made successfully")
        assert int(time.time(
        )) == announce_cog.announce_database_manager.get_last_use_date(
            guild.id)
async def test_rfr_create_message():
    config: dpytest.RunnerConfig = dpytest.get_config()
    guild: discord.Guild = config.guilds[0]
    channel: discord.TextChannel = guild.text_channels[0]
    embed_channel: discord.TextChannel = dpytest.back.make_text_channel(
        'EmbedChannel', guild)
    author: discord.Member = config.members[0]
    from utils import KoalaColours
    test_embed = discord.Embed(title="React for Role",
                               description="Roles below!",
                               colour=KoalaColours.KOALA_GREEN)
    test_embed.set_footer(text="ReactForRole")
    test_embed.set_thumbnail(url=KoalaBot.KOALA_IMAGE_URL)
    with mock.patch('cogs.ReactForRole.ReactForRole.prompt_for_input',
                    mock.AsyncMock(return_value=embed_channel.mention)):
        with mock.patch('cogs.ReactForRole.ReactForRole.wait_for_message',
                        mock.AsyncMock(return_value=(None, channel))):
            with mock.patch('cogs.ReactForRole.ReactForRole.is_user_alive',
                            mock.AsyncMock(return_value=True)):
                with mock.patch(
                        'discord.ext.test.backend.FakeHttp.edit_channel_permissions'
                ) as mock_edit_channel_perms:
                    with mock.patch('discord.Message.delete') as mock_delete:
                        await dpytest.message(KoalaBot.COMMAND_PREFIX +
                                              "rfr createMessage")
                        mock_edit_channel_perms.assert_called_once()
                        dpytest.verify_message(
                            "Okay, this will create a new react for role message in a channel of your choice."
                            "\nNote: The channel you specify will have its permissions edited to make it such that the "
                            "@ everyone role is unable to add new reactions to messages, they can only reaction with "
                            "existing ones. Please keep this in mind, or setup another channel entirely for this."
                        )
                        dpytest.verify_message(
                            "This should be a thing sent in the right channel."
                        )
                        dpytest.verify_message(
                            "Okay, what would you like the title of the react for role message to be? Please enter within 30 seconds."
                        )
                        dpytest.verify_message(
                            "Okay, didn't receive a title. Do you actually want to continue? Send anything to confirm this."
                        )
                        dpytest.verify_message(
                            "Okay, I'll just put in a default value for you, you can edit it later by using the k!rfr edit commands."
                        )
                        dpytest.verify_message(
                            "Okay, the title of the message will be \"React for Role\". What do you want the description to be?"
                        )
                        dpytest.verify_message(
                            "Okay, didn't receive a description. Do you actually want to continue? Send anything to confirm this."
                        )
                        dpytest.verify_message(
                            "Okay, I'll just put in a default value for you, you can edit it later by using the k!rfr edit command."
                        )
                        dpytest.verify_message(
                            "Okay, the description of the message will be \"Roles below!\".\n Okay, I'll create the react for role message now."
                        )
                        dpytest.verify_embed()
                        msg = dpytest.sent_queue.get_nowait()
                        assert "You can use the other k!rfr subcommands to change the message and add functionality as required." in msg.content
                        mock_delete.assert_called_once()
async def test_add_user_to_twitch_alert_custom_message(twitch_cog):
    test_custom_message = "We be live gamers!"

    guild = dpytest.backend.make_guild(name="TestGuild")
    channel = dpytest.backend.make_text_channel(name="TestChannel",
                                                guild=guild)
    dpytest.get_config().guilds.append(guild)
    dpytest.get_config().channels.append(channel)
    member = await dpytest.member_join(-1, name="TestUser", discrim=1)
    await dpytest.member_join(-1, dpytest.get_config().client.user)

    assert_embed = discord.Embed(title="Added User to Twitch Alert",
                                 description=f"Channel: {channel.id}\n"
                                 f"User: monstercat\n"
                                 f"Message: {test_custom_message}",
                                 colour=KOALA_GREEN)

    await dpytest.message(
        f"{KoalaBot.COMMAND_PREFIX}add_user_to_twitch_alert {channel.id} monstercat {test_custom_message}",
        channel=-1,
        member=member)
    dpytest.verify_embed(embed=assert_embed)

    sql_check_updated_server = f"SELECT custom_message FROM UserInTwitchAlert WHERE twitch_username='******' AND channel_id={channel.id}"
    assert twitch_cog.ta_database_manager.database_manager.db_execute_select(
        sql_check_updated_server) == [(test_custom_message, )]
Exemple #10
0
async def test_comicsblog_command(bot, expected_embed):
    bot.add_cog(comicsblog.Comicsblog(bot))
    dpytest.configure(bot)

    await dpytest.message('!comicsblog 2')

    dpytest.verify_embed(expected_embed)
async def test_remove_user_from_twitch_alert_with_message(twitch_cog):
    test_custom_message = "We be live gamers!"

    # Creates guild and channels and adds user and bot
    guild = dpytest.backend.make_guild(name="TestGuild")
    channel = dpytest.backend.make_text_channel(name="TestChannel",
                                                guild=guild)
    dpytest.get_config().guilds.append(guild)
    dpytest.get_config().channels.append(channel)
    member = await dpytest.member_join(-1, name="TestUser", discrim=1)
    await dpytest.member_join(-1, dpytest.get_config().client.user)

    # Creates Twitch Alert
    await dpytest.message(
        f"{KoalaBot.COMMAND_PREFIX}add_user_to_twitch_alert {channel.id} monstercat {test_custom_message}",
        channel=-1,
        member=member)

    sql_check_updated_server = f"SELECT custom_message FROM UserInTwitchAlert WHERE twitch_username='******' AND channel_id={channel.id}"
    assert twitch_cog.ta_database_manager.database_manager.db_execute_select(
        sql_check_updated_server) == [(test_custom_message, )]
    await dpytest.empty_queue()
    # Removes Twitch Alert
    await dpytest.message(
        f"{KoalaBot.COMMAND_PREFIX}remove_user_from_twitch_alert {channel.id} monstercat",
        channel=-1,
        member=member)
    new_embed = discord.Embed(title="Removed User from Twitch Alert",
                              colour=KOALA_GREEN,
                              description=f"Channel: {channel.id}\n"
                              f"User: monstercat")
    dpytest.verify_embed(new_embed)
    assert twitch_cog.ta_database_manager.database_manager.db_execute_select(
        sql_check_updated_server) == []
    pass
async def test_create_message_after_send_before_30_days(announce_cog):
    guild: discord.Guild = dpytest.get_config().guilds[0]
    author: discord.Member = guild.members[0]
    channel: discord.TextChannel = guild.channels[0]
    msg_mock: discord.Message = dpytest.back.make_message(
        'testMessage', author, channel)
    with mock.patch('discord.client.Client.wait_for',
                    mock.AsyncMock(return_value=msg_mock)):
        await dpytest.message(KoalaBot.COMMAND_PREFIX + 'announce create',
                              channel=channel)
        dpytest.verify_message(
            "Please enter a message, I'll wait for 60 seconds, no rush.")
        dpytest.verify_message(
            f"An announcement has been created for guild {guild.name}")
        dpytest.verify_embed()
        dpytest.verify_message()
        assert announce_cog.has_active_msg(guild.id)
        assert announce_cog.messages[guild.id].description == "testMessage"
        assert announce_cog.messages[guild.id].title == ""
        # sending the message
        await dpytest.message(KoalaBot.COMMAND_PREFIX + 'announce send',
                              channel=channel)
        for _ in guild.members:
            dpytest.verify_embed()
        dpytest.verify_message("The announcement was made successfully")
        # try creating another announcement immediately
        with mock.patch('discord.client.Client.wait_for',
                        mock.AsyncMock(return_value=msg_mock)):
            await dpytest.message(KoalaBot.COMMAND_PREFIX + 'announce create',
                                  channel=channel)
            dpytest.verify_message(
                "You have recently sent an announcement and cannot use this function for 30 days"
            )
            assert not announce_cog.has_active_msg(guild.id)
async def test_create_multiple_message(announce_cog):
    guild: discord.Guild = dpytest.get_config().guilds[0]
    author: discord.Member = guild.members[0]
    channel: discord.TextChannel = guild.channels[0]
    msg_mock: discord.Message = dpytest.back.make_message(
        'testMessage', author, channel)
    with mock.patch('discord.client.Client.wait_for',
                    mock.AsyncMock(return_value=msg_mock)):
        await dpytest.message(KoalaBot.COMMAND_PREFIX + 'announce create',
                              channel=channel)
        dpytest.verify_message(
            "Please enter a message, I'll wait for 60 seconds, no rush.")
        dpytest.verify_message(
            f"An announcement has been created for guild {guild.name}")
        dpytest.verify_embed()
        dpytest.verify_message()
        assert announce_cog.has_active_msg(guild.id)
        assert announce_cog.messages[guild.id].description == "testMessage"
        assert announce_cog.messages[guild.id].title == ""

        msg2_mock: discord.Message = dpytest.back.make_message(
            'testMessage2', author, channel)
        with mock.patch('discord.client.Client.wait_for',
                        mock.AsyncMock(return_value=msg2_mock)):
            await dpytest.message(KoalaBot.COMMAND_PREFIX + 'announce create',
                                  channel=channel)
            dpytest.verify_message(
                "There is currently an active announcement being created, you can use 'k!announce cancel' "
                "or 'k!announce send' to complete it")
            assert announce_cog.has_active_msg(guild.id)
            assert announce_cog.messages[guild.id].description == "testMessage"
            assert announce_cog.messages[guild.id].title == ""
async def test_add_mod_channel():
    channel = dpytest.backend.make_text_channel(name="TestChannel", guild=dpytest.get_config().guilds[0])
    dpytest.get_config().channels.append(channel)

    await dpytest.message(KoalaBot.COMMAND_PREFIX + "setupModChannel "+str(channel.id))
    assert_embed = createNewModChannelEmbed(channel)
    dpytest.verify_embed(embed=assert_embed)
    cleanup(dpytest.get_config().guilds[0].id)
Exemple #15
0
async def test_urban_cog_fails():

    user_input = "mlksjdfmlkjsdfmlkjsdf"
    embed = discord.Embed(
        title=f"Definition of {user_input} doesn't exist")  # noqa: E501

    await dpytest.message(f'!urban {user_input}')
    dpytest.verify_embed(embed)
Exemple #16
0
async def test_command_gif_help():

    expected_embed = discord.Embed(title="liste des gifs",
                                   description="foo\nbar",
                                   color=0x000FF)

    await dpytest.message('!gif help')
    dpytest.verify_embed(expected_embed)
async def test_edit_default_message_existing(twitch_cog):
    this_channel = dpytest.get_config().channels[0]
    assert_embed = discord.Embed(title="Default Message Edited",
                                 description=f"Guild: {dpytest.get_config().guilds[0].id}\n"
                                             f"Channel: {this_channel.id}\n"
                                             "Default Message: {user} is bad")

    await dpytest.message(KoalaBot.COMMAND_PREFIX + "edit_default_message " + str(this_channel.id) + " {user} is bad")
    dpytest.verify_embed(embed=assert_embed)
Exemple #18
0
async def test_on_message_gif(expected_foo_embed):

    try:
        await dpytest.message('!foo')
    except commands.errors.CommandNotFound:
        pass
    finally:
        dpytest.verify_embed(expected_foo_embed)
        await dpytest.empty_queue()
async def test_preview_consistent(announce_cog):
    guild: discord.Guild = dpytest.get_config().guilds[0]
    channel: discord.TextChannel = guild.channels[0]
    make_message(guild, announce_cog)
    embed: discord.Embed = announce_cog.construct_embed(guild)
    await dpytest.message(KoalaBot.COMMAND_PREFIX + 'announce preview',
                          channel=channel)
    dpytest.verify_embed(embed=embed)
    dpytest.verify_message()
async def test_edit_default_message_default_from_none(twitch_cog):
    this_channel = dpytest.get_config().channels[0]
    assert_embed = discord.Embed(title="Default Message Edited",
                                 description=f"Guild: {dpytest.get_config().guilds[0].id}\n"
                                             f"Channel: {this_channel.id}\n"
                                             f"Default Message: {TwitchAlert.DEFAULT_MESSAGE}")

    await dpytest.message(KoalaBot.COMMAND_PREFIX + f"edit_default_message {this_channel.id}")
    dpytest.verify_embed(embed=assert_embed)
Exemple #21
0
async def test_recrutement():
    await dpytest.message('!recrutement')

    expected_embed = discord.Embed(
        title='Rejoins la team DCTrad !',
        description="allez n'aie pas peur de cliquer et deviens un héros !",
        color=0x0000FF,
        url="http://www.dctrad.fr/viewforum.php?f=21")  # noqa: E501

    dpytest.verify_embed(expected_embed)
async def test_list_filtered_words():
    await dpytest.message(KoalaBot.COMMAND_PREFIX + "filter_word listing1")
    assertFilteredConfirmation("listing1","banned")
    await dpytest.message(KoalaBot.COMMAND_PREFIX + "filter_word listing2 risky")
    assertFilteredConfirmation("listing2","risky")

    await dpytest.message(KoalaBot.COMMAND_PREFIX + "check_filtered_words")
    assert_embed = filteredWordsEmbed(['listing1','listing2'],['banned','risky'], ['0','0'])
    dpytest.verify_embed(embed=assert_embed)
    cleanup(dpytest.get_config().guilds[0].id)
async def test_add_user_to_twitch_alert(twitch_cog):
    assert_embed = discord.Embed(title="Added User to Twitch Alert",
                                 description=f"Channel: {dpytest.get_config().channels[0].id}\n"
                                             f"User: monstercat\n"
                                             f"Message: {TwitchAlert.DEFAULT_MESSAGE}",
                                 colour=KOALA_GREEN)

    await dpytest.message(
        f"{KoalaBot.COMMAND_PREFIX}add_user_to_twitch_alert {dpytest.get_config().channels[0].id} monstercat")
    dpytest.verify_embed(embed=assert_embed)
Exemple #24
0
async def test_command_youtubelist_not_cancel(monkeypatch, mock_message_1,
                                              two_results, embed_two_results):

    monkeypatch.setattr(youtube, "search_youtube", lambda *args, **kwargs: two_results)  # noqa: E501

    await dpytest.message('!youtubelist 2 pastime paradise')
    dpytest.verify_embed(embed_two_results)

    # mock_message_1 fixture monkeypath wait_for, and '1' message is sent.

    dpytest.verify_message("https://www.youtube.com/watch?v=_H3Sv2zad6s")
async def test_define_weapon(bot, mocker):
    mocker.patch.object(dice, "roll_d6", return_value=4)

    dpytest.configure(bot)

    await dpytest.message("!def weapon Stinger 2 2 3 3 4 5 6")
    dpytest.verify_message("Added weapon `Stinger` damage `[2, 2, 3, 3, 4, 5, 6]` ignore_armor=False")

    await dpytest.message("!damage stinger medium")
    # FIXME: Figure out how to test the embed content here
    dpytest.verify_embed(allow_text=True)
Exemple #26
0
async def test_command_youtubelist_cancel(monkeypatch, mock_cancel,
                                          two_results, embed_two_results):

    monkeypatch.setattr(youtube, "search_youtube", lambda *args, **kwargs: two_results)  # noqa: E501

    await dpytest.message('!youtubelist 2 pastime paradise')
    dpytest.verify_embed(embed_two_results)

    # mock_cancel fixture monkeypath wait_for, and 'cancel' message is sent.

    dpytest.verify_message("Annulé !")
async def test_add_mod_channel_tag(text_filter_db_manager):
    channel = dpytest.backend.make_text_channel(name="TestChannel", guild=dpytest.get_config().guilds[0])
    dpytest.get_config().channels.append(channel)

    await dpytest.message(KoalaBot.COMMAND_PREFIX + "setupModChannel <#"+str(channel.id)+">")
    assert_embed = createNewModChannelEmbed(channel)
    dpytest.verify_embed(embed=assert_embed)

    result = text_filter_db_manager.database_manager.db_execute_select("SELECT channel_id FROM TextFilterModeration WHERE guild_id = ?;", args=[channel.guild.id])
    assert is_int(result[0][0])
    cleanup(dpytest.get_config().guilds[0].id)
async def test_remove_team_from_twitch_alert_wrong_guild(twitch_cog):
    guild = dpytest.backend.make_guild(name="TestGuild")
    channel = dpytest.backend.make_text_channel(name="TestChannel", guild=guild)
    dpytest.get_config().guilds.append(guild)
    dpytest.get_config().channels.append(channel)
    member = await dpytest.member_join(1, name="TestUser", discrim=1)
    await dpytest.member_join(1, dpytest.get_config().client.user)

    await dpytest.message(
        f"{KoalaBot.COMMAND_PREFIX}remove_team_from_twitch_alert {dpytest.get_config().channels[0].id} monstercat",
        channel=-1, member=member)
    dpytest.verify_embed(
        embed=TwitchAlert.error_embed("The channel ID provided is either invalid, or not in this server."))
Exemple #29
0
async def test_profile(database):
    await message("^register")
    await empty_queue()

    member = get_config().members[0]
    member1 = get_config().members[1]

    await message("^profile")
    verify_embed()
    await message(f"^profile {str(member)}")
    verify_embed()
    with pytest.raises(derrors.NotRegistered):
        await message(f"^profile {str(member1)}")
async def test_add_team_to_twitch_alert_wrong_guild(twitch_cog):
    # Creates guild and channels and adds user and bot
    guild = dpytest.backend.make_guild(name="TestGuild")
    channel = dpytest.backend.make_text_channel(name="TestChannel", guild=guild)
    dpytest.get_config().guilds.append(guild)
    dpytest.get_config().channels.append(channel)
    member = await dpytest.member_join(-1, name="TestUser", discrim=1)
    await dpytest.member_join(-1, dpytest.get_config().client.user)
    # Creates Twitch Alert
    await dpytest.message(
        f"{KoalaBot.COMMAND_PREFIX}add_team_to_twitch_alert {dpytest.get_config().channels[0].id} faze ", channel=-1,
        member=member)
    dpytest.verify_embed(
        embed=TwitchAlert.error_embed("The channel ID provided is either invalid, or not in this server."))
Exemple #31
0
async def test_nanowrimo():
    await message("^nanowrimo")
    verify_message("Valid options are 'novel', 'profile', and 'info'.")
    with pytest.raises(commands.MissingRequiredArgument):
        await message("^nano novel")
    await empty_queue()
    await message("^nano novel craftspider")
    if not sent_queue.empty():
        mes = await sent_queue.get()
        if mes.content != "Sorry, I couldn't find that user":
            await sent_queue.put(mes)
            verify_embed()

    with pytest.raises(commands.MissingRequiredArgument):
        await message("^nano profile")
    await empty_queue()
    await message("^nano profile craftspider")
    if not sent_queue.empty():
        mes = await sent_queue.get()
        if mes.content != "Sorry, I couldn't find that user on the NaNo site":
            await sent_queue.put(mes)
            verify_embed()

    await message("^nano info")
    verify_embed()
Exemple #32
0
async def test_info():
    await message("^info")
    verify_embed()
async def test_xkcd():
    await message("^xkcd")
    verify_embed()
async def test_smbc():
    await message("^smbc")
    verify_embed()