Skip to content

Commit

Permalink
Add automod to IRC
Browse files Browse the repository at this point in the history
  • Loading branch information
ajax146 committed Jul 25, 2024
1 parent 706e676 commit 4f78110
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions techsupport_bot/commands/relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from bidict import bidict
from core import auxiliary, cogs
from discord.ext import commands
from functions import automod

if TYPE_CHECKING:
import bot
Expand Down Expand Up @@ -411,6 +412,36 @@ async def send_message_from_irc(self: Self, split_message: dict[str, str]) -> No
mentions = self.get_mentions(
message=split_message["content"], channel=discord_channel
)

config = self.bot.guild_configs[str(discord_channel.guild.id)]
if "automod" in config.get("enabled_extensions", []):
automod_actions = automod.run_only_string_checks(
config, split_message["content"]
)
automod_final = automod.process_automod_violations(automod_actions)
if automod_final and automod_final.delete_message:
embed = discord.Embed(title="IRC Automod")
embed.description = (
f"**Blocked message:** {split_message['content']}\n"
f"**Reason: ** {automod_final.violation_string}\n"
f"**Message sent by:** {split_message['username']} ({split_message['hostmask']})\n"

Check notice on line 427 in techsupport_bot/commands/relay.py

View check run for this annotation

codefactor.io / CodeFactor

techsupport_bot/commands/relay.py#L427

Line too long (103/100) (line-too-long)
f"**In channel:** {split_message['channel']}"
)
embed.color = discord.Color.red()
try:
alert_channel = discord_channel.guild.get_channel(
int(config.extensions.automod.alert_channel.value)
)
except TypeError:
alert_channel = None

if not alert_channel:
return

await alert_channel.send(embed=embed)

return

mentions_string = auxiliary.construct_mention_string(targets=mentions)

embed = self.generate_sent_message_embed(split_message=split_message)
Expand Down

0 comments on commit 4f78110

Please sign in to comment.