Moved modlogs over to guild.py

pull/8/head
sgoudham 4 years ago
parent 92cc9b3c45
commit e9d8fc90a3

@ -4,11 +4,9 @@ from typing import Optional
from discord import Member, Embed from discord import Member, Embed
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, Cog, group cooldown, BucketType, Cog
import db from settings import enso_embedmod_colours, get_modlog_for_guild
from db import connection
from settings import enso_embedmod_colours, get_modlog_for_guild, storage_modlog_for_guild, remove_modlog_channel
async def ban_members(message, targets, reason): async def ban_members(message, targets, reason):
@ -117,137 +115,6 @@ class Moderation(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-----")
@group(invoke_without_command=True, usage="`[argument...]`")
@has_permissions(manage_guild=True)
@bot_has_permissions(administrator=True)
@cooldown(1, 1, BucketType.user)
async def modlogs(self, ctx):
"""Setup/Update/Delete Modlogs System"""
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]
# Setup pool
pool = await connection(db.loop)
# Setup pool connection and cursor
async with pool.acquire() as conn:
async with conn.cursor() as cur:
# Get the row of the guild
select_query = """SELECT * FROM guilds WHERE guildID = (%s)"""
val = ctx.guild.id,
# Execute the SQL Query
await cur.execute(select_query, val)
result = await cur.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:
# Set up the modlogs channel within the guild
mod_log_setup = True
await storage_modlog_for_guild(ctx, channelID, mod_log_setup)
@modlogs.command()
@has_permissions(manage_guild=True)
@bot_has_permissions(administrator=True)
@cooldown(1, 1, BucketType.user)
async def update(self, ctx, channelID: int):
"""Change the Channel that your Modlogs are Sent to"""
# Retrieve a list of channel id's in the guild
channels = [channel.id for channel in ctx.guild.channels]
# Setup pool
pool = await db.connection(db.loop)
# Setup up pool connection and cursor
async with pool.acquire() as conn:
async with conn.cursor() as cur:
# Get the guilds row from the guilds table
select_query = """SELECT * FROM guilds WHERE guildID = (%s)"""
vals = ctx.guild.id,
# Execute the SQL Query
await cur.execute(select_query, vals)
result = await cur.fetchone()
# Throw error if the modlog channel already exists and then stop the function
if result[2] is None:
await ctx.send("Looks like this guild has not setup a **Modlogs Channel**" +
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:
# Update the modlog channel within the database and cache
mod_log_setup = False
await storage_modlog_for_guild(ctx, channelID, mod_log_setup)
@modlogs.command()
@has_permissions(manage_guild=True)
@bot_has_permissions(administrator=True)
@cooldown(1, 1, BucketType.user)
async def delete(self, ctx):
"""Delete the Existing Modlogs System"""
# Setup pool
pool = await db.connection(db.loop)
# Setup up pool connection and cursor
async with pool.acquire() as conn:
async with conn.cursor() as cur:
# Get the guilds row from the guilds table
select_query = """SELECT * FROM guilds WHERE guildID = (%s)"""
vals = ctx.guild.id,
# Execute the SQL Query
await cur.execute(select_query, vals)
result = await cur.fetchone()
# Throw error if the modlog channel already exists and then stop the function
if result[2] is None:
await ctx.send("Looks like this guild has not setup a **Modlogs Channel**" +
f"\nPlease check **{ctx.prefix}help** for information on how to update/delete existing information")
return
# Setup up pool connection and cursor
async with pool.acquire() as conn:
async with conn.cursor() as cur:
# Update the existing prefix within the database
update_query = """UPDATE guilds SET modlogs = NULL WHERE guildID = (%s)"""
update_vals = ctx.guild.id,
# Execute the query
await cur.execute(update_query, update_vals)
await conn.commit()
# Delete channel from cache
remove_modlog_channel(str(ctx.guild.id))
# Sending confirmation message that the modmail system has been deleted
await ctx.send("**Modlogs System** successfully deleted!" +
f"\nPlease do **{ctx.prefix}help** to find out how to set Modmail again!")
@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)

Loading…
Cancel
Save