Skip to content

Commit

Permalink
🔖 v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
YunYouJun committed Sep 5, 2020
1 parent 54309a4 commit 9258688
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 19 deletions.
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "el-bot",
"version": "0.3.21",
"version": "0.4.0",
"description": "A quick qq bot framework for mirai.",
"main": "dist/index.js",
"files": [
Expand Down Expand Up @@ -76,9 +76,10 @@
"html-to-text": "^5.1.1",
"inquirer": "^7.3.3",
"js-yaml": "^3.14.0",
"mirai-ts": "^0.6.0",
"mirai-ts": "^0.6.1",
"mongodb": "^3.6.1",
"node-schedule": "^1.3.2",
"ora": "^5.0.0",
"progress": "^2.0.3",
"rss-parser": "^3.8.0",
"shelljs": "^0.8.4"
Expand All @@ -89,7 +90,7 @@
"@types/inquirer": "^7.3.1",
"@types/js-yaml": "^3.12.4",
"@types/mongodb": "^3.5.27",
"@types/node": "^14.6.3",
"@types/node": "^14.6.4",
"@types/node-schedule": "^1.3.0",
"@types/progress": "^2.0.3",
"@types/shelljs": "^0.8.8",
Expand All @@ -111,5 +112,12 @@
},
"directories": {
"lib": "https://github.com/YunYouJun/mirai-ts"
},
"ecosystem": {
"el-bot-api": "https://github.com/ElpsyCN/el-bot-api",
"el-bot-plugins": "https://github.com/ElpsyCN/el-bot-plugins",
"el-bot-docs": "https://github.com/ElpsyCN/el-bot-docs",
"el-bot-template": "https://github.com/ElpsyCN/el-bot-template",
"el-bot-web": "https://github.com/ElpsyCN/el-bot-web"
}
}
6 changes: 4 additions & 2 deletions src/bot/db.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Bot from ".";
import { MongoClient } from "mongodb";
import { dbConfig } from "../el";
import ora from "ora";

/**
* db 配置项
Expand All @@ -12,7 +13,7 @@ export async function connectDb(bot: Bot, dbConfig: dbConfig): Promise<void> {
const uri = dbConfig.uri || "mongodb://localhost:27017";
const name = dbConfig.name || "el-bot";

bot.logger.info(`连接 MongoDB 数据库「${name}...`);
const linkDb = ora(`连接 MongoDB 数据库「${name}`).start();
const client = await MongoClient.connect(uri, {
useUnifiedTopology: true,
}).catch((err) => {
Expand All @@ -22,7 +23,8 @@ export async function connectDb(bot: Bot, dbConfig: dbConfig): Promise<void> {
if (!client) return;

try {
bot.logger.success(`成功连接 MongoDB 数据库「${name}」`);
linkDb.succeed();

bot.client = client;
bot.db = client.db(name);
} catch (err) {
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/limit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,3 @@ export default function limit(ctx: Bot, options: LimitOptions) {
return data;
};
}

limit.version = "0.0.1";
limit.description = "限制消息频率";
11 changes: 11 additions & 0 deletions src/plugins/limit/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "limit",
"private": "true",
"version": "0.0.2",
"description": "限制消息频率",
"author": {
"name": "YunYouJun",
"url": "https://www.yunyoujun.cn",
"email": "me@yunyoujun.cn"
}
}
7 changes: 2 additions & 5 deletions src/plugins/rss.ts → src/plugins/rss/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import schedule from "node-schedule";
import Parser, { CustomFields } from "rss-parser";

import { MessageType, log } from "mirai-ts";
import ElBot from "../bot";
import Bot from "../bot";
import ElBot from "../../bot";
import Bot from "../../bot";

interface RssConfig {
name: string;
Expand Down Expand Up @@ -194,6 +194,3 @@ export default function rss(ctx: ElBot, options: RssConfig[]) {
}
});
}

rss.version = "0.0.1";
rss.description = "订阅 RSS 信息";
11 changes: 11 additions & 0 deletions src/plugins/rss/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "rss",
"private": "true",
"version": "0.0.2",
"description": "订阅 RSS 信息",
"author": {
"name": "YunYouJun",
"url": "https://www.yunyoujun.cn",
"email": "me@yunyoujun.cn"
}
}
Empty file added src/plugins/rss/template.ts
Empty file.
3 changes: 0 additions & 3 deletions src/plugins/teach/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,3 @@ export default async function teach(ctx: Bot, options: TeachOptions) {
}
});
}

teach.version = "0.1.0";
teach.description = "问答学习";
11 changes: 11 additions & 0 deletions src/plugins/teach/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "teach",
"private": "true",
"version": "0.1.0",
"description": "问答学习(教小云做事)",
"author": {
"name": "YunYouJun",
"url": "https://www.yunyoujun.cn",
"email": "me@yunyoujun.cn"
}
}
43 changes: 41 additions & 2 deletions src/plugins/workflow/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { EventType, MessageType } from "mirai-ts";
import Bot from "src/bot";
import fs from "fs";
import { parse } from "../../utils/config";
import { exec } from "shelljs";
import schedule from "node-schedule";

interface step {
name?: string;
Expand All @@ -28,9 +30,20 @@ type MessageAndEventType =
| EventType.EventType
| MessageType.ChatMessageType;

/**
* 定时格式
*/
interface Schedule {
cron: string;
}

