예제 #1
0
파일: twitch.py 프로젝트: EdwardBetts/PCBOT
def on_command(client: discord.Client, message: discord.Message, args: list):
    if args[0] == "!twitch":
        m = "Please see `!help twitch`."
        if len(args) > 1:
            # Assign a twitch channel to your name or remove it
            if args[1] == "set":
                if len(args) > 2:
                    twitch_channel = args[2]
                    twitch_channels.data["channels"][message.author.id] = twitch_channel
                    twitch_channels.save()
                    m = "Set your twitch channel to `{}`.".format(twitch_channel)
                else:
                    if message.author.id in twitch_channels.data["channels"]:
                        twitch_channels.data["channels"].pop(message.author.id)
                        twitch_channels.save()
                        m = "Twitch channel unlinked."

            # Return the member's or another member's twitch channel as a link
            elif args[1] == "get":
                if len(args) > 2:
                    member = client.find_member(message.server, args[2])
                else:
                    member = message.author

                if member:
                    # Send the link if member has set a channel
                    if member.id in twitch_channels.data["channels"]:
                        m = "{}'s twitch channel: https://secure.twitch.tv/{}.".format(
                            member.name,
                            twitch_channels.data["channels"][member.id]
                        )
                    else:
                        m = "No twitch channel assigned to {}!".format(member.name)
                else:
                    m = "Found no such member."

            # Set or get the twitch notify channel
            elif args[1] == "notify-channel":
                if message.author.permissions_in(message.channel).manage_server:
                    if len(args) > 2:
                        channel = client.find_channel(message.server, args[2])

                        if channel:
                            twitch_channels.data["notify-channel"] = channel.id
                            twitch_channels.save()
                            m = "Notify channel set to {}.".format(channel.mention)
                    else:
                        if "notify-channel" in twitch_channels.data:
                            twitch_channel = client.get_channel(twitch_channels.data["notify-channel"])
                            if twitch_channel:
                                m = "Twitch notify channel is {}.".format(twitch_channel)
                            else:
                                m = "The twitch notify channel no longer exists!"
                        else:
                            m = "A twitch notify channel has not been set."
                else:
                    m = "You need `Manage Server` to use this command."

        yield from client.send_message(message.channel, m)
예제 #2
0
def on_command(client: discord.Client, message: discord.Message, args: list):
    if args[0] == "!prank":
        name = "IT'S A"

        # Set the name and convert any mention to name (this ignores punctuation and converts "@PC," to "PC")
        if len(args) > 1 and len(message.clean_content) < 200:
            name_list = []

            for arg in args[1:]:
                steps = 3 if len(args) == 2 else 1
                member = client.find_member(message.server, arg, steps=steps)

                if member:
                    name_list.append(member.name)
                else:
                    channel = client.find_channel(message.server, arg, steps=0)

                    if channel:
                        name_list.append(channel.name)
                    else:
                        name_list.append(arg)

            name = " ".join(name_list)

        name = name.upper()

        # Initialize the image anhd font
        image_text = Image.new("RGBA", image_base.size, (255, 255, 255, 0))
        image_font = ImageFont.truetype(prank_path + "American Captain.ttf",
                                        50)
        image_context = ImageDraw.Draw(image_text)

        # Set width and height and scale down when necessary
        width, height = image_context.textsize(name, image_font)
        font_size = 50

        if width > image_width:
            scaled_font = None

            while width > image_width:
                scaled_font = ImageFont.truetype(
                    prank_path + "American Captain.ttf", font_size)
                width, height = image_context.textsize(name, scaled_font)
                font_size -= 1

            image_font = scaled_font

        # Set x and y coordinates for centered text
        x = (image_width - width) / 2
        y = (image_height - height / 2) - image_height / 1.3

        # Draw border
        shadow_offset = font_size // 25
        image_context.text((x - shadow_offset, y),
                           name,
                           font=image_font,
                           fill=(0, 0, 0, 255))
        image_context.text((x + shadow_offset, y),
                           name,
                           font=image_font,
                           fill=(0, 0, 0, 255))
        image_context.text((x, y - shadow_offset),
                           name,
                           font=image_font,
                           fill=(0, 0, 0, 255))
        image_context.text((x, y + shadow_offset),
                           name,
                           font=image_font,
                           fill=(0, 0, 0, 255))

        # Draw text
        image_context.text((x, y),
                           name,
                           font=image_font,
                           fill=(255, 255, 255, 255))

        # Combine the base image with the font image
        image = Image.alpha_composite(image_base, image_text)

        # Save and send the image
        image.save(prank_path + "pranked.png")
        yield from client.send_file(message.channel,
                                    prank_path + "pranked.png")
