-
Notifications
You must be signed in to change notification settings - Fork 0
/
moderation.py
67 lines (57 loc) · 3.2 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""
Commands for moderation, such as ban, kick and clearchat
"""
from typing import Optional
import discord
from discord.ext import commands
# TODO: Auto-moderation: spam filtering and alike
# TODO: warns, punishments, timed punishments
class Moderation(commands.Cog):
def __init__(self, bot: commands.Bot):
print('Loading Moderation module...', end='')
self.bot = bot
self.guild_config_cog = bot.get_cog('GuildConfigCog')
print(' Done')
# TODO: message filters
@commands.has_permissions(manage_messages=True)
@commands.command(aliases=['clear', 'cl'],
description='Clear chat',
brief='Clear chat',
help='Deletes specified count of messages in this channel. Can be used only by members with messages managing permission.')
async def clearchat(self, ctx: commands.Context, messages_count: int):
await ctx.message.delete()
deleted = await ctx.channel.purge(limit=messages_count) # type: ignore
await ctx.send('Deleted {} message(s)'.format(len(deleted)), delete_after=3)
@commands.has_permissions(ban_members=True)
@commands.command(description='Ban member', help='Ban specified member. Set delete_message_days to 0 to not delete any messages.')
async def ban(self, ctx: commands.Context, member: discord.Member, reason: Optional[str], delete_message_days: int = 0):
guild_config = await self.guild_config_cog.get_guild(ctx.guild)
await member.ban(reason=reason, delete_message_days=delete_message_days)
await ctx.send('Banned member '+str(member))
if reason is None:
reason = 'Reason not provided'
else:
reason = 'Reason: ' + reason
log_channel = await guild_config.get_log_channel()
if log_channel:
await log_channel.send('Banned {0}\nBy: {1}\n{2}'.format(str(member), ctx.author.mention, reason)) # type: ignore
@commands.has_permissions(ban_members=True)
@commands.command(aliases=['uban'], description='Unban user', help='Unban specified member.')
async def unban(self, ctx: commands.Context, member: discord.Member, reason: str = 'Not provided'):
guild_config = await self.guild_config_cog.get_guild(ctx.guild)
await member.unban(reason=reason)
await ctx.send('Unbanned member '+str(member))
log_channel = await guild_config.get_log_channel()
if log_channel:
await log_channel.send('Unbanned {0}\nBy: {1}\nReason: {2}'.format(str(member), ctx.author.mention, reason)) # type: ignore
@commands.has_permissions(kick_members=True)
@commands.command(description='Kick member', help='Kick specified member')
async def kick(self, ctx: commands.Context, member: discord.Member, reason: str = 'Not provided'):
guild_config = await self.guild_config_cog.get_guild(ctx.guild)
await member.kick(reason=reason)
await ctx.send('Kicked member '+str(member))
log_channel = await guild_config.get_log_channel()
if log_channel:
await log_channel.send('Kicked {0}\nBy: {1}\nReason: {2}'.format(str(member), ctx.author.mention, reason))
def setup(bot: commands.Bot):
bot.add_cog(Moderation(bot))