Compare commits

...

46 Commits

Author SHA1 Message Date
mol
3d1c8672dd 更新 .drone.yml
Some checks failed
continuous-integration/drone Build is failing
2024-11-06 14:53:57 +00:00
mol
05e936a067 Merge branch 'main' of git.liliyamol.cn:mol/mol-robot
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2023-12-25 10:59:30 +08:00
mol
5c93d3a30f fix: error effect app run 2023-12-25 10:58:47 +08:00
mol
61e81a1174 1.2.2 2023-12-25 10:55:07 +08:00
mol
f8840f9024 更新 README.md
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: mol <hiiragi10073@163.com>
2023-12-14 08:21:16 +00:00
mol
ba596d4f06 remove user limit
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 15:35:53 +08:00
mol
baba5dc342 1.2.1 2023-12-14 15:34:52 +08:00
mol
ba119d85c9 test
Some checks are pending
continuous-integration/drone/push Build is running
2023-12-14 15:33:41 +08:00
mol
0ce94d8cba test
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2023-12-14 15:05:30 +08:00
mol
cf18fdf532 test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 14:59:41 +08:00
mol
16196c46ac test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 14:35:47 +08:00
mol
579d39fa4a test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 13:59:47 +08:00
mol
d7a341afd0 test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 13:52:46 +08:00
mol
164b6fa28e test
Some checks are pending
continuous-integration/drone/push Build is running
2023-12-14 13:48:52 +08:00
mol
b1709958e4 test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 13:39:51 +08:00
mol
23d56963e4 test
Some checks are pending
continuous-integration/drone/push Build is running
2023-12-14 13:39:26 +08:00
mol
4242665b7a test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 13:30:20 +08:00
mol
c02d693417 test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 13:24:14 +08:00
mol
ea06c9fd14 test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 13:16:18 +08:00
mol
1f4d251aa1 test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 13:11:12 +08:00
mol
5daa6a2dfd test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 13:03:05 +08:00
mol
4d22f53531 test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 12:52:50 +08:00
mol
e01a9632ea test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 12:34:58 +08:00
mol
85060429bc test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 12:30:28 +08:00
mol
9e330e2de4 test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 12:04:19 +08:00
mol
752b6e8eb9 test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 11:59:26 +08:00
mol
91853e4296 test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 11:11:55 +08:00
mol
04f6858411 test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 11:01:45 +08:00
mol
216d1d90fa test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 10:52:43 +08:00
mol
8fc996ce83 test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 10:36:13 +08:00
mol
1fbe397078 test
Some checks are pending
continuous-integration/drone/push Build is running
2023-12-14 10:32:38 +08:00
mol
4a86ca162a test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 10:26:11 +08:00
mol
83964b678d test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 10:07:44 +08:00
mol
eb57171700 test
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2023-12-14 10:01:19 +08:00
mol
7bf234cf57 test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 09:56:51 +08:00
mol
c7bb8ec951 test 2023-12-14 09:53:33 +08:00
mol
fda78b5772 test
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2023-12-14 09:32:11 +08:00
mol
a1ef6311c4 test
Some checks reported errors
continuous-integration/drone/push Build was killed
2023-12-14 09:28:57 +08:00
mol
44ad5a973c test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-14 00:10:20 +08:00
mol
3cec0cad64 test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-13 23:59:35 +08:00
mol
c0a732ae55 test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-13 23:35:36 +08:00
mol
ae6d120605 test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-13 23:23:00 +08:00
mol
65a3a4ac99 test
Some checks are pending
continuous-integration/drone/push Build is running
2023-12-13 23:21:05 +08:00
mol
7f3af6b154 test
Some checks are pending
continuous-integration/drone/push Build is running
2023-12-13 22:17:45 +08:00
mol
98e48140d3 test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-13 21:19:20 +08:00
mol
6be7015b8a test
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-13 20:57:11 +08:00
19 changed files with 356 additions and 86 deletions

View File

@ -1,4 +1,3 @@
node_modules
.env
.prettierignore
.prettierrc.js

View File

