|
|
|
@ -12,13 +12,14 @@ from models.usage_service_model import UsageService
|
|
|
|
|
usage_service = UsageService(Path(os.environ.get("DATA_DIR", os.getcwd())))
|
|
|
|
|
model = Model(usage_service)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ModerationResult:
|
|
|
|
|
WARN = "warn"
|
|
|
|
|
DELETE = "delete"
|
|
|
|
|
NONE = "none"
|
|
|
|
|
|
|
|
|
|
class ThresholdSet:
|
|
|
|
|
|
|
|
|
|
class ThresholdSet:
|
|
|
|
|
def __init__(self, h_t, hv_t, sh_t, s_t, sm_t, v_t, vg_t):
|
|
|
|
|
self.keys = [
|
|
|
|
|
"hate",
|
|
|
|
@ -27,7 +28,7 @@ class ThresholdSet:
|
|
|
|
|
"sexual",
|
|
|
|
|
"sexual/minors",
|
|
|
|
|
"violence",
|
|
|
|
|
"violence/graphic"
|
|
|
|
|
"violence/graphic",
|
|
|
|
|
]
|
|
|
|
|
self.thresholds = [
|
|
|
|
|
h_t,
|
|
|
|
@ -70,7 +71,9 @@ class Moderation:
|
|
|
|
|
return embed
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def build_admin_warning_message(moderated_message, deleted_message=None, timed_out=None):
|
|
|
|
|
def build_admin_warning_message(
|
|
|
|
|
moderated_message, deleted_message=None, timed_out=None
|
|
|
|
|
):
|
|
|
|
|
embed = discord.Embed(
|
|
|
|
|
title="Potentially unwanted message in the "
|
|
|
|
|
+ moderated_message.guild.name
|
|
|
|
@ -81,12 +84,13 @@ class Moderation:
|
|
|
|
|
link = f"https://discord.com/channels/{moderated_message.guild.id}/{moderated_message.channel.id}/{moderated_message.id}"
|
|
|
|
|
embed.add_field(name="Message link", value=link, inline=False)
|
|
|
|
|
if deleted_message:
|
|
|
|
|
embed.add_field(name="Message deleted by: ", value=deleted_message, inline=False)
|
|
|
|
|
embed.add_field(
|
|
|
|
|
name="Message deleted by: ", value=deleted_message, inline=False
|
|
|
|
|
)
|
|
|
|
|
if timed_out:
|
|
|
|
|
embed.add_field(name="User timed out by: ", value=timed_out, inline=False)
|
|
|
|
|
return embed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def build_admin_moderated_message(moderated_message, response_message, user_kicked=None, timed_out=None):
|
|
|
|
|
direct_message_object = isinstance(moderated_message, discord.Message)
|
|
|
|
@ -125,8 +129,6 @@ class Moderation:
|
|
|
|
|
else:
|
|
|
|
|
return ModerationResult.NONE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# This function will be called by the bot to process the message queue
|
|
|
|
|
@staticmethod
|
|
|
|
|
async def process_moderation_queue(
|
|
|
|
@ -170,9 +172,15 @@ class Moderation:
|
|
|
|
|
|
|
|
|
|
elif moderation_result == ModerationResult.WARN:
|
|
|
|
|
response_message = await moderations_alert_channel.send(
|
|
|
|
|
embed=Moderation.build_admin_warning_message(to_moderate.message),
|
|
|
|
|
embed=Moderation.build_admin_warning_message(
|
|
|
|
|
to_moderate.message
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
await response_message.edit(
|
|
|
|
|
view=ModerationAdminView(
|
|
|
|
|
to_moderate.message, response_message
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
await response_message.edit(view=ModerationAdminView(to_moderate.message, response_message))
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
await moderation_queue.put(to_moderate)
|
|
|
|
@ -189,6 +197,7 @@ class ModerationAdminView(discord.ui.View):
|
|
|
|
|
super().__init__(timeout=None) # 1 hour interval to redo.
|
|
|
|
|
component_number = 0
|
|
|
|
|
self.message = message
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
self.moderation_message = moderation_message,
|
|
|
|
|
self.add_item(TimeoutUserButton(self.message, self.moderation_message, component_number, 1, nodelete, source_deleted))
|
|
|
|
|
component_number += 1
|
|
|
|
@ -203,6 +212,23 @@ class ModerationAdminView(discord.ui.View):
|
|
|
|
|
component_number += 1
|
|
|
|
|
if deleted_message:
|
|
|
|
|
self.add_item(KickUserButton(self.message, self.moderation_message, component_number))
|
|
|
|
|
=======
|
|
|
|
|
self.moderation_message = (moderation_message,)
|
|
|
|
|
if not nodelete:
|
|
|
|
|
self.add_item(DeleteMessageButton(self.message, self.moderation_message))
|
|
|
|
|
self.add_item(
|
|
|
|
|
TimeoutUserButton(self.message, self.moderation_message, 1, nodelete)
|
|
|
|
|
)
|
|
|
|
|
self.add_item(
|
|
|
|
|
TimeoutUserButton(self.message, self.moderation_message, 6, nodelete)
|
|
|
|
|
)
|
|
|
|
|
self.add_item(
|
|
|
|
|
TimeoutUserButton(self.message, self.moderation_message, 12, nodelete)
|
|
|
|
|
)
|
|
|
|
|
self.add_item(
|
|
|
|
|
TimeoutUserButton(self.message, self.moderation_message, 24, nodelete)
|
|
|
|
|
)
|
|
|
|
|
>>>>>>> db5e13a9cd12aa76f2e09dc7282c1cd6deb5a2b7
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DeleteMessageButton(discord.ui.Button["ModerationAdminView"]):
|
|
|
|
@ -219,10 +245,21 @@ class DeleteMessageButton(discord.ui.Button["ModerationAdminView"]):
|
|
|
|
|
await interaction.response.send_message(
|
|
|
|
|
"This message was deleted", ephemeral=True, delete_after=10
|
|
|
|
|
)
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
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[0].edit(
|
|
|
|
|
embed=Moderation.build_admin_warning_message(
|
|
|
|
|
self.message, deleted_message=interaction.user.mention
|
|
|
|
|
),
|
|
|
|
|
view=ModerationAdminView(
|
|
|
|
|
self.message, self.moderation_message, nodelete=True
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
>>>>>>> db5e13a9cd12aa76f2e09dc7282c1cd6deb5a2b7
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class KickUserButton(discord.ui.Button["ModerationAdminView"]):
|
|
|
|
@ -267,14 +304,35 @@ class TimeoutUserButton(discord.ui.Button["ModerationAdminView"]):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
await self.message.author.timeout(until = discord.utils.utcnow() + timedelta(hours=self.hours), reason="Breaking the server chat rules")
|
|
|
|
|
await self.message.author.timeout(
|
|
|
|
|
until=discord.utils.utcnow() + timedelta(hours=self.hours),
|
|
|
|
|
reason="Breaking the server chat rules",
|
|
|
|
|
)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
traceback.print_exc()
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
await interaction.response.send_message(
|
|
|
|
|
f"This user was timed out for {self.hours} hour(s)", ephemeral=True, delete_after=10
|
|
|
|
|
f"This user was timed out for {self.hours} hour(s)",
|
|
|
|
|
ephemeral=True,
|
|
|
|
|
delete_after=10,
|
|
|
|
|
)
|
|
|
|
|
moderation_message = (
|
|
|
|
|
self.moderation_message[0][0]
|
|
|
|
|
if self.nodelete
|
|
|
|
|
else self.moderation_message[0]
|
|
|
|
|
)
|
|
|
|
|
await 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
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
while isinstance(self.moderation_message, tuple):
|
|
|
|
|
self.moderation_message = self.moderation_message[0]
|
|
|
|
|
|
|
|
|
@ -285,3 +343,5 @@ class TimeoutUserButton(discord.ui.Button["ModerationAdminView"]):
|
|
|
|
|
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))
|
|
|
|
|
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> db5e13a9cd12aa76f2e09dc7282c1cd6deb5a2b7
|
|
|
|
|