Commit Graph

40 Commits

Author SHA1 Message Date
diamondburned c0a522a93e
session: Add OnInteractionError that logs by default 2023-01-01 18:01:08 +07:00
diamondburned 789afaa88f
session: Fix Connect->Open not handling ctx 2022-12-07 00:25:55 -08:00
Tyler Stuyfzand 769215970e
session: Introduce SendGateway (#356)
* Support SendGateway to help with voice usage

* Remove unnecessary Gateway interface function

* Add clarification comment

Co-authored-by: Tyler <admin@meow.tf>
2022-11-25 11:16:13 -08:00
diamondburned eb23d43cee
session: Connect to retry on non-fatal errors 2022-11-18 02:09:16 -08:00
diamondburned 1af71182d0
session: Add DontWaitForReady
This is a workaround for some cases where ReadyEvent cannot be delivered
successfully, e.g. in the case of an unmarshal failure.

We should handle BackgroundErrorEvents in the future that fatally exits
on any unmarshal errors.
2022-10-03 22:37:40 -07:00
diamondburned a14fcb893a
session: Fix Open not dying on ctx.Done 2022-10-03 22:10:20 -07:00
diamondburned 91b2c6c840
session: Add AddInteractionHandlerFunc
Also remove session.AddInteractionHandler (exported func).
2022-08-23 13:46:42 -07:00
diamondburned f00054bddf
webhook: Add session+state helpers 2022-08-22 02:18:54 -07:00
diamondburned d62c1169b5
session: Remove unused function initConnect 2022-08-22 01:08:24 -07:00
diamondburned 258b6149d7
session: Add Connect and Wait
This commit adds the Connect and Wait methods into session. This gives
the user a way to block the program until the session runs into an error
or the given ctx is done.

In most cases, Connect is useful when combined with
signal.NotifyContext, and so Connect is preferred over Open.
2022-08-14 16:11:40 -07:00
diamondburned 723aa0e4c3
session: Add Gateway{IsAlive,Error} methods
This commit adds the above 2 methods mostly for the user's convenience.

GatewayIsAlive will be useful when handling CloseError events and
determining if the session was fatal without needing to handle Open().

GatewayError builds upon GatewayIsAlive and returns an error. While the
user could call GatewayIsAlive and LastError themselves, doing so
without locking is technically racy if another thread wants to
reconnect.
2022-04-07 23:27:44 -07:00
diamondburned 54cadd2f45 gateway: Refactor for a better concurrent API
This commit refactors the whole package gateway as well as utils/ws
(formerly utils/wsutil) and voice/voicegateway. The new refactor
utilizes a design pattern involving a concurrent loop and an arriving
event channel.

An additional change was made to the way gateway events are typed.
Before, pretty much any type will satisfy a gateway event type, since
the actual type was just interface{}. The new refactor defines a
concrete interface that events can implement:

    type Event interface {
        Op() OpCode
        EventType() EventType
    }

Using this interface, the user can easily add custom gateway events
independently of the library without relying on string maps. This adds a
lot of type safety into the library and makes type-switching on Event
types much more reasonable.

Gateway error callbacks are also almost entirely removed in favor of
custom gateway events. A catch-all can easily be added like this:

    s.AddHandler(func(err error) {
        log.Println("gateway error:, err")
    })
2021-12-14 13:49:34 -08:00
diamondburned 7f4daccd2d
shard: Separate state's cabinet, fix return bugs
This commit makes it so that all sharded state.State instances will have
its own cabinet store on construction. This ensures that when a State is
reconnected, a Ready event won't wipe the cabinet for all other states.

This commit also fixes a bug with the Shard() and FromGuildID() getters.
2021-10-31 13:10:34 -07:00
diamondburned 5b328bdab0 shard: Remake shard manager (#226) 2021-06-14 15:22:55 -07:00
Samuel Hernandez 40e1a3757d *: Migrated Go Modules to v3 2021-06-01 19:59:01 -07:00
Maximilian von Lindern 8a7c6c48a7 session,bot: Remove references to CloseGracefully and use Close instead 2021-05-29 22:18:05 -07:00
diamondburned ac2f3ba68a Bot: Close gracefully by default 2021-01-29 23:25:15 -08:00
diamondburned 81b1a0a902 Session: Added a handleloop abstraction
This abstraction will mainly be in charge of handling events from a
channel and dispatching them to handlers in a thread safe manner. It
boxes synchronizing mechanisms inside a struct.
2020-11-17 12:15:05 -08:00
diamondburned 6cbe95d2b3 State: Fixed erroneous context setting and races in Ready 2020-11-14 15:30:18 -08:00
diamondburned 75df94d9f4 *: Migrated Go Modules to v2 2020-10-28 15:39:59 -07:00
diamondburned 86795e42a6 Session: Fixed a potential race condition on Close 2020-10-21 22:42:16 -07:00
mavolin ba4b224168 handler: move package from /handler to /utils/handler 2020-07-29 16:58:33 -07:00
diamondburned edb8a46ef2 Gateway: Added intent helpers and more context API support 2020-07-11 12:50:32 -07:00
diamondburned (Forefront) 16ed406c53 Session: Fixed a panic bug when the gateway fails 2020-06-29 11:00:07 -07:00
Maximilian von Lindern de3d0e2160
Gateway: Split GuildCreateEvent (#116)
* Session: fix event handler loop not getting properly closed

* Implement #113

* Session: move guild events to state

* Session: close hStop
2020-06-06 13:47:15 -07:00
mavolin 41ce1f389e
make all error messages lowercase 2020-05-16 23:14:49 +02:00
diamondburned (Forefront) 2afe683b7d Utils: Added HTTP drivers 2020-04-19 14:53:53 -07:00
diamondburned (Forefront) 4e4ebde93a Gateway: Deprecated Wait(), fixed ReconnectOP bug 2020-04-12 11:06:43 -07:00
diamondburned (Forefront) 2f597ebc0b Session: Added an AfterClose handler as a *session.Close event 2020-04-06 19:36:06 -07:00
diamondburned (Forefront) 33061e916f Gateway: Now waits for either READY or RESUMED before finishing Open() 2020-04-06 13:27:33 -07:00
diamondburned (Forefront) f0102d765f Gateway: Added a retry limit
State: Event handlers now handle all of Ready's Guilds field
Session: Added Wait, which blocks until SIGINT or Gateway error
2020-02-29 18:13:58 -08:00
diamondburned (Forefront) 4e9bd53b0f Gateway: Added extra events 2020-02-15 21:29:25 -08:00
diamondburned (Forefront) ac685b0df4 Minor fixes, undocumented things, and editorconfig 2020-01-19 13:54:16 -08:00
diamondburned (Forefront) 7f06d88d0f Updated heartbeat behavior 2020-01-18 22:22:03 -08:00
diamondburned 2dc983d243 Added simple example 2020-01-17 14:29:13 -08:00
diamondburned (Forefront) deafe15967 Moved internal/handler outside 2020-01-16 21:23:56 -08:00
diamondburned (Forefront) d627690835 Added session, started state 2020-01-16 21:17:46 -08:00
diamondburned (Forefront) 4a529dd2ec Added Session + Handlers 2020-01-16 18:08:03 -08:00
diamondburned 127c636310 Moved misc packages to internal 2020-01-15 10:32:54 -08:00
diamondburned 8fc7229c3f
Added an untested Gateway package 2020-01-14 20:43:34 -08:00