Skip to content

feat: allow reactions to also update the rsvp#7

Open
elizabethkang8 wants to merge 1 commit into
klrmngr:mainfrom
elizabethkang8:cursor-one-shot-reactions
Open

feat: allow reactions to also update the rsvp#7
elizabethkang8 wants to merge 1 commit into
klrmngr:mainfrom
elizabethkang8:cursor-one-shot-reactions

Conversation

@elizabethkang8

Copy link
Copy Markdown

Users can RSVP by reacting on the event announcement post, in addition to /rsvp.

  • New events get ✅ / ❓ / ❌ reactions on the announcement (Going / Maybe / Can't make it).
  • MessageReactionAdd / MessageReactionRemove handlers map those reactions to yes / maybe / no, persist via existing UpsertResponse / DeleteResponse, and refresh the event post.
  • Switching reactions keeps one RSVP per user (other RSVP reactions are cleared on the message).
  • /rsvp still works; both paths share a new refreshEventMessage helper.

I did not test this :^)

Comment thread reactions.go
Comment on lines +42 to +50
func reactionUserID(r *discordgo.MessageReaction) string {
if r == nil {
return ""
}
if r.UserID != "" {
return r.UserID
}
return ""
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently this function doesn't do anything, onReactionAdd and onReactionRemove are the only functions that call this and they already do a nil check for r.MessageReaction

Comment thread render.go
return buf.String(), nil
}

func refreshEventMessage(s *discordgo.Session, channelID string) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we change the implementation of this so that we don't have duplicate db reads from callers

Comment thread reactions.go
return ""
}
switch emoji.Name {
case "✅", "white_check_mark", "☑️", "✔️":

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need all these checks, just need the bot to respond to whatever reaction the bot initially adds

Comment thread reactions.go
Comment on lines +53 to +62
if r == nil || r.MessageReaction == nil {
return
}
userID := reactionUserID(r.MessageReaction)
if userID == "" && r.Member != nil && r.Member.User != nil {
userID = r.Member.User.ID
}
if userID == "" || userID == s.State.User.ID {
return
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we can simplify this down to

if r == nil || r.MessageReaction == nil || r.UserID == s.State.User.ID {
    return                              
}

and then just use r.messageReaction.UserID in UpsertResponse

Comment thread reactions.go
refreshEventMessage(s, r.ChannelID)
}

func onReactionRemove(s *discordgo.Session, r *discordgo.MessageReactionRemove) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar comment to above

Comment thread render.go
return buf.String(), nil
}

func refreshEventMessage(s *discordgo.Session, channelID string) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also move the location of this somewhere else so render.go stays pure template rendering

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants