1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-01 04:24:19 +00:00
Commit graph

109 commits

Author SHA1 Message Date
diamondburned c14e68ac77
discord: Add missing NumberOption MarshalJSON 2021-12-29 11:10:59 -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 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 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 6d89542403
utils: Remove unused json.AlwaysString 2021-11-16 14:36:41 -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 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
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
diamondburned b2e852d140
bot: Fix previous breaking change 2021-09-22 10:56:40 -07:00
diamondburned 76c25835b7
bot: Move bot to utils 2021-09-18 00:39:34 -07:00
Maximilian von Lindern 53c72c1e16 option: Move conflicting types into package discord 2021-08-30 13:23:43 -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
EvieDelta 29a3094a75
gateway: Possible Close/Send deadlock bug (#244)
when websocket send error happens in wsutil.(Websocket).SendCtx

Co-authored-by: EvieDelta <no public email>
2021-07-11 10:56:18 -07:00
samhza 37b8871c65
api: Update sending/editing messages for v9 (#230)
api.{Send,Edit}MessageData and their equivalents in package api/webhook
have been updated to add some fields added in Discord API v9.
(webhook.Client).EditMessage now also returns a message, because that
endpoint returns a message on success.
2021-06-17 23:32:11 -07:00
diamondburned 5b328bdab0 shard: Remake shard manager (#226) 2021-06-14 15:22:55 -07:00
Maximilian von Lindern f1f4f06979
*: Rename error types to have Error suffix (#215) 2021-06-06 12:40:24 -07:00
Samuel Hernandez 40e1a3757d *: Migrated Go Modules to v3 2021-06-01 19:59:01 -07:00
Maximilian von Lindern a3a3f5a1b8 wsutil: Make wsutil.GracefulCloser part of wsutil.Connection 2021-05-29 22:17:49 -07:00
unknown 3b212908a5 utils: Change Enum to int32 2021-05-29 14:16:44 -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 f5dc90c2d4 API: Add File.AttachmentURI for convenience 2021-02-24 01:59:33 -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
diamondburned 5252b5af8d httputil: Fix Timeout causing premature cancelation 2021-01-24 22:45:56 -08:00
diamondburned de3049b730 httputil: Fixed JSON body not reusable 2021-01-13 15:22:45 -08:00
diamondburned c6d8c741e8 CI: Add perseverance test for Gateway 2020-12-31 23:48:29 -08:00
diamondburned f1f052180b Heart: Improve thread-safety and pace responsiveness
This commit consists of these smaller commits:

    Gateway: SessionID to be a method for thread safety

	This commit breaks the SessionID field of the Gateway struct to
	be thread-safe by wrapping its access with a read-write mutex.
	As this is a bug fix, it is reasonable of a breaking change

    Heart: Allow later binding of event channel

    Voice: Use the new Heart API

    Heart: Fixed data races

    Heart: Allow changing pace, thread-safe Heartbeat
2020-12-31 01:32:45 -08:00
diamondburned 808dfb28bb httputil: Fixed Multipart writer not closing 2020-12-16 14:08:31 -08:00
diamondburned 525d0bb3f6 API: Move ExecuteWebhookData, add package sendpart for uploads
This commit moved ExecuteWebhookData from package api to package webhook
inside package api. This change required splitting the multipart
abstractions away from package api, so they are now inside package
sendpart in utils.

This commit will break code that uploads anything, as the type name is
now sendpart.File from api.SendMessageFile. The behavior should be the
same as before.
2020-12-16 13:11:11 -08:00
diamondburned d65807ce15 API: Potential rate limit fix for reactions 2020-12-11 17:58:52 -08:00
diamondburned 5a76b21ecf wsutil: Fixed irregular close 1000 error 2020-11-30 21:49:55 -08:00
Maximilian von Lindern 0a8b24339b
API: Added timeout if deadline is after rate limit (#173)
* Rate: don't sleep if sleep exceeds context deadline

* Httputil: add Client.Timeout

* Bot: set default API timeout to 5 minutes

* Rate: reduce calls to time.Now in Acquire

* API: Optimize to use deadline instead of recalculating

Co-authored-by: diamondburned <datutbrus@gmail.com>
2020-11-25 12:08:42 -08:00
mavolin b9d7ba4476 Option: fix nullable types getting serialized to nil on JSON null 2020-11-22 09:33:33 -08:00
diamondburned 1aaa2cbfe2 httputil: Removed debug logs 2020-11-14 15:36:18 -08:00
diamondburned 6cbe95d2b3 State: Fixed erroneous context setting and races in Ready 2020-11-14 15:30:18 -08:00
diamondburned f6e270ae9c json: Fixed a race condition with erroneous JSON streams 2020-11-14 14:18:50 -08:00
diamondburned a3aa490024 wsutil: Reset SendLimiter after Dial 2020-11-01 10:12:35 -08:00
diamondburned bd1696ef65 wsutil: Added super verbose logs 2020-11-01 10:12:31 -08:00
diamondburned a46d3c2c8d wsutil: Added possibly missing Reset cases and more debug logs 2020-10-31 15:54:51 -07:00
diamondburned 63310fdc95 wsutil: Added graceful close checking 2020-10-30 13:54:35 -07:00
diamondburned 16c1658163 {,Voice}Gateway: Refactored Closing
This commit refactors both wsutil, the normal Gateway and the Voice
Gateway to have better closing behavior, which should assume less and
cover edge cases completely.
2020-10-30 11:02:37 -07:00
diamondburned 8d21c5f43f Merge wsutil bug fixes and changes onto v2 2020-10-29 11:25:09 -07:00
diamondburned 7668fe940c wsutil: Websocket wrapper thread safety for simpler Conn impl
This commit removes the thread safety requirement that Conn
implementations must satisfy. It moves the mutex guards as well as the
multiple close wrapper over to the Websocket wrapper instead.
2020-10-29 11:24:45 -07:00
diamondburned 9b4b707070 Handler: Use a free list over a linked list 2020-10-28 23:55:39 -07:00
diamondburned ef48d686cd Handler: Changed to a linked list instead of a slice-backed map
This change should slightly improve the performance of the handler
container.

A rough benchmark was written and tested; the source code is at
https://gist.github.com/diamondburned/c369d13efda5c702a0e59874deee64bd.
2020-10-28 22:37:38 -07:00
diamondburned 33e7abd4db Merge wsutil fix from v1 into v2 2020-10-28 19:03:10 -07:00
diamondburned 160a4e6606 wsutil: Fixed data races involving getters 2020-10-28 19:00:59 -07:00
diamondburned 75df94d9f4 *: Migrated Go Modules to v2 2020-10-28 15:39:59 -07:00