diff --git a/plugins/commands/about.js b/commands/about.js similarity index 96% rename from plugins/commands/about.js rename to commands/about.js index 827786d..2ae70d6 100644 --- a/plugins/commands/about.js +++ b/commands/about.js @@ -1,5 +1,5 @@ -const version = require('../../version.json') -const {getMessage} = require('../../util/lang.js') +const version = require('../version.json') +const {getMessage} = require('../util/lang.js') const cp = require('child_process') module.exports = { execute: function (c) { diff --git a/plugins/commands/cb.js b/commands/cb.js similarity index 100% rename from plugins/commands/cb.js rename to commands/cb.js diff --git a/plugins/commands/cloop.js b/commands/cloop.js similarity index 97% rename from plugins/commands/cloop.js rename to commands/cloop.js index 3d93eeb..dac4f98 100644 --- a/plugins/commands/cloop.js +++ b/commands/cloop.js @@ -1,4 +1,4 @@ -const {getMessage} = require('../../util/lang.js') +const {getMessage} = require('../util/lang.js') module.exports = { execute: (c) => { const subcmd = c.args.splice(0, 1)[0] diff --git a/plugins/commands/eval.js b/commands/eval.js similarity index 59% rename from plugins/commands/eval.js rename to commands/eval.js index 8ed1fa9..fb5090a 100644 --- a/plugins/commands/eval.js +++ b/commands/eval.js @@ -1,4 +1,4 @@ -const index = require('../../index.js') // Not used in the code, but may be used by users of the command +const index = require('../index.js') // Not used in the code, but may be used by users of the command module.exports = { execute: (c) => { try { diff --git a/plugins/commands/help.js b/commands/help.js similarity index 100% rename from plugins/commands/help.js rename to commands/help.js diff --git a/plugins/commands/logoff.js b/commands/logoff.js similarity index 100% rename from plugins/commands/logoff.js rename to commands/logoff.js diff --git a/plugins/commands/netmsg.js b/commands/netmsg.js similarity index 94% rename from plugins/commands/netmsg.js rename to commands/netmsg.js index b3acbac..c4f9a33 100644 --- a/plugins/commands/netmsg.js +++ b/commands/netmsg.js @@ -1,4 +1,4 @@ -const { bot } = require('../../index.js') +const { bot } = require('../index.js') module.exports = { execute: (c) => { const json = { diff --git a/plugins/commands/refill.js b/commands/refill.js similarity index 100% rename from plugins/commands/refill.js rename to commands/refill.js diff --git a/plugins/commands/restart.js b/commands/restart.js similarity index 100% rename from plugins/commands/restart.js rename to commands/restart.js diff --git a/plugins/commands/say.js b/commands/say.js similarity index 100% rename from plugins/commands/say.js rename to commands/say.js diff --git a/plugins/commands/serverinfo.js b/commands/serverinfo.js similarity index 97% rename from plugins/commands/serverinfo.js rename to commands/serverinfo.js index 4f196db..dd3e9bf 100755 --- a/plugins/commands/serverinfo.js +++ b/commands/serverinfo.js @@ -1,7 +1,7 @@ const os = require('os') const cp = require('child_process') -const version = require('../../version.json') -const {getMessage,formatTime} = require('../../util/lang.js') +const version = require('../version.json') +const {getMessage,formatTime} = require('../util/lang.js') const fs = require('fs') const gr = function (l, text, value, color) { if (!color) color = 'white' diff --git a/plugins/commands/stop.js b/commands/stop.js similarity index 100% rename from plugins/commands/stop.js rename to commands/stop.js diff --git a/plugins/commands/template.js b/commands/template.js similarity index 100% rename from plugins/commands/template.js rename to commands/template.js diff --git a/plugins/commands/tpr.js b/commands/tpr.js similarity index 95% rename from plugins/commands/tpr.js rename to commands/tpr.js index ffd7bf0..4c3dcb2 100755 --- a/plugins/commands/tpr.js +++ b/commands/tpr.js @@ -1,4 +1,4 @@ -const {getMessage} = require('../../util/lang.js') +const {getMessage} = require('../util/lang.js') module.exports = { execute: function (c) { let uuid diff --git a/plugins/commands/verify.js b/commands/verify.js similarity index 100% rename from plugins/commands/verify.js rename to commands/verify.js diff --git a/plugins/command.js b/plugins/command.js index e8b07fb..1fd2878 100755 --- a/plugins/command.js +++ b/plugins/command.js @@ -1,35 +1,8 @@ -const fs = require('fs') const Command = require('../util/Command.js') const hashcheck = require('../util/hashcheck.js') const settings = require('../settings.json') const {getMessage} = require('../util/lang.js') -const cmds = Object.create(null) -const bpl = fs.readdirSync('./plugins/commands') -for (const i in bpl) { // Built-in loadCMD - if (!bpl[i].endsWith('.js')) { - continue - } - try { - const commandName = bpl[i].split('.js')[0] - cmds[commandName] = require(`./commands/${bpl[i]}`) - if (cmds[commandName].level === undefined) { - cmds[commandName].level = 0 - } - console.log('Loaded command ' + commandName) - if (cmds[commandName].aliases) { - for (const j in cmds[commandName].aliases) { - cmds[cmds[commandName].aliases[j]] = { - execute: cmds[commandName].execute, - desc: 'Alias to ' + commandName, - usage: cmds[commandName].usage, - level: cmds[commandName].level, - hidden: true, - consoleIndex: cmds[commandName].consoleIndex - } - } - } - } catch (e) { console.log(e) } -} +const cmds = require("../util/commands.js") const sortHelp = function sortHelp (c1, c2) { const level1 = cmds[c1.with[0]].level ? cmds[c1.with[0]].level : 0 @@ -176,6 +149,5 @@ module.exports = { ] }) } - }, - cmds + } } diff --git a/plugins/console.js b/plugins/console.js index 83d43da..995eb46 100644 --- a/plugins/console.js +++ b/plugins/console.js @@ -1,7 +1,7 @@ const readln = require('readline') const index = require('../index.js') const ConsoleCommand = require('../util/ConsoleCommand.js') -const newercommands = require('./command.js').cmds +const cmds = require("../util/commands.js") const rl = readln.createInterface({ input: process.stdin, output: process.stdout, @@ -9,22 +9,22 @@ const rl = readln.createInterface({ }) rl.on('line', (l) => { try { - if (newercommands[l.split(' ')[0].toLowerCase()]) { - if (newercommands[l.split(' ')[0].toLowerCase()].consoleIndex) { + if (cmds[l.split(' ')[0].toLowerCase()]) { + if (cmds[l.split(' ')[0].toLowerCase()].consoleIndex) { const tmpcmd = l.split(' ') const index2 = tmpcmd.splice(1, 1)[0] if (index2 === '*') { for (let i = 0; i < index.bot.length; i++) { const cmd = new ConsoleCommand(tmpcmd.join(' '), i) - newercommands[l.split(' ')[0].toLowerCase()].execute(cmd) + cmds[l.split(' ')[0].toLowerCase()].execute(cmd) } } else { const cmd = new ConsoleCommand(tmpcmd.join(' '), +index2) - newercommands[l.split(' ')[0].toLowerCase()].execute(cmd) + cmds[l.split(' ')[0].toLowerCase()].execute(cmd) } } else { const cmd = new ConsoleCommand(l, -2) - newercommands[l.split(' ')[0].toLowerCase()].execute(cmd) + cmds[l.split(' ')[0].toLowerCase()].execute(cmd) } } } catch (e) { diff --git a/util/ConsoleCommand.js b/util/ConsoleCommand.js index a7d3b28..c6b0d8a 100644 --- a/util/ConsoleCommand.js +++ b/util/ConsoleCommand.js @@ -1,6 +1,6 @@ // HOW TO WRITE CLASS JS const index = require('../index.js') -const { cmds } = require('../plugins/command.js') +const cmds = require('./commands.js') const parse = require('../util/chatparse_console.js') const settings = require('../settings.json') const {getMessage} = require('../util/lang.js') diff --git a/util/commands.js b/util/commands.js new file mode 100644 index 0000000..7d25194 --- /dev/null +++ b/util/commands.js @@ -0,0 +1,29 @@ +const fs = require('fs') +const cmds = Object.create(null) +const bpl = fs.readdirSync('./commands') +for (const i in bpl) { // Built-in loadCMD + if (!bpl[i].endsWith('.js')) { + continue + } + try { + const commandName = bpl[i].split('.js')[0] + cmds[commandName] = require(`../commands/${bpl[i]}`) + if (cmds[commandName].level === undefined) { + cmds[commandName].level = 0 + } + console.log('Loaded command ' + commandName) + if (cmds[commandName].aliases) { + for (const j in cmds[commandName].aliases) { + cmds[cmds[commandName].aliases[j]] = { + execute: cmds[commandName].execute, + desc: 'Alias to ' + commandName, + usage: cmds[commandName].usage, + level: cmds[commandName].level, + hidden: true, + consoleIndex: cmds[commandName].consoleIndex + } + } + } + } catch (e) { console.log(e) } +} +module.exports=cmds; \ No newline at end of file