Commit graph

36 commits

Author SHA1 Message Date
piper pentagram
056505d538 Merge branch 'voice-activity-events' into 'main'
Implement UserActive events

See merge request whom/bingobot!12
2024-11-14 18:59:11 +00:00
Piper Pentagram
fe860726b3 inline _activityTimerExists() into stopActivityTimer() 2024-11-14 10:58:15 -08:00
Piper Pentagram
9b00241d2b Implement UserActive events
This change introduces the UserActiveTimer,  which tracks voice activity
and emits UserActive events.

UserActiveTimer is basically a fancy wrapper around a context with
a deadline and cancelFunc. When a user joins a voice channel, a
UserActiveTimer is started.

If the user stays in the voice channel for an amount of time defined in the configs,
the timer context's deadline trips and a UserActive event is emitted. A new timer is then started.

If instead the user leaves the voice channel, the timer's context is
cancelled.

This change introduces two config values to manage this process:

VoiceActivityThresholdSeconds defines the length of time a user is
required to stay in vc before a UserActive event is generated.

VoiceActivityTimerSleepInterval defines how long the timer sleeps at any
one time. After this interval, it wakes up to check if its context has
been cancelled.

This change also changes the state package's UserEvent validation to
remove an import loop. We will now assume that the discord package
has already validated any UIDs it passes along to the state package.
2024-11-14 10:42:02 -08:00
8110037ddf Merge branch 'ava-test-ci' into 'main'
Add testing CI, update tests

See merge request whom/bingobot!14
2024-11-14 18:36:31 +00:00
9668106959 Fix state unit tests
Logging needs to be initialized in order for the state unit tests
to function without issue.

See previous commit ("Fix config unit tests") for more information.

Signed-off-by: Ava Affine <ava@sunnypup.io>
2024-11-14 10:31:25 -08:00
6afd0122c9 Fix config unit tests
Recent changes to config and logging modules have left the tests needing
to initialize both config and logging packages. This commit updates the
config module to automatically initialize into at least useful defaults
at module load time. This commit also fixes the config unit tests by
using the more up to date interface that the package provides.

Signed-off-by: Ava Affine <ava@sunnypup.io>
2024-11-14 10:27:45 -08:00
00fff032c7 Add testing CI
This commit extends our CI definitions to add a testing phase to the pipeline.
The testing phase is intended to be comprised of separate stages per package
that has tests included. Currently this consists of the state and config
packages.

Signed-off-by: Ava Affine <ava@sunnypup.io>
2024-11-14 09:57:06 -08:00
piper pentagram
1ca6b0b402 Merge branch 'config-singleton' into 'main'
Move the config package to a singleton pattern

See merge request whom/bingobot!11
2024-11-13 22:03:57 +00:00
piper pentagram
07223320af Move the config package to a singleton pattern 2024-11-13 22:03:57 +00:00
piper pentagram
abb19b8748 Merge branch 'add-debug-logger' into 'main'
Add logging.Debug() function

See merge request whom/bingobot!10
2024-11-09 01:09:19 +00:00
Piper Pentagram
cb55b48893 Add logging.Debug() function 2024-11-08 17:07:55 -08:00
piper pentagram
e89e3bbac9 Merge branch 'basic-discord-handlers' into 'main'
Create discord package and connect/disconnect handlers

See merge request whom/bingobot!9
2024-11-09 00:34:30 +00:00
Piper Pentagram
8b54f09a95 Check the session pointer for nil before calling session.connected 2024-11-08 16:33:49 -08:00
Piper Pentagram
bbcf6ef6cf Create discord package and connect/disconnect handlers
This change moves the discord session singleton to the internal/discord
package, and implements basic Connect/Disconnect handlers.
2024-11-08 16:26:05 -08:00
5e4662c8b0 Merge branch 'state-logging' into 'main'
Fill out logging TODOs in state package

See merge request whom/bingobot!8
2024-11-08 22:56:37 +00:00
Piper Pentagram
6d2375b396 Fill out logging TODOs in state package
This change adds logging where requested via TODOs in state.go.
2024-11-08 14:54:59 -08:00
dd2d8aa9b3 Merge branch 'less-wordy-logger' into 'main'
Make logging package usage less tedious

See merge request whom/bingobot!7
2024-11-08 22:36:10 +00:00
Piper Pentagram
665717d9e7 Make logging package usage less tedious
Before, we were exposing a Logger as logging.Log. This works, but
results in code calling Logger.Log.Info() which is a little wordy.

Instead, the logger is now kept private and we expose Info, Warn and
Error as public functions that wrap logger.Info, logger.Warn and
logger.Error.
2024-11-08 14:33:57 -08:00
5e4273390f Merge branch 'singleton-logger' into 'main'
Use a singleton pattern for logging

