コード例 #1
0
async def purge(message: discord.Message, *instances: members_and_channels, num: utils.int_range(1, 100)):
    """ Purge the given amount of messages from the specified members or all.
    You may also specify a channel to delete from.

    `num` is a number from 1 to 100. """
    instances = list(instances)

    channel = message.channel
    for instance in instances:
        if type(instance) is discord.Channel:
            channel = instance
            instances.remove(instance)
            break

    assert not any(i for i in instances if type(i) is discord.Channel), "**I can only purge in one channel.**"
    to_delete = []

    async for m in client.logs_from(channel, limit=100, before=message):
        if len(to_delete) >= num:
            break

        if not instances or m.author in instances:
            to_delete.append(m)

    deleted = len(to_delete)
    if deleted > 1:
        await client.delete_messages(to_delete)
    elif deleted == 1:
        await client.delete_message(to_delete[0])
    
    m = await client.say(message, "Purged **{}** message{}.".format(deleted, "" if deleted == 1 else "s"))

    # Remove both the command message and the feedback after 5 seconds
    await asyncio.sleep(5)
    await client.delete_messages([m, message])
コード例 #2
0
ファイル: basic.py プロジェクト: stoz/PCBOT
async def roll(message: discord.Message, num: utils.int_range(f=1) = 100):
    """ Roll a number from 1-100 if no second argument or second argument is not a number.
        Alternatively rolls `num` times (minimum 1). """
    rolled = random.randint(1, num)
    await client.say(
        message,
        "**{0.display_name}** rolls `{1}`.".format(message.author, rolled))
コード例 #3
0
async def jpeg(message: discord.Message, image_arg: image, *effect: utils.choice("small", "meme"),
               quality: utils.int_range(f=0, t=100)=5):
    """ Give an image some proper jpeg artifacting.

    Valid effects are: `small` """
    assert not image_arg.gif, "**JPEG saving only works on images.**"
    image_arg.set_extension("jpg", real_jpg=False if "meme" in effect else True)

    if effect:
        if "small" in effect:
            w, h = image_arg.object.size
            image_arg.modify(Image.Image.resize, (w // 3, h // 3))

    await send_image(message, image_arg, quality=quality)
コード例 #4
0
ファイル: moderate.py プロジェクト: PcBoy111/PCBOT
async def purge(message: discord.Message, num: utils.int_range(1, 100), *members: Annotate.Member):
    """ Purge the given amount of messages from the specified members or all.
    `num` is a number from 1 to 100. """
    to_delete = []

    async for m in client.logs_from(message.channel, limit=100, before=message):
        if len(to_delete) >= num:
            break

        if not members or m.author in members:
            to_delete.append(m)

    deleted = len(to_delete)
    if deleted > 1:
        await client.delete_messages(to_delete)
    elif deleted == 1:
        await client.delete_message(to_delete[0])

    await client.say(message, "Purged **{}** message{}.".format(deleted, "" if deleted == 1 else "s"))
コード例 #5
0
ファイル: builtin.py プロジェクト: Jeglet/pcbot
async def changelog_(message: discord.Message, num: utils.int_range(f=1) = 3):
    """ Get `num` requests from the changelog. Defaults to 3. """
    await client.say(message, await get_changelog(num))
コード例 #6
0
ファイル: builtin.py プロジェクト: xZwop/PCBOT
def changelog_(client: discord.Client, message: discord.Message, num: utils.int_range(f=1)=3):
    """ Get `num` requests from the changelog. Defaults to 3. """
    changelog = yield from get_changelog(num)
    yield from client.say(message, changelog)
コード例 #7
0
ファイル: basic.py プロジェクト: PcBoy111/PCBOT
async def roll(message: discord.Message, num: utils.int_range(f=1)=100):
    """ Roll a number from 1-100 if no second argument or second argument is not a number.
        Alternatively rolls `num` times (minimum 1). """
    rolled = random.randint(1, num)
    await client.say(message, "{0.mention} rolls `{1}`.".format(message.author, rolled))
コード例 #8
0
ファイル: builtin.py プロジェクト: PcBoy111/PCBOT
async def changelog_(message: discord.Message, num: utils.int_range(f=1)=3):
    """ Get `num` requests from the changelog. Defaults to 3. """
    await client.say(message, await get_changelog(num))