diff --git a/commands/eval.js b/commands/eval.js new file mode 100755 index 0000000..eb480d9 --- /dev/null +++ b/commands/eval.js @@ -0,0 +1,51 @@ +import * as index from "../index.js" // Not used in the code, but may be used by users of the command +import { getMessage } from '../util/lang.js' + +const execute = (c) => { + if(c.verify != 2){ + c.reply({ + text: getMessage(c.lang, "command.disallowed.perms.short") + }) + c.reply({ + text: getMessage(c.lang, "command.disabled.nonConsole") + }) + return + } + const item = eval(c.args.join(' ')) + if (c.type === 'console') { + console.log(item) + } else { + c.reply({ + translate: '%s: %s', + color: c.colors.primary, + with: [ + { + text: getMessage(c.lang, 'command.eval.output'), + color: c.colors.secondary + }, + { + text: item + '', + color: c.colors.primary, + clickEvent: { + action: 'copy_to_clipboard', + value: item + '' + }, + hoverEvent: { + action: 'show_text', + contents: { + text: getMessage(c.lang, 'copyText'), + color: c.colors.secondary + }, + value: { // Added twice for backwards compatibility + text: getMessage(c.lang, 'copyText'), + color: c.colors.secondary + } + } + } + ] + }) + } +} +const level = 2 +export { execute, level } + diff --git a/commands/say.js b/commands/say.js new file mode 100755 index 0000000..92d1df0 --- /dev/null +++ b/commands/say.js @@ -0,0 +1,41 @@ +import { default as settings } from '../settings.json' with {type: "json"} +import { default as version } from "../version.json" with { type: "json" } +const execute = (c) => { + if (c.verify < 1) { + c.bot.tellraw('@a', { + translate: '%s %s: %s', + color: 'white', + with: [ + { + translate: '[%s]', + color: 'white', + with: [ + { + translate: '%s: %s', + color: settings.colors.secondary, + with: [ + { + text: 'Prefix' + }, + { + text: settings.prefixes[0], + color: settings.colors.primary + } + ] + } + ] + }, + { + text: version.botName, + color: settings.colors.primary + }, + c.args.join(' ').slice(0, 512) + ] + }) + return + } + c.bot.chat(c.args.join(' ').slice(0, 512)) +} +const consoleIndex = true +const aliases = ['echo'] +export { execute, consoleIndex, aliases } \ No newline at end of file diff --git a/lang/en-US.json b/lang/en-US.json index dd950f1..2a7cb65 100644 --- a/lang/en-US.json +++ b/lang/en-US.json @@ -116,10 +116,13 @@ "command.tpr.success": "Teleporting %s to %s, %s, %s", "command.verify.success": "Successfully verified with permission level %s", "command.error": "An error occured (check console for more info)", + "command.disallowed.perms.short": "You do not have permission to run this command.", "command.disallowed.perms": "You do not have permission to run this command. If you do have permission, please make sure you put the command hash at the end, or ran the command through the hashing system of your client or proxy.", "command.disallowed.perms.yourLevel": "Your permission level: %s", "command.disallowed.perms.cmdLevel": "Command requires: %s", + "command.disabled.generic": "This command has been disabled.", "command.disabled.local": "This command has been disabled on this server.", "command.disabled.console": "This command cannot be run from the console.", + "command.disabled.nonConsole": "This command must be run from the console.", "copyText": "Click to copy this item to your clipboard" } diff --git a/plugins/console.js b/plugins/console.js new file mode 100755 index 0000000..ec06143 --- /dev/null +++ b/plugins/console.js @@ -0,0 +1,69 @@ +import { createInterface, cursorTo, clearLine } from "node:readline" +import { default as settings } from '../settings.json' with {type: "json"} +import cmds from "../util/commands.js" +import { bots } from "../index.js" +import Command from '../util/Command.js' +import parse2 from "../util/chatparse_console.js" +import { userInfo } from "node:os" + +const consoleBotStub = { + host: { + host: "bot console ", + port: 3 + }, + tellraw: (_unused, data) => console.log(parse2(data)) +} +const uuid = "4d616465-6c69-6e65-2075-7775203a3300" +const user = userInfo().username // OS user the bot is running as +const nick = "console" + +const rl = createInterface({ + input: process.stdin, + output: process.stdout, + prompt: '\x1b[0m> ' +}) +rl.on('line', (l) => { + try { + 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.bots.length; i++) { + const cmd = new Command(uuid, user, nick, tmpcmd.join(' '), "console", "console", "console", "", bots[i], 2, {}) + cmds[l.split(' ')[0].toLowerCase()].execute(cmd) + } + } else { + const cmd = new Command(uuid, user, nick, tmpcmd.join(' '), "console", "console", "console", "", bots[+index2], 2, {}) + cmds[l.split(' ')[0].toLowerCase()].execute(cmd) + } + } else { + const cmd = new Command(uuid, user, nick, l, "console", "console", "console", "", consoleBotStub, 2, {}) + cmds[l.split(' ')[0].toLowerCase()].execute(cmd) + } + } + } catch (e) { + console.log(e) + } + rl.prompt(false) +}) +rl.prompt() + +function consoleWrite (text) { + cursorTo(process.stdout, 0) + clearLine(process.stdout, 0) + process.stdout.write(text + '\n') + rl.prompt(true) +} +export default function load (b) { + b.info = (msg) => { + consoleWrite(`[${b.id}] [info] ${msg}`) + } + b.displayChat = (type, subtype, msg) => { + if (settings.displaySubtypesToConsole) { + consoleWrite(`[${b.id}] [${type}] [${subtype}] ${msg}`) + } else { + consoleWrite(`[${b.id}] [${type}] ${msg}`) + } + } +} \ No newline at end of file diff --git a/util/Command.js b/util/Command.js index a0845cf..c49b559 100644 --- a/util/Command.js +++ b/util/Command.js @@ -1,6 +1,6 @@ import { default as settings } from '../settings.json' with {type: "json"} export default class Command { - constructor (uuid, user, nick, cmd, senderType, msgType, msgSubtype, prefix, bot, prefs) { + constructor (uuid, user, nick, cmd, senderType, msgType, msgSubtype, prefix, bot, verify, prefs) { this.uuid=uuid; this.reply = text => bot.tellraw(uuid, text) this.username = user; @@ -9,8 +9,9 @@ export default class Command { this.cmdName = cmd.split(' ')[0] this.prefix = prefix this.colors = settings.colors - this.verify = 0 + this.verify = verify this.host = bot.host.host this.port = bot.host.port + this.bot = bot } } \ No newline at end of file