示例#1
0
	async def unprison(self, ctx, member:discord.Member, *, reason=None):

		if not authorize(ctx.author, C):
			await ctx.send("You aren't authorized to do this.")
			return

		if not f"{member.id}" in global_prison_log:
			await ctx.send("I didn't prison them, you'll have to do it manually.")
			return

		guild = ctx.guild

		await unprison_man(member, guild, reason=f"Let out early by {ctx.author.name}")

		embed = discord.Embed(title="UnPrisoned!", description=f"{longform_name(member)} has been unprisoned early. ", colour=discord.Colour.light_gray())
		embed.add_field(name="Moderator: ", value=longform_name(ctx.author), inline=False)
		embed.add_field(name="Reason:", value=reason, inline=False)

		try:
			await member.send(embed=embed)
		except:
			embed.set_footer(text="I couldn't DM them.")

		dbreason = f"\nReason: {reason}" if reason else None
		db.audit_log("UNPRISON", f"{ctx.author.name}#{ctx.author.discriminator}", ctx.author.id, f"{ctx.author.name}#{ctx.author.discriminator} ({ctx.author.id}) prisoned: {member.name}#{member.discriminator} ({member.id}){dbreason}", json.dumps({"user": ctx.author.id, "target":member.id, "reason":reason}))

		await ctx.send(embed=embed)
		await self.logchannel().send(embed=embed)
示例#2
0
    async def on_message_edit(self, before, after):
        if before.clean_content != after.clean_content:  # changed actual text

            user = after.author

            db.audit_log(
                "MESSAGEEDIT", f"{user.name}#{user.discriminator}", user.id,
                f"{longform_username(user)} edited a message from `{before.clean_content}` to `{after.clean_content}`",
                jsql({
                    "target": user.id,
                    "before": before.clean_content,
                    "after": after.clean_content
                }))

            embed = discord.Embed(
                title=f"Message Edit",
                description=f"{longform_username(user)} edited a message.")
            embed.set_author(name=longform_username(user),
                             icon_url=user.avatar_url_as(format="png"))
            embed.add_field(name="Before",
                            value=before.clean_content,
                            inline=False)
            embed.add_field(name="After",
                            value=after.clean_content,
                            inline=False)
            await self.logchannel().send(embed=embed)
示例#3
0
	async def prison(self, ctx, member:discord.Member, jailtime:str="0", *, reason=None):
		if not authorize(ctx.author, C):
			await ctx.send("You aren't authorized to do this.")
			return

		if ctx.author == member:
			await ctx.send("You can't prison yourself.")
			return

		if member.top_role >= ctx.author.top_role:
			await ctx.send("You can only prison people who you outrank.")
			return

		if f"{member.id}" in global_prison_log:
			await ctx.send("Already prisoned this person.")
			return

		guild = ctx.guild

		truetime = time_to_seconds(jailtime)

		if truetime < 0: # hotfix
			reason = f"{jailtime} {reason if reason else ''}"
			truetime = 0
			jailtime = "0"

		await prison_man(member, guild, {"time_jailed": time.time(), "sentence": truetime, "reason": reason, "admin": ctx.author, "member": member}, summary=f"Muted by {ctx.author.name} for {time_to_text(truetime)}. ({reason})")

		embed = discord.Embed(title="Prisoned!", description=f"{longform_name(member)} has been prisoned. ", colour=discord.Colour.light_gray())
		embed.add_field(name="Moderator: ", value=longform_name(ctx.author), inline=False)
		embed.add_field(name="Reason: ", value=reason, inline=False)
		embed.add_field(name="Time left for the sentence: ", value=time_to_text(truetime) if truetime != 0 else "Until released.", inline=False)
		embed.add_field(name="Extra Info: ", value=f"Use {C['prefix']}sentence to see how much time you or someone else has left")

		try:
			await member.send(embed=embed)
		except:
			embed.set_footer(text="I couldn't DM them.")

		await ctx.send(embed=embed)
		await self.logchannel().send(embed=embed)

		dbreason = f"\nReason: {reason}" if reason else None
		dbtime = time_to_text(truetime) if truetime else "Indefinitely"
		db.audit_log("PRISON", f"{ctx.author.name}#{ctx.author.discriminator}", ctx.author.id, f"{ctx.author.name}#{ctx.author.discriminator} ({ctx.author.id}) prisoned: {member.name}#{member.discriminator} ({member.id}) for {dbtime}{dbreason}", json.dumps({"user": ctx.author.id, "target":member.id, "reason":reason, "time": truetime}))

		if jailtime == "0":  # perma jail
			return

		await asyncio.sleep(truetime)

		embed = discord.Embed(title="Unprisoned", description=f"{longform_name(member)} has been unprisoned. ", colour=discord.Colour.light_gray())
		embed.add_field(name="Reason: ", value="Prison sentence has expired.", inline=False)
		try:
			await member.send(embed=embed)
		except:
			embed.set_footer(text="I couldn't DM them.")
		await self.logchannel().send(embed=embed)

		await unprison_man(member, guild, reason="Time expired.")
示例#4
0
    async def on_member_kick(self, guild, user):
        entry = await guild.audit_logs(
            limit=1, action=discord.AuditLogAction.kick).flatten()
        entry = entry[0]
        reason = ""
        if entry.reason:
            reason = f"\nReason: `{entry.reason}`"

        db.audit_log(
            "KICK", f"{entry.user.name}#{entry.user.discriminator}",
            entry.user.id,
            f"{longform_username(entry.user)} kicked: {longform_username(entry.target)}{reason}",
            jsql({
                "user": entry.user.id,
                "target": entry.target.id,
                "reason": entry.reason
            }))

        embed = discord.Embed(
            title=f"Member Kicked",
            description=
            f"{longform_username(entry.user)} kicked {longform_username(entry.target)}"
        )
        embed.set_author(name=longform_username(entry.user),
                         icon_url=entry.user.avatar_url_as(format="png"))
        if entry.reason: embed.add_field(name="Reason", value=entry.reason)
        await self.logchannel().send(embed=embed)
