Beispiel #1
0
async def on_message_edit(before, after):
    """
    add message to edited snipe store whenever a message is edited

    :param before: message before edit
    :param after: message after edit
    """
    with open(esni_json, "r") as esnipe_file:
        data = json.load(esnipe_file)

    profanity_check_msg = after.content.translate(
        str.maketrans("", "", string.punctuation))

    # check for profanity on edited message
    if profanity.contains_profanity(
            profanity_check_msg) or profanity.contains_profanity(
                replace_double_characters(profanity_check_msg)):
        try:
            await after.delete()

            embed = discord.Embed(
                description=
                f"**{after.author.mention} you are not allowed to say that.**",
                colour=discord.Colour.red(),
            )

            msg = await after.channel.send(embed=embed)

            em = discord.Embed(
                title="Deleted Message",
                description=
                f"From {after.author.mention} in <#{after.channel.id}>",
                colour=discord.Colour.red(),
            )

            em.add_field(name="Message", value=after.content)
            em.timestamp = datetime.datetime.utcnow()

            channel = client.get_channel(836139191666343966)
            await channel.send(embed=em)

            await asyncio.sleep(10)
            await msg.delete()

        except:
            pass

    data[str(before.channel.id)] = {
        "author": str(before.author),
        "content": before.content,
        "link": before.jump_url,
        "time": datetime.datetime.timestamp(datetime.datetime.utcnow()),
    }

    with open(esni_json, "w") as esnipe_file:
        json.dump(data, esnipe_file)
Beispiel #2
0
async def snipe(ctx):
    """
    display message that has just been deleted recently

    :param ctx: discord.py command context
    """
    # dont snipe if message is in registration channel
    if ctx.channel.id == 861952254072586240:
        return

    channel = ctx.channel

    with open(sni_json, "r") as snipe_file:
        data = json.load(snipe_file)

    try:
        message = data[str(channel.id)]

        profanity_check_msg = message["content"].translate(
            str.maketrans("", "", string.punctuation))

        # check for profanity in sniped message
        if profanity.contains_profanity(
                profanity_check_msg) or profanity.contains_profanity(
                    replace_double_characters(profanity_check_msg)):
            return await ctx.send(
                "Deleted message contains words which is not allowed.")

        # send Mike Wazowski emoji if message contains "discord.gg" or contains more than 5 emojis
        elif "discord.gg" in message["content"]:
            return await ctx.send("<:uhh:880305186827014195> ")

        if message["content"].count(":") > 11:
            return await ctx.send("<:uhh:880305186827014195> ")

        snipeEmbed = discord.Embed(
            title=f"Last Deleted message in #{channel.name}",
            description=f"{message['content']}",
        )

        snipeEmbed.set_footer(text=f"Message sent by {message['author']}")

        if message["attachment"]:
            snipeEmbed.set_image(url=message["attachment"])

        await ctx.send(embed=snipeEmbed)

    except:
        await ctx.send(f"There are no deleted messages in {channel.mention}")
Beispiel #3
0
    async def say(self, ctx, *, txt=None):

        if txt is None:
            return

        try:
            await ctx.message.delete()
        except discord.errors.NotFound:
            pass
        except:
            pass

        if profanity.contains_profanity(txt):
            await ctx.send("You cannot use banned words!")
            return

        if "--" in txt:
            txt = txt.split("--")
            channel = self.client.get_channel(int(txt[1]))
            txt = txt[0]
        else:
            channel = ctx.channel

        send = txt

        if ctx.author.guild_permissions.mention_everyone:
            allowed_mentions = discord.AllowedMentions(everyone=True,
                                                       roles=True)
        else:
            allowed_mentions = discord.AllowedMentions(everyone=False,
                                                       roles=False)

        try:
            webhooks = await channel.webhooks()
            webhook = discord.utils.get(webhooks, name="Rotom Bot")
            if webhook is None:
                webhook = await channel.create_webhook(name="Rotom Bot")

            await webhook.send(send,
                               username=ctx.author.name,
                               avatar_url=ctx.author.avatar_url,
                               allowed_mentions=allowed_mentions)
        except:
            msg = await ctx.send("Bot is missing `Manage Webhooks` permission."
                                 )

            await asyncio.sleep(3)
            try:
                await msg.delete()
            except:
                pass
Beispiel #4
0
    async def on_raw_reaction_add(self, payload):

        # return

        msgID = payload.message_id
        emoji = payload.emoji
        channel = self.client.get_channel(payload.channel_id)
        try:
            msg = await channel.fetch_message(msgID)
        except:
            pass

        users_list = []

        emoji_list = {
            "🇮🇳": "hi",
            "🇬🇧": "en",
            "🇪🇸": "Spanish",
            "🇯🇵": "japanese",
            "🇧🇩": "bangla",
            "🇫🇷": "french",
            "🇩🇪": "german",
            "🇰🇵": "korean",
            "🇳🇵": "nepali",
            "🇵🇭": "filipino",
            "🇺🇸": "en"
        }

        if str(emoji) in emoji_list:
            for r in msg.reactions:
                if str(r) in emoji_list:
                    users = await r.users().flatten()
                    users_list.extend(users)

            if len(users_list) > 1:
                return

            dest = emoji_list[str(emoji)]
            src = "auto"
            gtranslated = t.translate(msg.content, src=src, dest=dest)
            if profanity.contains_profanity(gtranslated.text):
                return

            try:
                await msg.reply(
                    f"{gtranslated.text}\nLanguage Detected: {translator.LANGUAGES[gtranslated.src].capitalize()}",
                    mention_author=False)
            except KeyError:
                pass