예제 #3
0
def on_command(client: discord.Client, message: discord.Message, args: list):
    if args[0] == "!twitch":
        m = "Please see `!help twitch`."
        if len(args) > 1:
            # Assign a twitch channel to your name or remove it
            if args[1] == "set":
                if len(args) > 2:
                    twitch_channel = args[2]
                    twitch_channels.data["channels"][
                        message.author.id] = twitch_channel
                    twitch_channels.save()
                    m = "Set your twitch channel to `{}`.".format(
                        twitch_channel)
                else:
                    if message.author.id in twitch_channels.data["channels"]:
                        twitch_channels.data["channels"].pop(message.author.id)
                        twitch_channels.save()
                        m = "Twitch channel unlinked."

            # Return the member's or another member's twitch channel as a link
            elif args[1] == "get":
                if len(args) > 2:
                    member = client.find_member(message.server, args[2])
                else:
                    member = message.author

                if member:
                    # Send the link if member has set a channel
                    if member.id in twitch_channels.data["channels"]:
                        m = "{}'s twitch channel: https://secure.twitch.tv/{}.".format(
                            member.name,
                            twitch_channels.data["channels"][member.id])
                    else:
                        m = "No twitch channel assigned to {}!".format(
                            member.name)
                else:
                    m = "Found no such member."

            # Set or get the twitch notify channel
            elif args[1] == "notify-channel":
                if message.author.permissions_in(
                        message.channel).manage_server:
                    if len(args) > 2:
                        channel = client.find_channel(message.server, args[2])

                        if channel:
                            twitch_channels.data["notify-channel"] = channel.id
                            twitch_channels.save()
                            m = "Notify channel set to {}.".format(
                                channel.mention)
                    else:
                        if "notify-channel" in twitch_channels.data:
                            twitch_channel = client.get_channel(
                                twitch_channels.data["notify-channel"])
                            if twitch_channel:
                                m = "Twitch notify channel is {}.".format(
                                    twitch_channel)
                            else:
                                m = "The twitch notify channel no longer exists!"
                        else:
                            m = "A twitch notify channel has not been set."
                else:
                    m = "You need `Manage Server` to use this command."

        yield from client.send_message(message.channel, m)
예제 #4
0
파일: prank.py 프로젝트: EdwardBetts/PCBOT
def on_command(client: discord.Client, message: discord.Message, args: list):
    if args[0] == "!prank":
        name = "IT'S A"

        # Set the name and convert any mention to name (this ignores punctuation and converts "@PC," to "PC")
        if len(args) > 1 and len(message.clean_content) < 200:
            name_list = []

            for arg in args[1:]:
                steps = 3 if len(args) == 2 else 1
                member = client.find_member(message.server, arg, steps=steps)

                if member:
                    name_list.append(member.name)
                else:
                    channel = client.find_channel(message.server, arg, steps=0)

                    if channel:
                        name_list.append(channel.name)
                    else:
                        name_list.append(arg)

            name = " ".join(name_list)

        name = name.upper()

        # Initialize the image anhd font
        image_text = Image.new("RGBA", image_base.size, (255, 255, 255, 0))
        image_font = ImageFont.truetype(prank_path + "American Captain.ttf", 50)
        image_context = ImageDraw.Draw(image_text)

        # Set width and height and scale down when necessary
        width, height = image_context.textsize(name, image_font)
        font_size = 50

        if width > image_width:
            scaled_font = None

            while width > image_width:
                scaled_font = ImageFont.truetype(prank_path + "American Captain.ttf", font_size)
                width, height = image_context.textsize(name, scaled_font)
                font_size -= 1

            image_font = scaled_font

        # Set x and y coordinates for centered text
        x = (image_width - width) / 2
        y = (image_height - height / 2) - image_height / 1.3

        # Draw border
        shadow_offset = font_size // 25
        image_context.text((x - shadow_offset, y), name, font=image_font, fill=(0, 0, 0, 255))
        image_context.text((x + shadow_offset, y), name, font=image_font, fill=(0, 0, 0, 255))
        image_context.text((x, y - shadow_offset), name, font=image_font, fill=(0, 0, 0, 255))
        image_context.text((x, y + shadow_offset), name, font=image_font, fill=(0, 0, 0, 255))

        # Draw text
        image_context.text((x, y), name, font=image_font, fill=(255, 255, 255, 255))

        # Combine the base image with the font image
        image = Image.alpha_composite(image_base, image_text)

        # Save and send the image
        image.save(prank_path + "pranked.png")
        yield from client.send_file(message.channel, prank_path + "pranked.png")