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:
parent
720b80679a
commit
430c0afaa6
6 changed files with 253 additions and 0 deletions
|
|
@ -226,3 +226,47 @@ func (te TestEvent) Validate() error {
|
|||
func (te TestEvent) Disposable() bool {
|
||||
return te.Dispose
|
||||
}
|
||||
|
||||
const (
|
||||
ConfessionsLinkEventGuildKey = "guild_id"
|
||||
ConfessionsLinkEventChannelKey = "channel_id"
|
||||
ConfessionsLinkEventCreatedKey = "created"
|
||||
ConfessionsLinkEventObsoleteKey = "obsolete"
|
||||
|
||||
BadConfessionsLinkEventError = "link event doesnt have required fields"
|
||||
)
|
||||
|
||||
type ConfessionsChannelLinkEvent struct {
|
||||
GuildID string
|
||||
ChannelID string
|
||||
Created time.Time
|
||||
}
|
||||
|
||||
func (e ConfessionsChannelLinkEvent) Type() EventType {
|
||||
return ConfessionsChannelLink
|
||||
}
|
||||
|
||||
func (e ConfessionsChannelLinkEvent) Time() time.Time {
|
||||
return e.Time()
|
||||
}
|
||||
|
||||
func (e ConfessionsChannelLinkEvent) Data() map[string]string {
|
||||
return map[string]string{
|
||||
ConfessionsLinkEventGuildKey: e.GuildID,
|
||||
ConfessionsLinkEventChannelKey: e.ChannelID,
|
||||
ConfessionsLinkEventCreatedKey: e.Created.Format(time.RFC3339),
|
||||
}
|
||||
}
|
||||
|
||||
func (e ConfessionsChannelLinkEvent) Validate() error {
|
||||
if len(e.ChannelID) > 1 || len(e.GuildID) > 1 {
|
||||
return errors.New(BadConfessionsLinkEventError)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e ConfessionsChannelLinkEvent) Disposable() bool {
|
||||
// TODO
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -183,6 +183,7 @@ const (
|
|||
Restoration
|
||||
UserActive
|
||||
Test
|
||||
ConfessionsChannelLink
|
||||
// ...
|
||||
|
||||
// leave this last
|
||||
|
|
@ -202,6 +203,8 @@ func EventTypeFromString(doc string) EventType {
|
|||
return UserActive
|
||||
case "Test":
|
||||
return Test
|
||||
case "ConfessionsChannelLink":
|
||||
return ConfessionsChannelLink
|
||||
default:
|
||||
// error case
|
||||
return NumEventTypes
|
||||
|
|
@ -215,6 +218,7 @@ func (et EventType) String() string {
|
|||
"Restoration",
|
||||
"UserActive",
|
||||
"Test",
|
||||
"ConfessionsChannelLink",
|
||||
}
|
||||
|
||||
if et < 0 || et >= NumEventTypes {
|
||||
|
|
@ -266,24 +270,28 @@ func (et EventType) MakeEvent(data map[string]string) (Event, error) {
|
|||
switch et {
|
||||
case Vote:
|
||||
return VoteEvent(data), nil
|
||||
|
||||
case Challenge:
|
||||
e, err := MakeUserEvent(data)
|
||||
if err != nil {
|
||||
return nil, errors.Join(errors.New(BadChallengeEvent), err)
|
||||
}
|
||||
return ChallengeEvent{*e}, nil
|
||||
|
||||
case Restoration:
|
||||
e, err := MakeUserEvent(data)
|
||||
if err != nil {
|
||||
return nil, errors.Join(errors.New(BadRestorationEvent), err)
|
||||
}
|
||||
return RestorationEvent{*e}, nil
|
||||
|
||||
case UserActive:
|
||||
e, err := MakeUserEvent(data)
|
||||
if err != nil {
|
||||
return nil, errors.Join(errors.New(BadUserActiveEvent), err)
|
||||
}
|
||||
return UserActiveEvent{*e}, nil
|
||||
|
||||
case Test:
|
||||
disp := false
|
||||
if v, ok := data[TestEventDisposeKey]; ok && v == "t" {
|
||||
|
|
@ -300,6 +308,33 @@ func (et EventType) MakeEvent(data map[string]string) (Event, error) {
|
|||
Dispose: disp,
|
||||
ID: id,
|
||||
}, nil
|
||||
|
||||
case ConfessionsChannelLink:
|
||||
gid, ok := data[ConfessionsLinkEventGuildKey]
|
||||
if !ok {
|
||||
return nil, errors.New(BadConfessionsLinkEventError)
|
||||
}
|
||||
|
||||
cid, ok := data[ConfessionsLinkEventChannelKey]
|
||||
if !ok {
|
||||
return nil, errors.New(BadConfessionsLinkEventError)
|
||||
}
|
||||
|
||||
ti, ok := data[ConfessionsLinkEventCreatedKey]
|
||||
if !ok {
|
||||
return nil, errors.New(BadConfessionsLinkEventError)
|
||||
}
|
||||
t, err := time.Parse(time.RFC3339, ti)
|
||||
if err != nil {
|
||||
return nil, errors.Join(errors.New(BadConfessionsLinkEventError), err)
|
||||
}
|
||||
|
||||
return ConfessionsChannelLinkEvent{
|
||||
GuildID: gid,
|
||||
ChannelID: cid,
|
||||
Created: t,
|
||||
}, nil
|
||||
|
||||
default:
|
||||
return nil, errors.New(BadEventTypeError)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue