jakevoytko / crbot

A Discord bot that acts as a call-and-response bot. It reacts to ? commands with the learned response.
MIT License
7 stars 3 forks source link

Prevent `?unlearn` from being used in PMs #13

Closed jakevoytko closed 7 years ago

jakevoytko commented 7 years ago

If you're gonna destroy a command, you should do it in public.

Relevant Discord discussion:

[10:03 AM] Jake: i'm thinking of changing ?learn and ?unlearn so they don't work from PMs. does anyone have any compelling use cases for keeping them? [10:03 AM] Jake: ^ these are the types of thoughts i wake up with suddenly at 3am, in case anyone was wondering [10:04 AM] BL: The compelling case is that it makes the surprise more fun [10:04 AM] BL: in a chat involving randos i'd def disallow but here it's great when you get surprised [10:11 AM] Timmes: i would say [10:11 AM] Timmes: keep ?learn in PMs [10:11 AM] Timmes: don't keep ?unlearn in PMs [10:14 AM] Timmes: the value of surprising someone with a ?navyseal is nontrivial, imo [10:15 AM] Timmes: but if you're ?unlearning something and destroying something someone created, you should have the balls to say "hey i'm a coward and don't want ?ryan anymore because it hurts what little of my feelings my children have left behind" [10:15 AM] Timmes: in public [10:15 AM] Timmes: where we all can see you

drvan commented 7 years ago

Per discordgo docs - need to grab the ChannelID from the Message struct, call Session.Channel(ChannelID) and check the resulting *Channel for IsPrivate - if true, reply with error requiring user to unlearn in public.

Looks to me like the ChannelID is passed around as 'channel' in the feature itself, so this may be as simple as adding the following lines to func (f *UnlearnFeature) Execute(s DiscordSession, channel string, command *Command):

c, err := s.Channel(channel)
if err != nil {
    fatal("This message didn't come from a valid channel", errors.New("wat"))
}
if c.IsPrivate {
    s.ChannelMessageSend(channel, fmt.Sprintf(MsgUnlearnMustBePublic, command.Unlearn.Call))
}

Will try to validate this and send PR.