@ -2,6 +2,11 @@ kind: pipeline # 定义一个管道
type: docker # 当前管道的类型
name: build # 当前管道的名称
volumes:
- name: cache
host:
path: /tmp/cache
steps: # 定义管道的执行步骤
# - name: build-project # 步骤名称
# image: node:18-bullseye # 当前步骤使用的镜像
@ -13,16 +18,37 @@ steps: # 定义管道的执行步骤
# - npm config set registry https://registry.npm.taobao.org
# - npm i
- name: cache # 加载缓存
image: drillster/drone-volume-cache
pull: if-not-exists
depends_on: [clone]
volumes:
- name: cache
path: /cache
settings:
restore: true
mount:
- ./node_modules
- name: build-tags
image: yxs970707/drone-web-tags
depends_on: [clone]
pull: if-not-exists
depends_on: [cache]
settings:
tags:
- latest
- name: install
image: node:18
pull: if-not-exists
depends_on: [build-tags]
commands:
- npm --registry https://registry.npm.taobao.org install
- name: build-image
image: plugins/docker
depends_on: [build-tags]
pull: if-not-exists
depends_on: [install]
settings:
username:
from_secret: docker_username
@ -30,8 +56,20 @@ steps: # 定义管道的执行步骤
from_secret: docker_passwd
dockerfile: Dockerfile
mirror: https://fpswa5tm.mirror.aliyuncs.com
registry: https://git.liliyamol.cn:8081
repo: git.liliyamol.cn:8081/mol/mol-robot
registry: https://git.liliyamol.cn
repo: git.liliyamol.cn/mol/mol-robot
- name: rebuild cache # 构建缓存
image: drillster/drone-volume-cache
pull: if-not-exists
depends_on: [build-image]
volumes:
- name: cache
path: /cache
settings:
rebuild: true
mount:
- ./node_modules
---
kind: pipeline # 定义一个管道
@ -59,11 +97,11 @@ steps:
secrets: [docker_username, docker_passwd]
script:
- echo ==-----==开始部署==-----==
- docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWD git.liliyamol.cn:8081
- docker pull git.liliyamol.cn:8081/mol/mol-robot:latest
- docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWD git.liliyamol.cn
- docker pull git.liliyamol.cn/mol/mol-robot:latest
- list=$(docker ps -a | grep mol-robot* | awk '{print $1}')
- test "$list" = "" && echo "none mol-robot containers running" || docker stop $list && docker container rm $list
# 过滤出dockerImages的id, 删除none镜像
- docker run -d -p 16808:8080 --name=mirai_robot_${DRONE_BUILD_NUMBER} --env-file /mnt/data/opt/mol-robot/.env git.liliyamol.cn:8081/mol/mol-robot:latest
- docker rmi $(docker images | grep "none" | awk '{print $3}')
- docker run -d -p 16808:8080 --restart=always --name=mol-robot_${DRONE_BUILD_NUMBER} --env-file /mnt/data/opt/mol-robot/.env git.liliyamol.cn/mol/mol-robot:latest
# - docker rmi $(docker images | grep "none" | awk '{print $3}')
- echo ==-----==部署成功==-----==

View File

@ -1,12 +1,11 @@
FROM node:18-bullseye as dep-builder
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install
# COPY package*.json ./
COPY . .
# RUN npm --registry https://registry.npm.taobao.org install
EXPOSE 8080

View File

