TotalFreedomBot/commands/moderation.py

100 lines
4.6 KiB
Python
Raw Normal View History

2020-10-28 11:47:39 +00:00
import datetime
2021-01-07 19:17:16 +00:00
import discord
2020-10-28 11:47:39 +00:00
from discord.ext import commands
2021-01-07 19:17:16 +00:00
from checks import is_mod_or_has_perms
from functions import read_json, write_json
2020-10-28 11:47:39 +00:00
muted_role_id = 769659653121900546
2020-10-28 11:47:39 +00:00
class Moderation(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.moderator_role_id = 769659653129896023
2020-10-28 11:47:39 +00:00
@commands.command()
@commands.has_permissions(kick_members=True)
async def kick(self, ctx, user: discord.Member, *, reason="No reason specified"):
"""Kicks a user from the guild."""
await user.kick(reason=f'{reason}** **by: {ctx.author.name}')
2021-01-07 19:17:16 +00:00
await ctx.send(
embed=discord.Embed(embed=f'{user.name} has been kicked by: {ctx.author.name} for reason: {reason}'))
print(
f"[{datetime.datetime.utcnow().replace(microsecond=0)} INFO]: [Moderation] Kicked {user.name} from {ctx.guild.name}")
2020-10-28 11:47:39 +00:00
@commands.command(aliases=['gtfo'])
@commands.has_permissions(ban_members=True)
async def ban(self, ctx, user: discord.Member, *, reason="No reason specified"):
"""Bans a user from the guild."""
await user.ban(reason=f'{reason} || by: {ctx.author.name}', delete_message_days=0)
2021-01-07 19:17:16 +00:00
await ctx.send(
embed=discord.Embed(description=f'{user.name} has been banned by: {ctx.author.name} for reason: {reason}'))
print(
f"[{datetime.datetime.utcnow().replace(microsecond=0)} INFO]: [Moderation] Banned {user.name} from {ctx.guild.name}")
2020-10-28 11:47:39 +00:00
@commands.command()
@commands.has_permissions(ban_members=True)
async def unban(self, ctx, user: discord.User, *, reason="No reason specified"):
"""Unbans a user from the guild."""
await ctx.guild.unban(user, reason=f'{reason} || by: {ctx.author.name}')
2021-01-07 19:17:16 +00:00
await ctx.send(embed=discord.Embed(
description=f'{user.name} has been unbanned by: {ctx.author.name} for reason: {reason}'))
print(
f"[{datetime.datetime.utcnow().replace(microsecond=0)} INFO]: [Moderation] Banned {user.name} from {ctx.guild.name}")
2020-10-28 11:47:39 +00:00
@commands.command(aliases=['massdelete', 'purge'])
2020-10-28 11:47:39 +00:00
@commands.has_permissions(manage_messages=True)
async def prune(self, ctx, msgs):
"""Purge messages from a channel."""
channel = ctx.channel
await channel.purge(limit=(int(msgs) + 1))
await ctx.send(embed=discord.Embed(description=f'{ctx.author.name} deleted {msgs} messages'))
2021-01-07 19:17:16 +00:00
print(
f'[{datetime.datetime.utcnow().replace(microsecond=0)} INFO]: [Moderation] {ctx.author.name} purged {msgs} messages in {ctx.guild.name}')
2020-10-28 11:47:39 +00:00
@commands.command(aliases=['stfu'])
@commands.has_permissions(manage_messages=True)
async def mute(self, ctx, member: discord.Member, *, reason=''):
"""Mutes a member of the server."""
muted_role = ctx.guild.get_role(muted_role_id)
await member.add_roles(muted_role, reason=f'{reason} || by {ctx.author.name}')
2020-10-28 11:47:39 +00:00
if reason == '':
reason = 'No reason specified'
await ctx.send(embed=discord.Embed(description=f'{member} muted by: {ctx.author.name} for: {reason}'))
2021-01-07 19:17:16 +00:00
print(
f'[{datetime.datetime.utcnow().replace(microsecond=0)} INFO]: [Moderation] Muted {member} in {ctx.guild.name}')
2020-10-28 11:47:39 +00:00
@commands.command()
@commands.has_permissions(manage_messages=True)
async def unmute(self, ctx, member: discord.Member, *, reason=''):
"""Unmutes a member of the server."""
muted_role = ctx.guild.get_role(muted_role_id)
await member.remove_roles(muted_role, reason=f'{reason} || by {ctx.author.name}')
2020-10-28 11:47:39 +00:00
await ctx.send(embed=discord.Embed(description=f'{member} unmuted by {ctx.author.name}'))
2021-01-07 19:17:16 +00:00
print(
f'[{datetime.datetime.utcnow().replace(microsecond=0)} INFO]: [Moderation] Unmuted {member} in {ctx.guild.name}')
2020-10-28 11:47:39 +00:00
@commands.command()
@commands.has_permissions(manage_roles=True)
async def setreaction(self, ctx, role: discord.Role = None, msg: discord.Message = None, emoji=None):
if role and msg and emoji:
2020-10-28 11:47:39 +00:00
await msg.add_reaction(emoji)
self.bot.reaction_roles.append([role.id, msg.id, emoji])
2020-11-21 12:54:54 +00:00
data = read_json('config')
data['reaction_roles'].append([role.id, msg.id, emoji])
2020-11-21 12:54:54 +00:00
print(data['reaction_roles'])
write_json('config', data)
2021-01-07 19:17:16 +00:00
@commands.command()
@is_mod_or_has_perms(manage_roles=True)
async def verify(self, ctx, member: discord.Member):
verify_role = ctx.guild.get_role(self.bot.verification_role)
await member.add_roles(verify_role)
await ctx.send(f'```Successfully verified: {member.name}```')
2020-10-28 11:47:39 +00:00
def setup(bot):
2020-10-28 12:24:38 +00:00
bot.add_cog(Moderation(bot))