diff --git a/commands/help.js b/commands/help.mjs similarity index 75% rename from commands/help.js rename to commands/help.mjs index 16dfb52..beacd46 100644 --- a/commands/help.js +++ b/commands/help.mjs @@ -1,6 +1,4 @@ -const fs = require('fs') -const cmds = Object.create(null) -const { getMessage } = require('../util/lang.js') +import { getMessage } from '../util/lang.js' const sortHelp = function sortHelp (c1, c2) { const level1 = cmds[c1.with[0]].level ? cmds[c1.with[0]].level : 0 @@ -8,21 +6,7 @@ const sortHelp = function sortHelp (c1, c2) { return level1 - level2 } -const bpl = fs.readdirSync('./commands') -for (const i in bpl) { - if (!bpl[i].endsWith('.js')) { - continue - } - try { - const commandName = bpl[i].split('.js')[0] - if (commandName !== 'help') { - cmds[commandName] = require(`./${bpl[i]}`) - if (cmds[commandName].level === undefined) { - cmds[commandName].level = 0 - } - } - } catch (e) { console.log(e) } -} +import { default as cmds } from '../util/commands.js' const printHelp = (c) => { const commandList = [] @@ -132,7 +116,7 @@ const printCmdHelp = (c) => { }) } -module.exports = { +export default { execute: (c) => { if (c.args.length > 0) { printCmdHelp(c) @@ -144,22 +128,3 @@ module.exports = { 'heko' // Parker2991 request ] } - -cmds.help = module.exports // Placed after to ensure that the correct values are added to cmds -if (cmds.help.level === undefined) { - cmds.help.level = 0 -} - -for (const i in cmds) { - if (cmds[i].aliases) { - for (const j in cmds[i].aliases) { - cmds[cmds[i].aliases[j]] = { - alias: i, - usage: cmds[i].usage, - level: cmds[i].level, - hidden: true, - consoleIndex: cmds[i].consoleIndex - } - } - } -} diff --git a/index.js b/index.js index a262afb..bd6c060 100755 --- a/index.js +++ b/index.js @@ -16,6 +16,7 @@ import { default as botplug_cmd } from "./plugins/command.mjs" import { default as botplug_cmdCore } from "./plugins/commandblock.mjs" import { default as botplug_selfCare } from "./plugins/selfcare.mjs" import { default as botplug_rejoin } from "./plugins/rejoin.mjs" +import { default as botplug_console } from "./plugins/console.mjs" botplug.push(botplug_test) botplug.push(botplug_chat) @@ -25,6 +26,7 @@ botplug.push(botplug_cmd) botplug.push(botplug_cmdCore) botplug.push(botplug_selfCare) botplug.push(botplug_rejoin) +botplug.push(botplug_console) const bpl = fs.readdirSync('plugins') diff --git a/plugins/console.js b/plugins/console.mjs similarity index 82% rename from plugins/console.js rename to plugins/console.mjs index f025f92..e82cc4f 100644 --- a/plugins/console.js +++ b/plugins/console.mjs @@ -1,7 +1,7 @@ -const readln = require('readline') -const index = require('../index.js') -const ConsoleCommand = require('../util/ConsoleCommand.js') -const cmds = require('../util/commands.js') +import * as readln from 'readline' +import { bot } from '../index.js' +import { default as ConsoleCommand } from '../util/ConsoleCommand.js' +import { default as cmds } from '../util/commands.js' const rl = readln.createInterface({ input: process.stdin, output: process.stdout, @@ -14,7 +14,7 @@ rl.on('line', (l) => { const tmpcmd = l.split(' ') const index2 = tmpcmd.splice(1, 1)[0] if (index2 === '*') { - for (let i = 0; i < index.bot.length; i++) { + for (let i = 0; i < bot.length; i++) { const cmd = new ConsoleCommand(tmpcmd.join(' '), i) cmds[l.split(' ')[0].toLowerCase()].execute(cmd) } @@ -40,7 +40,7 @@ function consoleWrite (text) { process.stdout.write(text + '\n') rl.prompt(true) } -module.exports = { +export default { load: (b) => { b.info = (msg) => { consoleWrite(`[${b.id}] [info] ${msg}`) diff --git a/util/ConsoleCommand.js b/util/ConsoleCommand.js index f062f23..317986e 100644 --- a/util/ConsoleCommand.js +++ b/util/ConsoleCommand.js @@ -1,6 +1,6 @@ -const index = require('../index.js') -const parse = require('../util/chatparse_console.js') -const settings = require('../settings.json') +import { bot } from '../index.js' +import { default as parse } from '../util/chatparse_console.js' +import { default as settings } from '../settings.json' with {type: "json"} class ConsoleCommand { constructor (cmd, index2) { this.send = () => {} @@ -12,7 +12,7 @@ class ConsoleCommand { this.msgType = '_bot_console' this.prefix = '' this.bot = index2 >= 0 - ? index.bot[index2] + ? bot[index2] : {} this.type = 'console' this.args = cmd.split(' ').slice(1) @@ -23,5 +23,4 @@ class ConsoleCommand { this.colors = settings.colors } } - -module.exports = ConsoleCommand +export default ConsoleCommand diff --git a/util/commands.js b/util/commands.js index 885df3d..35da58b 100644 --- a/util/commands.js +++ b/util/commands.js @@ -3,10 +3,12 @@ const cmds = Object.create(null) import { default as commandTest } from "../commands/test.mjs" import { default as commandSay } from "../commands/say.mjs" import { default as commandNetmsg } from "../commands/netmsg.mjs" +import { default as commandHelp } from "../commands/help.mjs" cmds.test = commandTest cmds.say = commandSay cmds.netmsg = commandNetmsg +cmds.help = commandHelp for(const commandName in cmds){ if (cmds[commandName].aliases) {