This commit adds a confessions feature that allows users to mark a
"confessional" channel and also to post anonymously to it. The changes
that this comprises of are as follows:
- New discord "slash" commands for both marking a confessional and
posting to it
- a bunch of stuff in the discord module to register and deregister
"slash" commands
- New event type to track marked confessionals
- confession module that processes new confession channel links
and also posts confessions to corresponding confessionals
Not included in this commit:
- a way to cleanup obsolete or reconfigured confession channel links
- access control for the confessional slash commands
Signed-off-by: Ava Affine <ava@sunnypup.io>
This commit introduces a deferred call to a state teardown function
This is needed to properly flush data to the backing documentbuffer
as well as to truncate its underlying store. In doing so we make
sure data loss from process termination is minimal to nil.
when ever a panic happens or a signal is thrown the call to Teardown() is made
Signed-off-by: Ava Affine <ava@sunnypup.io>
This commit refactors the state module to remove the eventCache and
introduce an eventStream instead. The eventStream is not a static array
but a DocumentBuffer, and thus many functions had to be altered. This
commit is best reviewed side by side with a before/after view instead of
just looking at the diff.
An Init() function is added to initialize the DocumentBuffer with config
values.
Facilities are added to both Event and EventType to allow for parsing
them to and from string documents.
a MakeEvent() function is added to create events of proper subtype based
on a general data map input.
ApplyToEvents() is added, which wraps around DocumentBuffer's Apply() method
to alter the filter input type with one that Marshals and Unmarshals events.
GetMatchingEvents() is now a proof of concept for DocumentBuffer's Apply()
PruneCache() is now no longer needed.
Signed-off-by: Ava Affine <ava@sunnypup.io>
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.
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>
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>