This commit separates the undocumented fields of Ready to
ReadyEventExtras. Realistically, this is never an issue for bots, but it
might cripple non-bot users when Discord makes breaking changes to the
API.
This change allows Ready to still be unmarshaled even when the
undocumented fields cannot be unmarshaled. It also adds a new json.Raw
field that allows the whole Ready event to be unmarshaled differently.
This new ReadyEventExtras is also no longer marshaled as part of Ready.
Instead, none of its field will be present. Although this is a breaking
change, it solely concerns non-bot APIs, so it's acceptable.
This reverts commit 660d9893e1.
The commit introduces regular incorrect reconnections. It will be
tracked in another branch and re-merged later once fixed.
* 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
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")
})
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.
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.
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.
* 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
* 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
- 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.
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
* 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