Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add guild_count property #1743

Merged
merged 2 commits into from
Jan 3, 2025
Merged

feat: add guild_count property #1743

merged 2 commits into from
Jan 3, 2025

Conversation

AstreaTSS
Copy link
Member

Pull Request Type

  • Feature addition
  • Bugfix
  • Documentation update
  • Code refactor
  • Tests improvement
  • CI/CD pipeline enhancement
  • Other: [Replace with a description]

Description

This PR adds a guild_count property to both Client and ClientUser. It does exactly as you may expect - it gets the number of guilds the client is in. Compared to len(bot.guilds), this method avoids using cache lookups, which takes up a significant amount of time as the number of guilds a bot is in grows.

The debug extension has been modified to use this property too, although the websocket ready instance was left as-is (sans a comment) since that could result in differing behavior - there are cases where len(bot.guilds) is not bot.guild_count, most notably if the guild is not in the cache. For normal users, though, this difference likely doesn't matter.

Changes

  • Added bot.guild_count.
  • Added bot.user.guild_count.
  • Make the debug extension use guild_count.
  • Add a TODO to potentially make the websocket ready code use this new property, if only after extensive testing.

Related Issues

N/A

Test Scenarios

import interactions as ipy

@ipy.slash_command()
async def test(ctx: ipy.SlashContext):
    await ctx.send(ctx.bot.guild_count)

Python Compatibility

A variant of this code has been working for over a year for the Realms Playerlist Bot.

  • I've ensured my code works on Python 3.10.x
  • I've ensured my code works on Python 3.11.x

Checklist

  • I've run the pre-commit code linter over all edited files
  • I've tested my changes on supported Python versions
  • I've added tests for my code, if applicable
  • I've updated / added documentation, where applicable

Signed-off-by: Astrea <25420078+AstreaTSS@users.noreply.github.com>
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.

Project coverage is 46.48%. Comparing base (bd900d9) to head (d9550f2).
Report is 4 commits behind head on unstable.

Files with missing lines Patch % Lines
interactions/ext/debug_extension/__init__.py 0.00% 1 Missing ⚠️
interactions/models/discord/user.py 66.66% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #1743      +/-   ##
============================================
+ Coverage     46.44%   46.48%   +0.04%     
============================================
  Files           149      149              
  Lines         16182    16193      +11     
============================================
+ Hits           7515     7528      +13     
+ Misses         8667     8665       -2     
Flag Coverage Δ
?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@silasary silasary merged commit dea3c79 into unstable Jan 3, 2025
9 of 12 checks passed
@silasary silasary deleted the guild-count branch January 3, 2025 02:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants