From 931fb3ea4a6eb767864b33df5bd17cfb48e1b919 Mon Sep 17 00:00:00 2001 From: Will Da Silva Date: Sun, 4 Oct 2020 22:44:49 -0400 Subject: Verify channel constants on startup Closes #393 --- bot/bot.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'bot/bot.py') diff --git a/bot/bot.py b/bot/bot.py index ffaf4284..92873ba4 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -45,7 +45,7 @@ class SeasonalBot(commands.Bot): connector=TCPConnector(resolver=AsyncResolver(), family=socket.AF_INET) ) self._guild_available = asyncio.Event() - + self.loop.create_task(self.check_channels()) self.loop.create_task(self.send_log("SeasonalBot", "Connected!")) @property @@ -149,6 +149,15 @@ class SeasonalBot(commands.Bot): log.info("Nickname set successfully") return True + async def check_channels(self) -> None: + await self.wait_until_guild_available() + all_channels = set(self.get_all_channels()) + for name, channel_id in vars(Channels).items(): + if name.startswith('_'): + continue + if channel_id not in all_channels: + log.error(f'Channel "{name}" with id {channel_id} missing') + async def send_log(self, title: str, details: str = None, *, icon: str = None) -> None: """Send an embed message to the devlog channel.""" await self.wait_until_guild_available() -- cgit v1.2.3 From b907c4cc6e943904e506ec49d3a28d98e9073625 Mon Sep 17 00:00:00 2001 From: Will Da Silva Date: Sun, 4 Oct 2020 22:47:16 -0400 Subject: Add docstring to check_channels --- bot/bot.py | 1 + 1 file changed, 1 insertion(+) (limited to 'bot/bot.py') diff --git a/bot/bot.py b/bot/bot.py index 92873ba4..c004414e 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -150,6 +150,7 @@ class SeasonalBot(commands.Bot): return True async def check_channels(self) -> None: + """Verifies that all channel constants refer to channels which exist.""" await self.wait_until_guild_available() all_channels = set(self.get_all_channels()) for name, channel_id in vars(Channels).items(): -- cgit v1.2.3 From 7bec6f4e9423d8e5a797a2a6e73cd235e0a5f0cf Mon Sep 17 00:00:00 2001 From: Will Da Silva Date: Sun, 4 Oct 2020 22:53:04 -0400 Subject: Capitalize "ID" in error message --- bot/bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/bot.py') diff --git a/bot/bot.py b/bot/bot.py index c004414e..b486201e 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -157,7 +157,7 @@ class SeasonalBot(commands.Bot): if name.startswith('_'): continue if channel_id not in all_channels: - log.error(f'Channel "{name}" with id {channel_id} missing') + log.error(f'Channel "{name}" with ID {channel_id} missing') async def send_log(self, title: str, details: str = None, *, icon: str = None) -> None: """Send an embed message to the devlog channel.""" -- cgit v1.2.3 From 53af90f92258905c2bfc4c2db2341dfd1fdc0124 Mon Sep 17 00:00:00 2001 From: xithrius Date: Sun, 24 Jan 2021 06:52:15 -0800 Subject: Fixed linting errors. --- bot/bot.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'bot/bot.py') diff --git a/bot/bot.py b/bot/bot.py index 112c9a48..81d59706 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -37,7 +37,6 @@ class Bot(commands.Bot): self.loop.create_task(self.check_channels()) self.loop.create_task(self.send_log(self.name, "Connected!")) - @property def member(self) -> Optional[discord.Member]: """Retrieves the guild member object for the bot.""" @@ -76,7 +75,7 @@ class Bot(commands.Bot): """Verifies that all channel constants refer to channels which exist.""" await self.wait_until_guild_available() all_channels = set(self.get_all_channels()) - for name, channel_id in vars(Channels).items(): + for name, channel_id in vars(constants.Channels).items(): if name.startswith('_'): continue if channel_id not in all_channels: -- cgit v1.2.3 From 167774ea84ec528845a17d41065983e3ef696d12 Mon Sep 17 00:00:00 2001 From: Shivansh-007 Date: Tue, 2 Mar 2021 15:51:56 +0530 Subject: Fix Channel Check to use channel ids instead of channel objects, and skip channel check if debug is true --- bot/bot.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'bot/bot.py') diff --git a/bot/bot.py b/bot/bot.py index 81d59706..176422aa 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -74,11 +74,16 @@ class Bot(commands.Bot): async def check_channels(self) -> None: """Verifies that all channel constants refer to channels which exist.""" await self.wait_until_guild_available() - all_channels = set(self.get_all_channels()) + + if constants.Client.debug: + log.info("Skipping Channels Check.") + return + + all_channels_ids = [channel.id for channel in set(self.get_all_channels())] for name, channel_id in vars(constants.Channels).items(): if name.startswith('_'): continue - if channel_id not in all_channels: + if channel_id not in all_channels_ids: log.error(f'Channel "{name}" with ID {channel_id} missing') async def send_log(self, title: str, details: str = None, *, icon: str = None) -> None: -- cgit v1.2.3 From 674838787fb1916dce98b50bae78159a54833c42 Mon Sep 17 00:00:00 2001 From: Shivansh-007 Date: Tue, 2 Mar 2021 16:00:24 +0530 Subject: Don't use sets --- bot/bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/bot.py') diff --git a/bot/bot.py b/bot/bot.py index 176422aa..e9750697 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -79,7 +79,7 @@ class Bot(commands.Bot): log.info("Skipping Channels Check.") return - all_channels_ids = [channel.id for channel in set(self.get_all_channels())] + all_channels_ids = [channel.id for channel in self.get_all_channels()] for name, channel_id in vars(constants.Channels).items(): if name.startswith('_'): continue -- cgit v1.2.3