This commit is contained in:
cdle
2023-06-21 22:24:58 +08:00
parent 3ca1543d3f
commit 88b84927f3
3 changed files with 17 additions and 25 deletions
+4 -2
View File
@@ -3,6 +3,7 @@
一个不太有用的机器人,不生产消息,只搬运消息。 一个不太有用的机器人,不生产消息,只搬运消息。
## 特性 ## 特性
- 简单易用的消息搬运功能。 - 简单易用的消息搬运功能。
- 简单强大的自定义回复功能。 - 简单强大的自定义回复功能。
- 完整支持 ECMAScript 5.1 的插件系统,基于 [otto](https://github.com/robertkrimen/otto)。 - 完整支持 ECMAScript 5.1 的插件系统,基于 [otto](https://github.com/robertkrimen/otto)。
@@ -291,7 +292,7 @@ interface Sender {
isAdmin(): boolean; //判断消息是否来自管理员 isAdmin(): boolean; //判断消息是否来自管理员
getPlatform(): string; //获取消息平台 getPlatform(): string; //获取消息平台
getBotId(): string; //获取机器人ID getBotId(): string; //获取机器人ID
reply(content: string) Promise<string>; //回复消息,媒体消息推荐使用CQ码实现,返回消息ID reply(content: string): string; //回复消息,媒体消息推荐使用CQ码实现,返回消息ID
recallMessage(meesageId: string | string[]): Promise<boolean>; //撤回消息 recallMessage(meesageId: string | string[]): Promise<boolean>; //撤回消息
kick(user_id: string): Promise<boolean>; //移出群聊 kick(user_id: string): Promise<boolean>; //移出群聊
unkick(user_id: string): Promise<boolean>; //取消移出群聊 unkick(user_id: string): Promise<boolean>; //取消移出群聊
@@ -384,7 +385,7 @@ interface Message{
class Adapter(botplt: string, botid: string) { class Adapter(botplt: string, botid: string) {
isAdapter(botid: string): boolean; //判断id是否为机器人 isAdapter(botid: string): boolean; //判断id是否为机器人
push(message: Message): [messageId: string[], error: string]; //推送消息,无视禁言设置 push(message: Message): string; //推送消息,无视禁言设置
getReplyMessage(): Promise<message: Message>; //获取一条回复消息,实际发送成功后,如果有id,请设置 message.message_id getReplyMessage(): Promise<message: Message>; //获取一条回复消息,实际发送成功后,如果有id,请设置 message.message_id
setReplyHandler(func: (message: Message): string): void; //设置回复事件处理方法,方法中返回消息ID,不推荐使用。 setReplyHandler(func: (message: Message): string): void; //设置回复事件处理方法,方法中返回消息ID,不推荐使用。
receive(message: Message): Sender; //接收一个消息,并返回一个Sender对象 receive(message: Message): Sender; //接收一个消息,并返回一个Sender对象
@@ -523,5 +524,6 @@ uuid(): string; //生成uuid
``` ```
### 项目赞助 ### 项目赞助
打开微信扫一扫,深入了解作者~ 打开微信扫一扫,深入了解作者~
![](https://raw.githubusercontent.com/cdle/sillyGirl/main/appreciate.jpg) ![](https://raw.githubusercontent.com/cdle/sillyGirl/main/appreciate.jpg)
+11 -4
View File
@@ -190,8 +190,11 @@ func (f *Factory) Init(botplt, botid string) {
f.demo = &CustomSender{ f.demo = &CustomSender{
f: f, f: f,
} }
if _, ok := Bots[[2]string{botplt, botid}]; ok { if v, ok := Bots[[2]string{botplt, botid}]; ok {
// go v.Destroy() if v.uuid != f.uuid {
go v.Destroy()
}
//
console.Warn("%s机器人%s因冲突销毁!", botplt, botid) console.Warn("%s机器人%s因冲突销毁!", botplt, botid)
} }
Bots[[2]string{botplt, botid}] = f Bots[[2]string{botplt, botid}] = f
@@ -549,17 +552,21 @@ type PUSH string
func (sender *CustomSender) Reply(msgs ...interface{}) (string, error) { func (sender *CustomSender) Reply(msgs ...interface{}) (string, error) {
var push = false var push = false
var content = ""
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{}{}
for _, item := range msgs { for _, item := range msgs {
switch item := item.(type) { switch item := item.(type) {
case PUSH: case PUSH:
push = true push = true
case string: case string:
content = item args = append(args, item)
} }
} }
if len(args) == 0 {
return "", errors.New("no content")
}
content := utils.FormatLog(args[0], args[1:]...)
if !push { if !push {
if IsNoReplyGroup(sender) { if IsNoReplyGroup(sender) {
return "", errors.New("is no reply group") return "", errors.New("is no reply group")
+2 -19
View File
@@ -260,25 +260,8 @@ func (sender *SenderJsIplm) IsAdmin() bool {
return sender.Message.IsAdmin() return sender.Message.IsAdmin()
} }
func (sender *SenderJsIplm) Reply(text string) interface{} { func (sender *SenderJsIplm) Reply(texts ...interface{}) interface{} {
// promise, resolve, reject := sender.Vm.NewPromise() i, err := sender.Message.Reply(texts...)
// go func() {
// defer func() {
// recover()
// }()
// if text == "" {
// resolve("")
// return
// }
// i, err := sender.Message.Reply(text)
// if err != nil {
// reject(err.Error())
// return
// }
// resolve(i)
// }()
// return promise
i, err := sender.Message.Reply(text)
if err != nil { if err != nil {
panic(Error(sender.Vm, err)) panic(Error(sender.Vm, err))
} }