Added console and some useful commands

This commit is contained in:
7cc5c4f330d47060 2024-10-26 22:10:16 -04:00
parent 1569f83dae
commit 7e14f4d241
Signed by: 7cc5c4f330d47060
SSH key fingerprint: SHA256:e+4tcZut1nBpe10PqjaO+Rvie0Q7W4qIvFzcUw+7riA
5 changed files with 167 additions and 2 deletions

51
commands/eval.js Executable file
View file

@ -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 }

41
commands/say.js Executable file
View file

@ -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 }

View file

@ -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"
}

69
plugins/console.js Executable file
View file

@ -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}`)
}
}
}

View file

@ -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
}
}