Add message purging (slash-only for now), closes #16
This commit is contained in:
parent
65b671faa2
commit
30f21c6b85
2 changed files with 58 additions and 1 deletions
|
@ -3,6 +3,7 @@ from discord import User
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from discord_slash import cog_ext, SlashContext
|
from discord_slash import cog_ext, SlashContext
|
||||||
from jarvis.utils.db import DBManager
|
from jarvis.utils.db import DBManager
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
class AdminCog(commands.Cog):
|
class AdminCog(commands.Cog):
|
||||||
|
@ -15,7 +16,7 @@ class AdminCog(commands.Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
config = jarvis.config.get_config()
|
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):
|
async def _ban(self, ctx: SlashContext, user: User = None, reason=None):
|
||||||
if not user or user == ctx.message.author:
|
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):
|
async def _kick_slash(self, ctx, user: User = None, reason=None):
|
||||||
await self._kick(ctx, user, reason)
|
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):
|
def setup(bot):
|
||||||
bot.add_cog(AdminCog(bot))
|
bot.add_cog(AdminCog(bot))
|
||||||
|
|
31
schema.yaml
31
schema.yaml
|
@ -54,6 +54,8 @@ jarvis:
|
||||||
reason: String, default "Mr. Stark is reviewing this channel. Please hold on."
|
reason: String, default "Mr. Stark is reviewing this channel. Please hold on."
|
||||||
admin: User ID, admin who locked channel
|
admin: User ID, admin who locked channel
|
||||||
guild: Guild ID
|
guild: Guild ID
|
||||||
|
duration: int, duration of lockdown in minutes, default 30
|
||||||
|
time: Datetime
|
||||||
|
|
||||||
settings:
|
settings:
|
||||||
guild: Guild ID
|
guild: Guild ID
|
||||||
|
@ -67,6 +69,12 @@ jarvis:
|
||||||
admin: User ID, admin who added autoreact
|
admin: User ID, admin who added autoreact
|
||||||
time: datetime
|
time: datetime
|
||||||
|
|
||||||
|
starboard:
|
||||||
|
guild: Guild ID
|
||||||
|
channel: Channel ID
|
||||||
|
admin: User ID, admin who created
|
||||||
|
time: Datetime
|
||||||
|
|
||||||
stars:
|
stars:
|
||||||
message: Message ID
|
message: Message ID
|
||||||
channel: Channel ID
|
channel: Channel ID
|
||||||
|
@ -75,9 +83,32 @@ jarvis:
|
||||||
time: Datetime
|
time: Datetime
|
||||||
|
|
||||||
modlog:
|
modlog:
|
||||||
|
channel: Channel ID
|
||||||
|
guild: Guild ID
|
||||||
|
admin: User ID, admin who created
|
||||||
|
time: Datetime
|
||||||
|
|
||||||
|
logentry:
|
||||||
user: User ID
|
user: User ID
|
||||||
activity: String
|
activity: String
|
||||||
|
channel: Optional(Channel ID), channel where activity occurred
|
||||||
|
guild: Guild ID
|
||||||
|
modlog: BsonID, target modlog
|
||||||
time: Datetime
|
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:
|
ctc2:
|
||||||
guesses:
|
guesses:
|
||||||
guess: String
|
guess: String
|
||||||
|
|
Loading…
Add table
Reference in a new issue