예제 #1
0
def on_message(client: discord.Client, message: discord.Message, args: list):
    if message.channel.is_private:
        return False

    channel = moderate.data.get(message.server.id, {}).get("nsfw-channel")

    if channel:
        # Check if message includes keyword nsfw and a link
        msg = message.content.lower()
        if "nsfw" in msg and ("http://" in msg or "https://"
                              in msg) and not message.channel == channel:
            if message.server.me.permissions_in(
                    message.channel).manage_messages:
                yield from client.delete_message(message)

            nsfw_channel = message.server.get_channel(
                moderate.data[message.server.id].get("nsfw-channel"))

            if nsfw_channel:
                yield from client.send_message(
                    message.channel,
                    "{}: **Please post NSFW content in {}**".format(
                        message.author.mention, nsfw_channel.mention))
            else:
                yield from client.send_message(
                    message.channel,
                    "{}: **I did not find the specified NSFW channel.** "
                    "If you wish to remove this feature, see `!help "
                    "nsfwchannel`.".format(message.server.owner.mention))
            return True

    return False
예제 #2
0
def on_message(client: discord.Client, message: discord.Message, args: list):
    if message.channel.is_private:
        return False

    channel = moderate.data.get(message.server.id, {}).get("nsfw-channel")

    if channel:
        # Check if message includes keyword nsfw and a link
        msg = message.content.lower()
        if "nsfw" in msg and ("http://" in msg or "https://" in msg) and not message.channel == channel:
            if message.server.me.permissions_in(message.channel).manage_messages:
                yield from client.delete_message(message)

            nsfw_channel = message.server.get_channel(moderate.data[message.server.id].get("nsfw-channel"))

            if nsfw_channel:
                yield from client.send_message(message.channel, "{}: **Please post NSFW content in {}**".format(
                    message.author.mention, nsfw_channel.mention
                ))
            else:
                yield from client.send_message(message.channel, "{}: **I did not find the specified NSFW channel.** "
                                                                "If you wish to remove this feature, see `!help "
                                                                "nsfwchannel`.".format(message.server.owner.mention))
            return True

    return False
예제 #3
0
def on_message(client: discord.Client, message: discord.Message, args: list):
    user_id = message.author.id

    # User alias check
    if aliases.data.get(user_id):
        success = False

        user_aliases = aliases.data[user_id]
        for name, command in user_aliases.items():
            execute = False
            msg = message.content

            if not command.get("case-sensitive", False):
                msg = msg.lower()

            if command.get("anywhere", False):
                if name in msg:
                    execute = True
            else:
                if msg.startswith(name):
                    execute = True

            # Add any mentions to the alias
            mention = ""
            if message.mentions:
                mentions = [member.mention for member in message.mentions]
                mention = " =>(" + ", ".join(mentions) + ")"

            if execute:
                if command.get("delete-message", False):
                    if message.server.me.permissions_in(
                            message.channel).manage_messages:
                        asyncio. async (client.delete_message(message))

                asyncio. async (client.send_message(
                    message.channel, "{}{}: {}".format(message.author.mention,
                                                       mention,
                                                       command.get("text"))))

                success = True

        return success

    # See if the user spelled definitely wrong
    for spelling in [
            "definately", "definatly", "definantly", "definetly", "definently",
            "defiantly"
    ]:
        if spelling in message.clean_content:
            yield from client.send_message(
                message.channel,
                "{} http://www.d-e-f-i-n-i-t-e-l-y.com/".format(
                    message.author.mention))
            return True

    return False
예제 #4
0
파일: alias.py 프로젝트: EdwardBetts/PCBOT
def on_message(client: discord.Client, message: discord.Message, args: list):
    user_id = message.author.id

    # User alias check
    if aliases.data.get(user_id):
        success = False

        user_aliases = aliases.data[user_id]
        for name, command in user_aliases.items():
            execute = False
            msg = message.content

            if not command.get("case-sensitive", False):
                msg = msg.lower()

            if command.get("anywhere", False):
                if name in msg:
                    execute = True
            else:
                if msg.startswith(name):
                    execute = True

            # Add any mentions to the alias
            mention = ""
            if message.mentions:
                mentions = [member.mention for member in message.mentions]
                mention = " =>(" + ", ".join(mentions) + ")"

            if execute:
                if command.get("delete-message", False):
                    if message.server.me.permissions_in(message.channel).manage_messages:
                        asyncio.async(client.delete_message(message))

                asyncio.async(client.send_message(
                    message.channel,
                    "{}{}: {}".format(message.author.mention, mention, command.get("text")))
                )

                success = True

        return success

    # See if the user spelled definitely wrong
    for spelling in ["definately", "definatly", "definantly", "definetly", "definently", "defiantly"]:
        if spelling in message.clean_content:
            yield from client.send_message(message.channel,
                                           "{} http://www.d-e-f-i-n-i-t-e-l-y.com/".format(message.author.mention))
            return True

    return False
