You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.5KB

  1. package main
  2. import (
  3. "fmt"
  4. "time"
  5. )
  6. type commandFunction func(*openIDSessionData, InWechatMsg) bool
  7. var commandMap = map[string]commandFunction{
  8. "版本信息": cmdVersion,
  9. "version": cmdVersion,
  10. //"所有命令": allCommand, //include it will cause initialization loop
  11. "echo": cmdEcho,
  12. "回音": cmdEcho,
  13. }
  14. func (ss *openIDSessionData) serveCommand(in InWechatMsg) (processed bool) {
  15. if in.header.MsgType == "text" {
  16. return ss.serveTextCommand(in)
  17. }
  18. processed = false
  19. return
  20. }
  21. func (ss *openIDSessionData) serveTextCommand(in InWechatMsg) (processed bool) {
  22. cmd := in.body.(TextMsg).Content
  23. if f, hasFunction := commandMap[cmd]; hasFunction {
  24. return f(ss, in)
  25. }
  26. if cmd == "所有命令" || cmd == "all command" {
  27. return allCommand(ss, in)
  28. }
  29. return false
  30. }
  31. func allCommand(ss *openIDSessionData, in InWechatMsg) (processed bool) {
  32. processed = true
  33. msg := "命令如下:\n"
  34. count := 0
  35. for k := range commandMap {
  36. count++
  37. msg = msg + fmt.Sprintf("%0d : %s \n", count, k)
  38. }
  39. in.replyText(msg)
  40. return
  41. }
  42. func cmdVersion(ss *openIDSessionData, in InWechatMsg) (processed bool) {
  43. processed = true
  44. in.replyText("这是测试版本" + time.Now().Format("2006/01/02 03:04:05"))
  45. return
  46. }
  47. func cmdEcho(ss *openIDSessionData, in InWechatMsg) (processed bool) {
  48. processed = true
  49. in.replyText("请输入不同类型的微信信息,比如文字,图片,视频,地址,链接,我们将原样回应您")
  50. procEcho.init(ss)
  51. procEcho.intro(ss)
  52. procEcho.start(ss, in)
  53. return
  54. }