This repository has been archived by the owner on Jul 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
moderation.py
52 lines (43 loc) · 2.08 KB
/
moderation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# This file is part of torn-bot.
#
# torn-bot is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# torn-bot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with torn-bot. If not, see <https://www.gnu.org/licenses/>.
from discord.ext import commands
import discord
from required import *
import dbutils
import asyncio
class Moderation(commands.Cog):
def __init__(self, logger):
self.logger = logger
@commands.command(pass_context=True)
@commands.cooldown(1, 15, commands.BucketType.guild)
async def purge(self, ctx, nummessages: int):
'''
Purges specified number of messages in the channel the command is invoked in
'''
if not check_admin(ctx.message.author) and dbutils.get_superuser() != ctx.message.author.id:
embed = discord.Embed()
embed.title = "Permission Denied"
embed.description = f'This command requires {ctx.message.author.name} to be an Administrator. ' \
f'This interaction has been logged.'
await ctx.send(embed=embed)
self.logger.warning(f'{ctx.message.author.name} has attempted to run purge, but is not an Administrator.')
return None
await ctx.message.delete()
await ctx.message.channel.purge(limit=nummessages, check=None, before=None)
self.logger.info(f'{nummessages} messages in {ctx.message.channel.name} have been purged by '
f'{ctx.message.author.mention}.')
message = await ctx.send(f'{nummessages} messages have been purged by {ctx.message.author.mention}.')
await asyncio.sleep(30)
await message.delete()