Commit Graph

187 Commits

Author SHA1 Message Date
p5nbTgip0r dcfc9b19d1 gateway: Add IsPending for GuildMemberUpdateEvent 2022-08-22 14:43:29 -07:00
diamondburned af940e5a37
gateway: Workaround for lack of heartbeat revival
Fixes a regression from v2's gateway.
2022-08-15 14:09:53 -07:00
diamondburned c71f48c163
Revert "ws: Add LastAcknowledgedBeat"
This reverts commit 660d9893e1.

The commit introduces regular incorrect reconnections. It will be
tracked in another branch and re-merged later once fixed.
2022-04-12 10:55:42 -07:00
diamondburned 660d9893e1
ws: Add LastAcknowledgedBeat
This commit adds ws.Handler.LastAcknowledgedBeat to allow ws.Gateway to
monitor whether or not the server is still reachable.

It fixes #324.
2022-04-12 10:38:41 -07:00
diamondburned 4108d10b44
gateway: Fix RequestGuildMembersCommand 2022-04-08 05:47:21 -07:00
diamondburned 816a53b1e1
gateway: Test ReadyEvent.Version 2022-04-02 22:52:57 -07:00
diamondburned 6b835a58c7
*: Increase test timeout duration
See if CI passes this time.
2022-04-02 22:44:08 -07:00
ItsLychee 92897b4fc3
discord: Support guild Scheduled Events (#319)
* implement the gateway side of guild scheduled event
* Add proper punctuation to each docstring
* Fix UserAdd and UserRemove events
* Add MANAGE_EVENTS permission
* Implement the API-side of scheduled events
* Add ScheduledEvent method
* Cleanup
2022-04-02 22:36:45 -07:00
diamondburned 08a1db0e4a
state: Fix up ReadyEvent 2022-04-01 04:42:55 -07:00
Neo 87be6b09c1 gateway: Added the struct field of the Thread Members Update event. 2022-03-09 11:02:30 -08:00
Sam 23f5771325
gateway: Remove 4003 from fatal close codes (#316)
https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway-gateway-close-event-codes
2022-02-25 05:10:31 -08:00
starshines 7727d140a0
gateway: Update CommunicationDisabledUntil in GuildMemberUpdateEvent.UpdateMember (#307) 2022-02-05 15:05:13 -08:00
diamondburned 82c2b9e840
gateway: Add Event = ws.Event 2021-12-25 15:17:20 -08:00
starshines bc8a2b0cae
discord: Add timeouts (#299) 2021-12-20 15:56:11 -08: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 331ec59dec discord: Refactor interactions and components
This commit gets rid of contain-it-all structs and instead opt for
interface union types containing underlying concrete types with no
overloading.

The code is much more verbose by doing this, but the API is much nicer
to use. The only disadvantage in that regard is the interface assertion
being too verbose and risky for users at times.
2021-11-12 11:38:36 -08:00
diamondburned 0d13edc8fd
gateway: Add ClientState and Capabilities for Identify
This commit preps the gateway for user account usage.
2021-11-03 15:29:29 -07:00
diamondburned efde3f4ea6
state, handler: Refactor state storage and sync handlers
This commit refactors a lot of packages.

It refactors the handler package, removing the Synchronous field and
replacing it the AddSyncHandler API, which allows each handler to
control whether or not it should be ran synchronously independent of
other handlers. This is useful for libraries that need to guarantee the
incoming order of events.

It also refactors the store interfaces to accept more interfaces. This
is to make the API more consistent as well as reducing potential useless
copies. The public-facing state API should still be the same, so this
change will mostly concern users with their own store implementations.

Several miscellaneous functions (such as a few in package gateway) were
modified to be more suitable to other packages, but those functions
should rarely ever be used, anyway.

Several tests are also fixed within this commit, namely fixing state's
intents bug.
2021-11-03 15:16:02 -07: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
Maximilian von Lindern 528281b739
gateway: Fix Context overwrite in Gateway.Open (#285)
* Gateway: Fix Gateway.Open overwriting the context argument

* WSUtil: Remove max context timeout in Websocket.Dial

* WSUtil: Use Websocket.Timeout if a no-deadline context is given to .Dial

* WSUtil: Add doc to Websocket.Timeout clarifying that it must not be changed after use
2021-10-20 15:06:06 -07:00
starshines ca70e0cca9
discord: Add per-guild avatars, ModifyMe -> ModifyCurrentUser (#278)
* v3: discord, api, gateway: add per-guild avatars

* api: rename ModifyMe to ModifyCurrentUser
2021-09-28 11:46:36 -07:00
samhza e203e31ab3
discord: Update to match current API docs (#277)
* discord: update permission constants

* discord: update MessageType constants, add ephemeral field to Attachment

Renamed ApplicationCommandMessage to ChatInputCommandMessage and add
ContextMenuCommand. Add the ephemeral field to Attachment.

* discord: add version field to Command

* gateway: remove ApplicationCommandUpdateEvent

52f1824451
2021-09-23 21:37:50 -07:00
Maximilian von Lindern 5d2d39d422
gateway: Fix typo in GuildEmojisUpdateEvent.Emojis JSON tag (#276) 2021-09-22 10:57:14 -07:00
samhza 4023a58f67
gateway: Change type of IdentifyData.Intents to option.Uint (#275) 2021-09-09 18:45:08 -07:00
samhza dc92845315
discord: move Interaction over; update api.CommandCreateData (#274)
- Moved gateway.InteractionCreateData to discord.Interaction, now
gateway.InteractionCreateData is a struct that wraps
discord.Interaction.
- Split InteractionData into CommandInteractionData and
ComponentInteractionData.
- Renamed ButtonInteraction to ComponentInteraction.
- Updated api.CommandCreateData to add new fields.
- Update Component types' Type() methods to pointer receivers.
2021-09-09 16:06:44 -07:00
starshines f7880b91ee
discord: Add select component type (#260) 2021-08-10 14:02:30 -07:00
Maximilian von Lindern c00567599b
api: Threads (#257)
* api/gateway: Implement threads

* discord/api: rename PermissionOverwrites fields to Overwrites

* discord: rename Minutes to ArchiveDuration

* discord: Rename ArchiveDuration constants

Co-authored-by: diamondburned <datutbrus@gmail.com>
2021-08-08 13:19:15 -07:00
Hamza Ali 0d7774bd6a
gateway: Skip unknown events while reconnecting (#255)
This change skips events that are unknown while the bot reconnects. This
is an event that is particularly rare as it requires unimplemented
events being called in the time before a bot's HELLO -> RESUME events
are called. This change explicitly returns unknown events as a special
time defined in wsutil/op.go and ignores them from reaching gateway/op.go
2021-08-03 18:00:31 -07:00
Starshine System 42aa73a592 gateway: change InteractionOption.Value to json.Raw, add helper methods 2021-08-03 09:07:09 -07:00
diamondburned 6c349d9750 shard: Unwrap Shard in ForEach 2021-06-24 21:20:58 -07:00
Germano Eichenberg 94090b92ff
discord, gateway: Add IsPending to Member & SupplementalMember (#231) 2021-06-17 13:40:57 -07:00
diamondburned da7c6c6dba gateway: Allow custom SessionID 2021-06-14 15:23:08 -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 df5954d2e1
all: Revert incorrect "GuildID" changes (#211) 2021-05-30 14:16:16 -07:00
Maximilian von Lindern 6c2fb008eb gateway: Rename RequestGuildMembersData.GuildID to GuildIDs for consistency 2021-05-29 22:17:55 -07:00
Maximilian von Lindern d2b70ebfa7 all: Remove deprecated symbols 2021-05-29 22:17:44 -07:00
diamondburned 694d6a2bba gateway: Clarify field presence for InteractionCreateEvent 2021-05-29 21:32:35 -07:00
Scott 10c8837000 api: Finalized buttons implementation (#200)
* all: Added Components fields to message-related types
* discord: Documented Reactions field
* discord: Implement fix for Component
* gateway: Added User and Message fields to InteractionCreateEvent
* api: Made InteractionResponseData fields optional for UpdateMessage responses
* api: Deprecated and updated interaction response types
* gateway: Update optional interaction event fields
* discord: Added ComponentWrap for json unmarshalling
* state: Update components on MessageUpdate
* Updated buttons example
2021-05-29 21:32:33 -07:00
Chan Wen Xu c880cb2fc8 interaction: Implement buttons 2021-05-29 14:16:44 -07:00
Starshine System 20166f33cc
gateway: fix Joined field in GuildCreateEvent (#193) 2021-04-11 16:56:05 -07:00
diamondburned 728bc5c472 Gateway: Test Reconnect error 2021-04-07 11:42:13 -07:00
Maximilian von Lindern ebc74e3168
Gateway: Sharding callback, proper closing (#190)
* Gateway: Fix gateway reconnect

This commit uses the correct timeout, Gateway.ReconnectTimeout, when reconnecting. Furthermore, it adds a delay between consecutive, failed reconnects.

* Gateway: Stop pacemaker when calling Gateway.CloseGracefully

* API: remove unnecessary leading/trailing whitespaces

* Gateway: Add Gateway.OnScalingRequired callback

* Gateway: Make all user initiated user closures graceful and ensure that closures are respected during reconnects

* Gateway: Fix typo

* Gateway: Add Gateway.ReconnectAttempts and deprecate .ReconnectTimeout

* Gateway: Add Gateway.Pause and reexport .Reconnect and .ReconnectCtx

* Gateway: Improve the Gateway.OnShardingRequired docs

* Wsutil: Code cleanup
2021-04-07 11:38:26 -07:00
diamondburned 9925461a25 Gateway: Potential fix for URL() 2021-04-05 12:20:56 -07:00
diamondburned c9a7ec8122 Gateway: Add URL test 2021-04-05 12:20:56 -07:00
diamondburned 2dadb0701d Gateway: Add automatic BotData connection
This commit modifies Gateway constructors to allow the user to easily
feed existing Identifier instances as well as updating those instances
to adhere to the Discord-returned gateway rate limits.

These changes should make it easier for typical bot sharding, although
automatic sharding is not implemented.
2021-04-05 12:20:56 -07:00
diamondburned 968112fb53 Discord: typed snowflake for Interaction 2021-02-17 17:41:19 -08:00
diamondburned 5a18435190 Gateway: Better Activities type for UpdateStatusData
This is a breaking change.
2021-02-07 17:03:12 -08:00
Maximilian von Lindern a969b11709
Gateway: Add graceful closing with CloseGracefully (#185)
* gateway: add the possibility of graceful closure

* wsutil: rename ConnGracefulCloser to GracefulCloser

* Gateway: rename Gateway.CloseSession to .CloseGracefully
2021-01-29 20:25:10 -08:00
Matthew Penner 7c3374543e Discord: Add basic support for slash commands 2021-01-27 10:44:14 -08:00