Skip to content

Commit

Permalink
feat: 添加reply相关的rule
Browse files Browse the repository at this point in the history
  • Loading branch information
huoxue1 committed Oct 9, 2021
1 parent efdd041 commit 2671dbc
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 120 deletions.
116 changes: 3 additions & 113 deletions event.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Package leafBot
// @Description:
package leafBot

import (
Expand All @@ -16,95 +18,13 @@ import (

log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson"

"github.com/huoxue1/leafBot/message" //nolint:gci
//nolint:gci
)

var (
c = make(chan Event, 10)
)

type (
anonymous struct {
Id int `json:"id"`
Name string `json:"name"`
Flag string `json:"flag"`
}

Files struct {
Id string `json:"id"`
Name string `json:"name"`
Size int64 `json:"size"`
Busid int64 `json:"busid"`
FileUrl string `json:"url"`
}

Status struct {
AppEnabled bool `json:"app_enabled"`
AppGood bool `json:"app_good"`
AppInitialized bool `json:"app_initialized"`
Good bool `json:"good"`
Online bool `json:"online"`
PluginsGood interface{} `json:"plugins_good"`
Stat struct {
PacketReceived int `json:"packet_received"`
PacketSent int `json:"packet_sent"`
PacketLost int `json:"packet_lost"`
MessageReceived int `json:"message_received"`
MessageSent int `json:"message_sent"`
DisconnectTimes int `json:"disconnect_times"`
LostTimes int `json:"lost_times"`
LastMessageTime int `json:"last_message_time"`
} `json:"stat"`
}

MessageIds struct {
MessageID int32 `json:"message_id"`
}

Senders struct {
Age int `json:"age"`
Area string `json:"area"`
Card string `json:"card"`
Level string `json:"level"`
NickName string `json:"nickname"`
Role string `json:"role"`
Sex string `json:"sex"`
Title string `json:"title"`
UserId int `json:"user_id"`
}

Event struct {
Anonymous anonymous `json:"anonymous"`
Font int `json:"font"`
GroupId int `json:"group_id"`
Message message.Message `json:"message"`
MessageType string `json:"message_type"`
PostType string `json:"post_type"`
RawMessage string `json:"raw_message"`
SelfId int `json:"self_id"`
Sender Senders `json:"sender"`
SubType string `json:"sub_type"`
UserId int `json:"user_id"`
Time int `json:"time"`
NoticeType string `json:"notice_type"`
RequestType string `json:"request_type"`
Comment string `json:"comment"`
Flag string `json:"flag"`
OperatorId int `json:"operator_id"`
File Files `json:"file"`
Duration int64 `json:"duration"`
TargetId int64 `json:"target_id"` //运气王id
HonorType string `json:"honor_type"`
MetaEventType string `json:"meta_event_type"`
Status Status `json:"status"`
Interval int `json:"interval"`
CardNew string `json:"card_new"` //新名片
CardOld string `json:"card_old"` //旧名片
MessageIds
}
)

var ENABLE = false // 是否启用gui

var (
Expand Down Expand Up @@ -716,33 +636,3 @@ func GetBotById(id int) Api {
bots := driver.GetBot(int64(id))
return bots.(Api)
}

// GetMsg
/**
* @Description:
* @receiver e
* @return message.Message
*/
func (e Event) GetMsg() message.Message {
return e.Message
}

func (e Event) GetPlainText() string {
content := ""
for _, mes := range e.Message {
if mes.Type == "text" {
content += mes.Data["text"]
}
}
return content
}

func (e Event) GetImages() []message.MessageSegment {
var images []message.MessageSegment
for _, mes := range e.Message {
if mes.Type == "image" {
images = append(images, mes)
}
}
return images
}
114 changes: 114 additions & 0 deletions event_struct.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package leafBot

import "github.com/huoxue1/leafBot/message"

type (
anonymous struct {
Id int `json:"id"`
Name string `json:"name"`
Flag string `json:"flag"`
}

Files struct {
Id string `json:"id"`
Name string `json:"name"`
Size int64 `json:"size"`
Busid int64 `json:"busid"`
FileUrl string `json:"url"`
}

Status struct {
AppEnabled bool `json:"app_enabled"`
AppGood bool `json:"app_good"`
AppInitialized bool `json:"app_initialized"`
Good bool `json:"good"`
Online bool `json:"online"`
PluginsGood interface{} `json:"plugins_good"`
Stat struct {
PacketReceived int `json:"packet_received"`
PacketSent int `json:"packet_sent"`
PacketLost int `json:"packet_lost"`
MessageReceived int `json:"message_received"`
MessageSent int `json:"message_sent"`
DisconnectTimes int `json:"disconnect_times"`
LostTimes int `json:"lost_times"`
LastMessageTime int `json:"last_message_time"`
} `json:"stat"`
}

MessageIds struct {
MessageID int32 `json:"message_id"`
}

Senders struct {
Age int `json:"age"`
Area string `json:"area"`
Card string `json:"card"`
Level string `json:"level"`
NickName string `json:"nickname"`
Role string `json:"role"`
Sex string `json:"sex"`
Title string `json:"title"`
UserId int `json:"user_id"`
}

Event struct {
Anonymous anonymous `json:"anonymous"`
Font int `json:"font"`
GroupId int `json:"group_id"`
Message message.Message `json:"message"`
MessageType string `json:"message_type"`
PostType string `json:"post_type"`
RawMessage string `json:"raw_message"`
SelfId int `json:"self_id"`
Sender Senders `json:"sender"`
SubType string `json:"sub_type"`
UserId int `json:"user_id"`
Time int `json:"time"`
NoticeType string `json:"notice_type"`
RequestType string `json:"request_type"`
Comment string `json:"comment"`
Flag string `json:"flag"`
OperatorId int `json:"operator_id"`
File Files `json:"file"`
Duration int64 `json:"duration"`
TargetId int64 `json:"target_id"` //运气王id
HonorType string `json:"honor_type"`
MetaEventType string `json:"meta_event_type"`
Status Status `json:"status"`
Interval int `json:"interval"`
CardNew string `json:"card_new"` //新名片
CardOld string `json:"card_old"` //旧名片
MessageIds
}
)

// GetMsg
/**
* @Description:
* @receiver e
* @return message.Message
*/
func (e Event) GetMsg() message.Message {
return e.Message
}

func (e Event) GetPlainText() string {
content := ""
for _, mes := range e.Message {
if mes.Type == "text" {
content += mes.Data["text"]
}
}
return content
}

func (e Event) GetImages() []message.MessageSegment {
var images []message.MessageSegment
for _, mes := range e.Message {
if mes.Type == "image" {
images = append(images, mes)
}
}
return images
}
49 changes: 42 additions & 7 deletions rule.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
// Package leafBot
// @Description:
package leafBot

type (
Rule func(Event, Api, *State) bool
)
import "strconv"

// Rule
/*
rule类型
*/
type Rule func(Event, Api, *State) bool

// MustReply
/**
* @Description:
* @param event
* @param api
* @param state
* @return bool
* example
*/
func MustReply(event Event, api Api, state *State) bool {
for _, segment := range event.Message {
if segment.Type == "reply" {
state.Data["reply_id"] = segment.Data["id"]
id, err := strconv.Atoi(segment.Data["id"])
if err != nil {
return false
}
state.Data["reply_msg"] = api.GetMsg(int32(id))
return true
}
}
return false
}

// OnlyToMe
/**
Expand All @@ -14,11 +44,8 @@ type (
*/
func OnlyToMe(event Event, _ Api, state *State) bool {
b := state.Data["only_tome"].(bool)
if b {
return true
}

return false
return b
}

// OnlySuperUser
Expand All @@ -41,6 +68,14 @@ func OnlySuperUser(event Event, _ Api, _ *State) bool {
return false
}

// OnlyGroupMessage
/**
* @Description:
* @param event
* @param _
* @return bool
* example
*/
func OnlyGroupMessage(event Event, _ Api) bool {
return event.MessageType == "group"
}

0 comments on commit 2671dbc

Please sign in to comment.