Skip to content

Commit

Permalink
feature branch version 3.20 (#67)
Browse files Browse the repository at this point in the history
* chore: change bot version

* fix: viewing voters for cleared suggestions (#70)

* feat: add cached counts route

* Feat/proxy (#71)

* Revert "chore: version 3.19 (#65)" (#69)

This reverts commit 222da50.

* feat: add support for proxy

* fix: git being dumb

* fix: misc
  • Loading branch information
Skelmis committed Jan 4, 2024
1 parent 5544cba commit 2b32680
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 10 deletions.
15 changes: 14 additions & 1 deletion suggestions/bot.py
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
32 changes: 32 additions & 0 deletions suggestions/cogs/view_voters_cog.py
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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}>")
Expand All @@ -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}>")
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion suggestions/locales/en_GB.json
Expand Up @@ -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."
}
5 changes: 4 additions & 1 deletion suggestions/main.py
Expand Up @@ -9,6 +9,7 @@
import textwrap
from traceback import format_exception

import aiohttp
import cooldowns
import disnake
from disnake import Locale
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion suggestions/state.py
Expand Up @@ -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
Expand Down Expand Up @@ -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,
)
Expand Down
24 changes: 18 additions & 6 deletions suggestions/zonis_routes.py
Expand Up @@ -37,6 +37,7 @@ def __init__(self, bot: SuggestionsBot):
"share_with_devs",
"refresh_premium",
"shared_guilds",
"cached_item_count",
)

async def start(self):
Expand Down Expand Up @@ -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

0 comments on commit 2b32680

Please sign in to comment.