Giter Club home page Giter Club logo

mirai-js's Issues

提供框架的 message 包装

不兼容更新:

对事件的响应,不再是简单的序列化,而是增加一个抽象层,同时提供行为
事件结构和行为将由框架包装和维护

  • 用来代替 Middleware 的部分增强功能,封装数据和行为
  • 用来解除开发者到 mirai-api-http messageType 消息结构的耦合

关于合并转发Forward类型

看了一下文档和代码里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发送出现了问题,可能是什么原因呢?

node运行示例文档中的问题

参照文档快速开始中的步骤, 我未安装git, 于是我download zip.
修改demo.js中authkey, qq, password后, 我先.\mcl登录bot, 而后使用cmd执行demo.js, 输出如下.
image

版本:
image

顺便快速开始这里的文档过于简略了..

bug: 发送的语音消息在 pc 客户端无法正常播放

如何复现:

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

实现"对话锁"中间件

配合即将实现的 Waiter#2, 保证在进行线性对话时不会重复触发对话,该事件处理器下只有一个对话正在进行。

提案征集

有没有什么好的点子,feature、bug、doc、refactor 等等。

欢迎在下方提出,或参与开发。

mirai-api-http 2.0 的不兼容

在使用 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); } })();

Error: Unexpected server response: 404

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();

Message not showing up in QQ group

  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}`)

Here is how mcl shows output
image

Here is the log of my code
image

However, the message doesn't show up.

Friend chat works perfectly.

关于Mirai-js v2.8.4上传语音PC端听不了的问题

代码复现如下:

//下载文件 到./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),
})

最终的在安卓手机端的效果为:
QQ图片20220909105116
音频文件可以听


电脑端的效果为:
image
音频文件不可听

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版本如下

"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信息是:

image

在MessageFromMessageId定义如下:

interface MessageFromMessageId {
    type: 'FriendMessage' | 'GroupMessage' | 'TempMessage';
    messageChain: MessageType[];
    sender: {
        id?: number;
        nickname?: string;
        remark?: string;
    }
}

开发文档首页Get Started链接404与奇怪的自动下滑

开发文档首页里面点击Get Started按钮会跳转到https://mirai-js-drincann.vercel.app/#/Preparation并显示404 Not found。然而正确的链接是https://mirai-js-drincann.vercel.app/#/v2.x/Preparation。这样的情况在手机端上浏览开发文档不太方便。

还有进入链接后会下滑到网页的Mirai-js文字位置,感觉怪怪的:
Screenshot_2022-02-19-22-36-30-590_mark via
建议移除这个行为或者直接下滑到下面的正文部分。

关于 中间件 Middleware 中 memberJoinRequestProcessor 的一些错误

在文档中关于加群消息的事件的中间件memberJoinRequestProcessor将MemberJoinRequestEvent写为NewFriendRequestEvent。按照示例的程序片段无法监听到加群请求。
QQ截图20210226132621
并且代码中也存在了相应的问题,修改示例程序使用正确的监听事件后程序将抛出消息格式错误的异常。
QQ截图20210226132441
在invitedJoinGroupRequestProcessor中间件的文档也存在同样的笔误。
QQ截图20210226132658

How to reply temp message coming from qq group

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

return await _sendTempMessage({

It seems this is the same issue with #136 , caused by Tencent security policy.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.