예제 #5
0
파일: pasta.py 프로젝트: EdwardBetts/PCBOT
def on_message(client: discord.Client, message: discord.Message, args: list):
    """ Here I'm using on_message instead of on_command in order to allow pastas
    to be triggered by the | notation. """
    if args[0] == "!pasta" or args[0].startswith("|"):
        if args[0].startswith("|"):
            org = args
            args = ["!pasta", org[0][1:]]
            args.extend(org[1:])
            asyncio.async(client.delete_message(message))
        if len(args) > 1:
            # List copypastas
            if args[1] == "-list":
                page = 1
                pasta_names = list(pastas.data.keys())

                if len(args) > 2:
                    try:
                        page = int(args[2])
                    except ValueError:
                        page = 1

                pasta_pages = []

                # Divide pasta_names into list of pages
                for i, pasta_name in enumerate(pasta_names):
                    p = int(i / page_size)  # Current page number

                    if i % page_size == 0:
                        pasta_pages.append([])

                    pasta_pages[p].append(pasta_name)

                # Don't go over page nor under
                page = len(pasta_pages) if page > len(pasta_pages) else 1

                m = "**Pastas (page {0}/{1}):** ```\n{2}\n```\n" \
                    "Use `!pasta -list [page]` to view another page.".format(page,
                                                                             len(pasta_pages),
                                                                             "\n".join(pasta_pages[page - 1]))

            # Add a copypasta
            elif args[1] == "--add":
                if len(args) > 3:
                    pasta_name = args[2].lower()
                    pasta = " ".join(args[3:])
                    if not pastas.data.get(pasta_name):
                        pastas.data[pasta_name] = pasta
                        pastas.save()
                        m = "Pasta `{}` set.".format(pasta_name)
                    else:
                        m = "Pasta `{0}` already exists. " \
                            "You can remove it with `!pasta --remove {0}`".format(pasta_name)
                else:
                    m = "Please follow the format of `!pasta --add <pastaname> <copypasta ...>`"

            # Remove a pasta
            elif args[1] == "--remove":
                if len(args) > 2:
                    pasta_name = " ".join(args[2:]).lower()
                    pasta = pastas.data.get(pasta_name)
                    if pasta:
                        pastas.data.pop(pasta_name)
                        pastas.save()
                        m = "Pasta `{}` removed. In case this was a mistake, here's the pasta: ```{}```".format(
                            pasta_name, pasta
                        )
                    else:
                        m = "No pasta by name `{}`.".format(pasta_name)
                else:
                    m = "Please specify a pasta to remove. `!pasta --remove <pastaname>`"

            # Retrieve and send pasta
            else:
                if pastas.data:
                    if args[1] == ".":
                        m = choice(list(pastas.data.values()))
                    else:
                        m = pastas.data.get(" ".join(args[1:]).lower()) or \
                            "Pasta `{0}` is undefined. " \
                            "Define with `!pasta --add \"{0}\" <copypasta ...>`".format(" ".join(args[1:]))
                else:
                    m = "There are no defined pastas. Define with `!pasta --add <pastaname> <copypasta ...>`"

                # Download and send the image if m is a link to an image (png, jpg, etc) although not gifs
                # if match(r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+", m):
                #     # TODO: Integrate aiohttp, disabled uploading for now.
                #     # Get the headers for the link before downloading the file
                #     request_head = requests.head(m)
                #     content_type = request_head.headers["content-type"]
                #
                #     if request_head.ok and content_type.startswith("image") and "gif" not in content_type:
                #         asyncio.async(client.send_typing(message.channel))  # Send typing to the channel
                #         request = requests.get(m)
                #
                #         file = BytesIO(request.content)
                #         filename = m
                #
                #         if "content-disposition" in request.headers:
                #             if "filename" in request.headers["content-disposition"]:
                #                 filename_match = search("filename=\"(?P<filename>\S+)\"",
                #                                         request.headers["content-disposition"])
                #                 if filename_match:
                #                     filename = filename_match.group("filename")
                #
                #         ext_match = match(r"^\S+\.(?P<ext>[a-zA-Z0-9]+)$", filename)
                #
                #         if ext_match:
                #             yield from client.send_file(message.channel, file,
                #                                         filename="image.{}".format(ext_match.group("ext")))
                #             m = None

        # No arguments
        else:
            m = "Please see `!help pasta`."

        if m:
            yield from client.send_message(message.channel, m)

        return True

    return False