Explorar el Código

serve multiple type of incoming msg

master
Patrick Peng Sun hace 8 años
padre
commit
f2a0205633
Se han modificado 1 ficheros con 38 adiciones y 9 borrados
  1. +38
    -9
      serveCommand.go

+ 38
- 9
serveCommand.go Ver fichero



import ( import (
"fmt" "fmt"
"strings"
"time" "time"
) )


} }


func (ss *openIDSessionData) serveCommand(in InWechatMsg) (processed bool) { func (ss *openIDSessionData) serveCommand(in InWechatMsg) (processed bool) {
if in.header.MsgType == "text" {
return ss.serveTextCommand(in)
switch in.header.MsgType {
case "text":
processed = ss.serveTextCommand(in)
case "image":
in.replyText("图片收到")
processed = true
case "voice":
processed = ss.serveTextCommand(in)
case "video":
case "shortvideo":
case "location":
case "link":
case "event":
processed = ss.serveEvents(in)
default:
processed = false
} }
processed = false
return return

} }


func (ss *openIDSessionData) serveTextCommand(in InWechatMsg) (processed bool) { func (ss *openIDSessionData) serveTextCommand(in InWechatMsg) (processed bool) {
cmd := in.body.(TextMsg).Content
if f, hasFunction := commandMap[cmd]; hasFunction {
return f(ss, in)
cmd := ""
if in.header.MsgType == "text" {
cmd = in.body.(TextMsg).Content
} else if in.header.MsgType == "voice" {
cmd = voice2Cmd(in.body.(VoiceMsg))
} }
if cmd == "所有命令" || cmd == "all command" {
return allCommand(ss, in)
if cmd != "" {
if f, hasFunction := commandMap[cmd]; hasFunction {
return f(ss, in)
}
if cmd == "所有命令" || cmd == "all command" {
return allCommand(ss, in)
}
} }
return false
return false //不认识的命令,我们选择这个信息不处理
} }


func allCommand(ss *openIDSessionData, in InWechatMsg) (processed bool) { func allCommand(ss *openIDSessionData, in InWechatMsg) (processed bool) {
} }


in.replyText(msg) in.replyText(msg)
in.replyText("Error")
return return
} }


procEcho.start(ss, in) procEcho.start(ss, in)
return return
} }

func voice2Cmd(v VoiceMsg) (cmd string) {
cmd = v.Recognition
cmd = strings.TrimSuffix(cmd, "。") //去掉末尾的标点符号,句号
return
}

Cargando…
Cancelar
Guardar