send.go 904 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package api
  2. import (
  3. "fmt"
  4. "github.com/gorilla/websocket"
  5. )
  6. func (conn *WsBot) Send_private_msg(user_id int, message string) error {
  7. err := conn.Wsconn.WriteMessage(websocket.TextMessage,
  8. []byte(fmt.Sprintf(`
  9. {
  10. "action":"send_private_msg",
  11. "params":{
  12. "user_id":%d,
  13. "message":"%s"
  14. }
  15. }
  16. `, user_id, message)))
  17. return err
  18. }
  19. func (conn *WsBot) Send_group_msg(group_id int, message string) error {
  20. err := conn.Wsconn.WriteMessage(websocket.TextMessage,
  21. []byte(fmt.Sprintf(`
  22. {
  23. "action":"send_group_msg",
  24. "params":{
  25. "group_id":%d,
  26. "message":"%s"
  27. }
  28. }
  29. `, group_id, message)))
  30. return err
  31. }
  32. func (conn *WsBot) Send_like(user_id int, times int) error {
  33. err := conn.Wsconn.WriteMessage(websocket.TextMessage,
  34. []byte(fmt.Sprintf(`
  35. {
  36. "action":"send_like",
  37. "params":{
  38. "user_id":%d,
  39. "times":"%d"
  40. }
  41. }
  42. `, user_id, times)))
  43. return err
  44. }