Compare commits
No commits in common. "dd98ecdcd1c2c0da1743f45b37b244f82798ab5f" and "2b0e24a4e98f458fcd5f3249ea880e3ce6d2edc3" have entirely different histories.
dd98ecdcd1
...
2b0e24a4e9
1 changed files with 9 additions and 41 deletions
|
@ -5,7 +5,7 @@ import discord
|
||||||
import humanize
|
import humanize
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
from pytimeparse2 import disable_dateutil, parse
|
from pytimeparse2 import disable_dateutil, parse
|
||||||
from redbot.core import Config, checks, commands, tasks
|
from redbot.core import Config, checks, commands
|
||||||
|
|
||||||
|
|
||||||
class Moderation(commands.Cog):
|
class Moderation(commands.Cog):
|
||||||
|
@ -115,11 +115,11 @@ class Moderation(commands.Cog):
|
||||||
database = await self.connect()
|
database = await self.connect()
|
||||||
cursor = database.cursor()
|
cursor = database.cursor()
|
||||||
try:
|
try:
|
||||||
cursor.execute(f"SELECT * FROM `moderation_{guild.id}`")
|
cursor.execute(f"SELECT * FROM `{guild.id}_moderation`")
|
||||||
logging.info("MySQL Table exists for server %s (%s)", guild.name, guild.id)
|
logging.info("MySQL Table exists for server %s (%s)", guild.name, guild.id)
|
||||||
except mysql.connector.errors.ProgrammingError:
|
except mysql.connector.errors.ProgrammingError:
|
||||||
query = f"""
|
query = f"""
|
||||||
CREATE TABLE `moderation_{guild.id}` (
|
CREATE TABLE `{guild.id}_moderation` (
|
||||||
moderation_id INT UNIQUE PRIMARY KEY NOT NULL,
|
moderation_id INT UNIQUE PRIMARY KEY NOT NULL,
|
||||||
timestamp INT NOT NULL,
|
timestamp INT NOT NULL,
|
||||||
moderation_type LONGTEXT NOT NULL,
|
moderation_type LONGTEXT NOT NULL,
|
||||||
|
@ -135,7 +135,7 @@ class Moderation(commands.Cog):
|
||||||
"""
|
"""
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
insert_query = f"""
|
insert_query = f"""
|
||||||
INSERT INTO `moderation_{guild.id}`
|
INSERT INTO `{guild.id}_moderation`
|
||||||
(moderation_id, timestamp, moderation_type, target_id, moderator_id, duration, end_timestamp, reason, resolved, resolve_reason, expired)
|
(moderation_id, timestamp, moderation_type, target_id, moderator_id, duration, end_timestamp, reason, resolved, resolve_reason, expired)
|
||||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||||
"""
|
"""
|
||||||
|
@ -143,7 +143,7 @@ class Moderation(commands.Cog):
|
||||||
cursor.execute(insert_query, insert_values)
|
cursor.execute(insert_query, insert_values)
|
||||||
database.commit()
|
database.commit()
|
||||||
database.close()
|
database.close()
|
||||||
logging.info("MySQL Table created for %s (%s)\nmoderation_%s", guild.name, guild.id, guild.id)
|
logging.info("MySQL Table created for %s (%s)\n%s_moderation", guild.name, guild.id, guild.id)
|
||||||
else:
|
else:
|
||||||
database.close()
|
database.close()
|
||||||
return
|
return
|
||||||
|
@ -165,29 +165,16 @@ class Moderation(commands.Cog):
|
||||||
end_timestamp = 0
|
end_timestamp = 0
|
||||||
database = await self.connect()
|
database = await self.connect()
|
||||||
cursor = database.cursor()
|
cursor = database.cursor()
|
||||||
cursor.execute(f"SELECT moderation_id FROM `moderation_{guild_id}` ORDER BY moderation_id DESC LIMIT 1")
|
cursor.execute(f"SELECT moderation_id FROM `{guild_id}_moderation` ORDER BY moderation_id DESC LIMIT 1")
|
||||||
moderation_id = cursor.fetchone()[0] + 1
|
moderation_id = cursor.fetchone()[0] + 1
|
||||||
sql = f"INSERT INTO `moderation_{guild_id}` (moderation_id, timestamp, moderation_type, target_id, moderator_id, duration, end_timestamp, reason, resolved, resolve_reason, expired) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
|
sql = f"INSERT INTO `{guild_id}_moderation` (moderation_id, timestamp, moderation_type, target_id, moderator_id, duration, end_timestamp, reason, resolved, resolve_reason, expired) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
|
||||||
val = (moderation_id, timestamp, moderation_type, target_id, author_id, duration, end_timestamp, f"{reason}", 0, "NULL", 0)
|
val = (moderation_id, timestamp, moderation_type, target_id, author_id, duration, end_timestamp, f"{reason}", 0, "NULL", 0)
|
||||||
cursor.execute(sql, val)
|
cursor.execute(sql, val)
|
||||||
database.commit()
|
database.commit()
|
||||||
database.close()
|
database.close()
|
||||||
logging.debug("MySQL row inserted into moderation_%s!\n%s, %s, %s, %s, %s, %s, %s, %s, 0, NULL", guild_id, moderation_id, timestamp, moderation_type, target_id, author_id, duration, end_timestamp, reason)
|
logging.debug("MySQL row inserted into %s_moderation!\n%s, %s, %s, %s, %s, %s, %s, %s, 0, NULL", guild_id, moderation_id, timestamp, moderation_type, target_id, author_id, duration, end_timestamp, reason)
|
||||||
|
|
||||||
@commands.hybrid_command(name="warn")
|
@commands.hybrid_command(name="mute", aliases=['timeout'])
|
||||||
@commands.mod()
|
|
||||||
async def warn(self, ctx: commands.Context, target: discord.Member, *, reason: str):
|
|
||||||
"""Warn a user."""
|
|
||||||
response = await ctx.send(content=f"{target.mention} has been warned!\n**Reason** - `{reason}`")
|
|
||||||
try:
|
|
||||||
embed = discord.Embed(title="Warned", description=f"You have been warned in [{ctx.guild.name}]({response.jump_url}).", color=await self.bot.get_embed_color(None))
|
|
||||||
embed.add_field(name='Reason', value=f"`{reason}`")
|
|
||||||
await target.send(embed=embed)
|
|
||||||
except discord.errors.HTTPException:
|
|
||||||
await response.edit(content=f"{response.content}\n*Failed to send DM, user likely has the bot blocked.*")
|
|
||||||
await self.mysql_log(ctx.guild.id, ctx.author.id, 'WARN', target.id, 'NULL', reason)
|
|
||||||
|
|
||||||
@commands.hybrid_command(name="mute", aliases=['timeout', 'tm'])
|
|
||||||
@commands.mod()
|
@commands.mod()
|
||||||
async def mute(self, ctx: commands.Context, target: discord.Member, duration: str, *, reason: str):
|
async def mute(self, ctx: commands.Context, target: discord.Member, duration: str, *, reason: str):
|
||||||
"""Mute a user."""
|
"""Mute a user."""
|
||||||
|
@ -209,25 +196,6 @@ class Moderation(commands.Cog):
|
||||||
await response.edit(content=f"{response.content}\n*Failed to send DM, user likely has the bot blocked.*")
|
await response.edit(content=f"{response.content}\n*Failed to send DM, user likely has the bot blocked.*")
|
||||||
await self.mysql_log(ctx.guild.id, ctx.author.id, 'MUTE', target.id, parsed_time, reason)
|
await self.mysql_log(ctx.guild.id, ctx.author.id, 'MUTE', target.id, parsed_time, reason)
|
||||||
|
|
||||||
@commands.hybrid_command(name="unmute", aliases=['untimeout', 'utm'])
|
|
||||||
@commands.mod()
|
|
||||||
async def unmute(self, ctx: commands.Context, target: discord.Member, *, reason: str = None):
|
|
||||||
"""Unmute a user."""
|
|
||||||
if target.is_timed_out() is False:
|
|
||||||
await ctx.send(f"{target.mention} is not muted!", allowed_mentions=discord.AllowedMentions(users=False))
|
|
||||||
return
|
|
||||||
await target.timeout(None)
|
|
||||||
if reason is None:
|
|
||||||
reason = "No reason given."
|
|
||||||
response = await ctx.send(content=f"{target.mention} has been unmuted!\n**Reason** - `{reason}`")
|
|
||||||
try:
|
|
||||||
embed = discord.Embed(title="Unmuted", description=f"You have been unmuted in [{ctx.guild.name}]({response.jump_url}).", color=await self.bot.get_embed_color(None))
|
|
||||||
embed.add_field(name='Reason', value=f"`{reason}`")
|
|
||||||
await target.send(embed=embed)
|
|
||||||
except discord.errors.HTTPException:
|
|
||||||
await response.edit(content=f"{response.content}\n*Failed to send DM, user likely has the bot blocked.*")
|
|
||||||
await self.mysql_log(ctx.guild.id, ctx.author.id, 'UNMUTE', target.id, 'NULL', reason)
|
|
||||||
|
|
||||||
@commands.group(autohelp=True)
|
@commands.group(autohelp=True)
|
||||||
@checks.admin()
|
@checks.admin()
|
||||||
async def moderationset(self, ctx: commands.Context):
|
async def moderationset(self, ctx: commands.Context):
|
||||||
|
|
Loading…
Reference in a new issue