Skip to content

Commit

Permalink
fix: try another method of tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonejt committed Sep 27, 2024
1 parent 1b7098d commit bdda0db
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 158 deletions.
30 changes: 12 additions & 18 deletions commands/dominator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Union
from loguru import logger as log
from sentry_sdk import start_transaction, trace as sentry_trace
from discord import (
ApplicationContext,
Bot,
Expand Down Expand Up @@ -60,16 +61,12 @@ async def message(
action: ACTION,
threshold: float,
) -> None:
if not ctx.author.guild_permissions.administrator:
await ctx.followup.send(
"you do not have permissions to configure notification settings"
)
return
await ctx.defer()
with start_transaction(name="/dominator message"):
await ctx.defer()

await self.configure_dominator(
ctx, MessageDominators, attribute, action, threshold
)
await self.configure_dominator(
ctx, MessageDominators, attribute, action, threshold
)

@base_dominator.command(description="configure member dominator")
@default_permissions(administrator=True)
Expand Down Expand Up @@ -105,17 +102,14 @@ async def member(
action: ACTION,
threshold: float,
) -> None:
if not ctx.author.guild_permissions.administrator:
await ctx.followup.send(
"you do not have permissions to configure notification settings"
)
return
await ctx.defer()
with start_transaction(name="/dominator member"):
await ctx.defer()

await self.configure_dominator(
ctx, MemberDominators, attribute, action, threshold
)
await self.configure_dominator(
ctx, MemberDominators, attribute, action, threshold
)

@sentry_trace
async def configure_dominator(
self,
ctx: ApplicationContext,
Expand Down
50 changes: 26 additions & 24 deletions commands/psycho_pass.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from loguru import logger as log
from sentry_sdk import start_transaction
from discord import (
ApplicationContext,
Bot,
Expand Down Expand Up @@ -26,27 +27,28 @@ def __init__(self, bot: Bot) -> None:
required=False,
)
async def psychopass(self, ctx: ApplicationContext, user: User) -> None:
log.debug("{} /psychopass user: @{}", ctx.guild_id, user)
await ctx.defer()
if user is not None:
log.info(
"@{} ({}) has requested the psycho-pass of @{} ({})",
ctx.user.name,
ctx.user.id,
user.name,
user.id,
)
psycho_pass = PsychoPasses.read(user.id)
await ctx.edit(embed=embed_psycho_pass(psycho_pass, ctx.user, user))
else:
log.info(
"@{} ({}) has requested the area stress level of {} ({})",
ctx.user.name,
ctx.user.id,
ctx.guild.name,
ctx.guild_id,
)
psycho_pass = CommmunityPsychoPasses.read(ctx.guild_id)
await ctx.edit(
embed=embed_community_psycho_pass(psycho_pass, ctx.user, ctx.guild)
)
with start_transaction(name="/psychopass"):
log.debug("{} /psychopass user: @{}", ctx.guild_id, user)
await ctx.defer()
if user is not None:
log.info(
"@{} ({}) has requested the psycho-pass of @{} ({})",
ctx.user.name,
ctx.user.id,
user.name,
user.id,
)
psycho_pass = PsychoPasses.read(user.id)
await ctx.edit(embed=embed_psycho_pass(psycho_pass, ctx.user, user))
else:
log.info(
"@{} ({}) has requested the area stress level of {} ({})",
ctx.user.name,
ctx.user.id,
ctx.guild.name,
ctx.guild_id,
)
psycho_pass = CommmunityPsychoPasses.read(ctx.guild_id)
await ctx.edit(
embed=embed_community_psycho_pass(psycho_pass, ctx.user, ctx.guild)
)
83 changes: 45 additions & 38 deletions commands/sibyl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Union
from loguru import logger as log
from sentry_sdk import start_transaction
from discord import (
Bot,
Cog,
Expand Down Expand Up @@ -38,44 +39,50 @@ async def sibyl(
log_channel: _TextChannel,
notify_target: Union[User, Role],
) -> None:
log.debug(
"{} /sibyl log_channel: #{} notify_role: @{}",
ctx.guild_id,
log_channel,
notify_target,
)
await ctx.respond(f"sibyl pong! response time: {int(ctx.bot.latency * 1000)}ms")

if log_channel is None and notify_target is None:
return
if not ctx.author.guild_permissions.administrator:
await ctx.followup.send(
"you do not have permissions to configure notification settings"
)
return

if notify_target is not None:
Communities.update(
{"communityID": ctx.guild_id, "discord_notify_target": notify_target.id}
)
discord_notify_target = int(
Communities.read(ctx.guild_id)["discord_notify_target"]
)
target = ctx.guild.get_member(discord_notify_target) or ctx.guild.get_role(
discord_notify_target
with start_transaction(name="/sibyl"):
log.debug(
"{} /sibyl log_channel: #{} notify_role: @{}",
ctx.guild_id,
log_channel,
notify_target,
)
await ctx.followup.send(
f"notification target has been updated to {target.mention}"
await ctx.respond(
f"sibyl pong! response time: {int(ctx.bot.latency * 1000)}ms"
)

if log_channel is not None:
Communities.update(
{"communityID": ctx.guild_id, "discord_log_channel": log_channel.id}
)
discord_log_channel = int(
Communities.read(ctx.guild_id)["discord_log_channel"]
)
channel = ctx.guild.get_channel(discord_log_channel)
await ctx.followup.send(
f"log channel has been updated to {channel.mention}"
)
if log_channel is None and notify_target is None:
return
if not ctx.author.guild_permissions.administrator:
await ctx.followup.send(
"you do not have permissions to configure notification settings"
)
return

if notify_target is not None:
Communities.update(
{
"communityID": ctx.guild_id,
"discord_notify_target": notify_target.id,
}
)
discord_notify_target = int(
Communities.read(ctx.guild_id)["discord_notify_target"]
)
target = ctx.guild.get_member(
discord_notify_target
) or ctx.guild.get_role(discord_notify_target)
await ctx.followup.send(
f"notification target has been updated to {target.mention}"
)

if log_channel is not None:
Communities.update(
{"communityID": ctx.guild_id, "discord_log_channel": log_channel.id}
)
discord_log_channel = int(
Communities.read(ctx.guild_id)["discord_log_channel"]
)
channel = ctx.guild.get_channel(discord_log_channel)
await ctx.followup.send(
f"log channel has been updated to {channel.mention}"
)
33 changes: 19 additions & 14 deletions events/guild.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from loguru import logger as log
from sentry_sdk import start_transaction
from discord import Bot, Cog, Guild, Activity, ActivityType


Expand All @@ -9,20 +10,24 @@ def __init__(self, bot: Bot) -> None:

@Cog.listener()
async def on_guild_join(self, guild: Guild) -> None:
activity = Activity(
name=f"{len(self.bot.guilds)} Classes", type=ActivityType.watching
)
await self.bot.change_presence(activity=activity)
log.info(
"sibyl-discord has been added to server: {} ({})", guild.name, guild.id
)
with start_transaction(name="on_guild_join"):
activity = Activity(
name=f"{len(self.bot.guilds)} Classes", type=ActivityType.watching
)
await self.bot.change_presence(activity=activity)
log.info(
"sibyl-discord has been added to server: {} ({})", guild.name, guild.id
)

@Cog.listener()
async def on_guild_remove(self, guild: Guild) -> None:
activity = Activity(
name=f"{len(self.bot.guilds)} Classes", type=ActivityType.watching
)
await self.bot.change_presence(activity=activity)
log.info(
"sibyl-discord has been removed from server: {} ({})", guild.name, guild.id
)
with start_transaction(name="on_guild_remove"):
activity = Activity(
name=f"{len(self.bot.guilds)} Classes", type=ActivityType.watching
)
await self.bot.change_presence(activity=activity)
log.info(
"sibyl-discord has been removed from server: {} ({})",
guild.name,
guild.id,
)
39 changes: 21 additions & 18 deletions events/member.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from loguru import logger as log
from sentry_sdk import start_transaction
from discord import Bot, Cog, Member
from clients.backend.psycho_pass.community_psycho_passes import CommmunityPsychoPasses
from events.moderation import moderate_member
Expand All @@ -11,26 +12,28 @@ def __init__(self, bot: Bot) -> None:

@Cog.listener()
async def on_member_join(self, member: Member) -> None:
log.info(
"@{} ({}) has joined server: {} ({})",
member.name,
member.id,
member.guild.name,
member.guild.id,
)
with start_transaction(name="on_member_join"):
log.info(
"@{} ({}) has joined server: {} ({})",
member.name,
member.id,
member.guild.name,
member.guild.id,
)

if not member.bot:
await moderate_member(member)
if not member.bot:
await moderate_member(member)

@Cog.listener()
async def on_member_remove(self, member: Member) -> None:
log.info(
"@{} ({}) has left server: {} ({})",
member.name,
member.id,
member.guild.name,
member.guild.id,
)
with start_transaction(name="on_member_remove"):
log.info(
"@{} ({}) has left server: {} ({})",
member.name,
member.id,
member.guild.name,
member.guild.id,
)

if not member.bot:
CommmunityPsychoPasses.update(member.guild.id, member.id)
if not member.bot:
CommmunityPsychoPasses.update(member.guild.id, member.id)
59 changes: 31 additions & 28 deletions events/message.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from loguru import logger as log
from sentry_sdk import start_transaction
from discord import Bot, Cog, Message
from events.moderation import moderate_message

Expand All @@ -10,34 +11,36 @@ def __init__(self, bot: Bot) -> None:

@Cog.listener()
async def on_message(self, message: Message) -> None:
if message.author.bot or message.channel.nsfw or not message:
return

log.info(
"`@{} ({}) has sent a new message in server: {} ({}) in channel: {} ({})",
message.author.name,
message.author.id,
message.guild.name,
message.guild.id,
message.channel.name,
message.channel.id,
)

await moderate_message(message)
with start_transaction(name="on_message"):
if message.author.bot or message.channel.nsfw or not message:
return

log.info(
"`@{} ({}) has sent a new message in server: {} ({}) in channel: {} ({})",
message.author.name,
message.author.id,
message.guild.name,
message.guild.id,
message.channel.name,
message.channel.id,
)

await moderate_message(message)

@Cog.listener()
async def on_message_edit(self, _before: Message, after: Message) -> None:
if after.author.bot or after.channel.nsfw or not after:
return

log.info(
"`@{} ({}) has edited a message in server: {} ({}) in channel: {} ({})",
after.author.name,
after.author.id,
after.guild.name,
after.guild.id,
after.channel.name,
after.channel.id,
)

await moderate_message(after)
with start_transaction(name="on_message_edit"):
if after.author.bot or after.channel.nsfw or not after:
return

log.info(
"`@{} ({}) has edited a message in server: {} ({}) in channel: {} ({})",
after.author.name,
after.author.id,
after.guild.name,
after.guild.id,
after.channel.name,
after.channel.id,
)

await moderate_message(after)
3 changes: 3 additions & 0 deletions events/moderation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime, UTC
from loguru import logger as log
from sentry_sdk import trace as sentry_trace
from discord import Member, Message
from clients.backend.ingest_message import ingest_message
from clients.backend.communities import Communities
Expand All @@ -11,6 +12,7 @@
from embeds.moderation import embed_message_moderation, embed_member_moderation


@sentry_trace
async def moderate_member(member: Member) -> None:
psycho_pass = PsychoPasses.read(member.id)
dominator = MemberDominators.read(member.guild.id)
Expand Down Expand Up @@ -77,6 +79,7 @@ async def moderate_member(member: Member) -> None:
)


@sentry_trace
async def moderate_message(message: Message) -> None:
analysis = analyze_comment(message.content)
dominator = MessageDominators.read(message.guild.id)
Expand Down
Loading

0 comments on commit bdda0db

Please sign in to comment.