|
|
@ -1,5 +1,6 @@
|
|
|
|
import asyncio
|
|
|
|
import asyncio
|
|
|
|
import datetime
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
from contextlib import closing
|
|
|
|
from datetime import timedelta
|
|
|
|
from datetime import timedelta
|
|
|
|
from typing import Optional
|
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
|
|
|
@ -8,13 +9,13 @@ from discord.ext import commands
|
|
|
|
from discord.ext.commands import command, guild_only, has_guild_permissions, bot_has_guild_permissions, Greedy, \
|
|
|
|
from discord.ext.commands import command, guild_only, has_guild_permissions, bot_has_guild_permissions, Greedy, \
|
|
|
|
has_permissions, bot_has_permissions, cooldown, BucketType
|
|
|
|
has_permissions, bot_has_permissions, cooldown, BucketType
|
|
|
|
|
|
|
|
|
|
|
|
from settings import enso_embedmod_colours
|
|
|
|
import db
|
|
|
|
|
|
|
|
from settings import enso_embedmod_colours, get_modlog_for_guild
|
|
|
|
# Store guildID's and modlog channel within a cached dictionary
|
|
|
|
|
|
|
|
modlogs = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def kick_members(message, targets, reason):
|
|
|
|
async def kick_members(message, targets, reason):
|
|
|
|
|
|
|
|
channel = message.guild.get_channel(get_modlog_for_guild(str(message.guild.id)))
|
|
|
|
|
|
|
|
|
|
|
|
for target in targets:
|
|
|
|
for target in targets:
|
|
|
|
if (message.guild.me.top_role.position > target.top_role.position
|
|
|
|
if (message.guild.me.top_role.position > target.top_role.position
|
|
|
|
and not target.guild_permissions.administrator):
|
|
|
|
and not target.guild_permissions.administrator):
|
|
|
@ -33,7 +34,7 @@ async def kick_members(message, targets, reason):
|
|
|
|
for name, value, inline in fields:
|
|
|
|
for name, value, inline in fields:
|
|
|
|
embed.add_field(name=name, value=value, inline=inline)
|
|
|
|
embed.add_field(name=name, value=value, inline=inline)
|
|
|
|
|
|
|
|
|
|
|
|
return embed
|
|
|
|
await channel.send(embed=embed)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Moderation(commands.Cog):
|
|
|
|
class Moderation(commands.Cog):
|
|
|
@ -46,13 +47,58 @@ class Moderation(commands.Cog):
|
|
|
|
async def on_ready(self):
|
|
|
|
async def on_ready(self):
|
|
|
|
print(f"{self.__class__.__name__} Cog has been loaded\n-----")
|
|
|
|
print(f"{self.__class__.__name__} Cog has been loaded\n-----")
|
|
|
|
|
|
|
|
|
|
|
|
@commands.group()
|
|
|
|
@commands.group(invoke_without_command=True, usage="`[argument...]`")
|
|
|
|
@has_permissions(manage_guild=True)
|
|
|
|
@has_permissions(manage_guild=True)
|
|
|
|
@bot_has_permissions(administrator=True)
|
|
|
|
@bot_has_permissions(administrator=True)
|
|
|
|
@cooldown(1, 1, BucketType.user)
|
|
|
|
@cooldown(1, 1, BucketType.user)
|
|
|
|
async def modlogs(self, ctx):
|
|
|
|
async def modlogs(self, ctx):
|
|
|
|
|
|
|
|
"""Setup/Update/Delete Modlogs System"""
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@modlogs.command()
|
|
|
|
|
|
|
|
@has_permissions(manage_guild=True)
|
|
|
|
|
|
|
|
@bot_has_permissions(administrator=True)
|
|
|
|
|
|
|
|
@cooldown(1, 1, BucketType.user)
|
|
|
|
|
|
|
|
async def setup(self, ctx, channelID: int):
|
|
|
|
|
|
|
|
"""Setup a Channel for the Kick/Ban/Mute Actions to be Logged In"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Retrieve a list of channel id's in the guild
|
|
|
|
|
|
|
|
channels = [channel.id for channel in ctx.guild.channels]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Checking if the modlogs channel already exists within the database
|
|
|
|
|
|
|
|
with db.connection() as conn:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Get the row of the guild
|
|
|
|
|
|
|
|
select_query = """SELECT * FROM guilds WHERE guildID = (?)"""
|
|
|
|
|
|
|
|
val = ctx.author.guild.id,
|
|
|
|
|
|
|
|
with closing(conn.cursor()) as cursor:
|
|
|
|
|
|
|
|
# Execute the SQL Query
|
|
|
|
|
|
|
|
cursor.execute(select_query, val)
|
|
|
|
|
|
|
|
result = cursor.fetchone()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Throw error if the modlog channel already exists and then stop the function
|
|
|
|
|
|
|
|
if result[2] is not None:
|
|
|
|
|
|
|
|
await ctx.send("Looks like this guild already has a **Modlogs Channel** set up!" +
|
|
|
|
|
|
|
|
f"\nPlease check **{ctx.prefix}help** for information on how to update/delete existing information")
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Abort the process if the channel does not exist within the guild
|
|
|
|
|
|
|
|
if channelID not in channels:
|
|
|
|
|
|
|
|
await ctx.send("**Invalid ChannelID Detected... Aborting Process**")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
# Checking if the guild already exists within the database
|
|
|
|
|
|
|
|
with db.connection() as conn:
|
|
|
|
|
|
|
|
# Get the author's row from the Members Table
|
|
|
|
|
|
|
|
insert_query = """INSERT INTO guilds (modlogs) VALUES (?)"""
|
|
|
|
|
|
|
|
val = channelID,
|
|
|
|
|
|
|
|
with closing(conn.cursor()) as cursor:
|
|
|
|
|
|
|
|
# Execute the SQL Query
|
|
|
|
|
|
|
|
cursor.execute(insert_query, val)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await ctx.send("Your **Modlogs Channel** is now successfully set up!" +
|
|
|
|
|
|
|
|
f"\nPlease refer to **{ctx.prefix}help** for any information")
|
|
|
|
|
|
|
|
|
|
|
|
@command(name="kick", aliases=["Kick"], usage="`<member>` `[reason]`")
|
|
|
|
@command(name="kick", aliases=["Kick"], usage="`<member>` `[reason]`")
|
|
|
|
@guild_only()
|
|
|
|
@guild_only()
|
|
|
|
@has_guild_permissions(kick_members=True)
|
|
|
|
@has_guild_permissions(kick_members=True)
|
|
|
@ -74,17 +120,10 @@ class Moderation(commands.Cog):
|
|
|
|
|
|
|
|
|
|
|
|
# As long as all members are valid
|
|
|
|
# As long as all members are valid
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
|
|
|
|
|
|
|
|
# Send embed of the kicked member
|
|
|
|
# Send embed of the kicked member
|
|
|
|
embed = await kick_members(ctx.message, members, reason)
|
|
|
|
await kick_members(ctx.message, members, reason)
|
|
|
|
message = await ctx.send(embed=embed)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Let the user read the message for 10 seconds
|
|
|
|
|
|
|
|
await asyncio.sleep(10)
|
|
|
|
|
|
|
|
# Delete the message
|
|
|
|
|
|
|
|
await message.delete()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@command(name="ban", aliases=["Ban"])
|
|
|
|
@command(name="ban", aliases=["Ban"], usage="`<member>` `[reason]`")
|
|
|
|
@guild_only()
|
|
|
|
@guild_only()
|
|
|
|
@has_guild_permissions(ban_members=True)
|
|
|
|
@has_guild_permissions(ban_members=True)
|
|
|
|
@bot_has_guild_permissions(ban_members=True)
|
|
|
|
@bot_has_guild_permissions(ban_members=True)
|
|
|
@ -104,7 +143,7 @@ class Moderation(commands.Cog):
|
|
|
|
await ctx.send(f"{ctx.author.name} **banned** {member.name}"
|
|
|
|
await ctx.send(f"{ctx.author.name} **banned** {member.name}"
|
|
|
|
f"\n**Reason:** '{reason}'")
|
|
|
|
f"\n**Reason:** '{reason}'")
|
|
|
|
|
|
|
|
|
|
|
|
@command(name="unban", aliases=["Unban"])
|
|
|
|
@command(name="unban", aliases=["Unban"], usage="`<member>` `[reason]`")
|
|
|
|
@guild_only()
|
|
|
|
@guild_only()
|
|
|
|
@has_guild_permissions(ban_members=True)
|
|
|
|
@has_guild_permissions(ban_members=True)
|
|
|
|
@bot_has_guild_permissions(ban_members=True)
|
|
|
|
@bot_has_guild_permissions(ban_members=True)
|
|
|
|