Skip to content

Commit

Permalink
- Fix boolean determining if live activity service should run (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
nwithan8 authored Apr 9, 2024
1 parent 225e1bf commit ab9db79
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
7 changes: 4 additions & 3 deletions modules/discord/services/base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import modules.logs as logging
from modules.discord import discord_utils
from modules.errors import TauticordDiscordCollectionFailure
from modules.utils import quote


Expand Down Expand Up @@ -56,7 +57,7 @@ async def collect_discord_voice_category(self,
category_name=category_name)

if not category:
raise Exception(f"Could not load {quote(category_name)} voice category. Exiting...")
raise TauticordDiscordCollectionFailure(f"Could not load {quote(category_name)} voice category. Exiting...")

logging.debug(f"{quote(category_name)} voice category collected.")
return category
Expand All @@ -74,7 +75,7 @@ async def collect_discord_text_channel(self,
channel_type=discord.ChannelType.text)

if not channel:
raise Exception(f"Could not load {quote(channel_name)} text channel. Exiting...")
raise TauticordDiscordCollectionFailure(f"Could not load {quote(channel_name)} text channel. Exiting...")

logging.debug(f"{quote(channel_name)} text channel collected.")
return channel
Expand All @@ -92,7 +93,7 @@ async def collect_discord_voice_channel(self,
channel_type=discord.ChannelType.voice)

if not channel:
raise Exception(f"Could not load {quote(channel_name)} voice channel. Exiting...")
raise TauticordDiscordCollectionFailure(f"Could not load {quote(channel_name)} voice channel. Exiting...")

logging.debug(f"{quote(channel_name)} voice channel collected.")
return channel
21 changes: 13 additions & 8 deletions modules/discord/services/live_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ async def associate_bot_callbacks(self):
self.on_raw_reaction_add = self.bot.event(self.on_raw_reaction_add)

async def enabled(self) -> bool:
return self.stats_settings.activity.enable
# Enable if voice channel activity stats are enabled and/or if the summary message is enabled
return self.stats_settings.activity.enable or self.use_summary_message

async def on_ready(self):
logging.info("Loading Tautulli summary service...")

# Prepare the summary message to be used for activity stats if enabled
summary_message = None
if self.use_summary_message:
logging.info("Loading Tautulli text channel settings...")
Expand Down Expand Up @@ -88,16 +90,24 @@ async def on_ready(self):
summary_message = await discord_utils.send_embed_message(embed=embed,
channel=self.tautulli_summary_channel)

if not summary_message:
raise TauticordSetupFailure("Could not prepare activity summary message")
if not summary_message:
raise TauticordSetupFailure("Could not prepare activity summary message")

# Start the version checking service if enabled (to add to the summary message)
if self.version_checker and self.version_checker.enable:
logging.info("Starting version checking service...")
# noinspection PyAsyncCall
asyncio.create_task(self.version_checker.monitor_for_new_version())

# Prepare the voice category for activity stats if enabled
activity_stats_voice_category = None
if self.stats_settings.activity.enable:
logging.info("Loading Tautulli activity stats settings...")
activity_stats_voice_category = await self.collect_discord_voice_category(
guild_id=self.guild_id,
category_name=self.stats_settings.activity.category_name)

# Run the activity stats updater
# minimum 5-second sleep time hard-coded, trust me, don't DDoS your server
refresh_time = max([5, self.refresh_time])
# This handles both text channel updates AND activity stats voice channel updates
Expand All @@ -113,11 +123,6 @@ async def on_ready(self):
# noinspection PyAsyncCall
asyncio.create_task(self.activity_monitor.run_service(interval_seconds=refresh_time))

if self.version_checker and self.version_checker.enable:
logging.info("Starting version checking service...")
# noinspection PyAsyncCall
asyncio.create_task(self.version_checker.monitor_for_new_version())

async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent) -> None:
if not self.tautulli_summary_channel or not self.activity_monitor:
return
Expand Down
9 changes: 9 additions & 0 deletions modules/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ def __init__(self, message: str):
super().__init__(code=302, message=message)


class TauticordDiscordCollectionFailure(TauticordException):
"""
Raised when an error occurs during collecting a Discord object
"""

def __init__(self, message: str):
super().__init__(code=303, message=message)


def determine_exit_code(exception: Exception) -> int:
"""
Determine the exit code based on the exception that was thrown
Expand Down

0 comments on commit ab9db79

Please sign in to comment.