Commit Graph

52 Commits

Author SHA1 Message Date
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 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 56aaed3d60 State: Fix data race between ready and guild create handler 2021-05-29 12:38:22 -07: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 d69d6750dc API: Separated min function 2020-12-26 16:08:41 -08:00
diamondburned 157d64b423 Moreatomic: Replaced invalid mutex with modified sync.Map impl 2020-12-19 02:35:13 -08:00
diamondburned 36c2f166be Moreatomic: Fixed upgradable mutex usage 2020-12-18 23:57:56 -08:00
diamondburned 3ddb472644 Moreatomic: Cave in and use upgradable mutex over sync.Map 2020-12-18 23:47:47 -08:00
diamondburned d65807ce15 API: Potential rate limit fix for reactions 2020-12-11 17:58:52 -08:00
diamondburned b8994ed0da Voice: Remove state-keeping of sessions
This commit gets rid of all the code that previously managed different
voice sessions in different guilds. This is because there is rarely ever
a need for this, and most bots that need this could do their own
keeping.

This change, although removes some features off of the package, adds a
lot of clarity on what to do exactly when it comes to connecting to a
voice channel.

In order to make the migration process a bit easier, an example has been
added which guides through using the voice.Session API.
2020-11-30 19:12:20 -08:00
diamondburned 44909beb5b Moreatomic: Fixed LoadOrStore sentinel bug 2020-11-29 17:19:05 -08:00
diamondburned c6679dc52c State: Separate Store into smaller interfaces, Cabinet API
This commit refactors the Store interface in State into smaller
interfaces in package store. These interfaces are combined into one
structure called a "Cabinet". The default implementation of those
interfaces have been rewritten in package defaultstore, while the old
no-op implementation stays with the store package.

This commit also omitted several state handlers for user events, as it
is unclear what they are actually structured like.
2020-11-29 16:57:58 -08:00
diamondburned 6ef093eb98 Gateway: Refactor, v8 user struct updates
This commit refactored several structures from package discord to be in
package gateway. Those structures are mostly presence ones, which per
official documentation has a lot more to do with the Gateway API than
the REST API or anything else.

This commit also renamed several global variables to have a more
consistent and obvious name.

As of v8, the user API has had a lot of minor and some major changes,
especially regarding its Ready event API. The most significant change is
the addition of the ReadySupplemental event as well as several changes
to the Ready field itself.

All of these changes above are breaking, and they have already broken
the state package. These breaking changes will be addressed in other
packages by the next commit.
2020-11-28 17:22:03 -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 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 75df94d9f4 *: Migrated Go Modules to v2 2020-10-28 15:39:59 -07:00
diamondburned 6c332ac145 {Voice,}Gateway: Fixed various race conditions
This commit fixes race conditions in both package voice, package
voicegateway and package gateway.

Originally, several race conditions exist when both the user's and the
pacemaker's goroutines both want to do several things to the websocket
connection. For example, the user's goroutine could be writing, and the
pacemaker's goroutine could trigger a reconnection. This is racey.

This issue is partially fixed by removing the pacer loop from package
heart and combining the ticker into the event (pacemaker) loop itself.

Technically, a race condition could still be triggered with care, but
the API itself never guaranteed any of those. As events are handled
using an internal loop into a channel, a race condition will not be
triggered just by handling events and writing to the websocket.
2020-10-22 10:47:27 -07:00
diamondburned 94cca0adca httputil: Fixed unlock of unlocked mutex bug 2020-08-04 14:09:43 -07:00
diamondburned 77b1b08bce Heart: Better synchronization on close methods 2020-07-30 12:44:50 -07:00
mavolin 8baf8ee84b Multipartutil: move back to package api 2020-07-29 16:58:33 -07:00
Maximilian von Lindern 32789bb6e2 *: Separate utils and internal (#129)
* Utils: move package utils/heart to internal/heart

* Utils: move package utils/moreatomic to internal/moreatomic

* Utils: move package utils/zlib to internal/zlib
2020-07-29 16:58:33 -07:00
Maximilian von Lindern e1d9685cdb API: separate token-based and bot-based interactions with webhooks (#130)
* API: separate token-based and bot-based interactions with webhooks

* API: move writeMultipart to internal/multipartutil

* Multipartutil: fix double filetype-suffix
2020-07-29 16:58:33 -07:00
diamondburned (Forefront) be12849668 Changed internal/ to utils/, allowing external imports 2020-04-08 19:28:40 -07:00
diamondburned (Forefront) 5750876348 Gateway: Fixed a race condition related to concurrent WS writes 2020-04-06 14:03:08 -07:00
diamondburned (Forefront) 9f5c2ac958 Gateway: Switched to gorilla/websocket, fixes #11 2020-04-06 13:27:29 -07:00
diamondburned (Forefront) 0aebea60bd Gateway: Minor bug fixes 2020-03-01 16:39:40 -08:00
diamondburned (Forefront) 14b9d8f43a API: Fixed unlock of unlocked mutex bug 2020-03-01 14:25:54 -08:00
diamondburned 76c7760c24 Gateway: Removed redundant context 2020-02-11 09:29:30 -08:00
diamondburned ff6669a58d internal/wsutil: Fixed error checking 2020-02-11 09:23:42 -08:00
diamondburned (Forefront) f33dc2ee75 API: Fixed major rate limiters not working 2020-02-09 12:54:16 -08:00
diamondburned 3288f2d19c
Gateway: Fix race conditions and fatal reconnecting (#7) 2020-02-07 22:17:27 -08:00
diamondburned (Forefront) 85b793a1a7 Fixed some race conditions 2020-02-02 14:12:54 -08:00
diamondburned (Forefront) b62ba3ecc0 More race condition fixes 2020-01-28 19:54:22 -08:00
diamondburned (Forefront) 7e73f00eb9 Fixed bug where ParseContent interface methods won't return a proper error 2020-01-20 20:25:47 -08:00
diamondburned (Forefront) 73f5cdec9e Added HTTP retry, fixed async JSON body corrupting 2020-01-20 11:28:55 -08:00
diamondburned (Forefront) 3ca1d352c9 Fixed a ridiculous race condition in the gateway 2020-01-20 03:06:20 -08:00
diamondburned (Forefront) 27e315ca66 Fixed bug where message state would screw up 2020-01-20 00:53:23 -08:00
diamondburned (Forefront) 9651de81c6 Heartbeat can now resume, bot will fatal (die) if it can't reconnect 2020-01-18 22:14:46 -08:00
diamondburned (Forefront) 189853de32 Removed test for removed function 2020-01-18 19:15:23 -08:00
diamondburned (Forefront) 05c8932166 Fixed SendComplex 2020-01-18 19:12:08 -08:00
diamondburned (Forefront) e98c533114 MeanwhileBody tests 2020-01-18 18:27:30 -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) cfa764b150 Fixed unit tests 2020-01-16 21:20:09 -08:00
diamondburned (Forefront) d627690835 Added session, started state 2020-01-16 21:17:46 -08:00
diamondburned (Forefront) 478b66fffa Merge branch 'master' of ssh://github.com/diamondburned/arikawa 2020-01-15 20:44:30 -08:00
diamondburned (Forefront) ef0dd9beef Added API integration tests 2020-01-15 20:44:11 -08:00