server_chat.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "bet24.com/log"
  6. "bet24.com/servers/coreservice/chat"
  7. "bet24.com/servers/coreservice/client"
  8. "github.com/pkg/errors"
  9. )
  10. func (s *Server) SendChatMsg(ctx context.Context, args *client.Request, reply *client.Reply) error {
  11. var req client.Chat_req
  12. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  13. log.Debug("Server.SendChatMsg unmarshal fail %v", err)
  14. return errors.New("unmarshal error")
  15. }
  16. ret := chat.SendChatMsg(req.ChannelID, req.SendUserID, req.FaceId, req.Sex, req.Vip, req.RecvUserID,
  17. req.NickName, req.FaceUrl, req.ChatMsg, req.IpAddress, req.MsgType, req.VipExpire)
  18. if ret {
  19. reply.Resp.RetCode = 1
  20. }
  21. return nil
  22. }
  23. func (s *Server) GetChatMsg(ctx context.Context, args *client.Request, reply *client.Reply) error {
  24. var req client.Chat_Msg_req
  25. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  26. log.Debug("Server.GetChatMsg unmarshal fail %v", err)
  27. return errors.New("unmarshal error")
  28. }
  29. reply.Resp.Data = chat.GetChatMsg(req.UserId, req.ChannelID)
  30. return nil
  31. }
  32. func (s *Server) SendChannelChat(ctx context.Context, args *client.Request, reply *client.Reply) error {
  33. var req client.ChannelChat_req
  34. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  35. log.Debug("Server.SendChannelChat unmarshal fail %v", err)
  36. return errors.New("unmarshal error")
  37. }
  38. reply.Resp.Data = chat.SendChannelChat(req.From, req.To, req.Message, req.MsgType)
  39. return nil
  40. }
  41. func (s *Server) SendGiftMessage(ctx context.Context, args *client.Request, reply *client.Reply) error {
  42. var req client.ChannelChat_req
  43. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  44. log.Debug("Server.SendGiftMessage unmarshal fail %v", err)
  45. return errors.New("unmarshal error")
  46. }
  47. reply.Resp.Data = chat.SendGiftMessage(req.From, req.To, req.Message)
  48. return nil
  49. }
  50. func (s *Server) GetChannelChat(ctx context.Context, args *client.Request, reply *client.Reply) error {
  51. var req client.GetChannelChat_req
  52. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  53. log.Debug("Server.GetChannelChat unmarshal fail %v", err)
  54. return errors.New("unmarshal error")
  55. }
  56. reply.Resp.Data = chat.GetChannelChat(req.ChannelKey, req.UserId)
  57. return nil
  58. }
  59. func (s *Server) GetChannelInfo(ctx context.Context, args *client.Request, reply *client.Reply) error {
  60. var req client.GetChannelChat_req
  61. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  62. log.Debug("Server.GetChannelInfo unmarshal fail %v", err)
  63. return errors.New("unmarshal error")
  64. }
  65. reply.Resp.Data = chat.GetChannelInfo(req.ChannelKey)
  66. return nil
  67. }
  68. func (s *Server) ClearChannelHistory(ctx context.Context, args *client.Request, reply *client.Reply) error {
  69. var req client.GetChannelChat_req
  70. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  71. log.Debug("Server.ClearChannelHistory unmarshal fail %v", err)
  72. return errors.New("unmarshal error")
  73. }
  74. chat.ClearChannelHistory(req.ChannelKey, req.UserId)
  75. return nil
  76. }
  77. func (s *Server) RemoveChannelChat(ctx context.Context, args *client.Request, reply *client.Reply) error {
  78. var req client.GetChannelChat_req
  79. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  80. log.Debug("Server.ClearChannelHistory unmarshal fail %v", err)
  81. return errors.New("unmarshal error")
  82. }
  83. chat.RemoveChannel(req.UserId, req.UserId2)
  84. return nil
  85. }
  86. // 获取机器人聊天列表
  87. func (s *Server) GetRobotChatList(ctx context.Context, args *client.Request, reply *client.Reply) error {
  88. list := chat.GetRobotChatList()
  89. d, _ := json.Marshal(list)
  90. reply.Resp.Data = string(d)
  91. return nil
  92. }
  93. // 获取机器人聊天信息
  94. func (s *Server) GetRobotChatInfo(ctx context.Context, args *client.Request, reply *client.Reply) error {
  95. var req client.Request_base
  96. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  97. log.Debug("Server.GetRobotChatInfo unmarshal fail %v", err)
  98. return errors.New("unmarshal error")
  99. }
  100. info := chat.GetRobotChatInfo(req.UserId)
  101. d, _ := json.Marshal(info)
  102. reply.Resp.Data = string(d)
  103. return nil
  104. }
  105. // 添加机器人聊天信息
  106. func (s *Server) AddRobotChatInfo(ctx context.Context, args *client.Request, reply *client.Reply) error {
  107. var req client.RobotChat_req
  108. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  109. log.Debug("Server.AddRobotChatInfo unmarshal fail %v", err)
  110. return errors.New("unmarshal error")
  111. }
  112. info := chat.AddRobotChatInfo(req.UserId, req.Msg, req.Seconds, req.BeginTime, req.EndTime)
  113. d, _ := json.Marshal(info)
  114. reply.Resp.Data = string(d)
  115. return nil
  116. }
  117. // 修改机器人聊天信息
  118. func (s *Server) UpdateRobotChatInfo(ctx context.Context, args *client.Request, reply *client.Reply) error {
  119. var req client.RobotChat_req
  120. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  121. log.Debug("Server.UpdateRobotChatInfo unmarshal fail %v", err)
  122. return errors.New("unmarshal error")
  123. }
  124. info := chat.UpdateRobotChatInfo(req.UserId, req.Msg, req.Seconds, req.BeginTime, req.EndTime)
  125. d, _ := json.Marshal(info)
  126. reply.Resp.Data = string(d)
  127. return nil
  128. }
  129. // 删除机器人聊天信息
  130. func (s *Server) DelRobotChatInfo(ctx context.Context, args *client.Request, reply *client.Reply) error {
  131. var req client.Request_base
  132. if err := json.Unmarshal([]byte(args.Data), &req); err != nil {
  133. log.Debug("Server.DelRobotChatInfo unmarshal fail %v", err)
  134. return errors.New("unmarshal error")
  135. }
  136. info := chat.DelRobotChatInfo(req.UserId)
  137. d, _ := json.Marshal(info)
  138. reply.Resp.Data = string(d)
  139. return nil
  140. }