See merge request whom/bingobot!6
2024-11-08 22:02:23 +00:00
Piper Pentagram
f86efba6bd Rename redundant init function
This change renames logging.InitLogger() to logging.Init().
2024-11-08 14:00:27 -08:00
Piper Pentagram
a82ba0f51b Use a singleton pattern for logging
This change migrates the internal/logging package to a singleton
pattern. It now exports a Log variable which can be acquired from any
other package.
2024-11-08 13:54:19 -08:00
piper pentagram
70fc746ed6 Merge branch 'ava-pubsub' into 'main'
Internal event state tracking and Pub/Sub model

See merge request whom/bingobot!5
2024-11-08 21:41:30 +00:00
568e6a3163 Internal event state tracking and Pub/Sub model
Internal state tracking:
This commit introduces the concept of internal events. The thought here
is that bingobot will track its current state not by variables set from
incoming discord event data but rather from a cache of internal events that
represent digested and simplified observations made and actions taken by
internal code. Currently the events that are defined include the following:

- UserActive Events:
  These events are intended to be generated when a user is noticed to have
  been sitting in a voice chat for more than 10 minutes, however they can be
  generated in response to anything that signifies that a user has been active

- Challenge Events:
  These events signify that a user has been challenged. They are intended to
  act as a primitive form of restraint from using bot features. It is intended
  that these are made only as a response to a successful vote.

- Restore Events:
  These events signify that a user has been restored to non-challenged status.
  It is intended that this only happens in response to a successful vote.

- Vote Events:
  These events serve as the primary means of consensus building, and represent the
  state of a single active ongoing or finished vote.

Currently the events are cached for 10 days and then discarded, but future work will
add an on disk document storage for old events should any functionality desire it.

This internal event cache is intended to be the authoritative source of truth for
information about user permissions, vote results, and any additional future
functionality that relies on shared state. It is accessed through a GetMatchingEvents
function that accepts both an event type and a map of optional metadata filters.
See state_test.go for examples of this functionality. In addition to the cache
search function there is also a Publisher/Subscriber setting elaborated on below.

Pub/Sub system:
This commit also introduces a Pub/Sub system for other internal packages and
feature modules to recieve live events and continually process updates from our
code as opposed to just handling discord events.

- PublishEvent()
  In this specific implementation anyone may become a Publisher by calling
  PublishEvent() on any structure that implements the Event interface. This
  provides for modules being able to define their own event types (so long as
  they also extend the central enum of EventType in state.go).

- SubscribeWithHistory()
  This returns a channel to the caller that returns copies of any event matching
  the input event type. This channel will be prepopulated with up to 256 most
  recent events already in the cache. Future work will make this number configurable.
  Each event published will be sent down all relevant channels at publish time.

- Subscribe()
  This returns a channel to the caller, as SubscribeWithHistory also does,
  with the sole caveat that there are no historical "old" cached events
  prepopulating the channel.

Finally, this commit also contains tests

Signed-off-by: Ava Affine <ava@sunnypup.io>
2024-11-07 12:43:38 -08:00
piper pentagram
39fe90d016 Merge branch 'move-internal-packages' into 'main'
Move internal packages

See merge request whom/bingobot!4
2024-11-07 00:02:58 +00:00
Piper Pentagram
450d425b04 move config & logging packages into internal submodules 2024-11-06 16:01:38 -08:00
piper pentagram
e525b7ff3b Merge branch 'setup-logging' into 'main'
Add JSON structured logging and log rotation

See merge request whom/bingobot!3
2024-11-06 22:24:14 +00:00
Piper Pentagram
c06d77485c Add JSON structured logging 2024-11-06 14:19:45 -08:00
piper pentagram
60b9d77873 Merge branch 'config-parsing' into 'main'
Add config parsing

See merge request whom/bingobot!2
2024-11-06 21:37:56 +00:00
Piper Pentagram
bea76cd380 Add config parsing 2024-11-06 13:32:37 -08:00
Piper Pentagram
44a2e7d6c8 include start script in artifacts 2024-11-06 11:54:36 -08:00
Piper Pentagram
9ccaef1208 remove dist folder because gitlab is stupid 2024-11-06 11:52:16 -08:00
Piper Pentagram
6fa9bafe11 don't tar up the binary because gitlab zips it anyway 2024-11-06 11:48:22 -08:00
piper pentagram
85bbb07524 basic build job 2024-11-06 19:45:08 +00:00
piper pentagram
5eb83783af Merge branch 'basic-discord-session' into 'main'
Setup basic discord session

See merge request whom/bingobot!1
2024-11-06 19:37:56 +00:00
Piper Pentagram
4b62347d5d Setup basic discord session 2024-11-06 11:34:45 -08:00
571aa3650e Initial commit 2024-11-06 17:42:49 +00:00