|
|
|
@ -92,9 +92,13 @@ class Moderation:
|
|
|
|
|
return embed
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def build_admin_moderated_message(moderated_message, response_message, user_kicked=None, timed_out=None):
|
|
|
|
|
def build_admin_moderated_message(
|
|
|
|
|
moderated_message, response_message, user_kicked=None, timed_out=None
|
|
|
|
|
):
|
|
|
|
|
direct_message_object = isinstance(moderated_message, discord.Message)
|
|
|
|
|
moderated_message = moderated_message if direct_message_object else moderated_message.message
|
|
|
|
|
moderated_message = (
|
|
|
|
|
moderated_message if direct_message_object else moderated_message.message
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Create a discord embed to send to the user when their message gets moderated
|
|
|
|
|
embed = discord.Embed(
|
|
|
|
@ -116,8 +120,8 @@ class Moderation:
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def determine_moderation_result(text, response):
|
|
|
|
|
warn_set = ThresholdSet(0.005,0.05,0.05,0.91,0.1,0.04,0.1)
|
|
|
|
|
delete_set = ThresholdSet(0.1,0.1,0.1,0.95,0.03,0.6,0.4)
|
|
|
|
|
warn_set = ThresholdSet(0.005, 0.05, 0.05, 0.91, 0.1, 0.04, 0.1)
|
|
|
|
|
delete_set = ThresholdSet(0.1, 0.1, 0.1, 0.95, 0.03, 0.6, 0.4)
|
|
|
|
|
|
|
|
|
|
warn_result, flagged_warn = warn_set.moderate(text, response)
|
|
|
|
|
delete_result, flagged_delete = delete_set.moderate(text, response)
|
|
|
|
@ -168,7 +172,15 @@ class Moderation:
|
|
|
|
|
to_moderate, response_message
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
await response_message.edit(view=ModerationAdminView(to_moderate.message, response_message, True, True, True))
|
|
|
|
|
await response_message.edit(
|
|
|
|
|
view=ModerationAdminView(
|
|
|
|
|
to_moderate.message,
|
|
|
|
|
response_message,
|
|
|
|
|
True,
|
|
|
|
|
True,
|
|
|
|
|
True,
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
elif moderation_result == ModerationResult.WARN:
|
|
|
|
|
response_message = await moderations_alert_channel.send(
|
|
|
|
@ -193,25 +205,73 @@ class Moderation:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ModerationAdminView(discord.ui.View):
|
|
|
|
|
def __init__(self, message, moderation_message, nodelete=False, deleted_message=False, source_deleted=False):
|
|
|
|
|
def __init__(
|
|
|
|
|
self,
|
|
|
|
|
message,
|
|
|
|
|
moderation_message,
|
|
|
|
|
nodelete=False,
|
|
|
|
|
deleted_message=False,
|
|
|
|
|
source_deleted=False,
|
|
|
|
|
):
|
|
|
|
|
super().__init__(timeout=None) # 1 hour interval to redo.
|
|
|
|
|
component_number = 0
|
|
|
|
|
self.message = message
|
|
|
|
|
self.moderation_message = moderation_message,
|
|
|
|
|
self.add_item(TimeoutUserButton(self.message, self.moderation_message, component_number, 1, nodelete, source_deleted))
|
|
|
|
|
self.moderation_message = (moderation_message,)
|
|
|
|
|
self.add_item(
|
|
|
|
|
TimeoutUserButton(
|
|
|
|
|
self.message,
|
|
|
|
|
self.moderation_message,
|
|
|
|
|
component_number,
|
|
|
|
|
1,
|
|
|
|
|
nodelete,
|
|
|
|
|
source_deleted,
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
component_number += 1
|
|
|
|
|
self.add_item(TimeoutUserButton(self.message, self.moderation_message, component_number, 6, nodelete, source_deleted))
|
|
|
|
|
self.add_item(
|
|
|
|
|
TimeoutUserButton(
|
|
|
|
|
self.message,
|
|
|
|
|
self.moderation_message,
|
|
|
|
|
component_number,
|
|
|
|
|
6,
|
|
|
|
|
nodelete,
|
|
|
|
|
source_deleted,
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
component_number += 1
|
|
|
|
|
self.add_item(TimeoutUserButton(self.message, self.moderation_message, component_number, 12, nodelete, source_deleted))
|
|
|
|
|
self.add_item(
|
|
|
|
|
TimeoutUserButton(
|
|
|
|
|
self.message,
|
|
|
|
|
self.moderation_message,
|
|
|
|
|
component_number,
|
|
|
|
|
12,
|
|
|
|
|
nodelete,
|
|
|
|
|
source_deleted,
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
component_number += 1
|
|
|
|
|
self.add_item(TimeoutUserButton(self.message, self.moderation_message, component_number, 24, nodelete, source_deleted))
|
|
|
|
|
self.add_item(
|
|
|
|
|
TimeoutUserButton(
|
|
|
|
|
self.message,
|
|
|
|
|
self.moderation_message,
|
|
|
|
|
component_number,
|
|
|
|
|
24,
|
|
|
|
|
nodelete,
|
|
|
|
|
source_deleted,
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
component_number += 1
|
|
|
|
|
if not nodelete:
|
|
|
|
|
self.add_item(DeleteMessageButton(self.message, self.moderation_message, component_number))
|
|
|
|
|
self.add_item(
|
|
|
|
|
DeleteMessageButton(
|
|
|
|
|
self.message, self.moderation_message, component_number
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
component_number += 1
|
|
|
|
|
if deleted_message:
|
|
|
|
|
self.add_item(KickUserButton(self.message, self.moderation_message, component_number))
|
|
|
|
|
|
|
|
|
|
self.add_item(
|
|
|
|
|
KickUserButton(self.message, self.moderation_message, component_number)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DeleteMessageButton(discord.ui.Button["ModerationAdminView"]):
|
|
|
|
@ -230,13 +290,18 @@ class DeleteMessageButton(discord.ui.Button["ModerationAdminView"]):
|
|
|
|
|
)
|
|
|
|
|
while isinstance(self.moderation_message, tuple):
|
|
|
|
|
self.moderation_message = self.moderation_message[0]
|
|
|
|
|
await self.moderation_message.edit(embed=Moderation.build_admin_warning_message(self.message, deleted_message=interaction.user.mention),
|
|
|
|
|
view=ModerationAdminView(self.message, self.moderation_message, nodelete=True))
|
|
|
|
|
|
|
|
|
|
await self.moderation_message.edit(
|
|
|
|
|
embed=Moderation.build_admin_warning_message(
|
|
|
|
|
self.message, deleted_message=interaction.user.mention
|
|
|
|
|
),
|
|
|
|
|
view=ModerationAdminView(
|
|
|
|
|
self.message, self.moderation_message, nodelete=True
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class KickUserButton(discord.ui.Button["ModerationAdminView"]):
|
|
|
|
|
def __init__(self, message, moderation_message, current_num ):
|
|
|
|
|
def __init__(self, message, moderation_message, current_num):
|
|
|
|
|
super().__init__(style=discord.ButtonStyle.danger, label="Kick User")
|
|
|
|
|
self.message = message
|
|
|
|
|
self.moderation_message = moderation_message
|
|
|
|
@ -245,7 +310,9 @@ class KickUserButton(discord.ui.Button["ModerationAdminView"]):
|
|
|
|
|
async def callback(self, interaction: discord.Interaction):
|
|
|
|
|
# Get the user and kick the user
|
|
|
|
|
try:
|
|
|
|
|
await self.message.author.kick(reason="You broke the server rules. Please rejoin and review the rules.")
|
|
|
|
|
await self.message.author.kick(
|
|
|
|
|
reason="You broke the server rules. Please rejoin and review the rules."
|
|
|
|
|
)
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
await interaction.response.send_message(
|
|
|
|
@ -254,13 +321,25 @@ class KickUserButton(discord.ui.Button["ModerationAdminView"]):
|
|
|
|
|
|
|
|
|
|
while isinstance(self.moderation_message, tuple):
|
|
|
|
|
self.moderation_message = self.moderation_message[0]
|
|
|
|
|
await self.moderation_message.edit(embed=Moderation.build_admin_moderated_message(self.message, self.moderation_message, user_kicked=interaction.user.mention)
|
|
|
|
|
, view=ModerationAdminView(self.message, self.moderation_message, nodelete=True, deleted_message=False))
|
|
|
|
|
|
|
|
|
|
await self.moderation_message.edit(
|
|
|
|
|
embed=Moderation.build_admin_moderated_message(
|
|
|
|
|
self.message,
|
|
|
|
|
self.moderation_message,
|
|
|
|
|
user_kicked=interaction.user.mention,
|
|
|
|
|
),
|
|
|
|
|
view=ModerationAdminView(
|
|
|
|
|
self.message,
|
|
|
|
|
self.moderation_message,
|
|
|
|
|
nodelete=True,
|
|
|
|
|
deleted_message=False,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TimeoutUserButton(discord.ui.Button["ModerationAdminView"]):
|
|
|
|
|
def __init__(self, message, moderation_message,current_num, hours, nodelete, source_deleted):
|
|
|
|
|
def __init__(
|
|
|
|
|
self, message, moderation_message, current_num, hours, nodelete, source_deleted
|
|
|
|
|
):
|
|
|
|
|
super().__init__(style=discord.ButtonStyle.danger, label=f"Timeout {hours}h")
|
|
|
|
|
self.message = message
|
|
|
|
|
self.moderation_message = moderation_message
|
|
|
|
@ -295,10 +374,28 @@ class TimeoutUserButton(discord.ui.Button["ModerationAdminView"]):
|
|
|
|
|
self.moderation_message = self.moderation_message[0]
|
|
|
|
|
|
|
|
|
|
if not self.source_deleted:
|
|
|
|
|
await self.moderation_message.edit(embed=Moderation.build_admin_warning_message(self.message, deleted_message=interaction.user.mention, timed_out=interaction.user.mention),
|
|
|
|
|
view=ModerationAdminView(self.message, self.moderation_message, nodelete=True))
|
|
|
|
|
await self.moderation_message.edit(
|
|
|
|
|
embed=Moderation.build_admin_warning_message(
|
|
|
|
|
self.message,
|
|
|
|
|
deleted_message=interaction.user.mention,
|
|
|
|
|
timed_out=interaction.user.mention,
|
|
|
|
|
),
|
|
|
|
|
view=ModerationAdminView(
|
|
|
|
|
self.message, self.moderation_message, nodelete=True
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
await self.moderation_message.edit(embed=Moderation.build_admin_moderated_message(self.message, self.moderation_message, timed_out=interaction.user.mention),
|
|
|
|
|
view=ModerationAdminView(self.message, self.moderation_message, nodelete=True, deleted_message=True, source_deleted=True))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await self.moderation_message.edit(
|
|
|
|
|
embed=Moderation.build_admin_moderated_message(
|
|
|
|
|
self.message,
|
|
|
|
|
self.moderation_message,
|
|
|
|
|
timed_out=interaction.user.mention,
|
|
|
|
|
),
|
|
|
|
|
view=ModerationAdminView(
|
|
|
|
|
self.message,
|
|
|
|
|
self.moderation_message,
|
|
|
|
|
nodelete=True,
|
|
|
|
|
deleted_message=True,
|
|
|
|
|
source_deleted=True,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|