diff --git a/.gitignore b/.gitignore index b1c8512..57d0253 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /launcher_accounts.json /node_modules -/package-lock.json \ No newline at end of file +/package-lock.json +/config.js \ No newline at end of file diff --git a/bot.js b/bot.js index 4014b97..0433d5f 100644 --- a/bot.js +++ b/bot.js @@ -17,15 +17,13 @@ const randomstring = require('randomstring') async function createBot (server, config, getBots, setNewBot, dcclient, rl) { const bot = new EventEmitter() bot.options = { - username: !server.kaboom - ? 'ChomeNS_Bot' - : randomstring.generate(8), - host: server.host, - port: server.port, + username: server.username ?? randomstring.generate(8), + host: server.host ?? 'localhost', + port: server.port ?? 25565, version: config.version, - kaboom: server.kaboom, - logging: server.logging, - useChat: server.useChat, + kaboom: server.kaboom ?? false, + logging: server.logging ?? true, + useChat: server.useChat ?? false, checkTimeoutInterval: config.timeoutInterval, hideErrors: true } @@ -56,7 +54,7 @@ async function createBot (server, config, getBots, setNewBot, dcclient, rl) { setNewBot(bot.server.host, bot) - const channel = dcclient.channels.cache.get(config.discord.servers[bot.server.host]) + const channel = dcclient.channels.cache.get(config.discord.servers[`${bot.server.host}:${bot.server.port}`]) channel.send( `Connecting to: \`${bot.server.host}:${bot.server.port}\`` diff --git a/config.js b/config.js index 7fd5650..602e324 100644 --- a/config.js +++ b/config.js @@ -54,23 +54,20 @@ module.exports = { timeoutInterval: 1000 * 40, self_care_check_interval: 2000, discord: { + prefix: '!', token: 'OTcxNjUwNDU2NzA5Mzk4NTY5.G3lKC2._XQNTTU1Jqmaam_A0JKSe93GP1vFZvDpiXqZzA', servers: { - 'sus.shhnowisnottheti.me': '990140129245020221', - 'play.kaboom.pw': '1000355361196355674', - '129.159.58.114': '998945155316973650', - '192.168.1.103': '1002806756885413978', - 'kitsune.icu': '1004006678460637315', - 'fallback.kitsune.icu': '1050764247518412850', - 'chayapak.chipmunk.land': '1010734897796763758', - 'play.chipmunk.land': '1042590315464364032', - 'mcslot.eu': '1057090538404323338' + 'play.kaboom.pw:25565': '1000355361196355674', + 'sus.shhnowisnottheti.me:25565': '990140129245020221', + 'kitsune.icu:61530': '1004006678460637315', + 'play.chipmunk.land:25565': '1042590315464364032', + 'mcslot.eu:25565': '1057090538404323338', + 'chayapak.chipmunk.land:25565': '1010734897796763758' }, embedsColors: { normal: '#FFFF00', error: '#FF0000' - }, - prefix: '!' + } }, servers: [ // logging means log to console @@ -90,7 +87,7 @@ module.exports = { }, { host: 'kitsune.icu', - port: 25565, + port: 61530, kaboom: true, logging: false, useChat: false @@ -103,14 +100,14 @@ module.exports = { useChat: false }, { - host: 'mcslot.eu', + host: 'chayapak.chipmunk.land', port: 25565, kaboom: true, logging: true, useChat: false }, { - host: 'chayapak.chipmunk.land', + host: 'mcslot.eu', port: 25565, kaboom: true, logging: true, diff --git a/default.js b/default.js new file mode 100644 index 0000000..d970846 --- /dev/null +++ b/default.js @@ -0,0 +1,78 @@ +module.exports = { + version: '1.19.2', + prefixes: [ + 'default*', + 'defaultcbot ', + '/defaultcbot ' + ], + commandsDir: '../commands', // this will be used by the commands.js in the plugins folder so it needs ../ + keys: { + normalKey: 'normal hash key here', + ownerHashKey: 'OwnerHash™ key here' + }, + proxy: { + enabled: true, + version: '1.19.2' + }, + console: true, + chat: { + messageLength: 100 + }, + core: { + layers: 3, + refillInterval: 1000 * 60, + customName: [ + { + text: 'ChomeNS ', + color: 'yellow' + }, + { + text: 'Core', + color: 'green' + }, + { + text: '\u2122', + color: 'gold' + } + ] + }, + self_care: { + prefix: true, + op: true, + cspy: true, + vanish: true, + nickname: true, + socialspy: true, + gamemode: true, + mute: true, + endCredits: true + }, + eval: { + serverUrl: 'http://localhost:4445/' + }, + reconnectTimeout: 1000 * 2, + timeoutInterval: 1000 * 40, + self_care_check_interval: 2000, + discord: { + prefix: 'default!', + token: 'token here', + servers: { + 'localhost:25565': '696969696969696969' + }, + embedsColors: { + normal: '#FFFF00', + error: '#FF0000' + } + }, + servers: [ + // logging means log to console + { + host: 'localhost', + port: 25565, + username: 'ChomeNS_Bot', + kaboom: false, + logging: true, + useChat: false + } + ] +} diff --git a/index.js b/index.js index d6a94c5..ab58203 100644 --- a/index.js +++ b/index.js @@ -1,27 +1,47 @@ -const readline = require('node:readline') -const { stdin: input, stdout: output } = require('node:process') -const rl = readline.createInterface({ input, output }) -const config = require('./config') +const fs = require('fs/promises') +const fileExist = require('./util/file-exists') +const path = require('path') const { createBot } = require('./bot') -const { Client, GatewayIntentBits } = require('discord.js') -const { MessageContent, GuildMessages, Guilds } = GatewayIntentBits -const dcclient = new Client({ intents: [Guilds, GuildMessages, MessageContent] }) +let config -let bots = [] +function load () { + // these stuff takes time to load so i move it here + const readline = require('node:readline') + const { stdin: input, stdout: output } = require('node:process') + const rl = readline.createInterface({ input, output }) + const { Client, GatewayIntentBits } = require('discord.js') + const { MessageContent, GuildMessages, Guilds } = GatewayIntentBits -dcclient.on('ready', () => { - for (const server of config.servers) { - const getBots = () => bots - const setNewBot = (server, bot) => { - bots = bots.filter((eachBot) => eachBot.server.host !== server) - bots.push(bot) + const dcclient = new Client({ intents: [Guilds, GuildMessages, MessageContent] }) + + let bots = [] + + dcclient.on('ready', () => { + for (const server of config.servers) { + const getBots = () => bots + const setNewBot = (server, bot) => { + bots = bots.filter((eachBot) => eachBot.server.host !== server) + bots.push(bot) + } + createBot(server, config, getBots, setNewBot, dcclient, rl) } - createBot(server, config, getBots, setNewBot, dcclient, rl) - } -}) + }) -dcclient.login(config.discord.token) + dcclient.login(config.discord.token) +} + +// TODO: improve this thing +async function checkConfig () { + if (!await fileExist(path.join(__dirname, 'config.js'))) { + console.error('Config file doesn\'t exist, so the default one was created') + await fs.copyFile(path.join(__dirname, 'default.js'), path.join(__dirname, 'config.js')) + } + config = require('./config') + load() +} + +checkConfig() process.on('uncaughtException', (e) => { console.log('uncaught ' + e.stack) diff --git a/plugins/console.js b/plugins/console.js index 5e84488..f21f5aa 100644 --- a/plugins/console.js +++ b/plugins/console.js @@ -11,7 +11,7 @@ function inject (bot, _dcclient, config, rl) { const chatMessage = require('prismarine-chat')(bot.version) function prefix (prefix, _message) { - const message = `[${moment().format('HH:mm:ss')} ${prefix}§r] [${bot.server.host}] ` + const message = `[${moment().format('DD/MM/YY HH:mm:ss')} ${prefix}§r] [${bot.server.host}] ` const component = chatMessage.MessageBuilder.fromString(message).toJSON() return chatMessage.fromNotch(component).toAnsi() + _message } diff --git a/plugins/discord.js b/plugins/discord.js index c111405..e3e06be 100644 --- a/plugins/discord.js +++ b/plugins/discord.js @@ -2,7 +2,7 @@ const { escapeMarkdown } = require('../util/escapeMarkdown') async function inject (bot, dcclient, config) { const chatMessage = require('prismarine-chat')(bot.version) - const channel = dcclient.channels.cache.get(config.discord.servers[bot.server.host]) + const channel = dcclient.channels.cache.get(config.discord.servers[`${bot.server.host}:${bot.server.port}`]) let queue = '' const queueInterval = setInterval(() => {