Compare commits
No commits in common. "d7524846620646236ff603de7407850138d7ade7" and "1c247636d171cd89d95d3c76aaac4e773e0a6977" have entirely different histories.
d752484662
...
1c247636d1
1 changed files with 60 additions and 164 deletions
|
@ -1,7 +1,6 @@
|
|||
import logging
|
||||
import time
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from typing import Union
|
||||
import discord
|
||||
import humanize
|
||||
import mysql.connector
|
||||
|
@ -12,7 +11,7 @@ from redbot.core.app_commands import Choice
|
|||
|
||||
|
||||
class Moderation(commands.Cog):
|
||||
"""Custom moderation cog.
|
||||
"""Custom cog moderation cog, meant to copy GalacticBot.
|
||||
Developed by SeaswimmerTheFsh."""
|
||||
|
||||
def __init__(self, bot):
|
||||
|
@ -46,7 +45,6 @@ class Moderation(commands.Cog):
|
|||
guilds: list[discord.Guild] = self.bot.guilds
|
||||
try:
|
||||
for guild in guilds:
|
||||
if not await self.bot.cog_disabled_in_guild(self, guild):
|
||||
await self.create_guild_table(guild)
|
||||
except ConnectionRefusedError:
|
||||
return
|
||||
|
@ -57,7 +55,6 @@ class Moderation(commands.Cog):
|
|||
@commands.Cog.listener('on_guild_join')
|
||||
async def db_generate_guild_join(self, guild: discord.Guild):
|
||||
"""This method prepares the database schema whenever the bot joins a guild."""
|
||||
if not await self.bot.cog_disabled_in_guild(self, guild):
|
||||
conf = await self.check_conf([
|
||||
'mysql_address',
|
||||
'mysql_database',
|
||||
|
@ -75,7 +72,6 @@ class Moderation(commands.Cog):
|
|||
@commands.Cog.listener('on_audit_log_entry_create')
|
||||
async def autologger(self, entry: discord.AuditLogEntry):
|
||||
"""This method automatically logs moderations done by users manually ("right clicks")."""
|
||||
if not await self.bot.cog_disabled_in_guild(self, entry.guild):
|
||||
if await self.config.guild(entry.guild.id).ignore_other_bots() is True:
|
||||
if entry.user.bot or entry.target.bot:
|
||||
return
|
||||
|
@ -177,17 +173,6 @@ class Moderation(commands.Cog):
|
|||
not_found_list.append(item)
|
||||
return not_found_list
|
||||
|
||||
def check_permissions(self, member: discord.Member, permissions: list, ctx: Union[commands.Context, discord.Interaction] = None):
|
||||
"""Checks if the bot has a specific permission (or a list of permissions) in a channel."""
|
||||
if ctx:
|
||||
resolved_permissions = ctx.channel.permissions_for(member)
|
||||
else:
|
||||
resolved_permissions = member.guild_permissions
|
||||
for permission in permissions:
|
||||
if not getattr(resolved_permissions, permission, False) and not resolved_permissions.administrator is True:
|
||||
return permission
|
||||
return False
|
||||
|
||||
async def mysql_log(self, guild_id: str, author_id: str, moderation_type: str, target_id: int, duration, reason: str):
|
||||
timestamp = int(time.time())
|
||||
if duration != "NULL":
|
||||
|
@ -316,14 +301,6 @@ class Moderation(commands.Cog):
|
|||
Why are you noting this user?
|
||||
silent: bool
|
||||
Should the user be messaged?"""
|
||||
if interaction.guild.get_member(target.id):
|
||||
target_member = interaction.guild.get_member(target.id)
|
||||
if interaction.guild.get_member(interaction.client.user.id).top_role <= target_member.top_role:
|
||||
await interaction.response.send_message(content="You cannot moderate members with a role higher than the bot!", ephemeral=True)
|
||||
return
|
||||
if interaction.user.top_role <= target_member.top_role:
|
||||
await interaction.response.send_message(content="You cannot moderate members with a higher role than you!", ephemeral=True)
|
||||
return
|
||||
await interaction.response.send_message(content=f"{target.mention} has recieved a note!\n**Reason** - `{reason}`")
|
||||
if silent is None:
|
||||
silent = not await self.config.guild(interaction.guild).dm_users()
|
||||
|
@ -347,14 +324,6 @@ class Moderation(commands.Cog):
|
|||
Why are you warning this user?
|
||||
silent: bool
|
||||
Should the user be messaged?"""
|
||||
if interaction.guild.get_member(target.id):
|
||||
target_member = interaction.guild.get_member(target.id)
|
||||
if interaction.guild.get_member(interaction.client.user.id).top_role <= target_member.top_role:
|
||||
await interaction.response.send_message(content="You cannot moderate members with a role higher than the bot!", ephemeral=True)
|
||||
return
|
||||
if interaction.user.top_role <= target_member.top_role:
|
||||
await interaction.response.send_message(content="You cannot moderate members with a higher role than you!", ephemeral=True)
|
||||
return
|
||||
await interaction.response.send_message(content=f"{target.mention} has been warned!\n**Reason** - `{reason}`")
|
||||
if silent is None:
|
||||
silent = not await self.config.guild(interaction.guild).dm_users()
|
||||
|
@ -380,18 +349,6 @@ class Moderation(commands.Cog):
|
|||
Why are you unbanning this user?
|
||||
silent: bool
|
||||
Should the user be messaged?"""
|
||||
if interaction.guild.get_member(target.id):
|
||||
target_member = interaction.guild.get_member(target.id)
|
||||
if interaction.guild.get_member(interaction.client.user.id).top_role <= target_member.top_role:
|
||||
await interaction.response.send_message(content="You cannot moderate members with a role higher than the bot!", ephemeral=True)
|
||||
return
|
||||
if interaction.user.top_role <= target_member.top_role:
|
||||
await interaction.response.send_message(content="You cannot moderate members with a higher role than you!", ephemeral=True)
|
||||
return
|
||||
permissions = self.check_permissions(interaction.client.user, ['moderate_members'], interaction)
|
||||
if permissions:
|
||||
await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True)
|
||||
return
|
||||
if target.is_timed_out() is True:
|
||||
await interaction.response.send_message(f"{target.mention} is already muted!", allowed_mentions=discord.AllowedMentions(users=False), ephemeral=True)
|
||||
return
|
||||
|
@ -427,18 +384,6 @@ class Moderation(commands.Cog):
|
|||
Why are you unmuting this user?
|
||||
silent: bool
|
||||
Should the user be messaged?"""
|
||||
if interaction.guild.get_member(target.id):
|
||||
target_member = interaction.guild.get_member(target.id)
|
||||
if interaction.guild.get_member(interaction.client.user.id).top_role <= target_member.top_role:
|
||||
await interaction.response.send_message(content="You cannot moderate members with a role higher than the bot!", ephemeral=True)
|
||||
return
|
||||
if interaction.user.top_role <= target_member.top_role:
|
||||
await interaction.response.send_message(content="You cannot moderate members with a higher role than you!", ephemeral=True)
|
||||
return
|
||||
permissions = self.check_permissions(interaction.client.user, ['moderate_members'], interaction)
|
||||
if permissions:
|
||||
await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True)
|
||||
return
|
||||
if target.is_timed_out() is False:
|
||||
await interaction.response.send_message(f"{target.mention} is not muted!", allowed_mentions=discord.AllowedMentions(users=False), ephemeral=True)
|
||||
return
|
||||
|
@ -470,18 +415,6 @@ class Moderation(commands.Cog):
|
|||
Why are you kicking this user?
|
||||
silent: bool
|
||||
Should the user be messaged?"""
|
||||
if interaction.guild.get_member(target.id):
|
||||
target_member = interaction.guild.get_member(target.id)
|
||||
if interaction.guild.get_member(interaction.client.user.id).top_role <= target_member.top_role:
|
||||
await interaction.response.send_message(content="You cannot moderate members with a role higher than the bot!", ephemeral=True)
|
||||
return
|
||||
if interaction.user.top_role <= target_member.top_role:
|
||||
await interaction.response.send_message(content="You cannot moderate members with a higher role than you!", ephemeral=True)
|
||||
return
|
||||
permissions = self.check_permissions(interaction.client.user, ['kick_members'], interaction)
|
||||
if permissions:
|
||||
await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True)
|
||||
return
|
||||
await interaction.response.send_message(content=f"{target.mention} has been kicked!\n**Reason** - `{reason}`")
|
||||
if silent is None:
|
||||
silent = not await self.config.guild(interaction.guild).dm_users()
|
||||
|
@ -518,18 +451,6 @@ class Moderation(commands.Cog):
|
|||
How many days of messages to delete?
|
||||
silent: bool
|
||||
Should the user be messaged?"""
|
||||
if interaction.guild.get_member(target.id):
|
||||
target_member = interaction.guild.get_member(target.id)
|
||||
if interaction.guild.get_member(interaction.client.user.id).top_role <= target_member.top_role:
|
||||
await interaction.response.send_message(content="You cannot moderate members with a role higher than the bot!", ephemeral=True)
|
||||
return
|
||||
if interaction.user.top_role <= target_member.top_role:
|
||||
await interaction.response.send_message(content="You cannot moderate members with a higher role than you!", ephemeral=True)
|
||||
return
|
||||
permissions = self.check_permissions(interaction.client.user, ['ban_members'], interaction)
|
||||
if permissions:
|
||||
await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True)
|
||||
return
|
||||
try:
|
||||
await interaction.guild.fetch_ban(target)
|
||||
await interaction.response.send_message(content=f"{target.mention} is already banned!", ephemeral=True)
|
||||
|
@ -575,18 +496,6 @@ class Moderation(commands.Cog):
|
|||
Why are you unbanning this user?
|
||||
silent: bool
|
||||
Should the user be messaged?"""
|
||||
if interaction.guild.get_member(target.id):
|
||||
target_member = interaction.guild.get_member(target.id)
|
||||
if interaction.guild.get_member(interaction.client.user.id).top_role <= target_member.top_role:
|
||||
await interaction.response.send_message(content="You cannot moderate members with a role higher than the bot!", ephemeral=True)
|
||||
return
|
||||
if interaction.user.top_role <= target_member.top_role:
|
||||
await interaction.response.send_message(content="You cannot moderate members with a higher role than you!", ephemeral=True)
|
||||
return
|
||||
permissions = self.check_permissions(interaction.client.user, ['moderate_members'], interaction)
|
||||
if permissions:
|
||||
await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True)
|
||||
return
|
||||
try:
|
||||
await interaction.guild.fetch_ban(target)
|
||||
except discord.errors.NotFound:
|
||||
|
@ -624,10 +533,6 @@ class Moderation(commands.Cog):
|
|||
Page to select
|
||||
epheremal: bool
|
||||
Hide the command response"""
|
||||
permissions = self.check_permissions(interaction.client.user, ['embed_links'], interaction)
|
||||
if permissions:
|
||||
await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True)
|
||||
return
|
||||
database = await self.connect()
|
||||
cursor = database.cursor()
|
||||
if target:
|
||||
|
@ -690,10 +595,6 @@ class Moderation(commands.Cog):
|
|||
Case number of the case you're trying to resolve
|
||||
reason: str
|
||||
Reason for resolving case"""
|
||||
permissions = self.check_permissions(interaction.client.user, ['embed_links'], interaction)
|
||||
if permissions:
|
||||
await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True)
|
||||
return
|
||||
conf = await self.check_conf(['mysql_database'])
|
||||
if conf:
|
||||
raise(LookupError)
|
||||
|
@ -754,10 +655,6 @@ class Moderation(commands.Cog):
|
|||
What case are you looking up?
|
||||
ephemeral: bool
|
||||
Hide the command response"""
|
||||
permissions = self.check_permissions(interaction.client.user, ['embed_links'], interaction)
|
||||
if permissions:
|
||||
await interaction.response.send_message(f"I do not have the `{permissions}` permission, required for this action.", ephemeral=True)
|
||||
return
|
||||
database = await self.connect()
|
||||
cursor = database.cursor()
|
||||
query = "SELECT * FROM moderation_%s WHERE moderation_id = %s;"
|
||||
|
@ -782,7 +679,6 @@ class Moderation(commands.Cog):
|
|||
db = await self.config.mysql_database()
|
||||
guilds: list[discord.Guild] = self.bot.guilds
|
||||
for guild in guilds:
|
||||
if not await self.bot.cog_disabled_in_guild(self, guild):
|
||||
tempban_query = f"SELECT target_id, moderation_id FROM moderation_{guild.id} WHERE end_timestamp != 0 AND end_timestamp <= %s AND moderation_type = 'TEMPBAN' AND expired = 0"
|
||||
try:
|
||||
cursor.execute(tempban_query, (time.time(),))
|
||||
|
|
Loading…
Reference in a new issue