Fixed privacy mode handler

master
Matthieu Lalonde 5 years ago
parent 8893c1fffa
commit ab75e0f89a

@ -22,7 +22,7 @@ var (
// User commands // User commands
"msg": "<Discord Mention> ...", "msg": "<Discord Mention> ...",
"status": "[Discord Mention...]", "status": "[Discord Mention...]",
"privacy": "<none|join|part|status|all>", "privacy": "<set|unset> <join|part|status|all>",
} }
) )
@ -280,22 +280,44 @@ func (b *Type) handleUserPrivacy(ds *discordgo.Session, dm *discordgo.Message, c
uu, _ := b.getUserByDiscordID(dm.Author.ID) uu, _ := b.getUserByDiscordID(dm.Author.ID)
c := strings.TrimSpace(ctx.Content) c := strings.TrimSpace(ctx.Content)
p := strings.Split(c, " ") p := strings.Split(c, " ")
if len(p) != 2 { if len(p) != 3 {
b.replyInvalidCommandFormat(ds, dm, ctx, "privacy") b.replyInvalidCommandFormat(ds, dm, ctx, "privacy")
return return
} }
pp := strings.ToLower(p[1:][0]) pa := strings.ToLower(p[1:][0])
if !utils.SliceContainsString([]string{"none", "join", "part", "status", "all"}, pp) { pp := strings.ToLower(p[1:][1])
if !utils.SliceContainsString([]string{"set", "unset"}, pa) {
b.replyInvalidCommandFormat(ds, dm, ctx, "privacy") b.replyInvalidCommandFormat(ds, dm, ctx, "privacy")
return return
} }
if pp == userPrivacyNone.String() { if !utils.SliceContainsString([]string{"join", "part", "status", "all"}, pp) {
uu.Privacy = userPrivacyNone b.replyInvalidCommandFormat(ds, dm, ctx, "privacy")
return
}
if pa == "unset" {
uu.Privacy = upClear(uu.Privacy, userPrivacyFromString(pp))
} else {
uu.Privacy = upSet(uu.Privacy, userPrivacyFromString(pp))
}
// XXX
pr := strings.ToTitle(pa) + " " + pp + ". Privacy mode: "
if uu.Privacy == userPrivacyAll {
pr += userPrivacyAll.String()
} else if uu.Privacy == userPrivacyNone {
pr += userPrivacyNone.String()
} else { } else {
upSet(uu.Privacy, userPrivacyFromString(pp)) if upHas(uu.Privacy, userPrivacyJoin) {
pr += "join "
}
if upHas(uu.Privacy, userPrivacyPart) {
pr += "part "
}
if upHas(uu.Privacy, userPrivacyStatus) {
pr += "status "
}
} }
b.dg.Session.ChannelMessageSendReply(dm.ChannelID, b.dg.Session.ChannelMessageSendReply(dm.ChannelID,
b.getMessageString("all_done", uu)+" Privacy set to: "+uu.Privacy.String(), b.getMessageString("all_done", uu)+" "+pr,
&discordgo.MessageReference{ &discordgo.MessageReference{
MessageID: dm.ID, MessageID: dm.ID,
ChannelID: dm.ChannelID, ChannelID: dm.ChannelID,

Loading…
Cancel
Save