{"id":17967670,"url":"https://github.com/yunyoujun/mirai-ts","last_synced_at":"2025-04-09T05:10:09.389Z","repository":{"id":43082077,"uuid":"273408012","full_name":"YunYouJun/mirai-ts","owner":"YunYouJun","description":"🔧 Mirai(QQ Bot) JavaScript/TypeScript SDK for Node.js/Browser","archived":false,"fork":false,"pushed_at":"2024-09-29T22:32:54.000Z","size":913,"stargazers_count":245,"open_issues_count":1,"forks_count":36,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-29T15:49:12.038Z","etag":null,"topics":["bot","javascript","mirai","nodejs","qq","sdk","typescript"],"latest_commit_sha":null,"homepage":"https://yunyoujun.github.io/mirai-ts/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/YunYouJun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["YunYouJun"]}},"created_at":"2020-06-19T05:02:37.000Z","updated_at":"2024-10-03T18:58:02.000Z","dependencies_parsed_at":"2024-11-07T12:31:56.204Z","dependency_job_id":"f6189ccd-2652-446e-a4db-27624fbb07b0","html_url":"https://github.com/YunYouJun/mirai-ts","commit_stats":{"total_commits":240,"total_committers":13,"mean_commits":18.46153846153846,"dds":0.07916666666666672,"last_synced_commit":"f8dd7d7bbe8abf784afbbe25abac114b8ee7dd3a"},"previous_names":[],"tags_count":44,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YunYouJun%2Fmirai-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YunYouJun%2Fmirai-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YunYouJun%2Fmirai-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YunYouJun%2Fmirai-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YunYouJun","download_url":"https://codeload.github.com/YunYouJun/mirai-ts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247980837,"owners_count":21027808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bot","javascript","mirai","nodejs","qq","sdk","typescript"],"created_at":"2024-10-29T14:09:15.522Z","updated_at":"2025-04-09T05:10:09.364Z","avatar_url":"https://github.com/YunYouJun.png","language":"TypeScript","funding_links":["https://github.com/sponsors/YunYouJun"],"categories":[],"sub_categories":[],"readme":"# [mirai-ts](https://github.com/YunYouJun/mirai-ts)\n\n[![docs](https://github.com/YunYouJun/mirai-ts/workflows/docs/badge.svg)](https://yunyoujun.github.io/mirai-ts/)\n[![Compatible Version](https://img.shields.io/badge/mirai--api--http-v2.3.3-blue)](https://github.com/project-mirai/mirai-api-http)\n[![npm](https://img.shields.io/npm/v/mirai-ts)](https://www.npmjs.com/package/mirai-ts)\n[![GitHub](https://img.shields.io/github/license/YunYouJun/mirai-ts)](https://github.com/YunYouJun/mirai-ts)\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/9b332231afb643df83b59cc8b4188278)](https://www.codacy.com/gh/YunYouJun/mirai-ts/dashboard?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=YunYouJun/mirai-ts\u0026utm_campaign=Badge_Grade)\n\n\u003c!-- [![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/project-mirai/mirai-api-http?label=mirai-api-http)](https://github.com/project-mirai/mirai-api-http) --\u003e\n\n[mirai-api-http](https://github.com/mamoe/mirai-api-http) 的 JavaScript/TypeScript SDK，附带声明文件，拥有良好的注释和类型提示。可运行于 Node.js 与浏览器端。\n\n![shindo-ai.gif](https://user-images.githubusercontent.com/25154432/110353530-1f9de280-8072-11eb-94b0-addcd8ca1ca4.png)\n\n\u003e 除了 Node.js，它还兼容浏览器端。这意味着你可以使用它来开发 Web 界面与你的 mirai 机器人进行交互。（可以参考还在咕的 [el-bot-web](https://github.com/ElpsyCN/el-bot-web)）\n\n## 如何使用\n\n\u003e 自行配置好你的 [mirai](https://github.com/mamoe/mirai) 与 [mirai-api-http](https://github.com/project-mirai/mirai-api-http)，确保 `localhost:你配置的端口号/about` 是可访问的。\n\u003e [settings.yml](https://github.com/project-mirai/mirai-api-http#settingyml%E6%A8%A1%E6%9D%BF) 中 `adapterSettings` 的 `http` 与 `ws` 是必须的。\n\n```sh\nnpm install mirai-ts\n# yarn add mirai-ts\n\n# 尝试新版本（比如 ES Module）\nnpm i mirai-ts@next\n```\n\n\u003e 由于 mirai-api-http 2.x 已经稳定，mirai-ts@latest 为 2.x 版本，如果您想使用 mirai-api-http 1.x，请安装 [mirai-ts@1.x](https://www.npmjs.com/package/mirai-ts/v/1.1.1) 版本。\n\n- [API 文档](https://yunyoujun.github.io/mirai-ts/)\n- [2.x 迁移指南](./migrate.md)\n\n## 快速开始\n\n### JavaScript\n\n[示例代码](./demo/index.js)\n\n```sh\nnode demo/index.js\n```\n\n### TypeScript\n\n[示例代码](./demo/index.ts)\n\n```sh\nts-node demo/index.ts\n```\n\n### Browser\n\n基于 mirai-ts 开发面向浏览器端的应用程序时，您还需要安装 [events](https://github.com/browserify/events) 以在浏览器端替代 Node.js 原生 events 模块。\n\n```sh\npnpm i events\n# yarn add events\n# npm install events mirai-ts\n```\n\n## Why Typescript \u0026 mirai-ts?\n\n\u003e Make JavaScript Great Again!\n\n- 更友好的提示：TypeScript 配合 VSCode 代码提示有奇效。\n- 更清晰的语义：函数命名与 mirai-api-http 保持一致。\n- 更易懂的注释：因为会用到 QQ 机器人 99.99% 是国人，所以是全中文注释。\n- 更优雅的结构：看起来是在自吹自擂，但自我感觉良好。\n- 更广泛的平台：支持 Node.js 与浏览器端，以及 WebSocket。\n\n## 简介\n\n### 结构\n\n`types` 目录下为对应类型定义\n\n- `api`: API 发送与响应\n  - `response`: API 响应格式\n- `contact`: 用户信息格式（如 Friend, Member, Group 等）\n- `event-type`: 事件类型\n- `message-type`: 消息类型\n\n### 工具类\n\n```js\nconst { Message, Logger, check, MessageType, EventType } = require('mirai-ts')\n```\n\n```ts\nimport { EventType, Logger, Message, MessageType, check } from 'mirai-ts'\n```\n\n\u003e 详情请参见 [API 文档](https://yunyoujun.github.io/mirai-ts/)。\n\n#### [Message](https://yunyoujun.github.io/mirai-ts/modules.html#message)\n\n- `Message`: 生成对应消息的辅助方法，如生成艾特某人的消息 `Message.At(qq)`\n\n\u003e 消息链应当是一个数组，如 `messageChain = [Message.At(qq), Message.Plain('来点色图')]`\n\n#### [Logger](https://yunyoujun.github.io/mirai-ts/classes/logger.html)\n\n简单的日志工具，当然你可以自由使用其他工具替代它。\n\n```ts\nimport { Logger } from 'mirai-ts'\n// 你可以自定义你的前缀\nconst logger = new Logger({ prefix: '[mirai-ts]' })\nlogger.success('We are free!')\n```\n\n#### [check](https://yunyoujun.github.io/mirai-ts/modules/check.html)\n\n消息匹配与检测。\n\n如判断消息链是否有艾特某人：\n\n```js\nconst { check } = require('mirai-ts')\n// msg 为消息链 MessageChain\n// qq 为 QQ 号\ncheck.isAt(msg, qq)\n\n// or just\nmsg.isAt(qq)\n// 留空则判断是否艾特机器人自身\n```\n\n## 示例模版\n\n- [el-bot](https://github.com/YunYouJun/el-bot/)：你可以参考它的使用方式，你也可以直接使用它。\n\nel-bot 展示了整个 mirai-ts 的使用流程，并内置了一些如自动应答、转发、命令行、RSS 等常用功能（默认插件），开箱即用。\n\n你只需要一些自定义的配置，而不再需要编写繁琐的脚本内容。\n\n但这并不是束缚，在插件系统中你仍然可以调用机器人所有的上下文，并通过编写插件的形式快速实现你想要的功能。\n\n\u003e 更多请参见文档 [el-bot | El Bot Docs](https://docs.bot.elpsy.cn/)\n\n## 开发\n\n```bash\n# clone 本项目\ngit clone https://github.com/YunYouJun/mirai-ts\ncd mirai-ts\n\n# 安装 mirai-console-loader，放置于 `mirai-ts/mcl` 文件夹下\n# https://github.com/iTXTech/mirai-console-loader\nmkdir mcl\ncd mcl\n# 修改链接下载 mcl 对应版本\nwget https://github.com/iTXTech/mirai-console-loader/releases/download/v2.1.1/mcl-2.1.1.zip\nunzip mcl-2.1.1.zip\nchmod +x mcl\n./mcl\n\n# 使用 mcl 安装 mirai-api-http\n# https://github.com/project-mirai/mirai-api-http#%E5%AE%89%E8%A3%85mirai-api-http\n./mcl --update-package net.mamoe:mirai-api-http --channel stable-v2 --type plugin\n# mcl 自动更新\n./mcl -u\n\ncd ..\npnpm mcl\n\n# 参考 https://github.com/project-mirai/mirai-login-solver-selenium 获取 ticket\n\n# 开发（监听文件变动并构建）（打开新终端窗口）\npnpm dev\n\n# 启动 demo（打开新终端窗口）\npnpm demo\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyunyoujun%2Fmirai-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyunyoujun%2Fmirai-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyunyoujun%2Fmirai-ts/lists"}