Beispiel #5
0
    async def trans(self, ctx, *, text):

        # return await ctx.send("Command in rebuilding...")

        src = "auto"
        dest = "en"
        det = False

        if "--" in text:
            text = text.split("--")
            if len(text) == 3:
                src = text[1].replace(" ", "")
                dest = text[2].replace(" ", "")

            else:
                src = text[1].replace(" ", "")
                dest = "en"

            to_trans = text[0]

        else:
            to_trans = text
            det = True

        to_trans = to_trans.strip()

        if det:

            if to_trans.isnumeric():
                msg = await ctx.fetch_message(int(to_trans))
                gtranslated = t.translate(msg.content, src=src, dest=dest)
                if profanity.contains_profanity(gtranslated.text):
                    await ctx.send("You cannot use banned words!")
                    return

                try:
                    await ctx.send(
                        f"{gtranslated.text}\nLanguage Detected: {translator.LANGUAGES[gtranslated.src].capitalize()}"
                    )
                except KeyError:
                    await ctx.send(
                        f"{gtranslated.text}\nLanguage Detected: Error in Detection..."
                    )

            else:
                gtranslated = t.translate(to_trans, src=src, dest=dest)
                if profanity.contains_profanity(gtranslated.text):
                    await ctx.send("You cannot use banned words!")
                    return

                try:
                    await ctx.send(
                        f"{gtranslated.text}\nLanguage Detected: {translator.LANGUAGES[gtranslated.src].capitalize()}"
                    )
                except KeyError:
                    await ctx.send(
                        f"{gtranslated.text}\nLanguage Detected: Error in Detection..."
                    )
        else:

            if to_trans.isnumeric():
                msg = await ctx.fetch_message(int(to_trans))
                gtranslated = t.translate(msg.content, src=src, dest=dest)
                if profanity.contains_profanity(gtranslated.text):
                    await ctx.send("You cannot use banned words!")
                    return

                await ctx.send(f"{msg.content}\n{gtranslated.text}")

            else:
                gtranslated = t.translate(to_trans, src=src, dest=dest)
                if profanity.contains_profanity(gtranslated.text):
                    await ctx.send("You cannot use banned words!")
                    return

                await ctx.send(f"{gtranslated.text}")
Beispiel #6
0
async def on_message(message):
    """
    execute function whenever someone sends a message

    :param message: message string
    """
    if message.author == client.user:
        return

    # ignore message if message is in Myuu channel
    if message.channel.id == 884745067607228456:
        return

    # when someone pings bot
    if client.user.mentioned_in(message):
        if "hello" in message.content.lower():
            await message.channel.send(
                f"Hello {message.author.mention}.\nMy prefix for this server is `{get_prefix(client, message)}`"
            )

    # check profanity in message
    # remove all punctuation from message
    profanity_check_msg = message.content.translate(
        str.maketrans("", "", string.punctuation))

    if profanity.contains_profanity(
            profanity_check_msg) or profanity.contains_profanity(
                replace_double_characters(profanity_check_msg)):

        # profanity checks only work in Pokehub server
        if message.guild.id == 676777139776913408:

            # ignore profanity in Genshin channel
            if message.channel.id == 882939775177355304:
                pass

            # ignore profanity if message is sent by a bot
            elif not message.author.bot:

                try:
                    await message.delete()
                except discord.errors.NotFound:
                    pass

                embed = discord.Embed(
                    description=
                    f"**{message.author.mention} you are not allowed to say that.**",
                    colour=discord.Colour.red(),
                )

                msg = await message.channel.send(embed=embed)

                em = discord.Embed(
                    title="Deleted Message",
                    description=
                    f"From {message.author.mention} in <#{message.channel.id}>",
                    colour=discord.Colour.red(),
                )

                em.add_field(name="Message", value=message.content)
                em.timestamp = datetime.datetime.utcnow()

                channel = client.get_channel(836139191666343966)
                await channel.send(embed=em)

                await asyncio.sleep(10)
                try:
                    await msg.delete()
                except discord.errors.NotFound:
                    pass

    # give trainers and advanced trainers role when they hit lv1 and lv15 respectively
    if message.channel.id == 775388498919948299:
        if "you just advanced to level 15!" in message.content:
            member_id = "".join(filter(lambda i: i.isdigit(), message.content))

            mem = await message.guild.fetch_member(int(member_id[:-2]))
            role = discord.utils.get(message.guild.roles,
                                     name="advanced-trainers")

            await mem.add_roles(role)

        if "you just advanced to level 1!" in message.content:
            member_id = "".join(filter(lambda i: i.isdigit(), message.content))

            mem = await message.guild.fetch_member(int(member_id[:-1]))
            role = discord.utils.get(message.guild.roles, name="trainers")

            if role not in mem.roles:

                await mem.add_roles(role)

    pfx = get_prefix(client, message).lower()

    if message.content.lower().startswith(pfx):
        message.content = (message.content[:len(pfx)].lower() +
                           message.content[len(pfx):])

    await client.process_commands(message)