You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 29, 2022. It is now read-only.
General Concept:
The idea behind using a ContextManager with a HivenClient is to be able to quickly use the Client and interact with the Hiven-API without having to focus too much on Event-listening or running it correctly. Still, more that you start the bot, run code and then the bot will stop as soon as the code finished you wanted to execute.
This could be useful for small interactions and quick changes, mainly consisting of a few lines, which can be then quickly executed. To that, if a user just wants to await something with HivenClient.wait_for('on_message_create'), they could do that in a few lines and then immediately stop the bot with a nice and more concise syntax.
on_ready and on_init won't be usable with that syntax since __aenter__ only returns when the Client received the ready state.
Usage:
Standard:
asyncwithopenhivenpy.HivenClient(token="insert token") asclient:
# Only runs in this scope and will stop when the code finished executing
asyncdefon_message_create(msg):
print("Received message")
asyncwithopenhivenpy.HivenClient(token="insert token") asclient:
client.event(on_message_create) # Calling the decorator directly for wrapping and adding the function
Changes:
Implementing __aenter__ and __aexit__ which will run and stop the bot. __aenter__ will then need to return when the ready function was called running parallel to the websocket.
Adding token as a static parameter to the HivenClient, which will make it not needed to provide a token on HivenClient.run(), but directly on construction
General Concept:
The idea behind using a ContextManager with a HivenClient is to be able to quickly use the Client and interact with the Hiven-API without having to focus too much on Event-listening or running it correctly. Still, more that you start the bot, run code and then the bot will stop as soon as the code finished you wanted to execute.
This could be useful for small interactions and quick changes, mainly consisting of a few lines, which can be then quickly executed. To that, if a user just wants to await something with
HivenClient.wait_for('on_message_create'), they could do that in a few lines and then immediately stop the bot with a nice and more concise syntax.on_readyandon_initwon't be usable with that syntax since__aenter__only returns when the Client received the ready state.Usage:
Changes:
__aenter__and__aexit__which will run and stop the bot.__aenter__will then need to return when the ready function was called running parallel to the websocket.tokenas a static parameter to the HivenClient, which will make it not needed to provide a token onHivenClient.run(), but directly on construction