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 once decorator to discord.Client #1940

Merged
merged 7 commits into from Feb 26, 2023

Conversation

OmLanke
Copy link
Contributor

@OmLanke OmLanke commented Feb 23, 2023

Summary

Adds a @client.once() decorator. Unlike @client.event or @client.listen(), functions decorated will run only once.
It wraps await client.wait_for(). Similar functionality is found in discord.js, as it extends Node's Event Emitter.

This is useful for having stuff run when the bot is ready for the first time, like database connections once ready and stuff.
(Side note - This can potentially be a race condition, as other events can start dispatching before db connects. Since there is no built in functionality to delay dispatching of ready until a function has returned, using the once decorator is the closest and simplest you can get)

Information

  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed).
  • This PR is not a code change (e.g. documentation, README, typehinting,
    examples, ...).

Checklist

  • I have searched the open pull requests for duplicates.
  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • If type: ignore comments were used, a comment is also left explaining why.

Signed-off-by: Om <92863779+Om1609@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Feb 24, 2023

Codecov Report

Merging #1940 (8f535fc) into master (2e09718) will decrease coverage by 0.03%.
The diff coverage is 6.25%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1940      +/-   ##
==========================================
- Coverage   33.36%   33.33%   -0.03%     
==========================================
  Files          97       97              
  Lines       18851    18867      +16     
==========================================
+ Hits         6289     6290       +1     
- Misses      12562    12577      +15     
Flag Coverage Δ
macos-latest-3.10 33.32% <6.25%> (-0.03%) ⬇️
macos-latest-3.11 33.32% <6.25%> (-0.03%) ⬇️
macos-latest-3.8 33.33% <6.25%> (-0.03%) ⬇️
macos-latest-3.9 33.33% <6.25%> (-0.03%) ⬇️
ubuntu-latest-3.10 33.32% <6.25%> (-0.03%) ⬇️
ubuntu-latest-3.11 33.32% <6.25%> (-0.03%) ⬇️
ubuntu-latest-3.8 33.33% <6.25%> (-0.03%) ⬇️
ubuntu-latest-3.9 33.33% <6.25%> (-0.03%) ⬇️
windows-latest-3.10 33.32% <6.25%> (-0.03%) ⬇️
windows-latest-3.11 33.32% <6.25%> (-0.03%) ⬇️
windows-latest-3.8 33.33% <6.25%> (-0.03%) ⬇️
windows-latest-3.9 33.33% <6.25%> (-0.03%) ⬇️

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

Impacted Files Coverage Δ
discord/client.py 27.05% <6.25%> (-0.68%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2e09718...8f535fc. Read the comment docs.

CHANGELOG.md Outdated Show resolved Hide resolved
OmLanke and others added 4 commits February 24, 2023 20:15
Co-authored-by: BobDotCom <71356958+BobDotCom@users.noreply.github.com>
Signed-off-by: Om <92863779+Om1609@users.noreply.github.com>
@Lulalaby Lulalaby enabled auto-merge (squash) February 24, 2023 15:44
@JustaSqu1d JustaSqu1d added the status: awaiting review Awaiting review from a maintainer label Feb 26, 2023
@Lulalaby Lulalaby merged commit 13dbcdd into Pycord-Development:master Feb 26, 2023
@OmLanke OmLanke mentioned this pull request Mar 3, 2023
9 tasks
@OmLanke OmLanke deleted the once-decorator branch March 12, 2023 14:04
@OmLanke OmLanke mentioned this pull request May 13, 2023
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Implements a feature status: awaiting review Awaiting review from a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants