x
This commit is contained in:
+22
-22
@@ -31,7 +31,7 @@ type Details struct {
|
|||||||
type CustomSender struct {
|
type CustomSender struct {
|
||||||
BaseSender
|
BaseSender
|
||||||
details Details
|
details Details
|
||||||
f *Factory
|
F *Factory
|
||||||
}
|
}
|
||||||
|
|
||||||
type MsgChan struct {
|
type MsgChan struct {
|
||||||
@@ -203,7 +203,7 @@ func (f *Factory) Init(botplt, botid string, params map[string]interface{}) {
|
|||||||
f.botid = botid
|
f.botid = botid
|
||||||
f.msgChan = make(chan MsgChan, 100000)
|
f.msgChan = make(chan MsgChan, 100000)
|
||||||
f.demo = &CustomSender{
|
f.demo = &CustomSender{
|
||||||
f: f,
|
F: f,
|
||||||
}
|
}
|
||||||
if v, ok := Bots[[2]string{botplt, botid}]; ok {
|
if v, ok := Bots[[2]string{botplt, botid}]; ok {
|
||||||
if v.uuid != f.uuid {
|
if v.uuid != f.uuid {
|
||||||
@@ -643,7 +643,7 @@ func (sender *CustomSender) GetChatID() string {
|
|||||||
return sender.details.ChatID
|
return sender.details.ChatID
|
||||||
}
|
}
|
||||||
func (sender *CustomSender) GetImType() string {
|
func (sender *CustomSender) GetImType() string {
|
||||||
return sender.f.botplt
|
return sender.F.botplt
|
||||||
}
|
}
|
||||||
func (sender *CustomSender) GetUserName() string {
|
func (sender *CustomSender) GetUserName() string {
|
||||||
return sender.details.Username
|
return sender.details.Username
|
||||||
@@ -665,16 +665,16 @@ func (sender *CustomSender) GetReplySenderUserID() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sender *CustomSender) GetBotID() string {
|
func (sender *CustomSender) GetBotID() string {
|
||||||
return sender.f.botid
|
return sender.F.botid
|
||||||
}
|
}
|
||||||
|
|
||||||
type PUSH string
|
type PUSH string
|
||||||
|
|
||||||
func (sender *CustomSender) Action(options map[string]interface{}) (interface{}, error) {
|
func (sender *CustomSender) Action(options map[string]interface{}) (interface{}, error) {
|
||||||
if sender.f.action != nil {
|
if sender.F.action != nil {
|
||||||
return sender.f.action(options), nil
|
return sender.F.action(options), nil
|
||||||
}
|
}
|
||||||
var platform = sender.f.botplt
|
var platform = sender.F.botplt
|
||||||
var any *common.Function
|
var any *common.Function
|
||||||
var one *common.Function
|
var one *common.Function
|
||||||
var result interface{}
|
var result interface{}
|
||||||
@@ -683,7 +683,7 @@ func (sender *CustomSender) Action(options map[string]interface{}) (interface{},
|
|||||||
if function.Reply != nil && function.Reply.Platform == platform {
|
if function.Reply != nil && function.Reply.Platform == platform {
|
||||||
if len(function.Reply.BotsID) == 0 {
|
if len(function.Reply.BotsID) == 0 {
|
||||||
any = function
|
any = function
|
||||||
} else if Contains(function.Reply.BotsID, sender.f.botid) {
|
} else if Contains(function.Reply.BotsID, sender.F.botid) {
|
||||||
one = function
|
one = function
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -711,7 +711,7 @@ func (sender *CustomSender) Action(options map[string]interface{}) (interface{},
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
vm.Set("action", proxy)
|
vm.Set("action", proxy)
|
||||||
vm.Set("adapter", sender.f)
|
vm.Set("adapter", sender.F)
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -720,8 +720,8 @@ func (sender *CustomSender) Action(options map[string]interface{}) (interface{},
|
|||||||
|
|
||||||
func (sender *CustomSender) Reply(msgs ...interface{}) (string, error) {
|
func (sender *CustomSender) Reply(msgs ...interface{}) (string, error) {
|
||||||
var push = false
|
var push = false
|
||||||
var platform = sender.f.botplt
|
var platform = sender.F.botplt
|
||||||
var bot_id = sender.f.botid
|
var bot_id = sender.F.botid
|
||||||
var args = []interface{}{}
|
var args = []interface{}{}
|
||||||
for _, item := range msgs {
|
for _, item := range msgs {
|
||||||
switch item := item.(type) {
|
switch item := item.(type) {
|
||||||
@@ -761,8 +761,8 @@ func (sender *CustomSender) Reply(msgs ...interface{}) (string, error) {
|
|||||||
for k, v := range sender.GetExpandMessageInfo() {
|
for k, v := range sender.GetExpandMessageInfo() {
|
||||||
msg[k] = v
|
msg[k] = v
|
||||||
}
|
}
|
||||||
if sender.f.umod { //订阅号模式
|
if sender.F.umod { //订阅号模式
|
||||||
v, loaded := sender.f.gmsgChan.LoadOrStore(user_id, &GMsgChan{})
|
v, loaded := sender.F.gmsgChan.LoadOrStore(user_id, &GMsgChan{})
|
||||||
ch := v.(*GMsgChan)
|
ch := v.(*GMsgChan)
|
||||||
if !loaded {
|
if !loaded {
|
||||||
// console.Debug("发送创建:", ch.Chan)
|
// console.Debug("发送创建:", ch.Chan)
|
||||||
@@ -781,14 +781,14 @@ func (sender *CustomSender) Reply(msgs ...interface{}) (string, error) {
|
|||||||
}
|
}
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
if sender.f.reply == nil { //未设置回复函数
|
if sender.F.reply == nil { //未设置回复函数
|
||||||
var any *common.Function
|
var any *common.Function
|
||||||
var one *common.Function
|
var one *common.Function
|
||||||
for _, function := range Functions {
|
for _, function := range Functions {
|
||||||
if function.Reply != nil && function.Reply.Platform == platform {
|
if function.Reply != nil && function.Reply.Platform == platform {
|
||||||
if len(function.Reply.BotsID) == 0 {
|
if len(function.Reply.BotsID) == 0 {
|
||||||
any = function
|
any = function
|
||||||
} else if Contains(function.Reply.BotsID, sender.f.botid) {
|
} else if Contains(function.Reply.BotsID, sender.F.botid) {
|
||||||
one = function
|
one = function
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -813,7 +813,7 @@ func (sender *CustomSender) Reply(msgs ...interface{}) (string, error) {
|
|||||||
})
|
})
|
||||||
vm.Set("msg", proxy)
|
vm.Set("msg", proxy)
|
||||||
vm.Set("message", proxy)
|
vm.Set("message", proxy)
|
||||||
vm.Set("adapter", sender.f)
|
vm.Set("adapter", sender.F)
|
||||||
})
|
})
|
||||||
return message_id, nil
|
return message_id, nil
|
||||||
} else { //存储消息
|
} else { //存储消息
|
||||||
@@ -821,10 +821,10 @@ func (sender *CustomSender) Reply(msgs ...interface{}) (string, error) {
|
|||||||
Msg: msg,
|
Msg: msg,
|
||||||
Chan: make(chan string),
|
Chan: make(chan string),
|
||||||
}
|
}
|
||||||
if sender.f.destroid {
|
if sender.F.destroid {
|
||||||
return "", errors.New("adapter destroid")
|
return "", errors.New("adapter destroid")
|
||||||
}
|
}
|
||||||
sender.f.msgChan <- c
|
sender.F.msgChan <- c
|
||||||
select {
|
select {
|
||||||
case id := <-c.Chan:
|
case id := <-c.Chan:
|
||||||
return id, nil
|
return id, nil
|
||||||
@@ -835,7 +835,7 @@ func (sender *CustomSender) Reply(msgs ...interface{}) (string, error) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//todo 阻塞延迟异常
|
//todo 阻塞延迟异常
|
||||||
v := sender.f.reply(msg)
|
v := sender.F.reply(msg)
|
||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -930,10 +930,10 @@ func (sender *CustomSender) GroupUnban(uid string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sender *CustomSender) IsAdmin() bool {
|
func (sender *CustomSender) IsAdmin() bool {
|
||||||
if sender.f.isAdmin == nil {
|
if sender.F.isAdmin == nil {
|
||||||
return Contains(strings.Split(MakeBucket(sender.f.botplt).GetString("masters"), "&"), sender.GetUserID())
|
return Contains(strings.Split(MakeBucket(sender.F.botplt).GetString("masters"), "&"), sender.GetUserID())
|
||||||
}
|
}
|
||||||
return sender.f.isAdmin(sender.GetUserID())
|
return sender.F.isAdmin(sender.GetUserID())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sender *CustomSender) GetID() string {
|
func (sender *CustomSender) GetID() string {
|
||||||
|
|||||||
+123
-6
@@ -111,6 +111,19 @@ func initNodePlugins() {
|
|||||||
} else {
|
} else {
|
||||||
// fmt.Println("非插件目录", event.Name)
|
// fmt.Println("非插件目录", event.Name)
|
||||||
}
|
}
|
||||||
|
tf := event.Name + "/node_modules/sillygirl.d.ts"
|
||||||
|
ti := event.Name + "/main.js"
|
||||||
|
if _, err := os.Stat(tf); err != nil {
|
||||||
|
os.Mkdir(event.Name+"/node_modules", 0700)
|
||||||
|
os.WriteFile(tf, []byte(typeat), 0700)
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
if _, err := os.Stat(ti); err != nil {
|
||||||
|
os.Mkdir(event.Name+"/node_modules", 0700)
|
||||||
|
os.WriteFile(ti, []byte(defaultScript(plugin_name)), 0700)
|
||||||
|
}
|
||||||
|
}()
|
||||||
} else if plugin_index {
|
} else if plugin_index {
|
||||||
// fmt.Println("增加插件", event.Name)
|
// fmt.Println("增加插件", event.Name)
|
||||||
// RemNodePlugin(plugin_name)
|
// RemNodePlugin(plugin_name)
|
||||||
@@ -207,8 +220,6 @@ func AddNodePlugin(path, name string) error {
|
|||||||
cmd := exec.Command("./node", path)
|
cmd := exec.Command("./node", path)
|
||||||
cmd.Dir = utils.ExecPath + "/language/node"
|
cmd.Dir = utils.ExecPath + "/language/node"
|
||||||
// cmd := exec.Command(utils.ExecPath+"/language/node/node", path)
|
// cmd := exec.Command(utils.ExecPath+"/language/node/node", path)
|
||||||
id := s.SetID()
|
|
||||||
cmd.Env = append(cmd.Env, "SENDER_ID="+id)
|
|
||||||
cmd.Env = append(cmd.Env, "PLUGIN_ID="+uuid)
|
cmd.Env = append(cmd.Env, "PLUGIN_ID="+uuid)
|
||||||
// 获取标准输出和标准错误输出的管道
|
// 获取标准输出和标准错误输出的管道
|
||||||
stdout, err := cmd.StdoutPipe()
|
stdout, err := cmd.StdoutPipe()
|
||||||
@@ -221,10 +232,6 @@ func AddNodePlugin(path, name string) error {
|
|||||||
// fmt.Printf("获取标准错误输出管道失败:%v\n", err)
|
// fmt.Printf("获取标准错误输出管道失败:%v\n", err)
|
||||||
// os.Exit(1)
|
// os.Exit(1)
|
||||||
}
|
}
|
||||||
err = cmd.Start()
|
|
||||||
if err != nil {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// file, err := os.Create("output.log")
|
// file, err := os.Create("output.log")
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
@@ -260,6 +267,12 @@ func AddNodePlugin(path, name string) error {
|
|||||||
}()
|
}()
|
||||||
processes.Store(cmd, s)
|
processes.Store(cmd, s)
|
||||||
if (plt) != "*" {
|
if (plt) != "*" {
|
||||||
|
id := s.SetID()
|
||||||
|
cmd.Env = append(cmd.Env, "SENDER_ID="+id)
|
||||||
|
err = cmd.Start()
|
||||||
|
if err != nil {
|
||||||
|
|
||||||
|
}
|
||||||
senders.Store(id, s)
|
senders.Store(id, s)
|
||||||
defer senders.Delete(id)
|
defer senders.Delete(id)
|
||||||
defer processes.Delete(cmd)
|
defer processes.Delete(cmd)
|
||||||
@@ -269,6 +282,10 @@ func AddNodePlugin(path, name string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
err = cmd.Start()
|
||||||
|
if err != nil {
|
||||||
|
|
||||||
|
}
|
||||||
processes.Range(func(key, value any) bool {
|
processes.Range(func(key, value any) bool {
|
||||||
p := key.(*exec.Cmd)
|
p := key.(*exec.Cmd)
|
||||||
if p == cmd {
|
if p == cmd {
|
||||||
@@ -296,3 +313,103 @@ func AddNodePlugin(path, name string) error {
|
|||||||
AddCommand([]*common.Function{f})
|
AddCommand([]*common.Function{f})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var typeat = `declare class Sender {
|
||||||
|
uuid: string;
|
||||||
|
private destoried;
|
||||||
|
constructor(uuid: string);
|
||||||
|
destructor(): void;
|
||||||
|
getUserId(): Promise<string | undefined>;
|
||||||
|
getUserName(): Promise<string | undefined>;
|
||||||
|
getChatId(): Promise<string | undefined>;
|
||||||
|
getChatName(): Promise<string | undefined>;
|
||||||
|
getMessageId(): Promise<string | undefined>;
|
||||||
|
getPlatform(): Promise<string | undefined>;
|
||||||
|
getBotId(): Promise<string | undefined>;
|
||||||
|
getContent(): Promise<string | undefined>;
|
||||||
|
param(key: number | string): Promise<string>;
|
||||||
|
setContent(content: string): Promise<undefined>;
|
||||||
|
continue(): Promise<undefined>;
|
||||||
|
getAdapter(): Promise<Adapter>;
|
||||||
|
listen(options?: {
|
||||||
|
rules?: string[];
|
||||||
|
timeout?: number;
|
||||||
|
handle?: (s: Sender) => Promise<string | void> | string | void;
|
||||||
|
listen_private?: boolean;
|
||||||
|
listen_group?: boolean;
|
||||||
|
allow_platforms?: string[];
|
||||||
|
prohibit_platforms?: string[];
|
||||||
|
allow_groups?: string[];
|
||||||
|
prohibit_groups?: string[];
|
||||||
|
allow_users?: string[];
|
||||||
|
prohibit_users?: string[];
|
||||||
|
persistent?: boolean;
|
||||||
|
}): Promise<Sender>;
|
||||||
|
holdOn(str: string): string;
|
||||||
|
reply(content: string): Promise<string | undefined>;
|
||||||
|
action(options: any): Promise<any | undefined>;
|
||||||
|
event(): Promise<any | undefined>;
|
||||||
|
}
|
||||||
|
declare class Bucket {
|
||||||
|
name: string;
|
||||||
|
constructor(name: string);
|
||||||
|
transform(v: string | undefined): string | number | boolean | undefined;
|
||||||
|
reverseTransform(value: any): string;
|
||||||
|
get(key: string, defaultValue?: any): Promise<any>;
|
||||||
|
set(key: string, value: any): Promise<{
|
||||||
|
message?: string;
|
||||||
|
changed?: boolean;
|
||||||
|
}>;
|
||||||
|
getAll(): Promise<any>;
|
||||||
|
delete(): Promise<undefined>;
|
||||||
|
keys(): Promise<string[] | undefined>;
|
||||||
|
len(): Promise<number | undefined>;
|
||||||
|
buckets(): Promise<string[] | undefined>;
|
||||||
|
watch(key: string, handle: (old: any, now: any, key: string) => StorageFinal | void | any): void;
|
||||||
|
_name(): Promise<string>;
|
||||||
|
}
|
||||||
|
interface StorageFinal {
|
||||||
|
echo?: string;
|
||||||
|
now?: any;
|
||||||
|
message?: string;
|
||||||
|
error?: string;
|
||||||
|
}
|
||||||
|
interface Message {
|
||||||
|
message_id?: string;
|
||||||
|
user_id: string;
|
||||||
|
chat_id?: string;
|
||||||
|
content: string;
|
||||||
|
user_name?: string;
|
||||||
|
chat_name?: string;
|
||||||
|
}
|
||||||
|
declare class Adapter {
|
||||||
|
platform: string | undefined;
|
||||||
|
bot_id: string | undefined;
|
||||||
|
call: any;
|
||||||
|
constructor(options: {
|
||||||
|
platform?: string;
|
||||||
|
bot_id?: string;
|
||||||
|
replyHandler?: (message: Message) => string | undefined;
|
||||||
|
actionHandler?: (message: Message) => string | undefined;
|
||||||
|
});
|
||||||
|
setActionHandler(func: (action: {}) => any): void;
|
||||||
|
receive(message: Message): Promise<Sender>;
|
||||||
|
push(message: Message): Promise<string>;
|
||||||
|
destroy(): Promise<void>;
|
||||||
|
sender(options: any): Promise<Sender>;
|
||||||
|
}
|
||||||
|
declare let sender: Sender;
|
||||||
|
declare function sleep(ms: number | undefined): Promise<unknown>;
|
||||||
|
export { Adapter, Bucket, sender, sleep };
|
||||||
|
`
|
||||||
|
|
||||||
|
func defaultScript(title string) string {
|
||||||
|
create_at := time.Now().Format("2006-01-02 15:04:05")
|
||||||
|
return `/**
|
||||||
|
* @title ` + title + `
|
||||||
|
* @create_at ` + create_at + `
|
||||||
|
* @description 🐒这个人很懒什么都没有留下
|
||||||
|
* @author ` + sillyGirl.GetString("author", "佚名") + `
|
||||||
|
* @version v1.0.0
|
||||||
|
*/`
|
||||||
|
}
|
||||||
|
|||||||
+5
-1
@@ -34,14 +34,16 @@ var senders sync.Map
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
func GetSender(uuid string) (common.Sender, error) {
|
func GetSender(uuid string) (common.Sender, error) {
|
||||||
|
|
||||||
if uuid == "" {
|
if uuid == "" {
|
||||||
return &CustomSender{
|
return &CustomSender{
|
||||||
f: &Factory{
|
F: &Factory{
|
||||||
botid: "*",
|
botid: "*",
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
v, ok := senders.Load(uuid)
|
v, ok := senders.Load(uuid)
|
||||||
|
fmt.Println("uuid", uuid, v, ok)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("not found sender")
|
return nil, errors.New("not found sender")
|
||||||
}
|
}
|
||||||
@@ -138,6 +140,7 @@ func (sg *SillyGirlService) SenderListen(stream srpc.SillyGirlService_SenderList
|
|||||||
// defer fmt.Println("已关闭,", "===")
|
// defer fmt.Println("已关闭,", "===")
|
||||||
for {
|
for {
|
||||||
req, err := stream.Recv()
|
req, err := stream.Recv()
|
||||||
|
|
||||||
// fmt.Println("carry", carry, err)
|
// fmt.Println("carry", carry, err)
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
break // 如果流已经关闭,则退出循环
|
break // 如果流已经关闭,则退出循环
|
||||||
@@ -146,6 +149,7 @@ func (sg *SillyGirlService) SenderListen(stream srpc.SillyGirlService_SenderList
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if carry != nil {
|
if carry != nil {
|
||||||
|
fmt.Println("req.Uuid", req.Uuid)
|
||||||
echo := req.GetUuid()
|
echo := req.GetUuid()
|
||||||
value := req.GetValue()
|
value := req.GetValue()
|
||||||
// fmt.Println("echo", echo, "value", value)
|
// fmt.Println("echo", echo, "value", value)
|
||||||
|
|||||||
+1
-2
@@ -115,7 +115,7 @@ func initPlugins() {
|
|||||||
if p.UUID != key {
|
if p.UUID != key {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if p.Type != "goja" { //下载目录插件
|
if p.Type != "goja" && p.Type != "" { //下载目录插件
|
||||||
// Content-Type
|
// Content-Type
|
||||||
var prefix = "?uuid=" + p.UUID
|
var prefix = "?uuid=" + p.UUID
|
||||||
address := p.Address
|
address := p.Address
|
||||||
@@ -149,7 +149,6 @@ func initPlugins() {
|
|||||||
Error: err,
|
Error: err,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Println(zipfile)
|
|
||||||
defer os.Remove(zipfile)
|
defer os.Remove(zipfile)
|
||||||
if err := unzip(zipfile, 0755); err != nil {
|
if err := unzip(zipfile, 0755); err != nil {
|
||||||
return &storage.Final{
|
return &storage.Final{
|
||||||
|
|||||||
+19
-2
@@ -7,6 +7,7 @@ import (
|
|||||||
"embed"
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@@ -100,8 +101,10 @@ func initWeb() {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// 将路径转换为相对路径
|
// 将路径转换为相对路径
|
||||||
|
|
||||||
relPath, err := filepath.Rel(dir, path)
|
relPath, err := filepath.Rel(dir, path)
|
||||||
relPath = name + "/" + relPath
|
relPath = name + "/" + relPath
|
||||||
|
is_index := relPath == "main.js"
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -124,8 +127,22 @@ func initWeb() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if is_index {
|
||||||
_, err = io.Copy(wr, file)
|
var data []byte
|
||||||
|
data, err = ioutil.ReadAll(file)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
su := &ScriptUtils{
|
||||||
|
script: string(data),
|
||||||
|
}
|
||||||
|
if su.GetValue("public") == "true" {
|
||||||
|
su.SetValue("public", "false")
|
||||||
|
}
|
||||||
|
_, err = wr.Write([]byte(su.script))
|
||||||
|
} else {
|
||||||
|
_, err = io.Copy(wr, file)
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -65,14 +65,22 @@ func main() {
|
|||||||
if t {
|
if t {
|
||||||
core.Logs.Info("Terminal机器人已连接")
|
core.Logs.Info("Terminal机器人已连接")
|
||||||
scanner := bufio.NewScanner(os.Stdin)
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
|
a := &core.Factory{}
|
||||||
|
a.Init("terminal", "default", nil)
|
||||||
|
a.SetReplyHandler(func(m map[string]interface{}) string {
|
||||||
|
fmt.Printf("\x1b[%dm%s \x1b[0m\n", 31, m[core.CONETNT])
|
||||||
|
return ""
|
||||||
|
})
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
data := scanner.Text()
|
data := scanner.Text()
|
||||||
f := &core.Faker{
|
s := &core.CustomSender{
|
||||||
Type: "terminal",
|
// Type: "terminal",
|
||||||
Message: string(data),
|
// Message: string(data),
|
||||||
Admin: true,
|
// Admin: true,
|
||||||
|
F: a,
|
||||||
}
|
}
|
||||||
core.Messages <- f
|
s.SetContent(data)
|
||||||
|
core.Messages <- s
|
||||||
}
|
}
|
||||||
core.Logs.Info("Terminal机器人异常,请检查运行环境设置,如果是docker环境,请附加-it参数")
|
core.Logs.Info("Terminal机器人异常,请检查运行环境设置,如果是docker环境,请附加-it参数")
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Vendored
+87
@@ -0,0 +1,87 @@
|
|||||||
|
declare class Sender {
|
||||||
|
uuid: string;
|
||||||
|
private destoried;
|
||||||
|
constructor(uuid: string);
|
||||||
|
destructor(): void;
|
||||||
|
getUserId(): Promise<string | undefined>;
|
||||||
|
getUserName(): Promise<string | undefined>;
|
||||||
|
getChatId(): Promise<string | undefined>;
|
||||||
|
getChatName(): Promise<string | undefined>;
|
||||||
|
getMessageId(): Promise<string | undefined>;
|
||||||
|
getPlatform(): Promise<string | undefined>;
|
||||||
|
getBotId(): Promise<string | undefined>;
|
||||||
|
getContent(): Promise<string | undefined>;
|
||||||
|
param(key: number | string): Promise<string>;
|
||||||
|
setContent(content: string): Promise<undefined>;
|
||||||
|
continue(): Promise<undefined>;
|
||||||
|
getAdapter(): Promise<Adapter>;
|
||||||
|
listen(options?: {
|
||||||
|
rules?: string[];
|
||||||
|
timeout?: number;
|
||||||
|
handle?: (s: Sender) => Promise<string | void> | string | void;
|
||||||
|
listen_private?: boolean;
|
||||||
|
listen_group?: boolean;
|
||||||
|
allow_platforms?: string[];
|
||||||
|
prohibit_platforms?: string[];
|
||||||
|
allow_groups?: string[];
|
||||||
|
prohibit_groups?: string[];
|
||||||
|
allow_users?: string[];
|
||||||
|
prohibit_users?: string[];
|
||||||
|
persistent?: boolean;
|
||||||
|
}): Promise<Sender>;
|
||||||
|
holdOn(str: string): string;
|
||||||
|
reply(content: string): Promise<string | undefined>;
|
||||||
|
action(options: any): Promise<any | undefined>;
|
||||||
|
event(): Promise<any | undefined>;
|
||||||
|
}
|
||||||
|
declare class Bucket {
|
||||||
|
name: string;
|
||||||
|
constructor(name: string);
|
||||||
|
transform(v: string | undefined): string | number | boolean | undefined;
|
||||||
|
reverseTransform(value: any): string;
|
||||||
|
get(key: string, defaultValue?: any): Promise<any>;
|
||||||
|
set(key: string, value: any): Promise<{
|
||||||
|
message?: string;
|
||||||
|
changed?: boolean;
|
||||||
|
}>;
|
||||||
|
getAll(): Promise<any>;
|
||||||
|
delete(): Promise<undefined>;
|
||||||
|
keys(): Promise<string[] | undefined>;
|
||||||
|
len(): Promise<number | undefined>;
|
||||||
|
buckets(): Promise<string[] | undefined>;
|
||||||
|
watch(key: string, handle: (old: any, now: any, key: string) => StorageFinal | void | any): void;
|
||||||
|
_name(): Promise<string>;
|
||||||
|
}
|
||||||
|
interface StorageFinal {
|
||||||
|
echo?: string;
|
||||||
|
now?: any;
|
||||||
|
message?: string;
|
||||||
|
error?: string;
|
||||||
|
}
|
||||||
|
interface Message {
|
||||||
|
message_id?: string;
|
||||||
|
user_id: string;
|
||||||
|
chat_id?: string;
|
||||||
|
content: string;
|
||||||
|
user_name?: string;
|
||||||
|
chat_name?: string;
|
||||||
|
}
|
||||||
|
declare class Adapter {
|
||||||
|
platform: string | undefined;
|
||||||
|
bot_id: string | undefined;
|
||||||
|
call: any;
|
||||||
|
constructor(options: {
|
||||||
|
platform?: string;
|
||||||
|
bot_id?: string;
|
||||||
|
replyHandler?: (message: Message) => string | undefined;
|
||||||
|
actionHandler?: (message: Message) => string | undefined;
|
||||||
|
});
|
||||||
|
setActionHandler(func: (action: {}) => any): void;
|
||||||
|
receive(message: Message): Promise<Sender>;
|
||||||
|
push(message: Message): Promise<string>;
|
||||||
|
destroy(): Promise<void>;
|
||||||
|
sender(options: any): Promise<Sender>;
|
||||||
|
}
|
||||||
|
declare let sender: Sender;
|
||||||
|
declare function sleep(ms: number | undefined): Promise<unknown>;
|
||||||
|
export { Adapter, Bucket, sender, sleep };
|
||||||
+1
-1
@@ -226,7 +226,7 @@ class Sender {
|
|||||||
persistent: options?.persistent,
|
persistent: options?.persistent,
|
||||||
plugin_id,
|
plugin_id,
|
||||||
};
|
};
|
||||||
if (options?.handle && "*" == (await this.getPlatform())) {
|
if (!this.uuid) {
|
||||||
params.persistent = true;
|
params.persistent = true;
|
||||||
}
|
}
|
||||||
const call = client.SenderListen();
|
const call = client.SenderListen();
|
||||||
|
|||||||
+1
-1
@@ -248,7 +248,7 @@ class Sender {
|
|||||||
persistent: options?.persistent,
|
persistent: options?.persistent,
|
||||||
plugin_id,
|
plugin_id,
|
||||||
};
|
};
|
||||||
if (options?.handle && "*" == (await this.getPlatform())) {
|
if (!this.uuid) {
|
||||||
params.persistent = true;
|
params.persistent = true;
|
||||||
}
|
}
|
||||||
const call = client.SenderListen();
|
const call = client.SenderListen();
|
||||||
|
|||||||
Reference in New Issue
Block a user