예제 #1
0
    async def on_reaction_add(self, reaction, user):

        if sql.get_belmsg(reaction.message.id) is not None:
            bel_id = sql.get_belmsg(reaction.message.id)
            bel_chid = sql.get_belmsg(reaction.message.id)[1]
            bel_ch = self.bot.get_channel(bel_chid)
            bel_msg = await bel_ch.fetch_message(bel_id[0])

            embed = discord.Embed(
                title="Nice message detected",
                description=
                f"A message in {reaction.message.channel.mention} was hyped!",
                color=0x000066)
            embed.set_author(name=reaction.message.author,
                             icon_url=reaction.message.author.avatar_url)
            embed.add_field(name="Content",
                            value=reaction.message.content,
                            inline=True)
            embed.add_field(name="Hype-Count",
                            value=reaction.count,
                            inline=True)

            await bel_msg.edit(embed=embed)
        else:
            remoj = sql.get_settings(reaction.message.guild.id)["remoj"]

            rcount = sql.get_settings(reaction.message.guild.id)["rcount"]

            belvchid = sql.get_settings(reaction.message.guild.id)["belvchid"]
            belvch = self.bot.get_channel(belvchid)

            if str(reaction.emoji) == str(remoj):
                if reaction.count >= rcount:
                    embed = discord.Embed(
                        title="Nice message detected",
                        description=
                        f"A message in {reaction.message.channel.mention} was hyped!",
                        color=0x000066)
                    embed.set_author(
                        name=reaction.message.author,
                        icon_url=reaction.message.author.avatar_url)
                    embed.add_field(name="Content",
                                    value=reaction.message.content,
                                    inline=True)
                    embed.add_field(name="Hype-Count",
                                    value=reaction.count,
                                    inline=True)

                    msg = await belvch.send(embed=embed)

                    sql.set_belmsg(reaction.message.id, msg.id, msg.channel.id)
예제 #2
0
    async def rss(self):
        await self.bot.wait_until_ready()
        servers = sql.get_servers()
        sids = list(servers.keys())

        for sid in sids:
            settings = sql.get_settings(sid)

            if settings is None:
                continue

            chid = settings["rsschid"]
            feed_url = settings["rssurl"]

            rfeed = feedparser.parse(feed_url)

            now = datetime.datetime.now().timestamp()
            pub_time = time.mktime(rfeed.entries[0].published_parsed)
            tolc = now - 1800

            if pub_time < tolc:
                continue
            if not rfeed.entries:
                continue

            title = rfeed.entries[0].title
            url = rfeed.entries[0].link

            channel = self.bot.get_channel(chid)

            await channel.send(f":newspaper: | **{title}**")
            await channel.send(url)

        def cog_unload():
            self.rss.stop()
    async def on_member_remove(self, member):
        guild = member.guild

        if not sql.settings_created(int(guild.id)):
            return
        kickmsgchid = sql.get_settings(guild.id)["kickmsgchid"]
        kickmsgch = self.bot.get_channel(kickmsgchid)

        leavemsgchid = sql.get_settings(guild.id)["kickmsgchid"]
        leavemsgch = self.bot.get_channel(leavemsgchid)

        als = guild.audit_logs(limit=1)
        async for entry in als:
            if entry.action == discord.AuditLogAction.kick:
                if entry.target == member:
                    reason = entry.reason
                    embed = discord.Embed(
                        title="User was kicked",
                        description=
                        f"{member.mention} was kicked from this server",
                        color=0xff9000)
                    embed.set_author(name=member, icon_url=member.avatar_url)
                    embed.add_field(name="Reason", value=reason)

                    await kickmsgch.send(embed=embed)

                else:
                    embed = discord.Embed(
                        title="User left",
                        description=f"{member.mention} left from this server",
                        color=0xfff500)
                    embed.set_author(name=member, icon_url=member.avatar_url)

                    await leavemsgch.send(embed=embed)
            elif entry.action != discord.AuditLogAction.ban:
                embed = discord.Embed(
                    title="User left",
                    description=f"{member.mention} left from this server",
                    color=0xfff500)
                embed.set_author(name=member, icon_url=member.avatar_url)

                await leavemsgch.send(embed=embed)
    async def on_member_update(self, before, after):
        guild = before.guild

        if not sql.settings_created(int(guild.id)):
            return
        rcmsgchid = sql.get_settings(guild.id)["rcmsgchid"]
        rcmsgch = self.bot.get_channel(rcmsgchid)

        if before.roles != after.roles:
            before_roles = [y.name.lower() for y in before.roles]
            after_roles = [y.name.lower() for y in after.roles]

            removed_roles = [
                elem for elem in before_roles if elem not in after_roles
            ]
            added_roles = [
                elem for elem in after_roles if elem not in before_roles
            ]

            if len(removed_roles) == 0:
                embed = discord.Embed(
                    title="Role was added",
                    description=
                    f"{after.mention} received role {added_roles[0]}",
                    color=0x006400)
                embed.set_author(name=after, icon_url=after.avatar_url)

                await rcmsgch.send(embed=embed)

            elif len(added_roles) == 0:
                embed = discord.Embed(
                    title="Role was removed",
                    description=f"{after.mention} lost role {removed_roles[0]}",
                    color=0xfff500)
                embed.set_author(name=after, icon_url=after.avatar_url)

                await rcmsgch.send(embed=embed)

        if before.nick != after.nick:
            embed = discord.Embed(
                title="Nickname changed",
                description=f"{after.mention} changed their nick",
                color=0x006400)
            embed.set_author(name=after, icon_url=after.avatar_url)
            embed.add_field(name="Old nick", value=before.nick, inline=True)
            embed.add_field(name="New nick", value=after.nick, inline=True)

            await rcmsgch.send(embed=embed)
