1.0.15 • Published 2 years ago

miraicq v1.0.15

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

MiraiCQ

MiraiCQ 是一个基于 MiraiCQ-API 开发的 NodeJS QQ机器人框架

使用了方便的 CQ 代码: 图片,xxxxx

安装

npm install miraicq

示例

简单

const { Bot, cq } = require('./Bot');
(async () => {
    const bot = new Bot(
        'ws://localhost:8080',      // WebSocket地址
        '验证密钥',                 // API验证密钥
        10000                      // 机器人QQ号
    );
    
        // 创建会话
    await bot.open(() => {

        // 群消息
        bot.on('GroupMessage', async (ctx) => {
            /* ctx:
            msg                    消息内容
            time                   时间
            messageId              消息ID
            from                   来源
            - id                     成员QQ号
            - name                   成员昵称
            - permission             成员权限 - 0:成员; 1:管理员; 2:群主;
            - specialTitle           专属街头
            - joinTimestamp          入群时间戳
            - muteTimeRemaining      禁言剩余时间(秒)
            - lastSpeakTimestamp     最后发言时间戳
            - group                  来源群
            - id                     群号
            - name                   群名称
            - permission             机器人权限 - 0:成员; 1:管理员; 2:群主;
            */

            // 回复消息
            //await ctx.reply('你发送了消息: ' + ctx.msg);

            // 发送语音消息 - 可传递 base64/path/url/id
            //await bot.sendGroupMessage(ctx.from.group.id, cq.voice('https://pic.ibaotu.com/17/97/19/75C888piCxWf.mp3'));

            // 回复图片消息 - 可传递 base64/path/url/id
            //await ctx.reply(cq.image('{ECE1E74B-4DB0-256E-BC54-71A43F9D2BDA}.jpg') + '\n Hi~ o(* ̄▽ ̄*)ブ\n' + cq.at(ctx.from.id, true) + '欢迎使用 MiraiCQ ' + cq.face(175));

            if (ctx.msg === '禁言我') {
                await bot.muteMember(ctx.from.group.id, ctx.from.id, 30)// 禁言 30 秒
            } else if (ctx.msg === '全体禁言') {
                await bot.muteAll(ctx.from.group.id)
            } else if (ctx.msg === '解除全体禁言') {
                await bot.unmuteAll(ctx.from.group.id)
            } else if (ctx.msg === '设置精华') {
                await bot.setEssence(ctx.messageId)
            }
        });


        // 好友消息
        bot.on('FriendMessage', async (ctx) => {
            /* ctx:
            msg                    消息内容
            time                   时间
            messageId              消息ID
            from                   来源
            - id                     好友QQ号
            - name                   好友昵称
            - remark                 好友备注
            */

            // 回复消息
            //await ctx.reply('你发送了消息: ' + ctx.msg);
        });
    });
})

完整

完整示例请查看: demo.js

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.9

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.12

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago