This commit is contained in:
cdle
2023-07-05 20:48:58 +08:00
parent aa708903a7
commit 5b5eee0718
3 changed files with 19 additions and 22 deletions
+7 -11
View File
@@ -7,7 +7,7 @@
- 简单易用的消息搬运功能。 - 简单易用的消息搬运功能。
- 简单强大的自定义回复功能。 - 简单强大的自定义回复功能。
- 完整支持 ECMAScript 5.1 的插件系统,基于 [otto](https://github.com/robertkrimen/otto)。 - 完整支持 ECMAScript 5.1 的插件系统,基于 [otto](https://github.com/robertkrimen/otto)。
- 支持通过内置的阉割版 `Express` / `fetch` ,接入互联网。 - 支持通过内置的阉割版 `Express` / `request` ,接入互联网。
- 内置 `Cron` ,轻松实现定时任务。 - 内置 `Cron` ,轻松实现定时任务。
- 持久化的 `Bucket` 存储模块。 - 持久化的 `Bucket` 存储模块。
- 支持同时接入多个平台多个机器人,自己开发。 - 支持同时接入多个平台多个机器人,自己开发。
@@ -270,7 +270,7 @@ interface Sender {
getUserName(): string; //获取用户昵称 getUserName(): string; //获取用户昵称
getChatId(): string; //获取群聊ID getChatId(): string; //获取群聊ID
getChatName(): string; //获取群聊名称 getChatName(): string; //获取群聊名称
getMessageId(): Promise<string>; //获取消息ID getMessageId(): {message_id: string, error: string}; //获取消息ID
getContent(): string; //获取消息内容 getContent(): string; //获取消息内容
continue(): void; //使消息继续往下匹配正则,消息正常第一次被匹配就会停止继续匹配 continue(): void; //使消息继续往下匹配正则,消息正常第一次被匹配就会停止继续匹配
setContent(content: string): void; //修改接收到的消息内容,可配合`continue`被其他规则匹配 setContent(content: string): void; //修改接收到的消息内容,可配合`continue`被其他规则匹配
@@ -345,12 +345,12 @@ interface Response {
} }
``` ```
### fetch ### request
`net/http` 封装而成,如有更多需求可以联系作者。 `net/http` 封装而成,如有更多需求可以联系作者。
```ts ```ts
function fetch(options: { function request(options: {
url: string; //请求地址 url: string; //请求地址
method: string; //请求方法 method: string; //请求方法
headers: { [key: string]: string }; //请求头 headers: { [key: string]: string }; //请求头
@@ -359,16 +359,12 @@ function fetch(options: {
form: { [key: string]: any }; //formData表单数据,优先于下面的body form: { [key: string]: any }; //formData表单数据,优先于下面的body
body: any; // 请求体,支持字符串、二进制,对象自动转json字符串和添加相应请求头 body: any; // 请求体,支持字符串、二进制,对象自动转json字符串和添加相应请求头
allow_redirects: boolean; // 是否允许重定向,默认允许 allow_redirects: boolean; // 是否允许重定向,默认允许
proxy: { proxy: {};
url: string, //代理地址,支持http、https、socks5 }): {
user: string, //
password: string, //
}
}): Promise<response:{
status: number; // 状态码,同statusCode status: number; // 状态码,同statusCode
headers: { [key: string]: string }; headers: { [key: string]: string };
body: any; body: any;
}> };
``` ```
### Adapter ### Adapter
+1 -1
View File
@@ -714,7 +714,7 @@ func (sender *CustomSender) Reply(msgs ...interface{}) (string, error) {
return id, nil return id, nil
case <-time.After(time.Second * 5): case <-time.After(time.Second * 5):
close(c.Chan) close(c.Chan)
return "", errors.New("get message_id timeout") return "", errors.New("获取消息ID超时")
} }
} }
} else { } else {
+9 -8
View File
@@ -196,12 +196,8 @@ func (sender *SenderJsIplm) SetLevel(l int) {
func (sender *SenderJsIplm) GetChatName() string { func (sender *SenderJsIplm) GetChatName() string {
return sender.Message.GetChatName() return sender.Message.GetChatName()
} }
func (sender *SenderJsIplm) GetMessageID() *goja.Promise { func (sender *SenderJsIplm) GetMessageID() string {
promise, resolve, _ := sender.Vm.NewPromise() return sender.Message.GetMessageID()
go func() {
resolve(sender.Message.GetMessageID())
}()
return promise
} }
func (sender *SenderJsIplm) GetMessageId() string { func (sender *SenderJsIplm) GetMessageId() string {
@@ -289,10 +285,15 @@ func (sender *SenderJsIplm) IsAdmin() bool {
func (sender *SenderJsIplm) Reply(texts ...interface{}) interface{} { func (sender *SenderJsIplm) Reply(texts ...interface{}) interface{} {
i, err := sender.Message.Reply(texts...) i, err := sender.Message.Reply(texts...)
var errstr interface{}
if err != nil { if err != nil {
panic(Error(sender.Vm, err)) // panic(Error(sender.Vm, err))
errstr = err.Error()
}
return map[string]interface{}{
"message_id": i,
"error": errstr,
} }
return i
} }
func (sender *SenderJsIplm) HoldOn(str ...string) string { func (sender *SenderJsIplm) HoldOn(str ...string) string {