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>
37 lines
960 B
Go
37 lines
960 B
Go
package discord
|
|
|
|
import (
|
|
"github.com/bwmarrin/discordgo"
|
|
"gitlab.com/whom/bingobot/internal/logging"
|
|
)
|
|
|
|
func addHandlers() {
|
|
session.s.AddHandler(handleConnect)
|
|
session.s.AddHandler(handleDisconnect)
|
|
session.s.AddHandler(handleVoiceStateUpdate)
|
|
session.s.AddHandler(handleCommand) // handles InteractionCreate
|
|
}
|
|
|
|
func handleConnect(s *discordgo.Session, e *discordgo.Connect) {
|
|
session.connected = true
|
|
logging.Info("discord session connected")
|
|
}
|
|
|
|
func handleDisconnect(s *discordgo.Session, e *discordgo.Disconnect) {
|
|
session.connected = false
|
|
logging.Info("discord session disconnected")
|
|
}
|
|
|
|
func handleVoiceStateUpdate(_ *discordgo.Session, e *discordgo.VoiceStateUpdate) {
|
|
if e.ChannelID == "" {
|
|
// user disconnected
|
|
logging.Info("user left channel", "uid", e.UserID)
|
|
stopActivityTimer(e.UserID)
|
|
|
|
return
|
|
}
|
|
|
|
// user connected
|
|
logging.Info("user joined channel", "uid", e.UserID, "channel", e.ChannelID)
|
|
startActivityTimer(e.UserID)
|
|
}
|