示例#5
0
    async def on_member_unban(self, guild, user):
        entry = await guild.audit_logs(
            limit=1, action=discord.AuditLogAction.unban).flatten()
        entry = entry[0]
        reason = ""
        if entry.reason:
            reason = f"\nReason: `{entry.reason}`"

        db.audit_log(
            "UNBAN", f"{entry.user.name}#{entry.user.discriminator}", user.id,
            f"{entry.user.name}#{entry.user.discriminator} ({entry.user.id}) unbanned: {entry.target.name}#{entry.target.discriminator} ({entry.target.id}){reason}",
            jsql({
                "user": entry.user.id,
                "target": entry.target.id,
                "reason": entry.reason
            }))
        db.expunge_ban(user.id)

        embed = discord.Embed(
            title=f"Member Unbanned",
            description=
            f"{longform_username(entry.user)} unbanned {longform_username(entry.target)}"
        )
        embed.set_author(name=longform_username(entry.user),
                         icon_url=entry.user.avatar_url_as(format="png"))
        if entry.reason:
            embed.add_field(name="Reason", value=entry.reason, inline=False)
        await self.logchannel().send(embed=embed)
示例#6
0
 async def on_message_delete(self, message):
     entry = await message.guild.audit_logs(
         limit=1, action=discord.AuditLogAction.message_delete).flatten()
     entry = entry[0]
     user = entry.user if entry.target == message.author else message.author
     db.audit_log(
         "MESSAGEDELETE", f"{user.name}#{user.discriminator}", user.id,
         f"{longform_username(user)} Deleted a message from {longform_username(message.author)}",
         jsql(message_to_json(message)))
     await self.logchannel().send(
         f"Message deleted by `{longform_username(user)}`.")
     for embed in message_to_list(message):
         await self.logchannel().send(embed=embed)
示例#7
0
 async def on_bulk_message_delete(self, messages):
     messages.sort(key=lambda r: r.created_at)
     entry = await messages[0].guild.audit_logs(
         limit=1,
         action=discord.AuditLogAction.message_bulk_delete).flatten()
     entry = entry[0]
     user = entry.user
     db.audit_log(
         "MESSAGEBULKDELETE", f"{user.name}#{user.discriminator}", user.id,
         f"{longform_username(user)} Deleted {len(messages)} messages.",
         jsql(messages_to_json(messages)))
     await self.logchannel().send(
         f"{len(messages)} messages deleted by `{longform_username(user)})`."
     )
     for message in messages:
         for embed in message_to_list(message):
             await self.logchannel().send(embed=embed)
示例#8
0
    async def on_member_update(self, before, after):
        if before.roles != after.roles:  # role update
            removed = list_subtract(before.roles, after.roles)
            added = list_subtract(after.roles, before.roles)
            removed_text = f"\nRemoved: {[i.name for i in removed]}" if len(
                removed) else ""
            added_text = f"\nAdded: {[i.name for i in added]}" if len(
                added) else ""
            entry = await after.guild.audit_logs(
                limit=1,
                action=discord.AuditLogAction.member_role_update).flatten()
            entry = entry[0]
            reason = ""
            if entry.reason:
                reason = f"\nReason: `{entry.reason}`"

            db.audit_log(
                "ROLEUPDATE", f"{entry.user.name}#{entry.user.discriminator}",
                entry.user.id,
                f"{longform_username(entry.user)} updated roles for {longform_username(entry.target)}{added_text}{removed_text}{reason}",
                jsql({
                    "added": [role.id for role in added],
                    "removed": [role.id for role in removed],
                    "reason": reason,
                    "target": entry.target.id
                }))

            embed = discord.Embed(
                title=f"Role Update",
                description=
                f"{longform_username(entry.user)} updated roles for {longform_username(entry.target)}"
            )
            embed.set_author(name=longform_username(entry.user),
                             icon_url=entry.user.avatar_url_as(format="png"))
            if len(added):
                embed.add_field(name="Added",
                                value=str([i.name for i in added]),
                                inline=False)
            if len(removed):
                embed.add_field(name="Removed",
                                value=str([i.name for i in removed]),
                                inline=False)
            if entry.reason: embed.add_field(name="Reason", value=entry.reason)
            await self.logchannel().send(embed=embed)

        if before.display_name != after.display_name:  # nickname update
            entry = await after.guild.audit_logs(
                limit=1,
                action=discord.AuditLogAction.member_update).flatten()
            entry = entry[0]

            db.audit_log(
                "NICKNAMEUPDATE",
                f"{entry.user.name}#{entry.user.discriminator}", entry.user.id,
                f"{longform_username(entry.user)} changed {longform_username(entry.target)}'s name from `{before.display_name}` to `{after.display_name}`",
                jsql({
                    "target": entry.target.id,
                    "before": before.display_name,
                    "after": after.display_name
                }))

            embed = discord.Embed(
                title=f"Nickname Update",
                description=
                f"{longform_username(entry.user)} changed {longform_username(entry.target)}'s nickname"
            )
            embed.set_author(name=longform_username(entry.user),
                             icon_url=entry.user.avatar_url_as(format="png"))
            embed.add_field(name="Before",
                            value=before.display_name,
                            inline=False)
            embed.add_field(name="After",
                            value=after.display_name,
                            inline=False)
            await self.logchannel().send(embed=embed)