mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-09-18 10:46:57 +00:00
rework /pubmsg to use MessageTargetType
This commit is contained in:
parent
ae1306387e
commit
898057cc20
3 changed files with 58 additions and 27 deletions
|
@ -76,17 +76,38 @@ func HBackendPublishRequest(w http.ResponseWriter, r *http.Request) {
|
|||
json := formData.Get("args")
|
||||
channel := formData.Get("channel")
|
||||
scope := formData.Get("scope")
|
||||
|
||||
target := MessageTargetTypeByName(scope)
|
||||
|
||||
if cmd == "" {
|
||||
w.WriteHeader(422)
|
||||
fmt.Fprintf(w, "Error: cmd cannot be blank")
|
||||
return
|
||||
}
|
||||
if channel == "" && (target == MsgTargetTypeChat || target == MsgTargetTypeMultichat || target == MsgTargetTypeWatching) {
|
||||
w.WriteHeader(422)
|
||||
fmt.Fprintf(w, "Error: channel must be specified")
|
||||
return
|
||||
}
|
||||
|
||||
cm := ClientMessage{MessageID: -1, Command: Command(cmd), origArguments: json}
|
||||
var count int
|
||||
if scope == "chat" {
|
||||
|
||||
switch target {
|
||||
case MsgTargetTypeSingle:
|
||||
// TODO
|
||||
case MsgTargetTypeChat:
|
||||
count = PublishToChat(channel, cm)
|
||||
} else if scope == "channel" {
|
||||
case MsgTargetTypeMultichat:
|
||||
// TODO
|
||||
case MsgTargetTypeWatching:
|
||||
count = PublishToWatchers(channel, cm)
|
||||
} else if scope == "global" {
|
||||
case MsgTargetTypeGlobal:
|
||||
count = PublishToAll(cm)
|
||||
} else {
|
||||
w.WriteHeader(400)
|
||||
fmt.Fprint(w, "Need to specify either chat or channel")
|
||||
case MsgTargetTypeInvalid:
|
||||
default:
|
||||
w.WriteHeader(422)
|
||||
fmt.Fprint(w, "Invalid 'scope'. must be single, chat, multichat, channel, or global")
|
||||
return
|
||||
}
|
||||
fmt.Fprint(w, count)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue