add date to console + big config change

This commit is contained in:
ChomeNS 2023-03-14 16:12:37 +07:00
parent e6773a9f62
commit 0f4aa08108
7 changed files with 138 additions and 44 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
/launcher_accounts.json /launcher_accounts.json
/node_modules /node_modules
/package-lock.json /package-lock.json
/config.js

16
bot.js
View file

@ -17,15 +17,13 @@ const randomstring = require('randomstring')
async function createBot (server, config, getBots, setNewBot, dcclient, rl) { async function createBot (server, config, getBots, setNewBot, dcclient, rl) {
const bot = new EventEmitter() const bot = new EventEmitter()
bot.options = { bot.options = {
username: !server.kaboom username: server.username ?? randomstring.generate(8),
? 'ChomeNS_Bot' host: server.host ?? 'localhost',
: randomstring.generate(8), port: server.port ?? 25565,
host: server.host,
port: server.port,
version: config.version, version: config.version,
kaboom: server.kaboom, kaboom: server.kaboom ?? false,
logging: server.logging, logging: server.logging ?? true,
useChat: server.useChat, useChat: server.useChat ?? false,
checkTimeoutInterval: config.timeoutInterval, checkTimeoutInterval: config.timeoutInterval,
hideErrors: true hideErrors: true
} }
@ -56,7 +54,7 @@ async function createBot (server, config, getBots, setNewBot, dcclient, rl) {
setNewBot(bot.server.host, bot) 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( channel.send(
`Connecting to: \`${bot.server.host}:${bot.server.port}\`` `Connecting to: \`${bot.server.host}:${bot.server.port}\``

View file

@ -54,23 +54,20 @@ module.exports = {
timeoutInterval: 1000 * 40, timeoutInterval: 1000 * 40,
self_care_check_interval: 2000, self_care_check_interval: 2000,
discord: { discord: {
prefix: '!',
token: 'OTcxNjUwNDU2NzA5Mzk4NTY5.G3lKC2._XQNTTU1Jqmaam_A0JKSe93GP1vFZvDpiXqZzA', token: 'OTcxNjUwNDU2NzA5Mzk4NTY5.G3lKC2._XQNTTU1Jqmaam_A0JKSe93GP1vFZvDpiXqZzA',
servers: { servers: {
'sus.shhnowisnottheti.me': '990140129245020221', 'play.kaboom.pw:25565': '1000355361196355674',
'play.kaboom.pw': '1000355361196355674', 'sus.shhnowisnottheti.me:25565': '990140129245020221',
'129.159.58.114': '998945155316973650', 'kitsune.icu:61530': '1004006678460637315',
'192.168.1.103': '1002806756885413978', 'play.chipmunk.land:25565': '1042590315464364032',
'kitsune.icu': '1004006678460637315', 'mcslot.eu:25565': '1057090538404323338',
'fallback.kitsune.icu': '1050764247518412850', 'chayapak.chipmunk.land:25565': '1010734897796763758'
'chayapak.chipmunk.land': '1010734897796763758',
'play.chipmunk.land': '1042590315464364032',
'mcslot.eu': '1057090538404323338'
}, },
embedsColors: { embedsColors: {
normal: '#FFFF00', normal: '#FFFF00',
error: '#FF0000' error: '#FF0000'
}, }
prefix: '!'
}, },
servers: [ servers: [
// logging means log to console // logging means log to console
@ -90,7 +87,7 @@ module.exports = {
}, },
{ {
host: 'kitsune.icu', host: 'kitsune.icu',
port: 25565, port: 61530,
kaboom: true, kaboom: true,
logging: false, logging: false,
useChat: false useChat: false
@ -103,14 +100,14 @@ module.exports = {
useChat: false useChat: false
}, },
{ {
host: 'mcslot.eu', host: 'chayapak.chipmunk.land',
port: 25565, port: 25565,
kaboom: true, kaboom: true,
logging: true, logging: true,
useChat: false useChat: false
}, },
{ {
host: 'chayapak.chipmunk.land', host: 'mcslot.eu',
port: 25565, port: 25565,
kaboom: true, kaboom: true,
logging: true, logging: true,

78
default.js Normal file
View file

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

View file

@ -1,8 +1,15 @@
const fs = require('fs/promises')
const fileExist = require('./util/file-exists')
const path = require('path')
const { createBot } = require('./bot')
let config
function load () {
// these stuff takes time to load so i move it here
const readline = require('node:readline') const readline = require('node:readline')
const { stdin: input, stdout: output } = require('node:process') const { stdin: input, stdout: output } = require('node:process')
const rl = readline.createInterface({ input, output }) const rl = readline.createInterface({ input, output })
const config = require('./config')
const { createBot } = require('./bot')
const { Client, GatewayIntentBits } = require('discord.js') const { Client, GatewayIntentBits } = require('discord.js')
const { MessageContent, GuildMessages, Guilds } = GatewayIntentBits const { MessageContent, GuildMessages, Guilds } = GatewayIntentBits
@ -22,6 +29,19 @@ dcclient.on('ready', () => {
}) })
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) => { process.on('uncaughtException', (e) => {
console.log('uncaught ' + e.stack) console.log('uncaught ' + e.stack)

View file

@ -11,7 +11,7 @@ function inject (bot, _dcclient, config, rl) {
const chatMessage = require('prismarine-chat')(bot.version) const chatMessage = require('prismarine-chat')(bot.version)
function prefix (prefix, _message) { 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() const component = chatMessage.MessageBuilder.fromString(message).toJSON()
return chatMessage.fromNotch(component).toAnsi() + _message return chatMessage.fromNotch(component).toAnsi() + _message
} }

View file

@ -2,7 +2,7 @@
const { escapeMarkdown } = require('../util/escapeMarkdown') const { escapeMarkdown } = require('../util/escapeMarkdown')
async function inject (bot, dcclient, config) { async function inject (bot, dcclient, config) {
const chatMessage = require('prismarine-chat')(bot.version) 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 = '' let queue = ''
const queueInterval = setInterval(() => { const queueInterval = setInterval(() => {