owobot/plugins/console.js

58 lines
1.6 KiB
JavaScript
Raw Normal View History

2024-07-30 05:56:23 -04:00
const readln = require('readline')
const index = require('../index.js')
const ConsoleCommand = require('../util/ConsoleCommand.js')
2024-08-04 01:41:32 -04:00
const cmds = require('../util/commands.js')
2024-09-19 00:50:02 -04:00
const settings = require('../settings.json')
2024-07-30 05:56:23 -04:00
const rl = readln.createInterface({
input: process.stdin,
output: process.stdout,
prompt: '\x1b[0m> '
2024-07-30 05:56:23 -04:00
})
rl.on('line', (l) => {
try {
2024-08-03 03:00:04 -04:00
if (cmds[l.split(' ')[0].toLowerCase()]) {
if (cmds[l.split(' ')[0].toLowerCase()].consoleIndex) {
2024-07-30 05:56:23 -04:00
const tmpcmd = l.split(' ')
const index2 = tmpcmd.splice(1, 1)[0]
if (index2 === '*') {
2024-09-11 23:44:17 -04:00
for (let i = 0; i < index.bots.length; i++) {
2024-07-30 05:56:23 -04:00
const cmd = new ConsoleCommand(tmpcmd.join(' '), i)
2024-08-03 03:00:04 -04:00
cmds[l.split(' ')[0].toLowerCase()].execute(cmd)
2024-07-30 05:56:23 -04:00
}
} else {
const cmd = new ConsoleCommand(tmpcmd.join(' '), +index2)
2024-08-03 03:00:04 -04:00
cmds[l.split(' ')[0].toLowerCase()].execute(cmd)
2024-07-30 05:56:23 -04:00
}
} else {
const cmd = new ConsoleCommand(l, -2)
2024-08-03 03:00:04 -04:00
cmds[l.split(' ')[0].toLowerCase()].execute(cmd)
2024-07-30 05:56:23 -04:00
}
}
} catch (e) {
console.log(e)
}
rl.prompt(false)
})
rl.prompt()
2024-08-04 02:49:20 -04:00
2024-07-30 05:56:23 -04:00
function consoleWrite (text) {
readln.cursorTo(process.stdout, 0)
readln.clearLine(process.stdout, 0)
process.stdout.write(text + '\n')
rl.prompt(true)
}
module.exports = {
load: (b) => {
b.info = (msg) => {
consoleWrite(`[${b.id}] [info] ${msg}`)
}
b.displayChat = (type, subtype, msg) => {
2024-09-19 22:21:01 -04:00
if (settings.displaySubtypesToConsole) {
consoleWrite(`[${b.id}] [${type}] [${subtype}] ${msg}`)
} else {
consoleWrite(`[${b.id}] [${type}] ${msg}`)
}
}
}
2024-07-30 05:56:23 -04:00
}