diff --git a/modules/discord/services/base_service.py b/modules/discord/services/base_service.py index a896188..5322097 100644 --- a/modules/discord/services/base_service.py +++ b/modules/discord/services/base_service.py @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/modules/discord/services/live_activity.py b/modules/discord/services/live_activity.py index a19e8cb..604f878 100644 --- a/modules/discord/services/live_activity.py +++ b/modules/discord/services/live_activity.py @@ -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...") @@ -88,9 +90,16 @@ 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...") @@ -98,6 +107,7 @@ async def on_ready(self): 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 @@ -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 diff --git a/modules/errors.py b/modules/errors.py index cae9eef..5f7e385 100644 --- a/modules/errors.py +++ b/modules/errors.py @@ -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