Skip to content

Commit

Permalink
Feat/proxy (#71)
Browse files Browse the repository at this point in the history
* Revert "chore: version 3.19 (#65)" (#69)

This reverts commit 222da50.

* feat: add support for proxy
  • Loading branch information
Skelmis authored Jan 4, 2024
1 parent 169cc02 commit 36be588
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 37 deletions.
15 changes: 14 additions & 1 deletion suggestions/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
22 changes: 6 additions & 16 deletions suggestions/cogs/help_guild_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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"]}
Expand Down
2 changes: 1 addition & 1 deletion suggestions/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
25 changes: 6 additions & 19 deletions suggestions/zonis_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def __init__(self, bot: SuggestionsBot):
"share_with_devs",
"refresh_premium",
"shared_guilds",
"cached_item_count",
)

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

0 comments on commit 36be588

Please sign in to comment.