From 30f21c6b85bb478234dd42c038bc892aff12f4e5 Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Wed, 30 Jun 2021 19:41:39 -0600 Subject: [PATCH] Add message purging (slash-only for now), closes #16 --- jarvis/cogs/admin.py | 28 +++++++++++++++++++++++++++- schema.yaml | 31 +++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/jarvis/cogs/admin.py b/jarvis/cogs/admin.py index 82c1267..4b3ddcf 100644 --- a/jarvis/cogs/admin.py +++ b/jarvis/cogs/admin.py @@ -3,6 +3,7 @@ from discord import User from discord.ext import commands from discord_slash import cog_ext, SlashContext from jarvis.utils.db import DBManager +from datetime import datetime class AdminCog(commands.Cog): @@ -15,7 +16,7 @@ class AdminCog(commands.Cog): def __init__(self, bot): self.bot = bot config = jarvis.config.get_config() - self.db = DBManager(config.mongo) + self.db = DBManager(config.mongo).mongo async def _ban(self, ctx: SlashContext, user: User = None, reason=None): if not user or user == ctx.message.author: @@ -78,6 +79,31 @@ class AdminCog(commands.Cog): async def _kick_slash(self, ctx, user: User = None, reason=None): await self._kick(ctx, user, reason) + async def _purge(self, ctx, amount: int = 30): + channel = ctx.message.channel + messages = [] + async for message in channel.history(limit=amount + 1): + messages.append(message) + await channel.delete_messages(messages) + self.db.purges.insert_one( + { + "channel": ctx.channel.id, + "guild": ctx.channel.guild.id, + "admin": ctx.author.id, + "count": amount, + "time": datetime.now(), + } + ) + + @cog_ext.cog_slash( + name="purge", + description="Purge messages from channel", + guild_ids=[578757004059738142], + ) + @commands.has_permissions(manage_messages=True) + async def _purge_slash(self, ctx, amount: int = 30): + await self._purge(ctx, amount) + def setup(bot): bot.add_cog(AdminCog(bot)) diff --git a/schema.yaml b/schema.yaml index 9e14d2d..46939f6 100644 --- a/schema.yaml +++ b/schema.yaml @@ -54,6 +54,8 @@ jarvis: reason: String, default "Mr. Stark is reviewing this channel. Please hold on." admin: User ID, admin who locked channel guild: Guild ID + duration: int, duration of lockdown in minutes, default 30 + time: Datetime settings: guild: Guild ID @@ -67,6 +69,12 @@ jarvis: admin: User ID, admin who added autoreact time: datetime + starboard: + guild: Guild ID + channel: Channel ID + admin: User ID, admin who created + time: Datetime + stars: message: Message ID channel: Channel ID @@ -75,9 +83,32 @@ jarvis: time: Datetime modlog: + channel: Channel ID + guild: Guild ID + admin: User ID, admin who created + time: Datetime + + logentry: user: User ID activity: String + channel: Optional(Channel ID), channel where activity occurred + guild: Guild ID + modlog: BsonID, target modlog time: Datetime + + blockpings: + role: Role ID + guild: Guild ID + admin: User ID, admin who created + time: Datetime + + purges: + channel: Channel ID + guild: Guild ID + admin: User ID, admin who purged + count: int, number of messages purged + time: Datetime + ctc2: guesses: guess: String