This commit is contained in:
cdle
2023-07-06 09:22:52 +08:00
parent 5b5eee0718
commit 2f38b8393e
10 changed files with 93 additions and 74 deletions
+5 -5
View File
@@ -293,11 +293,11 @@ interface Sender {
getPlatform(): string; //获取消息平台 getPlatform(): string; //获取消息平台
getBotId(): string; //获取机器人ID getBotId(): string; //获取机器人ID
reply(content: string): string; //回复消息,媒体消息推荐使用CQ码实现,返回消息ID reply(content: string): string; //回复消息,媒体消息推荐使用CQ码实现,返回消息ID
recallMessage(meesageId: string | string[]): Promise<boolean>; //撤回消息 recallMessage(meesageId: string | string[] | number): {error: string}; //撤回消息number类型时为延时毫秒
kick(user_id: string): Promise<boolean>; //移出群聊 kick(user_id: string): {error: string}; //移出群聊
unkick(user_id: string): Promise<boolean>; //取消移出群聊 unkick(user_id: string): {error: string}; //取消移出群聊
ban(user_id: string, duration: number): Promise<boolean>; //禁言,并指定时长 ban(user_id: string, duration: number): {error: string}; //禁言,并指定时长
unban(user_id: string): Promise<boolean>; //取消禁言 unban(user_id: string): {error: string}; //取消禁言
} }
``` ```
+35 -11
View File
@@ -740,36 +740,60 @@ func (sender *CustomSender) Copy() common.Sender {
return &new return &new
} }
func (sender *CustomSender) RecallMessage(ps ...interface{}) error { func (sender *CustomSender) RecallMessage(ps ...interface{}) {
recalls := []func(){}
var timeout int
for _, p := range ps { for _, p := range ps {
switch p := p.(type) { switch p := p.(type) {
case int, int64:
timeout = utils.Int(p)
case string: case string:
sender.Reply(mystr.BuildCQCode("delete", H{"id": p}, "")) if p != "" {
recalls = append(recalls, func() {
sender.Reply(mystr.BuildCQCode("delete", H{"id": p}, ""))
})
}
case []string: case []string:
for _, v := range p { for _, v := range p {
sender.Reply(mystr.BuildCQCode("delete", H{"id": v}, "")) if v != "" {
recalls = append(recalls, func() {
sender.Reply(mystr.BuildCQCode("delete", H{"id": v}, ""))
})
}
} }
case [][]string: case [][]string:
for _, v := range p { for _, v := range p {
for _, v2 := range v { for _, v2 := range v {
sender.Reply(mystr.BuildCQCode("delete", H{"id": v2}, "")) recalls = append(recalls, func() {
sender.Reply(mystr.BuildCQCode("delete", H{"id": v2}, ""))
})
} }
} }
} }
} }
return nil go func() {
if timeout != 0 {
time.Sleep(time.Millisecond * time.Duration(timeout))
}
for _, recall := range recalls {
recall()
}
}()
} }
func (sender *CustomSender) GroupKick(uid string, reject_add_request bool) { func (sender *CustomSender) GroupKick(uid string, reject_add_request bool) error {
sender.Reply(mystr.BuildCQCode("kick", H{"user_id": uid, "chat_id": sender.GetChatID(), "forever": reject_add_request}, "")) _, err := sender.Reply(mystr.BuildCQCode("kick", H{"user_id": uid, "chat_id": sender.GetChatID(), "forever": reject_add_request}, ""))
return err
} }
func (sender *CustomSender) GroupBan(uid string, duration int) { func (sender *CustomSender) GroupBan(uid string, duration int) error {
sender.Reply(mystr.BuildCQCode("ban", H{"user_id": uid, "chat_id": sender.GetChatID(), "duration": duration}, "")) _, err := sender.Reply(mystr.BuildCQCode("ban", H{"user_id": uid, "chat_id": sender.GetChatID(), "duration": duration}, ""))
return err
} }
func (sender *CustomSender) GroupUnban(uid string) { func (sender *CustomSender) GroupUnban(uid string) error {
sender.Reply(mystr.BuildCQCode("ban", H{"user_id": uid, "chat_id": sender.GetChatID(), "duration": 0}, "")) _, err := sender.Reply(mystr.BuildCQCode("ban", H{"user_id": uid, "chat_id": sender.GetChatID(), "duration": 0}, ""))
return err
} }
func (sender *CustomSender) IsAdmin() bool { func (sender *CustomSender) IsAdmin() bool {
+1 -1
View File
@@ -8,6 +8,6 @@
</head> </head>
<body> <body>
<div id="root"></div> <div id="root"></div>
<script src="/admin/umi.b07a580e.js"></script> <script src="/admin/umi.37bf7c95.js"></script>
</body></html> </body></html>
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+14 -13
View File
@@ -140,12 +140,12 @@ func (sender *Faker) Copy() common.Sender {
return &new return &new
} }
func (sender *Faker) GroupKick(uid string, reject_add_request bool) { func (sender *Faker) GroupKick(uid string, reject_add_request bool) error {
return nil
} }
func (sender *Faker) GroupBan(uid string, duration int) { func (sender *Faker) GroupBan(uid string, duration int) error {
return nil
} }
type BaseSender struct { type BaseSender struct {
@@ -299,8 +299,8 @@ func (sender *BaseSender) GetMessageID() string {
return "" return ""
} }
func (sender *BaseSender) RecallMessage(...interface{}) error { func (sender *BaseSender) RecallMessage(...interface{}) {
return nil
} }
func (sender *BaseSender) GetUserID() string { func (sender *BaseSender) GetUserID() string {
@@ -316,19 +316,20 @@ func (sender *BaseSender) GetImType() string {
return "" return ""
} }
func (sender *BaseSender) GroupKick(uid string, reject_add_request bool) { func (sender *BaseSender) GroupKick(uid string, reject_add_request bool) error {
return nil
} }
func (sender *BaseSender) GroupUnkick(uid string) { func (sender *BaseSender) GroupUnkick(uid string) error {
return nil
} }
func (sender *BaseSender) GroupBan(uid string, duration int) { func (sender *BaseSender) GroupBan(uid string, duration int) error {
return nil
} }
func (sender *BaseSender) GroupUnban(uid string) { func (sender *BaseSender) GroupUnban(uid string) error {
return nil
} }
+5 -5
View File
@@ -6,7 +6,7 @@ type Sender interface {
GetBotID() string GetBotID() string
GetImType() string GetImType() string
GetMessageID() string GetMessageID() string
RecallMessage(...interface{}) error RecallMessage(...interface{})
GetUserName() string GetUserName() string
GetChatName() string GetChatName() string
IsReply() bool IsReply() bool
@@ -33,10 +33,10 @@ type Sender interface {
ClearContinue() ClearContinue()
Await(Sender, func(Sender) interface{}, ...interface{}) interface{} Await(Sender, func(Sender) interface{}, ...interface{}) interface{}
Copy() Sender Copy() Sender
GroupKick(uid string, reject_add_request bool) GroupKick(uid string, reject_add_request bool) error
GroupUnkick(uid string) GroupUnkick(uid string) error
GroupBan(uid string, duration int) GroupBan(uid string, duration int) error
GroupUnban(uid string) GroupUnban(uid string) error
AtLast() AtLast()
UAtLast() UAtLast()
IsAtLast() bool IsAtLast() bool
+19 -24
View File
@@ -151,24 +151,7 @@ func (sender *SenderJsIplm) GetPlatform() string {
return sender.Message.GetImType() return sender.Message.GetImType()
} }
func (sender *SenderJsIplm) RecallMessage(p ...interface{}) { func (sender *SenderJsIplm) RecallMessage(p ...interface{}) {
np := []interface{}{} sender.Message.RecallMessage(p...)
var i = 0
for _, v := range p {
switch v.(type) {
case int, int32, int64, uint, int16:
i = utils.Int(v)
default:
np = append(np, v)
}
}
if i != 0 {
go func() {
sleep(i)
sender.Message.RecallMessage(np...)
}()
} else {
go sender.Message.RecallMessage(np...)
}
} }
func (sender *SenderJsIplm) GetUserName() string { func (sender *SenderJsIplm) GetUserName() string {
return sender.Message.GetUserName() return sender.Message.GetUserName()
@@ -216,16 +199,28 @@ func (sender *SenderJsIplm) GetChatId() string {
return sender.Message.GetChatID() return sender.Message.GetChatID()
} }
func (sender *SenderJsIplm) Kick(uid string) { func (sender *SenderJsIplm) Kick(uid string) interface{} {
sender.Message.GroupKick(uid, false) err := sender.Message.GroupKick(uid, false)
if err != nil {
return err.Error()
}
return nil
} }
func (sender *SenderJsIplm) Unkick(uid string) { func (sender *SenderJsIplm) Unkick(uid string) interface{} {
sender.Message.GroupUnkick(uid) err := sender.Message.GroupUnkick(uid)
if err != nil {
return err.Error()
}
return nil
} }
func (sender *SenderJsIplm) Ban(uid string, duration int) { func (sender *SenderJsIplm) Ban(uid string, duration int) interface{} {
sender.Message.GroupBan(uid, duration) err := sender.Message.GroupBan(uid, duration)
if err != nil {
return err.Error()
}
return nil
} }
func (sender *SenderJsIplm) Param(i interface{}) string { func (sender *SenderJsIplm) Param(i interface{}) string {
+12 -13
View File
@@ -9,7 +9,6 @@ import (
"reflect" "reflect"
"strings" "strings"
"sync" "sync"
"time"
"github.com/Dreamacro/clash/adapter" "github.com/Dreamacro/clash/adapter"
C "github.com/Dreamacro/clash/constant" C "github.com/Dreamacro/clash/constant"
@@ -32,14 +31,14 @@ type ProxyConfig struct {
Rules []string `json:"rules"` Rules []string `json:"rules"`
Plugins []string `json:"plugins"` Plugins []string `json:"plugins"`
Cipher string `json:"cipher,omitempty"` // Cipher string `json:"cipher,omitempty"`
Username string `json:"username,omitempty"` // Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"` // Password string `json:"password,omitempty"`
SkipCertVerify bool `json:"skip-cert-verify,omitempty"` // SkipCertVerify bool `json:"skip-cert-verify,omitempty"`
TLS bool `json:"tls,omitempty"` // TLS bool `json:"tls,omitempty"`
CreatedAt int `json:"created_at,omitempty"` // CreatedAt int `json:"created_at,omitempty"`
Remark string `json:"remark,omitempty"` // Remark string `json:"remark,omitempty"`
Enable bool `json:"enable,omitempty"` Enable bool `json:"enable,omitempty"`
// UDP bool `json:"udp,omitempty"` // UDP bool `json:"udp,omitempty"`
// Plugin string `json:"plugin,omitempty"` // Plugin string `json:"plugin,omitempty"`
// PluginOpts map[string]string `json:"plugin-opts,omitempty"` // PluginOpts map[string]string `json:"plugin-opts,omitempty"`
@@ -187,10 +186,10 @@ func init() {
// Port: ncfg.Port, // Port: ncfg.Port,
// } // }
} }
if ncfg.CreatedAt == 0 { // if ncfg.CreatedAt == 0 {
ncfg.CreatedAt = int(time.Now().Unix()) // ncfg.CreatedAt = int(time.Now().Unix())
new = "o:" + string(utils.JsonMarshal(ncfg)) // new = "o:" + string(utils.JsonMarshal(ncfg))
} // }
// ov, ok := Proxies.Load(nkey) // ov, ok := Proxies.Load(nkey)
// if ok && (!IsDifferent(ocfg, ncfg, []string{"Name", "UUID", "Rules", "Plugins"}) || checkProxy(ov.(C.Proxy))) { //代理依旧有效 // if ok && (!IsDifferent(ocfg, ncfg, []string{"Name", "UUID", "Rules", "Plugins"}) || checkProxy(ov.(C.Proxy))) { //代理依旧有效
// return nil // return nil