Confessions module

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 is contained in:
Ava Apples Affine 2025-01-08 13:40:11 -08:00
parent 720b80679a
commit 430c0afaa6
6 changed files with 253 additions and 0 deletions

View file

@ -0,0 +1,58 @@
package confession
import (
"errors"
"sync"
"github.com/bwmarrin/discordgo"
"gitlab.com/whom/bingobot/internal/logging"
"gitlab.com/whom/bingobot/internal/state"
)
/* Activity module
* This module posts anonymous confessions according to a linked channel map
*/
const (
ActivityModuleStartFail = "failed to start activity module"
)
var (
// guild ID to channel ID
linkLock sync.RWMutex
confessionChannelLinks map[string]state.ConfessionsChannelLinkEvent
)
func Start() error {
ch, err := state.ConfessionsChannelLink.Subscribe()
if err != nil {
return errors.Join(
errors.New(ActivityModuleStartFail),
err,
)
}
// process incoming events loop
go func() {
for {
ev := <- ch
e := ev.(state.ConfessionsChannelLinkEvent)
linkLock.Lock()
confessionChannelLinks[e.GuildID] = e
linkLock.Unlock()
}
}()
return nil
}
func MakeConfession(s *discordgo.Session, guildID string, content string) {
linkLock.RLock()
link, ok := confessionChannelLinks[guildID]
linkLock.RUnlock()
if !ok {
logging.Error("Failed to send confession in guild %s: no link exists in map", guildID)
return
}
s.ChannelMessageSend(link.ChannelID, content)
}