Commit Graph

869 Commits

Author SHA1 Message Date
diamondburned f5ae68c781
voice: Refactor and fix up
This commit refactors a lot of voice's internals to be more stable and
handle more edge cases from Discord's voice servers. It should result in
an overall more stable voice connection.

A few helper functions have been added into voice.Session. Some fields
will have been broken and changed to accomodate for the refactor, as
well.

Below are some commits that have been squashed in:

    voice: Fix Speaking() panic on closed
    voice: StopSpeaking should not error out
        The rationale is added as a comment into the Speaking() method.
    voice: Add TestKickedOut
    voice: Fix region change disconnecting
2022-01-18 21:31:46 -08:00
diamondburned f5e713dee5
api: Add RTCRegionID for ModifyChannelData 2022-01-18 21:31:46 -08:00
diamondburned 4fa2363f8a
Revert "voice: Example should use JoinChannelAndSpeak"
This reverts commit 85619b2976. It was
accidentally merged into v3 instead of 238-branch.
2022-01-18 21:28:23 -08:00
diamondburned 85619b2976
voice: Example should use JoinChannelAndSpeak 2022-01-18 18:26:29 -08:00
Juby210 2d3bf2974a
state: Fix decrementing reaction count (#302)
* state: fix updating reaction count in reaction remove event

* move r.Me branch to if
2022-01-17 16:35:49 -08:00
PL Pery 11432e426c
discord: Correct BulkOverwriteGuildCommands parameters (#301) 2022-01-03 13:38:38 -08:00
PL Pery 9cd0c7ed28
discord: Add CommandInteractionOptions (#300)
* feat: Find method on options

* doc comment
2022-01-03 13:37:18 -08:00
diamondburned bfd668ff99
discord: Fix unmarshaling PingInteraction 2022-01-02 23:55:57 -08:00
diamondburned c14e68ac77
discord: Add missing NumberOption MarshalJSON 2021-12-29 11:10:59 -08:00
diamondburned 5c4a989746
discord: Add CommandInteraction.Resolved 2021-12-27 15:10:09 -08:00
diamondburned 82c2b9e840
gateway: Add Event = ws.Event 2021-12-25 15:17:20 -08:00
diamondburned a4611b7ab4
state: Remove redundant token parameter 2021-12-25 15:08:01 -08:00
starshines bc8a2b0cae
discord: Add timeouts (#299) 2021-12-20 15:56:11 -08:00
avdb c2382028df
README: Fix broken links (#298) 2021-12-20 13:57:04 -08:00
diamondburned 4158db8715 state: Ignore state errors in API wrappers
This commit makes it so that all API wrapper methods under state will
ignore errors returned from the cabinet setters. This is because an
intermittent error from the state shouldn't shadow the actual result
from the Discord API.
2021-12-14 13:49:34 -08:00
diamondburned 054f4de0e1 state: Add NewWithIdentifier 2021-12-14 13:49:34 -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 07a2c407e0
discord: Fix incorrect Min/Max fields in command.go 2021-12-02 13:21:47 -08:00
diamondburned 172d448e74
discord: Add {Min,Max} into {Integer,Number}Option 2021-12-01 12:11:59 -08:00
diamondburned 7af6e23569
utils/httputil: Fix build error from previous commit 2021-11-29 12:41:13 -08:00
diamondburned 1e14369fc0
utils/httputil: HTTPError print JSON error if possible 2021-11-29 12:28:51 -08:00
diamondburned 8d78221de0
discord: Improve union interface documentation; fix *Option JSON 2021-11-25 15:02:24 -08:00
diamondburned 5c88317130
api: Fix CreateInteractionFollowup return 2021-11-23 22:53:27 -08:00
Samuel Hernandez c3b7383b77 discord: Add helper functions for creating commands and options 2021-11-18 15:15:03 -08:00
Samuel Hernandez 9edf2f9565 discord: Remove Choice types except for String, Integer, and Number
Choices are only valid for StringOptions, IntegerOptions, and
NumberOptions, so get rid of the invalid fields.
2021-11-18 15:15:03 -08:00
diamondburned 6d89542403
utils: Remove unused json.AlwaysString 2021-11-16 14:36:41 -08:00
diamondburned e6be4a3fab
discord: Minor comment tweaks 2021-11-16 14:36:07 -08:00
Tadeo Kondrak 9289303255 examples: Add autocomplete example 2021-11-15 14:30:48 -08:00
Tadeo Kondrak 2ec0e6b011
discord: Use json.Unmarshal instead for CommandInteractionOption (#292)
This ensures valid JSON strings are processed using the JSON rules, not
the Go rules.
2021-11-13 15:18:52 -08:00
Tadeo Kondrak c98e2f8730 discord: Add Options field to AutocompleteOption
This is used for subcommands.
2021-11-13 13:45:26 -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 8abd5bc86e
readme: Fix bot import path 2021-11-09 18:30:58 -08:00
diamondburned 5c6d0f8977
example: Fix CI for previous rename 2021-11-09 16:02:27 -08:00
diamondburned 1b154cb65f
example: Rename _example to 0-examples
This commit renames the examples folder so gopls can pick it up.
2021-11-09 15:56:51 -08:00
Hamza Ali 6fba21d704
api: Implement autocomplete components 2021-11-09 14:49:21 -08:00
Hamza Ali 028a341597
*: Update go dependencies 2021-11-09 14:49:18 -08:00
diamondburned 123f8bc41f
voice: Fix init inconsistencies
This commit fixes a few subtle bugs in the voice package. It slightly
refactors the connecting and reconnecting of voice sessions.
2021-11-04 14:21:46 -07:00
diamondburned accb2fc52b
example/undeleter: Fix AddSyncHandler 2021-11-03 15:43:07 -07:00
diamondburned 477695f2e6
readme: Fix build badge 2021-11-03 15:42:37 -07: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
diamondburned e8131db8df
discord: Add VoiceState.SelfVideo; fixes #287 2021-10-30 16:43:28 -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
Nat 918cce64e9
discord: Fix json tag for Guild.Features (#283) 2021-10-04 23:22:27 -07:00
samhza bfb644c124
api: Add CurrentApplication (#282)
* discord/api: support fetching bot's Application

* Update api/application.go

Co-authored-by: diamondburned <diamond@arikawa-hi.me>

Co-authored-by: diamondburned <diamond@arikawa-hi.me>
2021-10-03 13:31:48 -07:00
starshines 8ea320ccb9
discord: Add ChannelType field to CommandOption (#279)
* discord: add ChannelType field to CommandOption

* preallocate option.ChannelTypes

Co-authored-by: diamondburned <diamond@arikawa-hi.me>

Co-authored-by: diamondburned <diamond@arikawa-hi.me>
2021-09-28 14:12:04 -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
diamondburned 95231f5772
CI: Update dismock 2021-09-23 22:28:02 -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