From e3c40818ad5e84a5dab630e22eeaf486f99e083c Mon Sep 17 00:00:00 2001 From: skelmis Date: Sun, 17 Dec 2023 16:34:13 +1300 Subject: [PATCH 1/6] chore: change bot version --- suggestions/bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/suggestions/bot.py b/suggestions/bot.py index 6ec89c5..0c814d9 100644 --- a/suggestions/bot.py +++ b/suggestions/bot.py @@ -46,7 +46,7 @@ class SuggestionsBot(commands.AutoShardedInteractionBot, BotBase): def __init__(self, *args, **kwargs): - self.version: str = "Public Release 3.19" + self.version: str = "Public Release 3.20" self.main_guild_id: int = 601219766258106399 self.legacy_beta_role_id: int = 995588041991274547 self.automated_beta_role_id: int = 998173237282361425 From 2c24a1bcc80b56f0db32704fb4b3fbc0e9429b29 Mon Sep 17 00:00:00 2001 From: Ethan <47520067+Skelmis@users.noreply.github.com> Date: Thu, 4 Jan 2024 15:54:18 +1300 Subject: [PATCH 2/6] fix: viewing voters for cleared suggestions (#70) --- suggestions/cogs/view_voters_cog.py | 32 +++++++++++++++++++++++++++++ suggestions/locales/en_GB.json | 3 ++- suggestions/state.py | 3 ++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/suggestions/cogs/view_voters_cog.py b/suggestions/cogs/view_voters_cog.py index a184030..36b970b 100644 --- a/suggestions/cogs/view_voters_cog.py +++ b/suggestions/cogs/view_voters_cog.py @@ -12,6 +12,7 @@ from suggestions import Colors from suggestions.cooldown_bucket import InteractionBucket from suggestions.objects import Suggestion +from suggestions.objects.suggestion import SuggestionState if TYPE_CHECKING: from alaric import Document @@ -109,6 +110,13 @@ async def view_suggestion_voters( channel_id=interaction.channel_id, state=self.state, ) + if suggestion.state == SuggestionState.cleared: + return await interaction.send( + self.bot.get_locale( + "VIEW_VOTERS_CLEARED_SUGGESTION", interaction.locale + ), + ephemeral=True, + ) up_vote: disnake.Emoji = await self.bot.suggestion_emojis.default_up_vote() down_vote: disnake.Emoji = await self.bot.suggestion_emojis.default_down_vote() @@ -140,6 +148,14 @@ async def view_suggestion_up_voters( channel_id=interaction.channel_id, state=self.state, ) + if suggestion.state == SuggestionState.cleared: + return await interaction.send( + self.bot.get_locale( + "VIEW_VOTERS_CLEARED_SUGGESTION", interaction.locale + ), + ephemeral=True, + ) + data = [] for voter in suggestion.up_voted_by: data.append(f"<@{voter}>") @@ -165,6 +181,14 @@ async def view_suggestion_down_voters( channel_id=interaction.channel_id, state=self.state, ) + if suggestion.state == SuggestionState.cleared: + return await interaction.send( + self.bot.get_locale( + "VIEW_VOTERS_CLEARED_SUGGESTION", interaction.locale + ), + ephemeral=True, + ) + data = [] for voter in suggestion.down_voted_by: data.append(f"<@{voter}>") @@ -203,6 +227,14 @@ async def view_voters( guild_id=interaction.guild_id, state=self.state, ) + if suggestion.state == SuggestionState.cleared: + return await interaction.send( + self.bot.get_locale( + "VIEW_VOTERS_CLEARED_SUGGESTION", interaction.locale + ), + ephemeral=True, + ) + data = [] up_vote: disnake.Emoji = await self.bot.suggestion_emojis.default_up_vote() down_vote: disnake.Emoji = await self.bot.suggestion_emojis.default_down_vote() diff --git a/suggestions/locales/en_GB.json b/suggestions/locales/en_GB.json index 4d3cbc5..401c717 100644 --- a/suggestions/locales/en_GB.json +++ b/suggestions/locales/en_GB.json @@ -121,5 +121,6 @@ "SUGGESTION_ID_NAME": "suggestion_id", "SUGGESTION_ID_DESCRIPTION": "The suggestions ID you wish to reference.", "USER_ID_NAME": "user_id", - "USER_ID_DESCRIPTION": "The users discord id." + "USER_ID_DESCRIPTION": "The users discord id.", + "VIEW_VOTERS_CLEARED_SUGGESTION": "Cannot view a cleared suggestion." } diff --git a/suggestions/state.py b/suggestions/state.py index 8de4b46..befaa6a 100644 --- a/suggestions/state.py +++ b/suggestions/state.py @@ -12,6 +12,7 @@ from alaric import AQ from alaric.comparison import EQ from alaric.logical import AND +from alaric.meta import Negate from alaric.projections import PROJECTION, SHOW from bot_base import NonExistentEntry from bot_base.caches import TimedCache @@ -166,7 +167,7 @@ async def populate_sid_cache(self, guild_id: int) -> list: async def populate_view_voters_cache(self, guild_id: int) -> list: self.view_voters_cache.delete_entry(guild_id) data: List[Dict] = await self.database.suggestions.find_many( - AQ(EQ("guild_id", guild_id)), + AQ(AND(EQ("guild_id", guild_id), Negate(EQ("state", "cleared")))), projections=PROJECTION(SHOW("_id")), try_convert=False, ) From 43b5ee7ae8e512514564ab9d0ad202d7dc7af522 Mon Sep 17 00:00:00 2001 From: skelmis Date: Thu, 4 Jan 2024 16:22:47 +1300 Subject: [PATCH 3/6] feat: add cached counts route --- suggestions/zonis_routes.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/suggestions/zonis_routes.py b/suggestions/zonis_routes.py index 12d4f5f..5e9b284 100644 --- a/suggestions/zonis_routes.py +++ b/suggestions/zonis_routes.py @@ -37,6 +37,7 @@ def __init__(self, bot: SuggestionsBot): "share_with_devs", "refresh_premium", "shared_guilds", + "cached_item_count", ) async def start(self): @@ -79,3 +80,23 @@ async def share_with_devs(self, title, description, sender): ) embed.set_footer(text=f"Sender: {sender}") await channel.send(embed=embed) + + @client.route() + async def cached_item_count(self) -> dict[str, int]: + state = self.bot.state + stats = self.bot.stats + suggestions_queue_cog = self.bot.get_cog("SuggestionsQueueCog") + data = { + "state.autocomplete_cache": len(state.autocomplete_cache), + "state.guild_cache": len(state.guild_cache), + "state.view_voters_cache": len(state.view_voters_cache), + "state.guild_configs": len(state.guild_configs), + "state.user_configs": len(state.user_configs), + "stats.cluster_guild_cache": len(stats.cluster_guild_cache), + "stats.member_stats_cache": len(stats.member_stats_cache), + "suggestions_queue_cog.paginator_objects": len( + suggestions_queue_cog.paginator_objects # noqa + ), + } + + return data From 36be588d7b8c74d64df76a39f6f822855ed85c4a Mon Sep 17 00:00:00 2001 From: Ethan <47520067+Skelmis@users.noreply.github.com> Date: Thu, 4 Jan 2024 17:45:15 +1300 Subject: [PATCH 4/6] Feat/proxy (#71) * Revert "chore: version 3.19 (#65)" (#69) This reverts commit 222da50e8b43207a1c646651953854c4f2bd9772. * feat: add support for proxy --- suggestions/bot.py | 15 ++++++++++++++- suggestions/cogs/help_guild_cog.py | 22 ++++++---------------- suggestions/main.py | 2 +- suggestions/zonis_routes.py | 25 ++++++------------------- 4 files changed, 27 insertions(+), 37 deletions(-) diff --git a/suggestions/bot.py b/suggestions/bot.py index 0c814d9..347f075 100644 --- a/suggestions/bot.py +++ b/suggestions/bot.py @@ -46,7 +46,7 @@ class SuggestionsBot(commands.AutoShardedInteractionBot, BotBase): def __init__(self, *args, **kwargs): - self.version: str = "Public Release 3.20" + self.version: str = "Public Release 3.19" self.main_guild_id: int = 601219766258106399 self.legacy_beta_role_id: int = 995588041991274547 self.automated_beta_role_id: int = 998173237282361425 @@ -110,6 +110,19 @@ def __init__(self, *args, **kwargs): self.zonis: ZonisRoutes = ZonisRoutes(self) + async def launch_shard( + self, _gateway: str, shard_id: int, *, initial: bool = False + ) -> None: + # Use the proxy if set, else fall back to whatever is default + proxy: Optional[str] = os.environ.get("GW_PROXY", _gateway) + return await super().launch_shard(proxy, shard_id, initial=initial) + + async def before_identify_hook( + self, _shard_id: int | None, *, initial: bool = False # noqa: ARG002 + ) -> None: + # gateway-proxy + return + async def get_or_fetch_channel(self, channel_id: int) -> WrappedChannel: try: return await super().get_or_fetch_channel(channel_id) diff --git a/suggestions/cogs/help_guild_cog.py b/suggestions/cogs/help_guild_cog.py index 55f210e..4b1d602 100644 --- a/suggestions/cogs/help_guild_cog.py +++ b/suggestions/cogs/help_guild_cog.py @@ -76,26 +76,16 @@ async def instance_info( shard_id = self.bot.get_shard_id(guild_id) cluster_id = ( 1 - if shard_id < 5 - else 2 if shard_id < 10 - else 3 - if shard_id < 15 - else 4 + else 2 if shard_id < 20 - else 5 - if shard_id < 25 - else 6 + else 3 if shard_id < 30 - else 7 - if shard_id < 35 - else 8 + else 4 if shard_id < 40 - else 9 - if shard_id < 45 - else 10 + else 5 if shard_id < 50 - else 11 + else 6 ) await interaction.send( @@ -164,7 +154,7 @@ async def show_bot_status( title="Bot infrastructure status", ) down_shards: list[str] = [str(i) for i in range(53)] - down_clusters: list[str] = [str(i) for i in range(1, 12)] + down_clusters: list[str] = [str(i) for i in range(1, 7)] avg_bot_latency: list[float] = [] async with aiohttp.ClientSession( headers={"X-API-KEY": os.environ["GARVEN_API_KEY"]} diff --git a/suggestions/main.py b/suggestions/main.py index 602c79c..f1d6074 100644 --- a/suggestions/main.py +++ b/suggestions/main.py @@ -29,7 +29,7 @@ async def create_bot(database_wrapper=None) -> SuggestionsBot: total_shards = 53 cluster_id = int(os.environ["CLUSTER"]) offset = cluster_id - 1 - number_of_shards_per_cluster = 5 + number_of_shards_per_cluster = 10 shard_ids = [ i for i in range( diff --git a/suggestions/zonis_routes.py b/suggestions/zonis_routes.py index 5e9b284..f2bd73c 100644 --- a/suggestions/zonis_routes.py +++ b/suggestions/zonis_routes.py @@ -37,7 +37,6 @@ def __init__(self, bot: SuggestionsBot): "share_with_devs", "refresh_premium", "shared_guilds", - "cached_item_count", ) async def start(self): @@ -81,22 +80,10 @@ async def share_with_devs(self, title, description, sender): embed.set_footer(text=f"Sender: {sender}") await channel.send(embed=embed) - @client.route() - async def cached_item_count(self) -> dict[str, int]: - state = self.bot.state - stats = self.bot.stats - suggestions_queue_cog = self.bot.get_cog("SuggestionsQueueCog") - data = { - "state.autocomplete_cache": len(state.autocomplete_cache), - "state.guild_cache": len(state.guild_cache), - "state.view_voters_cache": len(state.view_voters_cache), - "state.guild_configs": len(state.guild_configs), - "state.user_configs": len(state.user_configs), - "stats.cluster_guild_cache": len(stats.cluster_guild_cache), - "stats.member_stats_cache": len(stats.member_stats_cache), - "suggestions_queue_cog.paginator_objects": len( - suggestions_queue_cog.paginator_objects # noqa - ), - } + async def refresh_premium(self, user_id: int): + # TODO Implement the ability to refresh premium states for a user + return True - return data + @client.route() + async def shared_guilds(self, guild_ids: list[int]): + return [gid for gid in guild_ids if gid in self.bot.guild_ids] From 470a0e9d5ebd87497c840e9acffc315421c45eb3 Mon Sep 17 00:00:00 2001 From: skelmis Date: Thu, 4 Jan 2024 17:46:44 +1300 Subject: [PATCH 5/6] fix: git being dumb --- suggestions/zonis_routes.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/suggestions/zonis_routes.py b/suggestions/zonis_routes.py index 5cbf873..5e9b284 100644 --- a/suggestions/zonis_routes.py +++ b/suggestions/zonis_routes.py @@ -37,6 +37,7 @@ def __init__(self, bot: SuggestionsBot): "share_with_devs", "refresh_premium", "shared_guilds", + "cached_item_count", ) async def start(self): @@ -81,10 +82,21 @@ async def share_with_devs(self, title, description, sender): await channel.send(embed=embed) @client.route() - async def refresh_premium(self, user_id: int): - # TODO Implement the ability to refresh premium states for a user - return True + async def cached_item_count(self) -> dict[str, int]: + state = self.bot.state + stats = self.bot.stats + suggestions_queue_cog = self.bot.get_cog("SuggestionsQueueCog") + data = { + "state.autocomplete_cache": len(state.autocomplete_cache), + "state.guild_cache": len(state.guild_cache), + "state.view_voters_cache": len(state.view_voters_cache), + "state.guild_configs": len(state.guild_configs), + "state.user_configs": len(state.user_configs), + "stats.cluster_guild_cache": len(stats.cluster_guild_cache), + "stats.member_stats_cache": len(stats.member_stats_cache), + "suggestions_queue_cog.paginator_objects": len( + suggestions_queue_cog.paginator_objects # noqa + ), + } - @client.route() - async def shared_guilds(self, guild_ids: list[int]): - return [gid for gid in guild_ids if gid in self.bot.guild_ids] + return data From 0d3264a7b011caf328c1e519fa2c7177a797ab7e Mon Sep 17 00:00:00 2001 From: skelmis Date: Thu, 4 Jan 2024 17:52:41 +1300 Subject: [PATCH 6/6] fix: misc --- suggestions/bot.py | 2 +- suggestions/main.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/suggestions/bot.py b/suggestions/bot.py index 396d9fa..329f260 100644 --- a/suggestions/bot.py +++ b/suggestions/bot.py @@ -46,7 +46,7 @@ class SuggestionsBot(commands.AutoShardedInteractionBot, BotBase): def __init__(self, *args, **kwargs): - self.version: str = "Public Release 3.18" + self.version: str = "Public Release 3.20" self.main_guild_id: int = 601219766258106399 self.legacy_beta_role_id: int = 995588041991274547 self.automated_beta_role_id: int = 998173237282361425 diff --git a/suggestions/main.py b/suggestions/main.py index f1d6074..f314eb4 100644 --- a/suggestions/main.py +++ b/suggestions/main.py @@ -9,6 +9,7 @@ import textwrap from traceback import format_exception +import aiohttp import cooldowns import disnake from disnake import Locale @@ -26,7 +27,9 @@ async def create_bot(database_wrapper=None) -> SuggestionsBot: is_prod: bool = True if os.environ.get("PROD", None) else False if is_prod: - total_shards = 53 + async with aiohttp.ClientSession() as session: + async with session.get("http://localhost:7878/shard-count") as resp: + total_shards = int(await resp.text()) cluster_id = int(os.environ["CLUSTER"]) offset = cluster_id - 1 number_of_shards_per_cluster = 10