@ -1,3 +1,88 @@
### 模儿bot
### 模儿bot
友链:[mirai-js](https://drincann.github.io/Mirai-js/#/v2.x/Bot?id=on)
模儿bot是一个提供与mirai-api-http交互的webhook服务器并提供一些小工具的bot。
#### 功能
1. webhook服务器
> http请求方式, method="post", enctype="application/json", path=/
请求示例
```
{
"event": "sendForwardMessage",
"subs": {
"groups": [],
"users": []
},
"from": "新闻",
"messages": [
{
"message": "PlayStation Plus二档会员十二月阵容给他爱5、FF起源等",
"imgUrls": [
"http://img2.a9vg.com/i/a9-article-list_x256/cms3.0/2023/1214/20231214104321-2309-33362.jpg"
],
"originUrl": "http://www.a9vg.com/article/215182"
}
],
"body": "Hello World",
}
```
请求参数说明
发送转发消息请求
|参数|类型|说明|是否必填|可选项|
|--|--|--|--|--|
|event|string|发送消息的类型|是|`sendForwardMessage`|
|subs|object|指定接收消息的群或者人|是|--|
|from|string|转发消息时,指定发送人的名称|否|--|
|messages|message[]|转发的消息列表|是|--|
发送一般消息请求
|参数|类型|说明|是否必填|可选项|
|--|--|--|--|--|
|event|string|发送消息的类型|是|`sendMessage2`|
|subs|object|指定接收消息的群或者人|是|--|
|from|string|转发消息时,指定发送人的名称|否|--|
|messages|string[]|转发的消息列表|是|--|
|imgUrls|string[]|图片地址|否|--|
|originUrl|string|源地址|否|--|
|at|number|需要at的qq号|否|--|
2. 聊天指令
1. 厨娘
- 随机菜肴推荐 #模儿晚上吃什么)
#### 安装运行
1. 直接运行
```shell
npm i -g node@18.17.0
npm i
touch .env
# 修改 .env 文件
vim .env
node app.js
```
2. docker 运行(开发中)
#### 环境配置
```
MIRAI_HTTP_API_HOST=<mirai-api-http地址>
MIRAI_HTTP_API_VERIFY_KEY=<mirai-api-http密钥>
WEB_HOOK_PORT=<webhook服务器端口>
QQ=<机器人qq号>
DEFAULT_SUB_GROUPS=<默认订阅群(暂时无用)>
DEFAULT_SUB_USERS=<默认订阅人 (暂时无用)>
IMG_NUMBER_IN_ONE_MESSAGE=<单个消息允许的配图数量>
COOK_SUB_GROUPS=<订阅厨娘的群>
MASTER=<管理员qq号>
```
#### 友链
- [mirai-js](https://drincann.github.io/Mirai-js/#/v2.x/Bot?id=on)
- [今天我们来做菜](https://github.com/YunYouJun/cook)

30
app.js
View File

@ -1,8 +1,8 @@
import fs from 'fs';
import { join } from 'path';
import CreateBot from '#root/bot/index.js';
import CreateWebhookServer from '#root/http/index.js';
import logger from '#root/utils/logger.js';
import handlers from './handlers/index.js';
import plugins from '#root/plugins/index.js';
let retryCount = 0;
@ -33,22 +33,26 @@ let retryCount = 0;
});
logger('bot 连接成功!!');
bot.mountPlugin(plugins);
logger('开启 webhook 服务器');
const webhook = new CreateWebhookServer();
logger('开始引入handler函数');
const files = fs.readdirSync('./handlers');
const handlers = files
.filter((it) => /\.js$/.test(it))
.map((it) => {
let fPath = join(__dirname, './handlers', it);
return {
event: it.split('.').slice(0, -1).join('.'),
handler: require(fPath).bind(this, bot),
};
});
webhook.registerHanlder(handlers);
// const files = fs.readdirSync('./handlers');
// const handlers = files
// .filter((it) => /\.js$/.test(it))
// .map((it) => {
// let fPath = join(__dirname, './handlers', it);
// return {
// event: it.split('.').slice(0, -1).join('.'),
// handler: require(fPath).bind(this, bot),
// };
// });
webhook.registerHandler(handlers.map(i => ({ event: i.event, handler: i.handler.bind(this, bot) })));
webhook.startListen(port);
logger(`开始监听端口: ${port}`);
bot.sendMessageToFriend(+process.env.MASTER, '模儿bot已就绪');
})(process.env.WEB_HOOK_PORT);

View File