interface On {
schedule: [Schedule];
}

interface WorkflowConfig {
name: string;
on: MessageAndEventType | MessageAndEventType[];
on: On | MessageAndEventType | MessageAndEventType[];
jobs: Jobs;
}

Expand All @@ -39,14 +52,26 @@ interface WorkflowConfig {
*/
function createWorkflow(ctx: Bot, workflow: WorkflowConfig) {
const mirai = ctx.mirai;
if (!workflow.on) return;

if (Array.isArray(workflow.on)) {
workflow.on.forEach((on) => {
trigger(on);
});
} else {
} else if (typeof workflow.on === "string") {
trigger(workflow.on);
} else if ((workflow.on as On).schedule) {
(workflow.on as On).schedule.forEach((singleSchedule) => {
schedule.scheduleJob(singleSchedule.cron, () => {
doJobs(workflow.jobs);
});
});
}

/**
* 触发
* @param type
*/
function trigger(type: MessageAndEventType) {
mirai.on(type, (msg) => {
Object.keys(workflow.jobs).forEach((name) => {
Expand All @@ -59,6 +84,20 @@ function createWorkflow(ctx: Bot, workflow: WorkflowConfig) {
});
});
}

/**
* 运行 jobs 中终端命令
*/
function doJobs(jobs: Jobs) {
Object.keys(jobs).forEach((name) => {
const job = jobs[name];
job.steps.forEach((step) => {
if (step.run) {
exec(step.run);
}
});
});
}
}

export default function workflow(ctx: Bot) {
Expand Down
11 changes: 11 additions & 0 deletions src/plugins/workflow/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "workflow",
"private": "true",
"version": "0.0.1",
"description": "工作流",
"author": {
"name": "YunYouJun",
"url": "https://www.yunyoujun.cn",
"email": "me@yunyoujun.cn"
}
}
2 changes: 1 addition & 1 deletion src/utils/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function statement(ctx: Bot) {
chalk.cyan("el-bot") + " 是一个非盈利的开源项目,仅供交流学习使用。"
);
ctx.logger.warning(
"请勿用于商业或非法用途,非法使用而与腾讯公司产生的一切纠纷均与原作者无关。"
"请勿用于商业或非法用途,因使用而与腾讯公司产生的一切纠纷均与原作者无关。"
);
console.log("-----------------------------------------------");
}

0 comments on commit 9258688

Please sign in to comment.