drincann / mirai-js Goto Github PK
View Code? Open in Web Editor NEW运行在 Node.js、浏览器下,基于 mirai-api-http 的 QQ 机器人开发框架。
Home Page: https://mirai-js-drincann.vercel.app
License: GNU Affero General Public License v3.0
运行在 Node.js、浏览器下,基于 mirai-api-http 的 QQ 机器人开发框架。
Home Page: https://mirai-js-drincann.vercel.app
License: GNU Affero General Public License v3.0
不兼容更新:
对事件的响应,不再是简单的序列化,而是增加一个抽象层,同时提供行为
事件结构和行为将由框架包装和维护
同步的中间件机制实现
看了一下文档和代码里Message类里似乎没有合并转发的相关内容?
我自己添加了相关的代码:
Message.js
class Forward extends MessageType {
constructor({
nodeList
}) {
super({
type: 'Forward'
});
this.nodeList = nodeList;
}
}
...
addForward(senderId, time, senderName, messageChain) {
let nodeList = {
senderId: senderId,
time: time.getTime(),
senderName: senderName,
messageChain: messageChain.getMessageChain()
};
this.messageChain.push(new Forward({
nodeList
}));
return this;
}
Message.d.ts
addForward(senderId: Number, time: Date, senderName: String, messageChain: Message): Message;
但是在使用时会发生报错:
mirai-js: error core.sendGroupMessage
(node:27016) UnhandledPromiseRejectionWarning: Error: 无效参数
似乎是在与mcl的post发送出现了问题,可能是什么原因呢?
机器人由于被挤下线之后,触发监听事件,参照autoRelogin中间件的方法,重新登录之后,仍然无法正常运作
类似这个 Python
Mirai 项目 - GraiaProject 的这个功能 文档
相关 commit
: GraiaProject/Application@136053f
如何复现:
bot.sendMessage({
friend: 1019933576,
message: new Message().addVoiceId(
(await bot.uploadVoice({ type: 'friend', filename: './1.mp3' }))?.voiceId
),
})
问题:
语音消息在 pc 端显示损坏,无法播放,在移动端正常。
版本:
23:13:19 [INFO] iTXTech Mirai Console Loader version 2.1.0-71ec418
23:13:19 [INFO] https://github.com/iTXTech/mirai-console-loader
23:13:19 [INFO] This program is licensed under GNU AGPL v3
23:13:22 [INFO] Mirai Console Loader Announcement:
Mirai Console Loader 公告栏
如果在图片上传的时候遇到问题请与我们联系 (需要提供图片文件源本)
`- 如 Unsupported image type for ExternalResource *
` considering use gif/png/bmp/jpg format.
`- Tracker: https://github.com/mamoe/mirai/issues/new/choose
常用资源整合
`- https://mirai.mamoe.net/topic/653
MCL 已推出 2.1.0,更好的支持 Mirai 2.11 的插件系统,建议更新。
23:13:22 [INFO] Verifying "net.mamoe:mirai-console" v2.12.1
23:13:22 [INFO] Verifying "net.mamoe:mirai-console-terminal" v2.12.1
23:13:22 [INFO] Verifying "net.mamoe:mirai-core-all" v2.12.1
23:13:22 [INFO] Verifying "org.itxtech:mcl-addon" v2.0.2
正在写
https://github.com/project-mirai/mirai-api-http/releases/tag/v2.6.0
涉及一些带有 messageId 参数的接口
配合即将实现的 Waiter
#2, 保证在进行线性对话时不会重复触发对话,该事件处理器下只有一个对话正在进行。
有没有什么好的点子,feature、bug、doc、refactor 等等。
欢迎在下方提出,或参与开发。
在事件流的上下文对象提供 bot 实例引用,对 Middleware 解耦
在使用 mirai-api-http 2.0 时出现404错误
(node:40099) UnhandledPromiseRejectionWarning: Error: Request failed with status code 404
代码:
(async ()=>{ try{ var isLoggedIn = await Bot.isBotLoggedIn({ baseUrl:'http://localhost:8080', verifyKey:verfyKey, qq:user.No1.ID }) if(isLoggedIn){ log.info(``QQ:${user.No1.ID} has logged!``); }else{ var {message} = await Bot.sendCommand({ baseUrl:'http://localhost:8080', verifyKey:verfyKey, command:'/login', args: [user.No1.ID,user.No1.PASSWORD] }) log.info(message); } }catch(error){ log.error(error); } })();
events.js:174
throw er; // Unhandled 'error' event
^
Error: Unexpected server response: 404
at ClientRequest.req.on (D:\Coding\BobHBot\node_modules\ws\lib\websocket.js:728:7)
at ClientRequest.emit (events.js:198:13)
at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:556:21)
at HTTPParser.parserOnHeadersComplete (_http_common.js:109:17)
at Socket.socketOnData (_http_client.js:442:20)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead (internal/stream_base_commons.js:94:17)
Emitted 'error' event at:
at abortHandshake (D:\Coding\BobHBot\node_modules\ws\lib\websocket.js:896:15)
at ClientRequest.req.on (D:\Coding\BobHBot\node_modules\ws\lib\websocket.js:728:7)
[... lines matching original stack trace ...]
at Socket.Readable.push (_stream_readable.js:224:10)
在发过一条消息过后,报错,之后无法发送消息
代码:
const { Bot,Message } = require('mirai-js');
const bot = new Bot();
async function Main(){
// 连接到一个 mirai-api-http 服务
await bot.open({
baseUrl: 'http://127.0.0.1:2003',
verifyKey: '[key]',
// 要绑定的 qq,须确保该用户已在 mirai-console 登录
qq: 2400006639,
});
console.log("connected!");
await bot.sendMessage({
friend: '1550000009',
// Message 实例,表示一条消息
message: new Message().addText('hello world!')
});
await bot.sendMessage({
// 群号
group: '580000000',
// 是 http server 接口所需的原始格式,若提供则优先使用
message: [
{ type: 'Plain', text: '1234'},
{ type: 'Image', url:'[URL]'}
],
});
await bot.close();
}
Main();
await bot.sendMessage({
group: data.sender.group.id,
message: new Message().addAt(data.sender.id).addText(` ${result}`),
})
console.log(`${data.sender.id}: reply to ${data.sender.id} in ${data.sender.group.id}`)
However, the message doesn't show up.
Friend chat works perfectly.
pr welcome
研究一下中间件模式,改一改
会话锁中间件的自动解锁支持
例如 /remove 1019933576
将被解析为 { command: 'remove', args: ['1019933576'], }
用来方便地制作功能
实现包装同步 io 的中间件,包装 waiter 的方法提供简易同步对话调用方式。
代码复现如下:
//下载文件 到./temp/1.mp3 可以忽略
let aimUrl = 'http://music.163.com/song/media/outer/url?id=481859794.mp3';
await downLoadFile("./temp/1.mp3",aimUrl);
//uploadVoice 上传下载好的文件
const {voiceId} = await .bot.uploadVoice({type:"group",filename:"./temp/1.mp3"});
//通过voiceId发送文件
await bot.sendMessage({
group: 1169617978,
message: new myBot.Message().addVoiceId(voiceId),
})
package.json文件
{
"dependencies": {
"axios": "^0.27.2",
"cheerio": "^1.0.0-rc.12",
"crypto": "^1.0.1",
"crypto-js": "^4.1.1",
"fetch": "^1.1.0",
"gm": "^1.23.1",
"http": "^0.0.1-security",
"mirai-js": "^2.8.4",
"node-cron": "^3.0.2",
"node-schedule": "^2.1.0"
}
}
MCL上的版本显示
09:38:19 [INFO] iTXTech Mirai Console Loader version 2.1.0-71ec418
09:38:19 [INFO] https://github.com/iTXTech/mirai-console-loader
09:38:19 [INFO] This program is licensed under GNU AGPL v3
09:38:22 [INFO] Mirai Console Loader Announcement:
Mirai Console Loader 公告栏
如果在图片上传的时候遇到问题请与我们联系 (需要提供图片文件源本)`- 如 Unsupported image type for ExternalResource *
` considering use gif/png/bmp/jpg format.
`- Tracker: https://github.com/mamoe/mirai/issues/new/choose
常用资源整合
`- https://mirai.mamoe.net/topic/653
MCL 已推出 2.1.0,更好的支持 Mirai 2.11 的插件系统,建议更新。
09:38:22 [INFO] Verifying "net.mamoe:mirai-console" v2.12.1
09:38:22 [INFO] Verifying "net.mamoe:mirai-console-terminal"
v2.12.1
09:38:22 [INFO] Verifying "net.mamoe:mirai-core-all" v2.12.1
09:38:22 [INFO] Verifying "org.itxtech:mcl-addon" v2.0.2
09:38:22 [INFO] Verifying "org.bouncycastle:bcprov-jdk15on" v
mirai-js版本如下
"mirai-js": "^2.8.4"
mah版本如下:
2022-09-22 12:08:13 I/plugin: Successfully loaded plugin net.mamoe.mirai-api-http v2.6.1
mcl版本如下:
12:08:07 [INFO] iTXTech Mirai Console Loader version 2.1.0-71ec418
12:08:07 [INFO] https://github.com/iTXTech/mirai-console-loader
12:08:07 [INFO] This program is licensed under GNU AGPL v3
12:08:11 [INFO] Mirai Console Loader Announcement:
Mirai Console Loader 公告栏
如果在图片上传的时候遇到问题请与我们联系 (需要提供图片文件源本)
`- 如 Unsupported image type for ExternalResource *
` considering use gif/png/bmp/jpg format.
`- Tracker: https://github.com/mamoe/mirai/issues/new/choose
常用资源整合
`- https://mirai.mamoe.net/topic/653
MCL 已推出 2.1.0,更好的支持 Mirai 2.11 的插件系统,建议更新。
12:08:11 [INFO] Verifying "net.mamoe:mirai-console" v2.12.1
12:08:11 [INFO] Verifying "net.mamoe:mirai-console-terminal" v2.12.1
12:08:11 [INFO] Verifying "net.mamoe:mirai-core-all" v2.12.1
12:08:11 [INFO] Verifying "org.itxtech:mcl-addon" v2.0.2
12:08:11 [INFO] Verifying "org.bouncycastle:bcprov-jdk15on" v1.64
2022-09-22 12:08:12 I/main: Starting mirai-console...
2022-09-22 12:08:12 I/main: Backend: version 2.12.1, built on 2022-07-31 17:49:27.
2022-09-22 12:08:12 I/main: Frontend Terminal: version 2.12.1, provided by Mamoe Technologies
用TS编写如下代码,监听群消息撤回事件:
bot.on('GroupRecallEvent', async ctx => {
const msg = await myBot.bot.getMessageById({ messageId: ctx.messageId, target: ctx.group.id });
// repeat the msg recalled just now
console.log(msg);
bot.sendMessage({ group: msg.sender.group.id, message: msg.messageChain, }); //error
})
error错误信息
类型“{ id?: number | undefined; nickname?: string | undefined; remark?: string | undefined; }”上不存在属性“group”。
但是根据文档:https://drincann.github.io/Mirai-js/#/v2.x/Bot?id=getmessagebyid 可知msg结构是这样的:
在BOinterface MessageFromMessageId {
type: 'FriendMessage' | 'GroupMessage' | 'TempMessage';
messageChain: MessageType[];
sender: {
id?: number;
nickname?: string;
remark?: string;
}
}
但是实际输出msg信息是:
在MessageFromMessageId定义如下:
interface MessageFromMessageId {
type: 'FriendMessage' | 'GroupMessage' | 'TempMessage';
messageChain: MessageType[];
sender: {
id?: number;
nickname?: string;
remark?: string;
}
}
在开发文档首页里面点击Get Started按钮会跳转到https://mirai-js-drincann.vercel.app/#/Preparation并显示404 Not found。然而正确的链接是https://mirai-js-drincann.vercel.app/#/v2.x/Preparation。这样的情况在手机端上浏览开发文档不太方便。
message plain 类型,等价于 text,作为可选项提供 mah 一致语意
能否添加 QQ 的 emoji 添加到 MessageType 🤔
大概是这样 Nzzz964@5f08720
I've tried
await bot.sendMessage({
temp: true,
friend: data.sender.id,
group: data.sender.group.id,
message: new Message().addAt(data.sender.id).addText(` ${result}`),
})
console.log(`${new Date().toLocaleString()} ${data.sender.id}: reply to ${data.sender.id} from ${data.sender.group.id} temp message`)
But senders received no replies.
I've checked
https://github.com/project-mirai/mirai-api-http/blob/master/docs/api/API.md#%E5%8F%91%E9%80%81%E4%B8%B4%E6%97%B6%E4%BC%9A%E8%AF%9D%E6%B6%88%E6%81%AF
and
Line 364 in 3ba8e6d
It seems this is the same issue with #136 , caused by Tencent security policy.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.