@ -1,7 +1,6 @@
import pkg from 'mirai-js';
import Queue from '#root/utils/queue.js';
import logger from '#root/utils/logger.js';
import plugins from '#root/plugins/index.js';
const { Bot } = pkg;
@ -19,27 +18,25 @@ export default class CreateBot {
verifyKey: config.verifyKey,
qq: config.qq,
});
this.mountPlugin(plugins);
}
async sendMessageToFriend(qq, message) {
sendMessageToFriend(qq, message) {
logger(`发送好友[${qq}]消息进入消息队列`);
return this.queue
.addMethod(this.bot.sendMessage.bind(this.bot, { friend: qq, message }))
.then(
(res) => {
logger(`发送好友[${qq}]消息成功 ${res}`);
return res;
return ['success', res];
},
(e) => {
logger.warning(`发送好友[${qq}]消息失败,错误信息${e}`);
return Promise.reject(e);
return ['failed', e];
},
);
}
async sendMessageToGroup(groupId, message) {
sendMessageToGroup(groupId, message) {
logger(`发送群[${groupId}]消息进入消息队列`);
return this.queue
.addMethod(
@ -48,18 +45,18 @@ export default class CreateBot {
.then(
(res) => {
logger(`发送群[${groupId}]消息成功 ${res}`);
return res;
return ['success', res];
},
(e) => {
logger.warning(`发送群[${groupId}]消息失败,错误信息${e}`);
return Promise.reject(e);
return ['failed', e];
},
);
}
mountPlugin(plugins) {
for (let plugin of plugins) {
plugin.install(this.bot, this.queue);
plugin(this);
}
}
}

View File

@ -6,18 +6,18 @@ export const command = {
export const defaultSubs = {
groups: process.env.DEFAULT_SUB_GROUPS
? process.env.DEFAULT_SUB_GROUPS.split(',')
? process.env.DEFAULT_SUB_GROUPS.split(',').map(item => +item)
: [],
users: process.env.DEFAULT_SUB_USERS
? process.env.DEFAULT_SUB_USERS.split(',')
? process.env.DEFAULT_SUB_USERS.split(',').map(item => +item)
: [],
};
export const cookSubs = {
groups: process.env.COOK_SUB_GROUPS
? process.env.COOK_SUB_GROUPS.split(',')
? process.env.COOK_SUB_GROUPS.split(',').map(item => +item)
: [],
users: process.env.COOK_SUB_USERS
? process.env.COOK_SUB_USERS.split(',')
? process.env.COOK_SUB_USERS.split(',').map(item => +item)
: [],
};

14
handlers/index.js Normal file
View File

@ -0,0 +1,14 @@
import sendForwardMessage from './sendForwardMessage.js'
import sendMessage from './sendMessage.js'
import sendMessage2 from './sendMessage2.js'
export default [{
event: 'sendMessage',
handler: sendMessage
}, {
event: 'sendForwardMessage',
handler: sendForwardMessage
}, {
event: 'sendMessage2',
handler: sendMessage2
}]

View File

@ -1,6 +1,7 @@
import { Message } from 'mirai-js';
import pkg from 'mirai-js';
import { defaultSubs } from '#root/config/index.js';
import logger from '#root/utils/logger.js';
const { Message } = pkg
export default function sendForwardMessage(bot, data) {
logger('开始执行handler: sendForwardMessage');
@ -23,8 +24,8 @@ export default function sendForwardMessage(bot, data) {
if (imgUrls) {
Array.isArray(imgUrls)
? imgUrls
.slice(0, process.env.IMG_NUMBER_IN_ONE_MESSAGE || 1)
.forEach((url) => msgContent.addImageUrl(url))
.slice(0, process.env.IMG_NUMBER_IN_ONE_MESSAGE || 1)
.forEach((url) => msgContent.addImageUrl(url))
: msgContent.addImageUrl(imgUrls);
}
// 添加来源地址

View File

@ -1,6 +1,7 @@
import { Message } from 'mirai-js';
import pkg from 'mirai-js';
import { defaultSubs } from '#root/config/index.js';
import logger from '#root/utils/logger.js';
const { Message } = pkg
// 方法已废弃
export default function sendMessage(bot, data) {

View File

@ -1,6 +1,7 @@
import { Message } from 'mirai-js';
import pkg from 'mirai-js';
import { defaultSubs } from '#root/config/index.js';
import logger from '#root/utils/logger.js';
const { Message } = pkg
export default function sendMessage2(bot, data) {
logger('开始执行handler: sendMessage2');
@ -30,8 +31,8 @@ export default function sendMessage2(bot, data) {
if (imgUrls) {
Array.isArray(imgUrls)
? imgUrls
.slice(0, process.env.IMG_NUMBER_IN_ONE_MESSAGE || 1)
.forEach((url) => msgContent.addImageUrl(url))
.slice(0, process.env.IMG_NUMBER_IN_ONE_MESSAGE || 1)
.forEach((url) => msgContent.addImageUrl(url))
: msgContent.addImageUrl(imgUrls);
}
// 添加来源地址

View File

@ -51,7 +51,7 @@ export default class CreateWebhookServer {
.listen(port || 8080);
}
registerHanlder(handlers) {
registerHandler(handlers) {
logger(`${handlers.map((item) => item.event).join('、')}函数已引入`);
this.handlers.push(...handlers);
}

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "mirai-middle-server",
"version": "1.2.0",
"version": "1.2.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "mirai-middle-server",
"version": "1.2.0",
"version": "1.2.2",
"dependencies": {
"dayjs": "^1.11.7",
"mirai-js": "^2.8.11",

View File

@ -1,6 +1,6 @@
{
"name": "mirai-middle-server",
"version": "1.2.0",
"version": "1.2.2",
"description": "使用miraijs开发,用于连接kuginn等外部服务与mirai通信的中转服务器",
"author": "mol",
"main": "app.js",
@ -20,4 +20,4 @@
"devDependencies": {
"dotenv": "^16.1.1"
}
}
}

View File

@ -1,18 +1,18 @@
import getDb from '../db/index.js';
import logger from '#root/utils/logger.js'
export async function getRandomRecipe(limit = 5) {
logger(`随机${limit}个食谱`)
const data = await getDb();
const len = data.length;
const list = [];
const indexList = new Set();
while (indexList.size === limit) {
while (indexList.size < limit) {
const index = Math.floor(Math.random() * len);
if (!indexList.has(index)) {
indexList.set(index);
indexList.add(index);
list.push(data[index]);
}
}
return list;
}

93
plugins/cook/db/food.js Normal file
View File

@ -0,0 +1,93 @@
export const emojiMap = new Map([
[
'土豆', '🥔'
],
[
'胡萝卜', '🥕'
],
[
'花菜', '🥦'
],
[
'白萝卜', '🥣'
],
[
'西葫芦', '🥒'
],
[
'番茄', '🍅'
],
[
'西红柿', '🍅'
],
[
'芹菜', '🥬'
],
[
'黄瓜', '🥒'
],
[
'洋葱', '🧅'
],
[
'莴笋', '🎍'
],
[
'菌菇', '🍄'
],
[
'茄子', '🍆'
],
[
'豆腐', '🍲'
],
[
'包菜', '🥗'
],
[
'白菜', '🥬'
],
[
'午餐肉', '🥓'
],
[
'香肠', '🌭'
],
[
'腊肠', '🌭'
],
[
'鸡肉', '🐤'
],
[
'猪肉', '🐷'
],
[
'鸡蛋', '🥚'
],
[
'虾', '🦐'
],
[
'牛肉', '🐮'
],
[
'骨头', '🦴'
],
[
'鱼Todo', '🐟'
],
[
'面食', '🍝'
],
[
'面包', '🍞'
],
[
'米', '🍚'
],
[
'方便面', '🍜'
]
]
)

View File

@ -1,19 +1,40 @@
import { createParser } from 'node-csv';
import pkg from 'node-csv';
import logger from '#root/utils/logger.js';
import { emojiMap } from './food.js'
import path from 'path';
const __dirname = path.dirname(new URL(import.meta.url).pathname);
const { createParser } = pkg
let recipeData;
let loaded = false;
function parser() {
csv = createParser();
const csv = createParser();
return new Promise((r, j) => {
csv.parserFile('./recipe.csv', function (err, data) {
csv.parseFile(path.join(__dirname, './recipe.csv'), function (err, data) {
if (err) {
logger.err(err);
return j();
}
logger('食谱加载成功');
recipeData = data;
const keys = data.shift()
keys[0] = keys[0].slice(1)
recipeData = data.map(d => {
const res = {}
keys.forEach((key, index) => {
if (key) {
let text = d[index]
if (key === 'stuff') {
text = text.split('、').map(t => {
return `${emojiMap.has(t) ? emojiMap.get(t) + ' ' : ''}${t}`
}).join('、')
}
res[key] = text
}
})
return res
});
loaded = true;
r(recipeData);
});
@ -24,6 +45,11 @@ export default async function getDb() {
if (loaded) {
return recipeData;
} else {
return await parser();
await parser()
return recipeData;
}
}
// getDb().then((res) => {
// // console.log(recipeData)
// })

View File

@ -2,24 +2,31 @@ import pkg from 'mirai-js';
import { cookSubs, command } from '#root/config/index.js';
import { getRandomRecipe } from './api/index.js';
import { genRecipeMessage } from './utils/index.js';
import logger from '#root/utils/logger.js'
const { Middleware } = pkg;
const { Middleware, Message } = pkg;
const cookCommand = command.cook;
let Bot;
let Queue;
const commandHandle = {
random: randomCook,
};
function randomCook(text, data) {
async function randomCook(text, data) {
const limit = Number.parseInt(text) > 0 ? Number.parseInt(text) : 5;
const recipeList = getRandomRecipe(limit);
const recipeList = await getRandomRecipe(limit);
const message = genRecipeMessage(recipeList, '给你推荐');
switch (data.type) {
case 'GroupMessage':
Bot.sendMessageToGroup(data.sender.group.id, message);
const forwardMsg = Message.createForwardMessage();
forwardMsg.addForwardNode({
senderId: process.env.QQ,
time: 0,
senderName: '厨娘·模儿',
messageChain: message
})
Bot.sendMessageToGroup(data.sender.group.id, forwardMsg);
break;
case 'FriendMessage':
Bot.sendMessageToFriend(data.sender.id, message);
@ -27,20 +34,23 @@ function randomCook(text, data) {
}
function cookInit() {
Bot.on(
Bot.bot.on(
'GroupMessage',
new Middleware().groupFilter(cookSubs.groups).done(dealCommon),
new Middleware().groupFilter(cookSubs.groups).textProcessor().done(dealCommon),
);
Bot.on(
Bot.bot.on(
'FriendMessage',
new Middleware().friendFilter(cookSubs.users).done(dealCommon),
new Middleware().textProcessor().done(dealCommon),
);
Bot.sendMessageToFriend(+process.env.MASTER, '厨娘系统 启动!');
logger('cook 初始化完成')
}
function dealCommon(data) {
logger('开始处理指令')
const [commandText, ...contentText] = data.text.trim().split(' ');
for (let com of cookCommand.keys()) {
for (let com of Object.keys(cookCommand)) {
if (cookCommand[com].includes(commandText)) {
commandHandle[com](contentText, data);
break;
@ -48,8 +58,8 @@ function dealCommon(data) {
}
}
export default function install(bot, queue) {
export default function install(bot) {
Bot = bot;
Queue = queue;
cookInit();
logger('cook 插件加载成功')
}

View File

@ -1,19 +1,21 @@
import pkg from 'mirai-js'
const { Message } = pkg
export function genRecipeMessage(recipeList, header, footer) {
const textList = [];
for (let recipe of recipeList) {
textList.push(
`${recipe.name}\n准备材料:${recipe.stuff}\n使用厨具:${recipe.tools}\nhttps://www.bilibili.com/video/${recipe.bv}`,
);
}
const msg = new Message()
if (header) {
textList.shift(header);
msg.addText(`${header}\n\n`);
}
recipeList.forEach((recipe, index)=> {
msg.addText(`${index + 1}. ${recipe.name}\n`)
msg.addText(`\t· 材料:${recipe.stuff}\n`)
msg.addText(`\t· 厨具:${recipe.tools}\n`)
msg.addText(`\t· 制作视频https://www.bilibili.com/video/${recipe.bv}\n\n`)
})
if (footer) {
textList.push(footer);
msg.addText(`${footer}`);
}
return textList.join('\n----------\n');
return msg
}