예제 #5
0
    async def report(self, ctx, mlink):
        dsid = int(mlink.split("/")[4])

        if not sql.settings_created(dsid):
            return

        reportchid = sql.get_settings(dsid)["reportchid"]
        reportch = self.bot.get_channel(reportchid)

        embed = discord.Embed(
            title=f"{ctx.message.author} reported a message on this guild",
            url=mlink)
        embed.set_author(name=ctx.message.author,
                         icon_url=ctx.message.author.avatar_url)

        await reportch.send(content="@nothere", embed=embed)
    async def on_member_ban(self, guild, user):
        if not sql.settings_created(int(guild.id)):
            return
        banmsgchid = sql.get_settings(guild.id)["banmsgchid"]
        banmsgch = self.bot.get_channel(banmsgchid)

        log = guild.audit_logs(limit=1)

        async for entry in log:
            reason = entry.reason

        embed = discord.Embed(
            title="User banned",
            description=f"{user.mention} was banned from this server",
            color=0xff0000)
        embed.set_author(name=user, icon_url=user.avatar_url)
        embed.add_field(name="Reason", value=reason)

        await banmsgch.send(embed=embed)
    async def on_message_delete(self, message):
        if message.author.bot:
            return

        if not sql.settings_created(int(message.guild.id)):
            return

        logchid = sql.get_settings(message.guild.id)["logchid"]
        logch = self.bot.get_channel(logchid)

        embed = discord.Embed(
            title="Message deleted",
            description=f"A message in {message.channel.mention} was deleted",
            color=0xff0000)
        embed.set_author(name=message.author,
                         icon_url=message.author.avatar_url)
        embed.add_field(name="Content", value=message.content, inline=True)

        await logch.send(embed=embed)
    async def on_member_unban(self, guild, user):
        print("Unbanning")
        if not sql.settings_created(int(guild.id)):
            return

        unbanchid = sql.get_settings(guild.id)["unbanchid"]
        unbanch = self.bot.get_channel(unbanchid)

        log = guild.audit_logs(limit=1)

        async for entry in log:
            reason = entry.reason

        embed = discord.Embed(
            title="User unbanned",
            description=f"{user.mention} was unbanned from this server",
            color=0x006400)
        embed.set_author(name=user)
        embed.add_field(name="Reason", value=reason, inline=False)

        await unbanch.send(embed=embed)
    async def on_message_edit(self, before, after):
        if before.author.bot:
            return

        if before.content == after.content:
            return

        if not sql.settings_created(int(before.guild.id)):
            return

        logchid = sql.get_settings(before.guild.id)["logchid"]
        logch = self.bot.get_channel(logchid)

        embed = discord.Embed(
            title="Message edited",
            url=after.jump_url,
            description=
            f"A message in {after.channel.mention} was edited by {after.author.mention}",
            color=0xfff500)
        embed.set_author(name=after.author, icon_url=after.author.avatar_url)
        embed.add_field(name="Before edit", value=before.content, inline=True)
        embed.add_field(name="After edit", value=after.content, inline=True)

        await logch.send(embed=embed)