Add message purging (slash-only for now), closes #16

This commit is contained in:
Zeva Rose 2021-06-30 19:41:39 -06:00
parent 65b671faa2
commit 30f21c6b85
2 changed files with 58 additions and 1 deletions

View file

@ -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))

View file

@ -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