Skip to content

Commit

Permalink
重写QQ消息处理方法,提高稳定性
Browse files Browse the repository at this point in the history
  • Loading branch information
nyancatda committed Nov 18, 2021
1 parent 9ba9a32 commit 14363d8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
39 changes: 24 additions & 15 deletions src/InformationProcessing/QQMessageProcessing.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package InformationProcessing

import (
"math"
"strconv"
"strings"

"xyz.nyan/ShionBot/src/MediaWikiAPI"
"xyz.nyan/ShionBot/src/MessagePushAPI"
"xyz.nyan/ShionBot/src/Plugin/GetWikiInfo"
"xyz.nyan/ShionBot/src/Plugin/Command"
"xyz.nyan/ShionBot/src/Plugin/GetWikiInfo"
"xyz.nyan/ShionBot/src/Struct"
"xyz.nyan/ShionBot/src/utils"
"xyz.nyan/ShionBot/src/utils/Language"
Expand Down Expand Up @@ -68,30 +67,40 @@ func QQNudgeEventMessageProcessing(json Struct.WebHookJson) {
func QQMessageProcessing(json Struct.WebHookJson) {
switch json.Type {
case "GroupMessage":
if json.MessageChain[1].(map[string]interface{})["type"] == "Plain" {
text := json.MessageChain[1].(map[string]interface{})["text"]
find, QueryText, Command := CommandExtraction(sns_name_qq, json, text.(string))
//不处理非正常消息
if len(json.MessageChain) < 2 {
return
}
if json.MessageChain[1].Type == "Plain" {
text := json.MessageChain[1].Text
find, QueryText, Command := CommandExtraction(sns_name_qq, json, text)
if find {
GroupID := strconv.Itoa(json.Sender.Group.Id)
quoteID := strconv.Itoa(int(math.Floor(json.MessageChain[0].(map[string]interface{})["id"].(float64))))
quoteID := strconv.Itoa(json.MessageChain[0].Id)
UserID := strconv.Itoa(json.Sender.Id)
MessagePushAPI.SendNudge(json.Sender.Id, json.Sender.Group.Id, "Group")
QQsendGroupWikiInfo(json, UserID, Command, GroupID, QueryText, quoteID)
}
}
case "FriendMessage":
if json.MessageChain[1].(map[string]interface{})["type"] == "Plain" {
text := json.MessageChain[1].(map[string]interface{})["text"]
find, QueryText, Command := CommandExtraction(sns_name_qq, json, text.(string))
if len(json.MessageChain) < 2 {
return
}
if json.MessageChain[1].Type == "Plain" {
text := json.MessageChain[1].Text
find, QueryText, Command := CommandExtraction(sns_name_qq, json, text)
if find {
UserID := strconv.Itoa(json.Sender.Id)
QQsendFriendWikiInfo(json, Command, UserID, QueryText)
}
}
case "TempMessage":
if json.MessageChain[1].(map[string]interface{})["type"] == "Plain" {
text := json.MessageChain[1].(map[string]interface{})["text"]
find, QueryText, Command := CommandExtraction(sns_name_qq, json, text.(string))
if len(json.MessageChain) < 2 {
return
}
if json.MessageChain[1].Type == "Plain" {
text := json.MessageChain[1].Text
find, QueryText, Command := CommandExtraction(sns_name_qq, json, text)
if find {
UserID := strconv.Itoa(json.Sender.Id)
GroupID := json.Sender.Group.Id
Expand All @@ -105,16 +114,16 @@ func QQMessageProcessing(json Struct.WebHookJson) {

//设置消息返回
func QQSettingsMessageProcessing(json Struct.WebHookJson) {
text := json.MessageChain[1].(map[string]interface{})["text"]
countSplit := strings.Split(text.(string), "/")
text := json.MessageChain[1].Text
countSplit := strings.Split(text, "/")
Text := countSplit[1]
Message, Bool := Command.Command(sns_name_qq, json, Text)
if Bool {
UserID := strconv.Itoa(json.Sender.Id)
switch json.Type {
case "GroupMessage":
GroupID := strconv.Itoa(json.Sender.Group.Id)
quoteID := strconv.Itoa(int(math.Floor(json.MessageChain[0].(map[string]interface{})["id"].(float64))))
quoteID := strconv.Itoa(json.MessageChain[0].Id)
MessagePushAPI.SendMessage(sns_name_qq, "Group", UserID, GroupID, Message, true, quoteID, "", 0)
case "FriendMessage":
UserID := strconv.Itoa(json.Sender.Id)
Expand Down
18 changes: 12 additions & 6 deletions src/Struct/WebHook.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package Struct

type WebHookJson struct {
//QQ
Type string `json:"type"`
Sender Sender `json:"sender"`
FromId int `json:"fromId"`
Target int `json:"target"`
MessageChain []interface{} `json:"messageChain"`
Subject Subject `json:"subject"`
Type string `json:"type"`
Sender Sender `json:"sender"`
FromId int `json:"fromId"`
Target int `json:"target"`
MessageChain []MessageChain `json:"messageChain"`
Subject Subject `json:"subject"`

//Telegram
Update_id int `json:"update_id"`
Expand Down Expand Up @@ -40,6 +40,12 @@ type Group struct {
Id int `json:"id"`
Name string `json:"name"`
}
type MessageChain struct {
Type string `json:"type"`
Id int `json:"id"`
Time int `json:"time"`
Text string `json:"text"`
}
type Subject struct {
Id int `json:"id"`
Kind string `json:"kind"`
Expand Down

0 comments on commit 14363d8

Please sign in to comment.