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 possibility to start bot via async context manager #1801

Merged

Conversation

Snawe
Copy link
Contributor

@Snawe Snawe commented Nov 26, 2022

Summary

This is a feature pull request. It allowes you to start the bot via an async context manager.

Till now you were able to subclass Bot with something like

class MyBot(commands.Bot):
    def __init__(self, **kwargs: Any):
        super().__init__(
            **kwargs,
        )
        [...]

MyBot().run("token")

Now you can also start the bot via an async context manager

async with MyBot(**kwargs) as bot:
    await bot.start("token")

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.

@Snawe Snawe requested a review from a team as a code owner November 26, 2022 08:01
@Lulalaby
Copy link
Member

Thanks for the pull request!
We'll look into it by time.

@Lulalaby Lulalaby force-pushed the feat/add_async_context_manager branch from 999c22f to 1b03207 Compare November 27, 2022 19:39
@Snawe
Copy link
Contributor Author

Snawe commented Dec 5, 2022

If you need something, leme know ;)

@codecov
Copy link

codecov bot commented Jan 5, 2023

Codecov Report

Merging #1801 (8df12fc) into master (f553fde) will decrease coverage by 0.01%.
The diff coverage is 27.27%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1801      +/-   ##
==========================================
- Coverage   33.32%   33.32%   -0.01%     
==========================================
  Files          97       97              
  Lines       18916    18927      +11     
==========================================
+ Hits         6304     6307       +3     
- Misses      12612    12620       +8     
Flag Coverage Δ
macos-latest-3.10 33.30% <27.27%> (-0.01%) ⬇️
macos-latest-3.11 33.30% <27.27%> (-0.01%) ⬇️
macos-latest-3.8 33.31% <27.27%> (-0.01%) ⬇️
macos-latest-3.9 33.31% <27.27%> (-0.01%) ⬇️
ubuntu-latest-3.10 33.30% <27.27%> (-0.01%) ⬇️
ubuntu-latest-3.11 33.30% <27.27%> (-0.01%) ⬇️
ubuntu-latest-3.8 33.31% <27.27%> (-0.01%) ⬇️
ubuntu-latest-3.9 33.31% <27.27%> (-0.01%) ⬇️
windows-latest-3.10 33.30% <27.27%> (-0.01%) ⬇️
windows-latest-3.11 33.30% <27.27%> (-0.01%) ⬇️
windows-latest-3.8 33.31% <27.27%> (-0.01%) ⬇️
windows-latest-3.9 33.31% <27.27%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
discord/client.py 27.23% <27.27%> (+<0.01%) ⬆️

Continue to review full report in Codecov by Sentry.

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

Copy link
Member

@JustaSqu1d JustaSqu1d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please resolve merge conflicts.

@JustaSqu1d JustaSqu1d added status: in progress Work in Progess feature Implements a feature labels Jan 9, 2023
@Snawe
Copy link
Contributor Author

Snawe commented Jan 14, 2023

I did a rebase on master... but there were no conflicts. Not sure what you meant.

@Snawe
Copy link
Contributor Author

Snawe commented Jan 14, 2023

Also, since this feature is done, it would be nice if you could remove the "in progress" label again ;)

@VincentRPS VincentRPS added status: awaiting review Awaiting review from a maintainer and removed status: in progress Work in Progess labels Jan 14, 2023
discord/client.py Outdated Show resolved Hide resolved
@Snawe
Copy link
Contributor Author

Snawe commented Jan 25, 2023

Any chance getting this merged? ;)

@AquaQuokka

This comment was marked as abuse.

Copy link
Member

@BobDotCom BobDotCom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a changelog entry for this

@Dorukyum
Copy link
Member

Dorukyum commented Mar 9, 2023

Could this be shown in the docs / basic examples?

@Snawe Snawe force-pushed the feat/add_async_context_manager branch from 2f43a9c to a96dcbe Compare April 2, 2023 09:58
@Snawe
Copy link
Contributor Author

Snawe commented Apr 2, 2023

@BobDotCom changelog added
@Dorukyum basic example added

@Lulalaby Lulalaby dismissed stale reviews from BobDotCom and VincentRPS April 3, 2023 11:08

resolved

examples/basic_async_bot.py Outdated Show resolved Hide resolved
@Snawe Snawe force-pushed the feat/add_async_context_manager branch from e7e5f0c to a4b537d Compare April 7, 2023 11:16
Add basic example to start the bot with an async context manager.
The example contains a `/hello` slash command which responds with a
"Hellp @author".
@Snawe Snawe force-pushed the feat/add_async_context_manager branch from 9ee2b4f to 2f7680f Compare April 7, 2023 11:18
JustaSqu1d
JustaSqu1d previously approved these changes Apr 7, 2023
Lulalaby
Lulalaby previously approved these changes Apr 18, 2023
Signed-off-by: Lala Sabathil <lala@pycord.dev>
@Lulalaby Lulalaby merged commit 8a913c3 into Pycord-Development:master Apr 18, 2023
28 checks passed
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

8 participants