Skip to content

Commit

Permalink
add music generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Sirius0v0 committed Oct 8, 2021
1 parent 56362c8 commit 1910008
Show file tree
Hide file tree
Showing 12 changed files with 346 additions and 4 deletions.
25 changes: 23 additions & 2 deletions config-template/permission-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
]
},
"_noAbbreviated": {
"activation": true,
"activation": false,
"help": null,
"isadmin": [
"member",
Expand All @@ -204,7 +204,7 @@
]
},
"_wordCloud": {
"activation": true,
"activation": false,
"help": null,
"isadmin": [
"admin",
Expand All @@ -222,6 +222,27 @@
"admin",
"owner"
]
},
"_搜图": {
"activation": true,
"help": null,
"isadmin": [
"member",
"admin",
"owner"
]
},
"_musicgen": {
"activation": true,
"help": {
"desc": "生成音乐",
"cmd": "-musicgen"
},
"isadmin": [
"member",
"admin",
"owner"
]
}
}
}
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ const { repeater } = require("./plugins/plugin-repeater"); // 复读
const { noAbbreviated } = require("./plugins/plugin-yyds"); // 好好说话
const { getWordCloud, getMessage } = require("./plugins/wordCloud/plugin-wordcloud"); // 词云分析
const { echo } = require("./plugins/plugin-echo"); // 复述功能
const { findPic } = require("./plugins/plugin-findPic"); // 搜图
const { musicgen } = require("./plugins/musicgen/plugin-musicgen"); // 生成音乐
// 通知类插件
const { increase } = require("./plugins/plugin-increase"); // 入群欢迎
const { decrease } = require("./plugins/plugin-decrease"); // 退群
Expand Down Expand Up @@ -141,6 +143,12 @@ bot.on("message.group.normal", function (e) {
case "-mc": // mcbot
await ping(_bot, e, args).catch(errorHandler);
break;
case "-pic":
await findPic(_bot, e, args).catch(errorHandler);
break;
case "-musicgen":
await musicgen(_bot, e, args).catch(errorHandler);
break;
// case "-wordcloud": // 词云分析
// getWordCloud(_bot, e, args);
// break;
Expand Down
51 changes: 51 additions & 0 deletions lib/remove.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const path = require("path");
const fs = require("fs");
/**
* 删除文件夹下所有文件及文件夹下所有文件
* @param {*} path
*/
function emptyDir(path) {
const files = fs.readdirSync(path);
files.forEach(file => {
const filePath = `${path}/${file}`;
const stats = fs.statSync(filePath);
if (stats.isDirectory()) {
emptyDir(filePath);
} else {
fs.unlinkSync(filePath);
}
});
}
exports.emptyDir = emptyDir;

/**
* 删除指定路径下的所有空文件夹
* @param {*} path
*/
function rmEmptyDir(path, level = 0) {
const files = fs.readdirSync(path);
if (files.length > 0) {
let tempFile = 0;
files.forEach(file => {
tempFile++;
rmEmptyDir(`${path}/${file}`, 1);
});
if (tempFile === files.length && level !== 0) {
fs.rmdirSync(path);
}
}
else {
level !== 0 && fs.rmdirSync(path);
}
}
exports.rmEmptyDir = rmEmptyDir;

/**
* 清空指定路径下的所有文件及文件夹
* @param {*} path
*/
function clearDir(path) {
emptyDir(path);
rmEmptyDir(path);
}
exports.clearDir = clearDir;
28 changes: 27 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"account": 123456789,
"botNickname": "灵喵",
"owner": 123456789,
"version": "2.2.1",
"version": "2.3.0",
"description": "",
"main": "index.js",
"scripts": {
Expand All @@ -15,10 +15,13 @@
"axios": "^0.21.4",
"cheerio": "^1.0.0-rc.10",
"jimp": "^0.16.1",
"log4js": "^6.3.0",
"mathjs": "^9.4.4",
"midi-writer-js": "^2.0.1",
"minecraft-protocol": "^1.26.5",
"mongodb": "^4.1.0",
"oicq": "^1.19.3",
"quick-midi": "^1.0.1",
"seed-random": "^2.2.0"
},
"devDependencies": {
Expand Down
49 changes: 49 additions & 0 deletions plugins/musicgen/Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const path = require("path");
const musicListDir = path.join(__dirname, "../../config-template/config");
const { _readFileSync } = require("../../lib/file");
const fs = require("fs");

class Data {

constructor() {
this._music_list = {};
this.load()
}

load = () => {
try {
this._music_list = _readFileSync(musicListDir, "musicList");
} catch (error) {
console.log(error.message);
}
}

dump = () => {
_readFileSync(musicListDir, "musicList"); // 没有则创建配置文件
fs.writeFileSync(musicListDir + "/musicList.json", JSON.stringify(this._music_list, null, '\t'));
}

getMusicList = () => {
let musicList = this._music_list;
return musicList;
}

updateMusic = (uname = null, music = null) => {
let musicList = this.getMusicList();
if (typeof musicList[uname] === "undefined") musicList[uname] = music;
this._music_list = musicList;
this.dump();
}

getMusicName = () => {
let musicList = this._music_list;
return Object.keys(musicList);
}

getMusic = (uname = null) => {
let musicList = this._music_list;
return musicList[uname];
}
}

exports.Data = Data;
Binary file added plugins/musicgen/cache/1633705882.mid
Binary file not shown.
Binary file added plugins/musicgen/cache/1633705882.wav
Binary file not shown.
Binary file added plugins/musicgen/cache/1633706127.mid
Binary file not shown.
Binary file added plugins/musicgen/cache/1633706127.wav
Binary file not shown.
Binary file added plugins/musicgen/midi2wav.jar
Binary file not shown.
Loading

0 comments on commit 1910008

Please sign in to comment.