use standard and not google cuz BAD

This commit is contained in:
ChomeNS 2022-11-27 14:35:28 +07:00
parent 37f88488f6
commit 1a7e5af054
66 changed files with 1622 additions and 1615 deletions

View file

@ -4,7 +4,7 @@
"es2021": true
},
"extends": [
"google"
"standard"
],
"parserOptions": {
"ecmaVersion": "latest",

178
bot.js
View file

@ -1,20 +1,20 @@
/* eslint-disable max-len */
const mc = require('minecraft-protocol');
const crypto = require('crypto');
const colorConvert = require('color-convert');
const sleep = require('sleep-promise');
const generateEaglerUsername = require('./util/generateEaglerUsername');
const {EventEmitter} = require('events');
const {loadPlugins} = require('./util/loadPlugins');
const uuid = require('uuid-by-string');
const moment = require('moment-timezone');
const cowsay = require('cowsay2');
const cows = require('cowsay2/cows');
const util = require('node:util');
const {VM} = require('vm2');
const randomstring = require('randomstring');
const mineflayer = require('mineflayer');
const mc = require('minecraft-protocol')
const crypto = require('crypto')
const colorConvert = require('color-convert')
const sleep = require('sleep-promise')
const generateEaglerUsername = require('./util/generateEaglerUsername')
const { EventEmitter } = require('events')
const { loadPlugins } = require('./util/loadPlugins')
const uuid = require('uuid-by-string')
const moment = require('moment-timezone')
const cowsay = require('cowsay2')
const cows = require('cowsay2/cows')
const util = require('node:util')
const { VM } = require('vm2')
const randomstring = require('randomstring')
const mineflayer = require('mineflayer')
/**
* makes the bot
@ -26,63 +26,63 @@ const mineflayer = require('mineflayer');
* @param {object} rl readline.
* @return {object} the bot object
*/
async function createBot(server, config, getBots, setNewBot, dcclient, rl) {
const bot = new EventEmitter();
async function createBot (server, config, getBots, setNewBot, dcclient, rl) {
const bot = new EventEmitter()
bot.options = {
username: !server.kaboom ?
'ChomeNS_Bot' :
randomstring.generate(8),
username: !server.kaboom
? 'ChomeNS_Bot'
: randomstring.generate(8),
host: server.host,
port: server.port,
version: config.version,
kaboom: server.kaboom,
checkTimeoutInterval: '30000',
keepAlive: false,
hideErrors: true,
};
bot._client = mc.createClient(bot.options);
bot.version = bot._client.version;
bot.write = (name, data) => bot._client.write(name, data);
hideErrors: true
}
bot._client = mc.createClient(bot.options)
bot.version = bot._client.version
bot.write = (name, data) => bot._client.write(name, data)
bot.end = (reason = 'end', event) => {
bot.emit('end', reason, event);
bot.removeAllListeners();
bot._client.end();
bot._client.removeAllListeners();
};
bot.visibility = false;
bot.getBots = getBots;
bot.getplayerusername = {};
bot.emit('end', reason, event)
bot.removeAllListeners()
bot._client.end()
bot._client.removeAllListeners()
}
bot.visibility = false
bot.getBots = getBots
bot.getplayerusername = {}
await sleep(200);
await sleep(200)
setNewBot(bot.options.host, bot);
setNewBot(bot.options.host, bot)
await loadPlugins(bot, dcclient, config, rl);
await loadPlugins(bot, dcclient, config, rl)
const channel = dcclient.channels.cache.get(config.discord.servers[bot.options.host]);
const channel = dcclient.channels.cache.get(config.discord.servers[bot.options.host])
bot.playersAddedPlayers = {};
bot.getplayerusername = {};
bot.playersAddedPlayers = {}
bot.getplayerusername = {}
bot._client.on('login', async function(data) {
bot.entityId = data.entityId;
bot.uuid = bot._client.uuid;
bot.username = bot._client.username;
chatMessage = require('prismarine-chat')(bot.version);
const mcData = require('minecraft-data')(bot.version);
bot._client.on('login', async function (data) {
bot.entityId = data.entityId
bot.uuid = bot._client.uuid
bot.username = bot._client.username
const chatMessage = require('prismarine-chat')(bot.version)
const mcData = require('minecraft-data')(bot.version)
bot.console.info(
`Successfully logged in to: ${bot.options.host}:${bot.options.port}`,
);
`Successfully logged in to: ${bot.options.host}:${bot.options.port}`
)
channel.send(
`Successfully logged in to: \`${bot.options.host}:${bot.options.port}\``,
);
bot.eaglercrashstarted = false;
`Successfully logged in to: \`${bot.options.host}:${bot.options.port}\``
)
bot.eaglercrashstarted = false
bot.vmoptions = {
timeout: 2000,
sandbox: {
run(cmd) {
bot.core.run(cmd);
run (cmd) {
bot.core.run(cmd)
},
mc,
mineflayer,
@ -93,19 +93,19 @@ async function createBot(server, config, getBots, setNewBot, dcclient, rl) {
chatMessage,
crypto,
colorConvert,
bruhifyText(message) {
bruhifyText (message) {
if (
typeof message !== 'string'
) throw new SyntaxError('message must be a string');
bot.bruhifyText = message.substring(0, 1000);
) throw new SyntaxError('message must be a string')
bot.bruhifyText = message.substring(0, 1000)
},
generateEaglerUsername,
cowsay,
cows,
mcData,
},
};
bot.vm = new VM(bot.vmoptions);
mcData
}
}
bot.vm = new VM(bot.vmoptions)
// await sleep(1400);
// bot.tellraw('@a', [
@ -126,24 +126,24 @@ async function createBot(server, config, getBots, setNewBot, dcclient, rl) {
// color: 'gold',
// },
// ]);
});
})
bot.on('player_added', (player) => {
bot.playersAddedPlayers[player.name] = player.UUID;
bot.getplayerusername[player.UUID] = player.name;
});
bot.playersAddedPlayers[player.name] = player.UUID
bot.getplayerusername[player.UUID] = player.name
})
bot._client.on('end', function(reason) {
bot.end(reason, 'end');
});
bot._client.on('end', function (reason) {
bot.end(reason, 'end')
})
bot.once('end', (reason, event) => {
bot.console.info(
`Disconnected from ${bot.options.host} (${event} event): ${util.inspect(reason)}`,
);
channel.send(`Disconnected: \`${util.inspect(reason)}\``);
`Disconnected from ${bot.options.host} (${event} event): ${util.inspect(reason)}`
)
channel.send(`Disconnected: \`${util.inspect(reason)}\``)
let timeout = config.reconnectTimeout;
let timeout = config.reconnectTimeout
try {
if (reason.text) {
@ -151,35 +151,35 @@ async function createBot(server, config, getBots, setNewBot, dcclient, rl) {
'Wait 5 seconds before connecting, thanks! :)' ||
reason.text ===
'You are logging in too fast, try again later.'
) timeout = 1000 * 7;
) timeout = 1000 * 7
}
} catch (e) {
bot.console.error(e);
bot.console.error(e)
}
setTimeout(() => {
bot.end();
createBot(server, config, getBots, setNewBot, dcclient, rl);
}, timeout);
});
bot.end()
createBot(server, config, getBots, setNewBot, dcclient, rl)
}, timeout)
})
bot._client.on('keep_alive', (packet) => {
bot.write('keep_alive', {keepAliveId: packet.keepAliveId});
});
bot.write('keep_alive', { keepAliveId: packet.keepAliveId })
})
bot._client.on('kick_disconnect', function(data) {
const parsed = JSON.parse(data.reason);
bot.end(parsed, 'kick_disconnect');
});
bot._client.on('kick_disconnect', function (data) {
const parsed = JSON.parse(data.reason)
bot.end(parsed, 'kick_disconnect')
})
bot._client.on('disconnect', function(data) {
const parsed = JSON.parse(data.reason);
bot.end(parsed, 'disconnect');
});
bot._client.on('disconnect', function (data) {
const parsed = JSON.parse(data.reason)
bot.end(parsed, 'disconnect')
})
bot._client.on('error', function() {});
bot._client.on('error', function () {})
return bot;
return bot
};
module.exports = {createBot};
module.exports = { createBot }

View file

@ -5,10 +5,10 @@ module.exports = {
description: 'Sudos everyone on Ayunboom!',
trusted: 1,
usage: '<hash> <c:|command>',
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.core.run(`essentials:sudo * ${args.slice(1).join(' ')}`);
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.core.run(`essentials:sudo * ${args.slice(1).join(' ')}`)
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message) {
bot.core.run(`essentials:sudo * ${args.join(' ')}`);
},
};
discordExecute: function (bot, username, usernameraw, sender, prefix, args, channeldc, message) {
bot.core.run(`essentials:sudo * ${args.join(' ')}`)
}
}

View file

@ -1,19 +1,19 @@
/* eslint-disable max-len */
const {MessageEmbed} = require('discord.js');
const { MessageEmbed } = require('discord.js')
module.exports = {
name: 'botuser',
alias: [],
description: 'Shows the bot\'s username and UUID',
usage: '',
trusted: 0,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.tellraw(selector, [{text: 'The bot\'s username is: ', color: 'white'}, {text: `${bot.username}`, color: 'gold', clickEvent: {action: 'copy_to_clipboard', value: `${bot.username}`}, hoverEvent: {action: 'show_text', contents: [{text: 'Click here to copy the username to your clipboard', color: 'green'}]}}, {text: ' and the UUID is: '}, {text: `${bot.uuid}`, color: 'aqua', clickEvent: {action: 'copy_to_clipboard', value: `${bot.uuid}`}, hoverEvent: {action: 'show_text', contents: [{text: 'Click here to copy the UUID to your clipboard', color: 'green'}]}}]);
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.tellraw(selector, [{ text: 'The bot\'s username is: ', color: 'white' }, { text: `${bot.username}`, color: 'gold', clickEvent: { action: 'copy_to_clipboard', value: `${bot.username}` }, hoverEvent: { action: 'show_text', contents: [{ text: 'Click here to copy the username to your clipboard', color: 'green' }] } }, { text: ' and the UUID is: ' }, { text: `${bot.uuid}`, color: 'aqua', clickEvent: { action: 'copy_to_clipboard', value: `${bot.uuid}` }, hoverEvent: { action: 'show_text', contents: [{ text: 'Click here to copy the UUID to your clipboard', color: 'green' }] } }])
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message) {
discordExecute: function (bot, username, usernameraw, sender, prefix, args, channeldc, message) {
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Bot\'s User')
.setDescription(`The bot's username is: \`${bot.username}\` and the UUID is: \`${bot.uuid}\``);
channeldc.send({embeds: [Embed]});
},
};
.setDescription(`The bot's username is: \`${bot.username}\` and the UUID is: \`${bot.uuid}\``)
channeldc.send({ embeds: [Embed] })
}
}

View file

@ -1,5 +1,5 @@
/* eslint-disable max-len */
const {MessageEmbed} = require('discord.js');
const { MessageEmbed } = require('discord.js')
module.exports = {
name: 'botvisibility',
alias: ['botvis', 'togglevis', 'togglevisibility'],
@ -7,58 +7,58 @@ module.exports = {
usage: [
'<hash> <true|false>',
'<hash> <on|off>',
'<hash>',
'<hash>'
],
trusted: 1,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
if (args[1] === 'true' || args[1] === 'on') {
bot.visibility = true;
bot.chat('/essentials:vanish disable');
bot.tellraw(selector, [{text: 'The bot\'s visibility is now ', color: 'white'}, {text: 'visible', color: 'green'}]);
bot.visibility = true
bot.chat('/essentials:vanish disable')
bot.tellraw(selector, [{ text: 'The bot\'s visibility is now ', color: 'white' }, { text: 'visible', color: 'green' }])
} else if (args[1] === 'false' || args[1] === 'off') {
bot.visibility = false;
bot.chat('/essentials:vanish enable');
bot.tellraw(selector, [{text: 'The bot\'s visibility is now ', color: 'white'}, {text: 'invisible', color: 'gold'}]);
bot.visibility = false
bot.chat('/essentials:vanish enable')
bot.tellraw(selector, [{ text: 'The bot\'s visibility is now ', color: 'white' }, { text: 'invisible', color: 'gold' }])
} else if (!args[1]) {
bot.visibility = !bot.visibility;
const greenOrGold = bot.visibility ? 'green' : 'gold';
const visibleOrInvisible = bot.visibility ? 'visible' : 'invisible';
const enableOrDisable = bot.visibility ? 'disable' : 'enable';
bot.chat(`/essentials:vanish ${enableOrDisable}`);
bot.tellraw(selector, [{text: 'The bot\'s visibility is now ', color: 'white'}, {text: visibleOrInvisible, color: greenOrGold}]);
bot.visibility = !bot.visibility
const greenOrGold = bot.visibility ? 'green' : 'gold'
const visibleOrInvisible = bot.visibility ? 'visible' : 'invisible'
const enableOrDisable = bot.visibility ? 'disable' : 'enable'
bot.chat(`/essentials:vanish ${enableOrDisable}`)
bot.tellraw(selector, [{ text: 'The bot\'s visibility is now ', color: 'white' }, { text: visibleOrInvisible, color: greenOrGold }])
} else {
throw new SyntaxError('Invalid argument');
throw new SyntaxError('Invalid argument')
}
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message) {
discordExecute: function (bot, username, usernameraw, sender, prefix, args, channeldc, message) {
if (args[0] === 'true' || args[0] === 'on') {
bot.visibility = true;
bot.chat('/essentials:vanish disable');
bot.visibility = true
bot.chat('/essentials:vanish disable')
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Bot\'s Visibility')
.setDescription('The bot\'s visibility is now visible');
channeldc.send({embeds: [Embed]});
.setDescription('The bot\'s visibility is now visible')
channeldc.send({ embeds: [Embed] })
} else if (args[0] === 'false' || args[0] === 'off') {
bot.visibility = false;
bot.chat('/essentials:vanish enable');
bot.visibility = false
bot.chat('/essentials:vanish enable')
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Bot\'s Visibility')
.setDescription('The bot\'s visibility is now invisible');
channeldc.send({embeds: [Embed]});
.setDescription('The bot\'s visibility is now invisible')
channeldc.send({ embeds: [Embed] })
} else if (!args[0]) {
bot.visibility = !bot.visibility;
const visibleOrInvisible = bot.visibility ? 'visible' : 'invisible';
const enableOrDisable = bot.visibility ? 'disable' : 'enable';
bot.chat(`/essentials:vanish ${enableOrDisable}`);
bot.visibility = !bot.visibility
const visibleOrInvisible = bot.visibility ? 'visible' : 'invisible'
const enableOrDisable = bot.visibility ? 'disable' : 'enable'
bot.chat(`/essentials:vanish ${enableOrDisable}`)
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Bot\'s Visibility')
.setDescription(`The bot\'s visibility is now ${visibleOrInvisible}`);
channeldc.send({embeds: [Embed]});
.setDescription(`The bot's visibility is now ${visibleOrInvisible}`)
channeldc.send({ embeds: [Embed] })
} else {
throw new SyntaxError('Invalid argument');
throw new SyntaxError('Invalid argument')
}
},
};
}
}

View file

@ -1,20 +1,20 @@
/* eslint-disable max-len */
const {MessageEmbed} = require('discord.js');
const { MessageEmbed } = require('discord.js')
module.exports = {
name: 'bruhify',
alias: [],
description: 'RecycleBot bruhify but actionbar',
usage: '<message>',
trusted: 0,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.bruhifyText = args.join(' ');
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.bruhifyText = args.join(' ')
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc) {
bot.bruhifyText = args.join(' ');
discordExecute: function (bot, username, usernameraw, sender, prefix, args, channeldc) {
bot.bruhifyText = args.join(' ')
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Bruhify')
.setDescription(`Bruhify set to: ${bot.bruhifyText}`);
channeldc.send({embeds: [Embed]});
},
};
.setDescription(`Bruhify set to: ${bot.bruhifyText}`)
channeldc.send({ embeds: [Embed] })
}
}

View file

@ -5,10 +5,10 @@ module.exports = {
description: 'Executes a command in the command core',
usage: '<command>',
trusted: 0,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.core.run(args.join(' '));
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.core.run(args.join(' '))
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc) {
bot.core.run(args.join(' '));
},
};
discordExecute: function (bot, username, usernameraw, sender, prefix, args, channeldc) {
bot.core.run(args.join(' '))
}
}

View file

@ -1,42 +1,42 @@
/* eslint-disable max-len */
const changelog = require('../changelog.json');
const {MessageEmbed} = require('discord.js');
const changelog = require('../changelog.json')
const { MessageEmbed } = require('discord.js')
module.exports = {
name: 'changelog',
alias: ['changelogs'],
description: 'Shows the bot\'s changelog',
usage: '',
trusted: 0,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
const component = [];
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
const component = []
component.push({text: 'Changelogs ', color: 'green'});
component.push({text: '(', color: 'dark_gray'});
component.push({text: changelog.length, color: 'gray'});
component.push({text: ')', color: 'dark_gray'});
component.push({text: ':', color: 'gray'});
component.push('\n');
component.push({ text: 'Changelogs ', color: 'green' })
component.push({ text: '(', color: 'dark_gray' })
component.push({ text: changelog.length, color: 'gray' })
component.push({ text: ')', color: 'dark_gray' })
component.push({ text: ':', color: 'gray' })
component.push('\n')
changelog.forEach((message, number) => {
number += 1;
component.push({text: number, color: 'gray'});
component.push({text: ' - ', color: 'dark_gray'});
component.push({text: message, color: 'gray'});
component.push('\n');
});
component.pop();
number += 1
component.push({ text: number, color: 'gray' })
component.push({ text: ' - ', color: 'dark_gray' })
component.push({ text: message, color: 'gray' })
component.push('\n')
})
component.pop()
bot.tellraw(selector, component);
bot.tellraw(selector, component)
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc) {
let changelogs = '';
discordExecute: function (bot, username, usernameraw, sender, prefix, args, channeldc) {
let changelogs = ''
changelog.forEach((message, number) => {
number += 1;
changelogs += `\`${number}\` - \`${message}\`` + '\n';
});
number += 1
changelogs += `\`${number}\` - \`${message}\`` + '\n'
})
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle(`Changelogs (${changelog.length})`)
.setDescription(changelogs);
channeldc.send({embeds: [Embed]});
},
};
.setDescription(changelogs)
channeldc.send({ embeds: [Embed] })
}
}

View file

@ -6,20 +6,18 @@ module.exports = {
description: 'Clears the chat',
usage: '[specific] <player>',
trusted: 0,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
if (args[0] === 'specific') {
bot.tellraw(args[1], [{text: `${'\n'.repeat(100)}`, color: 'white'}, {text: `Your chat has been cleared by ${username}.`, color: 'dark_green'}]);
return;
bot.tellraw(args[1], [{ text: `${'\n'.repeat(100)}`, color: 'white' }, { text: `Your chat has been cleared by ${username}.`, color: 'dark_green' }])
} else {
bot.tellraw(selector, [{text: `${'\n'.repeat(100)}`, color: 'white'}, {text: 'The chat has been cleared.', color: 'dark_green'}]);
bot.tellraw('@a', [{ text: `${'\n'.repeat(100)}`, color: 'white' }, { text: 'The chat has been cleared.', color: 'dark_green' }])
}
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message) {
discordExecute: function (bot, username, usernameraw, sender, prefix, args, channeldc, message) {
if (args[0] === 'specific') {
bot.tellraw(args[1], [{text: `${'\n'.repeat(100)}`, color: 'white'}, {text: `Your chat has been cleared by ${username} (on Discord).`, color: 'dark_green'}]);
return;
bot.tellraw(args[1], [{ text: `${'\n'.repeat(100)}`, color: 'white' }, { text: `Your chat has been cleared by ${username} (on Discord).`, color: 'dark_green' }])
} else {
bot.tellraw(selector, [{text: `${'\n'.repeat(100)}`, color: 'white'}, {text: 'The chat has been cleared.', color: 'dark_green'}]);
bot.tellraw('@a', [{ text: `${'\n'.repeat(100)}`, color: 'white' }, { text: 'The chat has been cleared.', color: 'dark_green' }])
}
},
};
}
}

View file

@ -5,14 +5,14 @@ module.exports = {
alias: ['ccq'],
usage: '',
trusted: 0,
execute: function(bot) {
execute: function (bot) {
if (bot.queue[0]) {
bot.chatQueue = [];
bot.chatQueue = []
}
},
discordExecute: function(bot) {
discordExecute: function (bot) {
if (bot.queue[0]) {
bot.chatQueue = [];
bot.chatQueue = []
}
},
};
}
}

View file

@ -1,59 +1,59 @@
/* eslint-disable require-jsdoc */
/* eslint-disable max-len */
const {MessageEmbed} = require('discord.js');
function add(command, interval, bot) {
const id = setInterval(() => bot.core.run(command), interval);
const { MessageEmbed } = require('discord.js')
function add (command, interval, bot) {
const id = setInterval(() => bot.core.run(command), interval)
bot.cloops.push({id, interval, command});
bot.cloops.push({ id, interval, command })
}
function remove(item, bot) {
clearInterval(bot.cloops[item].id);
function remove (item, bot) {
clearInterval(bot.cloops[item].id)
bot.cloops.splice(item, 1);
bot.cloops.splice(item, 1)
}
function clear(bot) {
for (const interval of bot.cloops) clearInterval(interval.id);
function clear (bot) {
for (const interval of bot.cloops) clearInterval(interval.id)
bot.cloops = [];
bot.cloops = []
}
function list(bot, discord, channeldc, selector) {
const message = [];
function list (bot, discord, channeldc, selector) {
const message = []
if (discord) {
for (const [id, cloop] of Object.entries(bot.cloops)) {
message.push(id);
message.push(' > ');
message.push(`\`${cloop.command}\``);
message.push(' - ');
message.push(cloop.interval);
message.push('\n');
message.push(id)
message.push(' > ')
message.push(`\`${cloop.command}\``)
message.push(' - ')
message.push(cloop.interval)
message.push('\n')
}
message.pop();
message.pop()
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Cloops')
.setDescription(message.join(''));
channeldc.send({embeds: [Embed]});
return;
.setDescription(message.join(''))
channeldc.send({ embeds: [Embed] })
return
}
message.push({text: 'Cloops:', color: 'green'});
message.push('\n');
message.push({ text: 'Cloops:', color: 'green' })
message.push('\n')
for (const [id, cloop] of Object.entries(bot.cloops)) {
message.push({text: id, color: 'aqua'});
message.push({text: ' > ', color: 'gold'});
message.push({text: cloop.command, color: 'green'});
message.push({text: ' - ', color: 'gold'});
message.push({text: cloop.interval, color: 'green'});
message.push('\n');
message.push({ text: id, color: 'aqua' })
message.push({ text: ' > ', color: 'gold' })
message.push({ text: cloop.command, color: 'green' })
message.push({ text: ' - ', color: 'gold' })
message.push({ text: cloop.interval, color: 'green' })
message.push('\n')
}
message.pop();
message.pop()
bot.tellraw(selector, message);
bot.tellraw(selector, message)
}
module.exports = {
name: 'cloop',
@ -63,55 +63,55 @@ module.exports = {
'<hash> <add> <interval> <command>',
'<hash> <remove> <index>',
'<hash> <removeall>',
'<hash> <list>',
'<hash> <list>'
],
trusted: 1,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
if (!bot.cloops) bot.cloops = [];
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
if (!bot.cloops) bot.cloops = []
if (args[1] === 'add' && args[3]) {
if (!Number(args[2]) && Number(args[2]) !== 0) throw new SyntaxError('Invalid interval');
add(args.slice(3).join(' '), args[2], bot);
bot.tellraw(selector, [{text: 'Added command ', color: 'white'}, {text: `${args.slice(3).join(' ')}`, color: 'aqua'}, {text: ' with interval ', color: 'white'}, {text: `${args[2]}`, color: 'green'}, {text: ' to the cloops', color: 'white'}]);
if (!Number(args[2]) && Number(args[2]) !== 0) throw new SyntaxError('Invalid interval')
add(args.slice(3).join(' '), args[2], bot)
bot.tellraw(selector, [{ text: 'Added command ', color: 'white' }, { text: `${args.slice(3).join(' ')}`, color: 'aqua' }, { text: ' with interval ', color: 'white' }, { text: `${args[2]}`, color: 'green' }, { text: ' to the cloops', color: 'white' }])
} else if (args[1] === 'list') {
list(bot, false, null, selector);
list(bot, false, null, selector)
} else if (args[1] === 'remove') {
remove(args[2], bot);
bot.tellraw(selector, [{text: 'Removed cloop '}, {text: args[2], color: 'aqua'}]);
remove(args[2], bot)
bot.tellraw(selector, [{ text: 'Removed cloop ' }, { text: args[2], color: 'aqua' }])
} else if (args[1] === 'removeall') {
clear(bot);
bot.tellraw(selector, [{text: 'Removed all looped commands', color: 'white'}]);
clear(bot)
bot.tellraw(selector, [{ text: 'Removed all looped commands', color: 'white' }])
} else {
throw new SyntaxError('Invalid argument');
throw new SyntaxError('Invalid argument')
}
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message) {
if (!bot.cloops) bot.cloops = [];
discordExecute: function (bot, username, usernameraw, sender, prefix, args, channeldc, message) {
if (!bot.cloops) bot.cloops = []
if (args[0] === 'add' && args[2]) {
if (!Number(args[1]) && Number(args[1]) !== 0) throw new SyntaxError('Invalid interval');
add(args.slice(2).join(' '), args[1], bot);
if (!Number(args[1]) && Number(args[1]) !== 0) throw new SyntaxError('Invalid interval')
add(args.slice(2).join(' '), args[1], bot)
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Cloop')
.setDescription(`Added cloop \`${args.slice(2).join(' ')}\` with interval ${args[1]} to the cloops`);
channeldc.send({embeds: [Embed]});
.setDescription(`Added cloop \`${args.slice(2).join(' ')}\` with interval ${args[1]} to the cloops`)
channeldc.send({ embeds: [Embed] })
} else if (args[0] === 'list') {
list(bot, true, channeldc);
list(bot, true, channeldc)
} else if (args[0] === 'remove') {
remove(args[1], bot);
remove(args[1], bot)
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Cloop')
.setDescription(`Removed cloop \`${args[1]}\``);
channeldc.send({embeds: [Embed]});
.setDescription(`Removed cloop \`${args[1]}\``)
channeldc.send({ embeds: [Embed] })
} else if (args[0] === 'removeall') {
clear(bot);
clear(bot)
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Cloop')
.setDescription('Removed all looped commands');
channeldc.send({embeds: [Embed]});
.setDescription('Removed all looped commands')
channeldc.send({ embeds: [Embed] })
} else {
throw new Error('Invalid argument');
throw new Error('Invalid argument')
}
},
};
}
}

View file

@ -1,22 +1,22 @@
/* eslint-disable max-len */
const cowsay = require('cowsay2');
const cows = require('cowsay2/cows');
const {MessageEmbed} = require('discord.js');
const cowsay = require('cowsay2')
const cows = require('cowsay2/cows')
const { MessageEmbed } = require('discord.js')
module.exports = {
name: 'cowsay',
alias: [],
description: 'Moo',
usage: [
'<cow> <message>',
'<list (not support on Discord)>',
'<list (not support on Discord)>'
],
trusted: 0,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
if (args[0]==='list') {
const listed = Object.keys(cows);
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
if (args[0] === 'list') {
const listed = Object.keys(cows)
let primary = true;
const message = [];
let primary = true
const message = []
listed.forEach((value) => {
message.push({
@ -24,21 +24,21 @@ module.exports = {
color: (!((primary = !primary)) ? 'gold' : 'yellow'),
clickEvent: {
action: 'suggest_command',
value: `${prefix}cowsay ${value} `,
},
});
});
value: `${prefix}cowsay ${value} `
}
})
})
bot.tellraw(selector, message);
bot.tellraw(selector, message)
} else {
bot.tellraw(selector, {text: cowsay.say(args.slice(1).join(' '), {cow: cows[args[0]]})});
bot.tellraw(selector, { text: cowsay.say(args.slice(1).join(' '), { cow: cows[args[0]] }) })
}
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message, config) {
discordExecute: function (bot, username, usernameraw, sender, prefix, args, channeldc, message, config) {
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Cowsay')
.setDescription(cowsay.say(args.slice(1).join(' '), {cow: cows[args[0]]}));
channeldc.send({embeds: [Embed]});
},
};
.setDescription(cowsay.say(args.slice(1).join(' '), { cow: cows[args[0]] }))
channeldc.send({ embeds: [Embed] })
}
}

View file

@ -1,16 +1,16 @@
/* eslint-disable max-len */
const sleep = require('sleep-promise');
const sleep = require('sleep-promise')
/**
* crash server
* @param {object} bot bot object
*/
async function crash(bot) {
bot.core.run('data merge storage crash {data:[0]}');
async function crash (bot) {
bot.core.run('data merge storage crash {data:[0]}')
await sleep(1000);
await sleep(1000)
for (let i = 0; i < 256; i++) bot.core.run('data modify storage crash data append from storage crash data[]');
for (let i = 0; i < 256; i++) bot.core.run('data modify storage crash data append from storage crash data[]')
}
module.exports = {
@ -19,10 +19,10 @@ module.exports = {
description: 'Crashes the server',
usage: '<hash>',
trusted: 1,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
crash(bot);
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
crash(bot)
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message) {
crash(bot);
},
};
discordExecute: function (bot, username, usernameraw, sender, prefix, args, channeldc, message) {
crash(bot)
}
}

View file

@ -1,19 +1,19 @@
/* eslint-disable max-len */
const {MessageEmbed} = require('discord.js');
const { MessageEmbed } = require('discord.js')
module.exports = {
name: 'creator',
alias: [],
description: 'Shows the bot\'s creator',
usage: '',
trusted: 0,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.tellraw(selector, [{text: 'ChomeNS Bot ', color: 'yellow'}, {text: 'was created by ', color: 'white'}, {text: 'chayapak', color: 'gold'}]);
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.tellraw(selector, [{ text: 'ChomeNS Bot ', color: 'yellow' }, { text: 'was created by ', color: 'white' }, { text: 'chayapak', color: 'gold' }])
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message) {
discordExecute: function (bot, username, usernameraw, sender, prefix, args, channeldc, message) {
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Creator')
.setDescription('ChomeNS Bot was created by chayapak');
channeldc.send({embeds: [Embed]});
},
};
.setDescription('ChomeNS Bot was created by chayapak')
channeldc.send({ embeds: [Embed] })
}
}

View file

@ -5,20 +5,20 @@ module.exports = {
description: 'Shows the discord invite',
usage: '',
trusted: 0,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.tellraw(selector, [
{
text: 'The Discord invite is ',
color: 'white',
color: 'white'
},
{
text: 'https://discord.gg/xdgCkUyaA4',
color: 'blue',
clickEvent: {
action: 'open_url',
value: 'https://discord.gg/xdgCkUyaA4',
},
},
]);
},
};
value: 'https://discord.gg/xdgCkUyaA4'
}
}
])
}
}

View file

@ -1,7 +1,7 @@
/* eslint-disable max-len */
const {resize} = require('../util/image');
const axios = require('axios');
const sharp = require('sharp');
const { resize } = require('../util/image')
const axios = require('axios')
const sharp = require('sharp')
module.exports = {
name: 'draw',
@ -9,32 +9,32 @@ module.exports = {
alias: [],
trusted: 0,
usage: '<image url (JPEG, PNG, WebP, AVIF, GIF, SVG, TIFF)>',
execute: async function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
execute: async function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
try {
const url = args.join(' ');
const url = args.join(' ')
const image = await axios.get('https://http-proxy.nongsonchome.repl.co', {
params: {
uri: url,
uri: url
},
responseType: 'arraybuffer',
});
responseType: 'arraybuffer'
})
const loaded = sharp(image.data);
const loaded = sharp(image.data)
const metadata = await loaded
.metadata();
.metadata()
const {width, height} = resize(metadata.width, metadata.height);
const { width, height } = resize(metadata.width, metadata.height)
const {data, info} = await loaded
.resize({fit: 'fill', kernel: 'nearest', width, height})
const { data, info } = await loaded
.resize({ fit: 'fill', kernel: 'nearest', width, height })
.raw()
.toBuffer({resolveWithObject: true});
.toBuffer({ resolveWithObject: true })
bot.draw(data, info);
bot.draw(data, info)
} catch (e) {
bot.tellraw(selector, {text: 'SyntaxError: Invalid URL', color: 'red'});
bot.tellraw(selector, { text: 'SyntaxError: Invalid URL', color: 'red' })
}
},
};
}
}

View file

@ -5,18 +5,18 @@ module.exports = {
description: 'Lags Eaglercraft and crashes it',
usage: '<on|off> <hash>',
trusted: 1,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
if (args[1] === 'on') {
bot.eaglercrashstarted = true;
bot.eaglercrash = setInterval(async function() {
if (bot.eaglercrashstarted === true) return bot.core.run('minecraft:playsound block.note_block.harp record @a ~ ~ ~ 100000000000000000000000000000000000000 1 0');
}, 0);
bot.core.run('minecraft:tellraw @a ["",{"text":"Eaglercrash started","color":"white"}]');
bot.eaglercrashstarted = true
bot.eaglercrash = setInterval(async function () {
if (bot.eaglercrashstarted === true) return bot.core.run('minecraft:playsound block.note_block.harp record @a ~ ~ ~ 100000000000000000000000000000000000000 1 0')
}, 0)
bot.core.run('minecraft:tellraw @a ["",{"text":"Eaglercrash started","color":"white"}]')
}
if (args[1] === 'off') {
clearInterval(bot.eaglercrash);
bot.eaglercrashstarted = false;
bot.core.run('minecraft:tellraw @a ["",{"text":"Eaglercrash stopped","color":"white"}]');
clearInterval(bot.eaglercrash)
bot.eaglercrashstarted = false
bot.core.run('minecraft:tellraw @a ["",{"text":"Eaglercrash stopped","color":"white"}]')
}
},
};
}
}

View file

@ -5,10 +5,10 @@ module.exports = {
description: 'Says a message',
usage: '<message>',
trusted: 0,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.chat(args.join(' '));
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.chat(args.join(' '))
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc) {
bot.chat(args.join(' '));
},
};
discordExecute: function (bot, username, usernameraw, sender, prefix, args, channeldc) {
bot.chat(args.join(' '))
}
}

View file

@ -5,10 +5,10 @@ module.exports = {
description: 'Ends the bot\'s client',
usage: '<hash>',
trusted: 1,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.end('end command');
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.end('end command')
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message) {
bot.end('end command');
},
};
discordExecute: function (bot, username, usernameraw, sender, prefix, args, channeldc, message) {
bot.end('end command')
}
}

View file

@ -5,11 +5,11 @@ module.exports = {
description: 'Summon any entity!',
usage: '[specific] <player>',
trusted: 0,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
// eslint-disable-next-line no-unused-vars
const mcData = require('minecraft-data')(bot.version);
const mcData = require('minecraft-data')(bot.version)
throw new Error('Execute Bypass is patched so this command will be broken for now!');
throw new Error('Execute Bypass is patched so this command will be broken for now!')
// if (!args[0]) return;
// const entity = mcData.entitiesByName[args[0]];
// if (!entity) throw new SyntaxError('Invalid entity');
@ -20,5 +20,5 @@ module.exports = {
// bot.core.run('minecraft:execute unless entity @s[name= run ] run execute as @a at ' + args[2] + ' run summon minecraft:' + entity.name);
// bot.tellraw(selector, [{text: `Entity `, color: 'white'}, {text: entity.displayName, color: 'green'}, {text: ' spawning at ', color: 'white'}, {text: `${args[2]}`, color: 'aqua'}]);
// }
},
};
}
}

View file

@ -1,10 +1,10 @@
/* eslint-disable max-len */
const {MessageEmbed} = require('discord.js');
const {VM} = require('vm2');
const axios = require('axios');
const util = require('util');
const querystring = require('querystring');
const {stylize} = require('../util/colors/minecraft');
const { MessageEmbed } = require('discord.js')
const { VM } = require('vm2')
const axios = require('axios')
const util = require('util')
const querystring = require('querystring')
const { stylize } = require('../util/colors/minecraft')
module.exports = {
name: 'eval',
alias: [],
@ -13,18 +13,18 @@ module.exports = {
usage: [
'<run> <code>',
'<reset>',
'<server (eval server)> <code>',
'<server (eval server)> <code>'
],
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
if (args[0] === 'run') {
try {
bot.tellraw(selector, {text: `${util.inspect(bot.vm.run(args.slice(1).join(' ')), {stylize: stylize})}`.substring(0, 32000)});
bot.tellraw(selector, { text: `${util.inspect(bot.vm.run(args.slice(1).join(' ')), { stylize })}`.substring(0, 32000) })
} catch (err) {
bot.tellraw(selector, {text: `${util.inspect(err).replaceAll('runner', 'chayapak1')}`, color: 'red'});
bot.tellraw(selector, { text: `${util.inspect(err).replaceAll('runner', 'chayapak1')}`, color: 'red' })
}
}
if (args[0] === 'reset') {
bot.vm = new VM(bot.vmoptions);
bot.vm = new VM(bot.vmoptions)
}
if (args[0] === 'server') {
axios
@ -32,44 +32,40 @@ module.exports = {
html: false,
showErrorMsg: false,
colors: 'minecraft',
code: args[1],
code: args[1]
})).then((res) => {
bot.tellraw(selector, {text: `${res.data}`});
bot.tellraw(selector, { text: `${res.data}` })
}).catch((err) => {
bot.tellraw(selector, {text: `${err}`, color: 'red'});
});
bot.tellraw(selector, { text: `${err}`, color: 'red' })
})
}
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message, config) {
discordExecute: function (bot, username, usernameraw, sender, prefix, args, channeldc, message, config) {
if (args[0] === 'run') {
try {
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Output')
.setDescription(`\`\`\`${util.inspect(bot.vm.run(args.slice(1).join(' '))).substring(0, 1950)}\`\`\``);
channeldc.send({embeds: [Embed]});
} catch (err) {
throw err;
}
.setDescription(`\`\`\`${util.inspect(bot.vm.run(args.slice(1).join(' '))).substring(0, 1950)}\`\`\``)
channeldc.send({ embeds: [Embed] })
} else if (args[0] === 'reset') {
bot.vm = new VM(bot.vmoptions);
bot.vm = new VM(bot.vmoptions)
} else if (args[0] === 'server') {
axios
.post(config.eval.serverUrl, querystring.stringify({
html: false,
showErrorMsg: false,
code: args[1],
code: args[1]
})).then((res) => {
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Output')
.setDescription(`\`\`\`${res.data}\`\`\``);
channeldc.send({embeds: [Embed]});
.setDescription(`\`\`\`${res.data}\`\`\``)
channeldc.send({ embeds: [Embed] })
}).catch((err) => {
throw err;
});
throw err
})
} else {
throw new SyntaxError('Invalid argument');
throw new SyntaxError('Invalid argument')
}
},
};
}
}

View file

@ -5,7 +5,7 @@ module.exports = {
description: 'Execute command bypassed',
usage: '<hash> <command>',
trusted: 1,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.core.run('minecraft:execute unless entity @s[name= run ] run ' + args.slice(1).join(' '));
},
};
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.core.run('minecraft:execute unless entity @s[name= run ] run ' + args.slice(1).join(' '))
}
}

View file

@ -5,7 +5,7 @@ module.exports = {
description: 'Gamemode everyone',
usage: '<hash> <gamemode>',
trusted: 1,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.core.run(`minecraft:execute unless entity @s[name= run ] run gamemode ${args[1]} @a[name=!${bot.username}]`);
},
};
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.core.run(`minecraft:execute unless entity @s[name= run ] run gamemode ${args[1]} @a[name=!${bot.username}]`)
}
}

View file

@ -1,69 +1,69 @@
/* eslint-disable require-jsdoc */
/* eslint-disable no-var */
/* eslint-disable max-len */
const {MessageEmbed} = require('discord.js');
const { MessageEmbed } = require('discord.js')
module.exports = {
name: 'help',
alias: ['heko', 'cmds', 'commands'],
description: 'Shows the help',
usage: '[command]',
trusted: 0,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
if (args[0]) {
for (const command of bot.command_handler.commands) {
function run() {
let alias = command.name;
function run () {
let alias = command.name
if (command.alias.toString() !== '') {
alias = command.alias.join(', ');
alias = command.alias.join(', ')
}
const usage = [];
const usage = []
if (typeof command.usage === 'string') {
usage.push({text: `${prefix}${command.name} `, color: 'gold'});
usage.push({text: command.usage, color: 'aqua'});
usage.push({ text: `${prefix}${command.name} `, color: 'gold' })
usage.push({ text: command.usage, color: 'aqua' })
} else {
command.usage.forEach((value) => {
usage.push({text: `${prefix}${command.name} `, color: 'gold'});
usage.push({text: value, color: 'aqua'});
usage.push('\n');
});
usage.pop();
usage.push({ text: `${prefix}${command.name} `, color: 'gold' })
usage.push({ text: value, color: 'aqua' })
usage.push('\n')
})
usage.pop()
}
const component = [];
component.push({text: prefix + command.name, color: 'gold'});
component.push({text: ` (${alias})`, color: 'white'});
component.push({text: ' - ', color: 'gray'});
component.push({text: command.description, color: 'gray'});
const component = []
component.push({ text: prefix + command.name, color: 'gold' })
component.push({ text: ` (${alias})`, color: 'white' })
component.push({ text: ' - ', color: 'gray' })
component.push({ text: command.description, color: 'gray' })
component.push('\n');
component.push('\n')
component.push({text: 'Trust level: ', color: 'green'});
component.push({text: command.trusted, color: 'yellow'});
component.push({ text: 'Trust level: ', color: 'green' })
component.push({ text: command.trusted, color: 'yellow' })
component.push('\n');
component.push('\n')
component.push({text: 'Supported on Discord: ', color: 'green'});
component.push({text: command.discordExecute ? 'true' : 'false', color: 'gold'});
component.push({ text: 'Supported on Discord: ', color: 'green' })
component.push({ text: command.discordExecute ? 'true' : 'false', color: 'gold' })
component.push('\n');
component.push('\n')
component.push(usage);
component.push(usage)
bot.tellraw(selector, component);
bot.tellraw(selector, component)
}
if (command.name === args[0]) run();
if (command.name === args[0]) run()
for (const alias of command.alias) {
if (alias === args[0]) run();
if (alias === args[0]) run()
}
};
} else {
const generalCommands = [];
const trustedCommands = [];
const ownerCommands = [];
function component(command, color) {
const generalCommands = []
const trustedCommands = []
const ownerCommands = []
function component (command, color) {
return {
text: command.name + ' ',
color,
@ -71,72 +71,72 @@ module.exports = {
action: 'show_text',
contents: [{
text: 'Click here to see the information for this command',
color: 'green',
}],
color: 'green'
}]
},
clickEvent: {
action: 'run_command',
value: `${prefix}help ${command.name}`,
},
};
value: `${prefix}help ${command.name}`
}
}
};
for (const command of bot.command_handler.commands) {
if (command.trusted !== 0) continue;
generalCommands.push(component(command, 'green'));
if (command.trusted !== 0) continue
generalCommands.push(component(command, 'green'))
}
for (const command of bot.command_handler.commands) {
if (command.trusted !== 1) continue;
trustedCommands.push(component(command, 'red'));
if (command.trusted !== 1) continue
trustedCommands.push(component(command, 'red'))
}
for (const command of bot.command_handler.commands) {
if (command.trusted !== 2) continue;
ownerCommands.push(component(command, 'dark_red'));
if (command.trusted !== 2) continue
ownerCommands.push(component(command, 'dark_red'))
}
const pre = [{text: 'Commands ', color: 'gray'}, {text: '(', color: 'dark_gray'}, {text: 'Length: ', color: 'gray'}, {text: bot.command_handler.commands.length, color: 'green'}, {text: ') ', color: 'dark_gray'}, {text: '(', color: 'dark_gray'}, {text: '⬤ Public', color: 'green'}, {text: ' ⬤ Trusted', color: 'red'}, {text: ' ⬤ Owner', color: 'dark_red'}, {text: ') - ', color: 'dark_gray'}];
bot.tellraw(selector, [pre, generalCommands, trustedCommands, ownerCommands]);
const pre = [{ text: 'Commands ', color: 'gray' }, { text: '(', color: 'dark_gray' }, { text: 'Length: ', color: 'gray' }, { text: bot.command_handler.commands.length, color: 'green' }, { text: ') ', color: 'dark_gray' }, { text: '(', color: 'dark_gray' }, { text: '⬤ Public', color: 'green' }, { text: ' ⬤ Trusted', color: 'red' }, { text: ' ⬤ Owner', color: 'dark_red' }, { text: ') - ', color: 'dark_gray' }]
bot.tellraw(selector, [pre, generalCommands, trustedCommands, ownerCommands])
}
},
discordExecute: async function(bot, username, usernameraw, sender, prefix, args, channeldc) {
discordExecute: async function (bot, username, usernameraw, sender, prefix, args, channeldc) {
if (args[0]) {
for (const command of bot.command_handler.commands) {
function run() {
let alias = command.name;
function run () {
let alias = command.name
if (command.alias.toString() !== '') {
alias = command.alias.join(', ');
alias = command.alias.join(', ')
}
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle(`${prefix + command.name} (${alias}) - ${command.description}`)
.setDescription(`Trust level: ${command.trusted}
Supported: ${command.discordExecute ? 'true' : 'false'}
${prefix + command.name} ${command.usage}`,
);
channeldc.send({embeds: [Embed]});
${prefix + command.name} ${command.usage}`
)
channeldc.send({ embeds: [Embed] })
}
if (command.name === args[0]) run();
if (command.name === args[0]) run()
for (const alias of command.alias) {
if (alias === args[0]) run();
if (alias === args[0]) run()
}
};
} else {
let supportedCommands = '';
let unsupportedCommands = '';
let supportedCommands = ''
let unsupportedCommands = ''
for (const command of bot.command_handler.commands) {
if (!command.discordExecute) continue;
supportedCommands += command.name + ' ';
if (!command.discordExecute) continue
supportedCommands += command.name + ' '
}
for (const command of bot.command_handler.commands) {
if (command.discordExecute) continue;
unsupportedCommands += command.name + ' ';
if (command.discordExecute) continue
unsupportedCommands += command.name + ' '
}
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle(`Commands (Length: ${bot.command_handler.commands.length})`)
.setDescription('**Supported Commands**\n' + supportedCommands + '\n**Unsupported Commands**\n' + unsupportedCommands);
channeldc.send({embeds: [Embed]});
.setDescription('**Supported Commands**\n' + supportedCommands + '\n**Unsupported Commands**\n' + unsupportedCommands)
channeldc.send({ embeds: [Embed] })
}
},
};
}
}

View file

@ -1,19 +1,19 @@
/* eslint-disable max-len */
const {MessageEmbed} = require('discord.js');
const { MessageEmbed } = require('discord.js')
module.exports = {
name: 'list',
alias: [],
description: 'List players',
usage: '',
trusted: 0,
execute: async function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
execute: async function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
try {
const component = [];
component.push({text: 'Players ', color: 'green'});
component.push({text: '(', color: 'dark_gray'});
component.push({text: bot.players.list.length, color: 'gray'});
component.push({text: ')', color: 'dark_gray'});
component.push('\n');
const component = []
component.push({ text: 'Players ', color: 'green' })
component.push({ text: '(', color: 'dark_gray' })
component.push({ text: bot.players.list.length, color: 'gray' })
component.push({ text: ')', color: 'dark_gray' })
component.push('\n')
for (const property of bot.players.list) {
// if (property.match.startsWith('@')) continue;
component.push({
@ -21,57 +21,57 @@ module.exports = {
color: 'yellow',
clickEvent: {
action: 'copy_to_clipboard',
value: property.name,
value: property.name
},
hoverEvent: {
action: 'show_text',
contents: [{
text: 'Click here to copy the username to your clipboard',
color: 'green',
}],
},
});
color: 'green'
}]
}
})
component.push({
text: ' ',
color: 'dark_gray',
});
color: 'dark_gray'
})
component.push({
text: property.UUID,
color: 'aqua',
clickEvent: {
action: 'copy_to_clipboard',
value: property.UUID,
value: property.UUID
},
hoverEvent: {
action: 'show_text',
contents: [{
text: 'Click here to copy the UUID to your clipboard',
color: 'green',
}],
},
});
component.push('\n');
color: 'green'
}]
}
component.pop();
bot.tellraw(selector, component);
})
component.push('\n')
}
component.pop()
bot.tellraw(selector, component)
} catch (e) {
return;
}
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc) {
discordExecute: function (bot, username, usernameraw, sender, prefix, args, channeldc) {
try {
let players = '';
let players = ''
for (const property of bot.players.list) {
// if (property.match.startsWith('@')) continue;
players += `\`${property.name}\` \`${property.UUID}\`` + '\n';
players += `\`${property.name}\` \`${property.UUID}\`` + '\n'
}
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle(`Players (${bot.players.list.length})`)
.setDescription(players.substring(0, 4096));
channeldc.send({embeds: [Embed]});
.setDescription(players.substring(0, 4096))
channeldc.send({ embeds: [Embed] })
} catch (e) {
return;
}
},
};
}
}

View file

@ -1,144 +1,147 @@
/* eslint-disable no-case-declarations */
/* eslint-disable require-jsdoc */
/* eslint-disable max-len */
const fs = require('fs/promises');
const {MessageEmbed} = require('discord.js');
const path = require('path');
const fileExists = require('../util/file-exists');
const fileList = require('../util/file-list');
const axios = require('axios');
const os = require('os');
const fs = require('fs/promises')
const { MessageEmbed } = require('discord.js')
const path = require('path')
const fileExists = require('../util/file-exists')
const fileList = require('../util/file-list')
const axios = require('axios')
const os = require('os')
let SONGS_PATH;
let SONGS_PATH
if (os.hostname() === 'chomens-kubuntu') {
SONGS_PATH = path.join(__dirname, '..', '..', 'nginx-html', 'midis');
SONGS_PATH = path.join(__dirname, '..', '..', 'nginx-html', 'midis')
} else {
SONGS_PATH = path.join(__dirname, '..', 'midis');
SONGS_PATH = path.join(__dirname, '..', 'midis')
}
async function play(bot, values, discord, channeldc, selector) {
let song
async function play (bot, values, discord, channeldc, selector) {
try {
const filepath = values.join(' ');
const absolutePath = await resolve(filepath);
song = bot.music.load(await fs.readFile(absolutePath), path.basename(absolutePath));
bot.music.queue.push(song);
bot.music.play(song);
const filepath = values.join(' ')
const absolutePath = await resolve(filepath)
song = bot.music.load(await fs.readFile(absolutePath), path.basename(absolutePath))
bot.music.queue.push(song)
bot.music.play(song)
if (discord) {
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Music')
.setDescription(`Added ${song.name} to the song queue`);
channeldc.send({embeds: [Embed]});
.setDescription(`Added ${song.name} to the song queue`)
channeldc.send({ embeds: [Embed] })
} else {
bot.tellraw(selector, [{text: 'Added ', color: 'white'}, {text: song.name, color: 'gold'}, {text: ' to the song queue', color: 'white'}]);
bot.tellraw(selector, [{ text: 'Added ', color: 'white' }, { text: song.name, color: 'gold' }, { text: ' to the song queue', color: 'white' }])
}
} catch (e) {
if (discord) {
const Embed = new MessageEmbed()
.setColor('#FF0000')
.setTitle('Error')
.setDescription(`\`\`\`SyntaxError: Invalid file\`\`\``);
channeldc.send({embeds: [Embed]});
.setDescription('```SyntaxError: Invalid file```')
channeldc.send({ embeds: [Embed] })
} else {
bot.tellraw(selector, {text: 'SyntaxError: Invalid file', color: 'red'});
bot.tellraw(selector, { text: 'SyntaxError: Invalid file', color: 'red' })
}
}
}
async function playUrl(bot, values, discord, channeldc, selector) {
async function playUrl (bot, values, discord, channeldc, selector) {
try {
const url = values.join(' ');
const url = values.join(' ')
const response = await axios.get('https://http-proxy.nongsonchome.repl.co', {
params: {
uri: url,
uri: url
},
responseType: 'arraybuffer',
});
song = bot.music.load(response.data, url);
bot.music.queue.push(song);
bot.music.play(song);
responseType: 'arraybuffer'
})
song = bot.music.load(response.data, url)
bot.music.queue.push(song)
bot.music.play(song)
if (discord) {
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Music')
.setDescription(`Added ${song.name} to the song queue`);
channeldc.send({embeds: [Embed]});
.setDescription(`Added ${song.name} to the song queue`)
channeldc.send({ embeds: [Embed] })
} else {
bot.tellraw(selector, [{text: 'Added ', color: 'white'}, {text: song.name, color: 'gold'}, {text: ' to the song queue', color: 'white'}]);
bot.tellraw(selector, [{ text: 'Added ', color: 'white' }, { text: song.name, color: 'gold' }, { text: ' to the song queue', color: 'white' }])
}
} catch (e) {
if (discord) {
const Embed = new MessageEmbed()
.setColor('#FF0000')
.setTitle('Error')
.setDescription(`\`\`\`SyntaxError: Invalid URL\`\`\``);
channeldc.send({embeds: [Embed]});
.setDescription('```SyntaxError: Invalid URL```')
channeldc.send({ embeds: [Embed] })
} else {
bot.tellraw(selector, {text: 'SyntaxError: Invalid URL', color: 'red'});
bot.tellraw(selector, { text: 'SyntaxError: Invalid URL', color: 'red' })
}
}
}
async function resolve(filepath) {
async function resolve (filepath) {
if (!path.isAbsolute(filepath) && await fileExists(SONGS_PATH)) {
return path.join(SONGS_PATH, filepath);
return path.join(SONGS_PATH, filepath)
}
return filepath;
return filepath
}
async function list(bot, discord, channeldc, prefix, selector, args) {
async function list (bot, discord, channeldc, prefix, selector, args) {
try {
let absolutePath;
if (args[1]) absolutePath = await resolve(path.join(SONGS_PATH, args.slice(1).join(' ')));
else absolutePath = await resolve(SONGS_PATH);
let absolutePath
if (args[1]) absolutePath = await resolve(path.join(SONGS_PATH, args.slice(1).join(' ')))
else absolutePath = await resolve(SONGS_PATH)
if (!absolutePath.includes('midis')) throw new Error('bro trying to hack my server?!/1?!');
if (!absolutePath.includes('midis')) throw new Error('bro trying to hack my server?!/1?!')
const listed = await fileList(absolutePath);
const listed = await fileList(absolutePath)
if (discord) {
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Songs')
.setDescription(listed.join(', '));
channeldc.send({embeds: [Embed]});
return;
.setDescription(listed.join(', '))
channeldc.send({ embeds: [Embed] })
return
}
let primary = true;
const message = [];
let primary = true
const message = []
for (const value of listed) {
const isFile = (await fs.lstat(path.join(absolutePath, value))).isFile();
const isFile = (await fs.lstat(path.join(absolutePath, value))).isFile()
message.push({
text: value + ' ',
color: (!((primary = !primary)) ? 'gold' : 'yellow'),
clickEvent: {
action: 'suggest_command',
value: `${prefix}music ${isFile ? 'play' : 'list'} ${path.join(args.slice(1).join(' '), value)}`,
value: `${prefix}music ${isFile ? 'play' : 'list'} ${path.join(args.slice(1).join(' '), value)}`
},
hoverEvent: {
action: 'show_text',
contents: [
{text: 'Name: ', color: 'white'},
{text: value, color: 'gold'},
{ text: 'Name: ', color: 'white' },
{ text: value, color: 'gold' },
'\n',
{text: 'Click here to suggest the command!', color: 'green'},
],
},
});
{ text: 'Click here to suggest the command!', color: 'green' }
]
}
})
};
bot.tellraw(selector, message);
bot.tellraw(selector, message)
} catch (e) {
if (discord) {
const Embed = new MessageEmbed()
.setColor('#FF0000')
.setTitle('Error')
.setDescription(`\`\`\`${e.toString()}\`\`\``);
channeldc.send({embeds: [Embed]});
.setDescription(`\`\`\`${e.toString()}\`\`\``)
channeldc.send({ embeds: [Embed] })
} else {
bot.tellraw(selector, {text: e.toString(), color: 'red'});
bot.tellraw(selector, { text: e.toString(), color: 'red' })
}
}
};
@ -156,182 +159,182 @@ module.exports = {
'<list> [directory]',
'<skip>',
'<nowplaying>',
'<queue>',
'<queue>'
],
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
switch (args[0]) {
case 'play':
play(bot, args.slice(1), false, null, selector);
break;
play(bot, args.slice(1), false, null, selector)
break
case 'playurl':
playUrl(bot, args.slice(1), false, null, selector);
break;
playUrl(bot, args.slice(1), false, null, selector)
break
case 'stop':
try {
bot.tellraw(selector, {text: 'Cleared the song queue'});
bot.tellraw(selector, { text: 'Cleared the song queue' })
} catch (e) {
return;
return
}
bot.music.stop();
break;
bot.music.stop()
break
case 'skip':
try {
bot.tellraw(selector, [{text: 'Skipping '}, {text: bot.music.song.name, color: 'gold'}]);
bot.music.skip();
bot.tellraw(selector, [{ text: 'Skipping ' }, { text: bot.music.song.name, color: 'gold' }])
bot.music.skip()
} catch (e) {
throw new Error('No music is currently playing!');
throw new Error('No music is currently playing!')
}
break;
break
case 'loop':
switch (args[1]) {
case 'off':
bot.music.loop = 0;
bot.music.loop = 0
bot.tellraw(selector, [
{
text: 'Looping is now ',
text: 'Looping is now '
},
{
text: 'disabled',
color: 'red',
},
]);
break;
color: 'red'
}
])
break
case 'current':
bot.music.loop = 1;
bot.music.loop = 1
bot.tellraw(selector, [
{
text: 'Now Looping ',
text: 'Now Looping '
},
{
text: song.name,
color: 'gold',
},
]);
break;
case 'all':
bot.music.loop = 2;
bot.tellraw(selector, {
text: 'Now looping every song in the queue',
});
break;
default:
throw new SyntaxError('Invalid argument');
color: 'gold'
}
break;
])
break
case 'all':
bot.music.loop = 2
bot.tellraw(selector, {
text: 'Now looping every song in the queue'
})
break
default:
throw new SyntaxError('Invalid argument')
}
break
case 'list':
list(bot, false, null, prefix, selector, args);
break;
list(bot, false, null, prefix, selector, args)
break
case 'nowplaying':
bot.tellraw(selector, [
{
text: 'Now playing ',
text: 'Now playing '
},
{
text: bot.music.song.name,
color: 'gold',
},
]);
break;
color: 'gold'
}
])
break
case 'queue':
const queueWithName = [];
bot.music.queue.forEach((song) => queueWithName.push(song.name));
const queueWithName = []
bot.music.queue.forEach((song) => queueWithName.push(song.name))
bot.tellraw(selector, [
{
text: 'Queue: ',
color: 'green',
color: 'green'
},
{
text: queueWithName.join(', '),
color: 'aqua',
},
]);
break;
color: 'aqua'
}
])
break
default:
throw new SyntaxError('Invalid argument');
throw new SyntaxError('Invalid argument')
}
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message) {
let Embed;
discordExecute: function (bot, username, usernameraw, sender, prefix, args, channeldc, message) {
let Embed
switch (args[0]) {
case 'play':
play(bot, args.slice(1), true, channeldc);
break;
play(bot, args.slice(1), true, channeldc)
break
case 'playurl':
playUrl(bot, args.slice(1), true, channeldc);
break;
playUrl(bot, args.slice(1), true, channeldc)
break
case 'stop':
try {
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Stop')
.setDescription('Cleared the song queue');
channeldc.send({embeds: [Embed]});
.setDescription('Cleared the song queue')
channeldc.send({ embeds: [Embed] })
} catch (e) {
return;
return
}
bot.music.stop();
break;
bot.music.stop()
break
case 'skip':
try {
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Skip')
.setDescription(`Skipping ${bot.music.song.name}`);
channeldc.send({embeds: [Embed]});
bot.music.skip();
.setDescription(`Skipping ${bot.music.song.name}`)
channeldc.send({ embeds: [Embed] })
bot.music.skip()
} catch (e) {
throw new Error('No music is currently playing!');
throw new Error('No music is currently playing!')
}
break;
break
case 'loop':
switch (args[1]) {
case 'off':
bot.music.loop = 0;
bot.music.loop = 0
Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Loop')
.setDescription('Looping is now disabled');
channeldc.send({embeds: [Embed]});
break;
.setDescription('Looping is now disabled')
channeldc.send({ embeds: [Embed] })
break
case 'current':
bot.music.loop = 1;
bot.music.loop = 1
Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Loop')
.setDescription(`Now looping ${song.name}`);
channeldc.send({embeds: [Embed]});
break;
.setDescription(`Now looping ${song.name}`)
channeldc.send({ embeds: [Embed] })
break
case 'all':
bot.music.loop = 2;
bot.music.loop = 2
Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Loop')
.setDescription('Now looping every song in the queue');
channeldc.send({embeds: [Embed]});
break;
.setDescription('Now looping every song in the queue')
channeldc.send({ embeds: [Embed] })
break
}
break;
break
case 'list':
list(bot, true, channeldc, prefix, '@a', args);
break;
list(bot, true, channeldc, prefix, '@a', args)
break
case 'nowplaying':
Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Now playing')
.setDescription(`Now playing ${bot.music.song.name}`);
channeldc.send({embeds: [Embed]});
break;
.setDescription(`Now playing ${bot.music.song.name}`)
channeldc.send({ embeds: [Embed] })
break
case 'queue':
const queueWithName = [];
bot.music.queue.forEach((song) => queueWithName.push(song.name));
const queueWithName = []
bot.music.queue.forEach((song) => queueWithName.push(song.name))
Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Queue')
.setDescription(queueWithName.join(', '));
channeldc.send({embeds: [Embed]});
break;
.setDescription(queueWithName.join(', '))
channeldc.send({ embeds: [Embed] })
break
default:
throw new SyntaxError('Invalid argument');
throw new SyntaxError('Invalid argument')
}
},
};
}
}

View file

@ -5,41 +5,43 @@ module.exports = {
description: 'Broadcasts a message to all of the servers that the bot is connected',
usage: '<message>',
trusted: 0,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
const component = [
{
text: '[',
color: 'dark_gray',
color: 'dark_gray'
},
{
text: bot.options.host === 'kitsune.icu' ? 'kit' : bot.options.host,
color: 'gray',
color: 'gray'
},
bot.options.host === 'kitsune.icu' ? {
bot.options.host === 'kitsune.icu'
? {
text: 'sune.icu',
color: 'gray',
} : '',
color: 'gray'
}
: '',
{
text: '] ',
color: 'dark_gray',
color: 'dark_gray'
},
{
text: username,
color: 'gray',
color: 'gray'
},
{
text: ' \u203a ',
color: 'dark_gray',
color: 'dark_gray'
},
{
text: args.join(' '),
color: 'gray',
},
];
color: 'gray'
}
]
const bots = bot.getBots();
const bots = bot.getBots()
bots.forEach((bot) => {
bot.tellraw(selector, component);
});
},
};
bot.tellraw(selector, component)
})
}
}

View file

@ -4,10 +4,10 @@ module.exports = {
description: 'Resets the bot\'s command core',
usage: '',
trusted: 0,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.core.loopPlace();
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.core.loopPlace()
},
discordExecute: function(bot) {
bot.core.loopPlace();
},
};
discordExecute: function (bot) {
bot.core.loopPlace()
}
}

View file

@ -1,14 +1,14 @@
/* eslint-disable max-len */
const {between} = require('../util/between');
const { between } = require('../util/between')
module.exports = {
name: 'rtp',
alias: [],
description: 'Randomly teleports the player',
usage: '',
trusted: 0,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
const rtppos = `${between(20000000, 500000)} 100 ${between(20000000, 500000)}`;
bot.tellraw(selector, [{text: 'Teleporting ', color: 'white'}, {text: username, color: 'aqua'}, {text: ' to ', color: 'white'}, {text: rtppos, color: 'green'}, {text: '...', color: 'white'}]);
bot.core.run(`essentials:teleport ${sender} ${rtppos}`);
},
};
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
const rtppos = `${between(20000000, 500000)} 100 ${between(20000000, 500000)}`
bot.tellraw(selector, [{ text: 'Teleporting ', color: 'white' }, { text: username, color: 'aqua' }, { text: ' to ', color: 'white' }, { text: rtppos, color: 'green' }, { text: '...', color: 'white' }])
bot.core.run(`essentials:teleport ${sender} ${rtppos}`)
}
}

View file

@ -1,33 +1,34 @@
/* eslint-disable no-eval */
/* eslint-disable max-len */
const util = require('util');
const {stylize} = require('../util/colors/minecraft');
const {MessageEmbed} = require('discord.js');
const util = require('util')
const { stylize } = require('../util/colors/minecraft')
const { MessageEmbed } = require('discord.js')
module.exports = {
name: 'servereval',
alias: [],
description: 'Basically eval command but without vm2',
trusted: 2,
usage: '<ownerhash> <code>',
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
try {
bot.tellraw(selector, {text: util.inspect(eval(args.slice(1).join(' ')), {stylize}).substring(0, 32766)});
bot.tellraw(selector, { text: util.inspect(eval(args.slice(1).join(' ')), { stylize }).substring(0, 32766) })
} catch (err) {
bot.tellraw(selector, {text: util.inspect(err).replaceAll('runner', 'chayapak1'), color: 'red'});
bot.tellraw(selector, { text: util.inspect(err).replaceAll('runner', 'chayapak1'), color: 'red' })
}
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message, config) {
discordExecute: function (bot, username, usernameraw, sender, prefix, args, channeldc, message, config) {
try {
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Output')
.setDescription(util.inspect(eval(args.join(' ')), {stylize}));
channeldc.send({embeds: [Embed]});
.setDescription(util.inspect(eval(args.join(' ')), { stylize }))
channeldc.send({ embeds: [Embed] })
} catch (err) {
const Embed = new MessageEmbed()
.setColor('#FF0000')
.setTitle('Error')
.setDescription(`\`\`\`${util.inspect(err).replaceAll('runner', 'chayapak1')}\`\`\``);
channeldc.send({embeds: [Embed]});
.setDescription(`\`\`\`${util.inspect(err).replaceAll('runner', 'chayapak1')}\`\`\``)
channeldc.send({ embeds: [Embed] })
}
},
};
}
}

View file

@ -1,40 +1,40 @@
/* eslint-disable max-len */
const {MessageEmbed} = require('discord.js');
const { MessageEmbed } = require('discord.js')
module.exports = {
name: 'test',
alias: [],
description: 'Tests if the bot is working',
usage: '',
trusted: 0,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.tellraw(selector, [
{
text: `Username: ${username},`,
color: 'green',
color: 'green'
},
{
text: ` Raw username: ${usernameraw},`,
color: 'green',
color: 'green'
},
{
text: ` Sender UUID: ${sender},`,
color: 'green',
color: 'green'
},
{
text: ` Prefix: ${prefix},`,
color: 'green',
color: 'green'
},
{
text: ` Args: ${args.join(', ').toString()}`,
color: 'green',
color: 'green'
}
])
},
]);
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc) {
discordExecute: function (bot, username, usernameraw, sender, prefix, args, channeldc) {
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Hello!')
.setDescription('This is the first ever command to be discordified!' + '\n' + `More info: Username: ${username}, Prefix: ${prefix}, Args: ${args.join(' ')}`);
channeldc.send({embeds: [Embed]});
},
};
.setDescription('This is the first ever command to be discordified!' + '\n' + `More info: Username: ${username}, Prefix: ${prefix}, Args: ${args.join(' ')}`)
channeldc.send({ embeds: [Embed] })
}
}

View file

@ -1,44 +1,42 @@
/* eslint-disable max-len */
const {MessageEmbed} = require('discord.js');
const moment = require('moment-timezone');
const { MessageEmbed } = require('discord.js')
const moment = require('moment-timezone')
module.exports = {
name: 'time',
alias: [],
description: 'Shows the time',
usage: '<timezone>',
trusted: 0,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
const timezone = args.join(' ');
const momented = moment().tz(timezone).format('dddd, MMMM Do, YYYY, hh:mm:ss A');
const component = [{text: 'The current date and time for the timezone ', color: 'white'}, {text: timezone, color: 'aqua'}, {text: ' is: ', color: 'white'}, {text: `${momented}`, color: 'green'}];
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
const timezone = args.join(' ')
const momented = moment().tz(timezone).format('dddd, MMMM Do, YYYY, hh:mm:ss A')
const component = [{ text: 'The current date and time for the timezone ', color: 'white' }, { text: timezone, color: 'aqua' }, { text: ' is: ', color: 'white' }, { text: `${momented}`, color: 'green' }]
if (timezone.toLowerCase() === 'asia/bangkok' || timezone.toLowerCase() === 'utc') {
bot.tellraw(selector, component);
return;
bot.tellraw(selector, component)
} else if (momented === moment().format('dddd, MMMM Do, YYYY, hh:mm:ss A')) {
throw new SyntaxError('Invalid timezone');
throw new SyntaxError('Invalid timezone')
} else {
bot.tellraw(selector, component);
bot.tellraw(selector, component)
}
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc) {
const timezone = args.join(' ');
const momented = moment().tz(timezone).format('dddd, MMMM Do, YYYY, hh:mm:ss A');
const description = `The current date and time for the timezone ${timezone} is: ${momented}`;
discordExecute: function (bot, username, usernameraw, sender, prefix, args, channeldc) {
const timezone = args.join(' ')
const momented = moment().tz(timezone).format('dddd, MMMM Do, YYYY, hh:mm:ss A')
const description = `The current date and time for the timezone ${timezone} is: ${momented}`
if (timezone.toLowerCase() === 'asia/bangkok' || timezone.toLowerCase() === 'utc') {
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Time')
.setDescription(description);
channeldc.send({embeds: [Embed]});
return;
.setDescription(description)
channeldc.send({ embeds: [Embed] })
} else if (momented === moment().format('dddd, MMMM Do, YYYY, hh:mm:ss A')) {
throw new SyntaxError('Invalid timezone');
throw new SyntaxError('Invalid timezone')
} else {
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Time')
.setDescription(description);
channeldc.send({embeds: [Embed]});
.setDescription(description)
channeldc.send({ embeds: [Embed] })
}
},
};
}
}

View file

@ -5,7 +5,7 @@ module.exports = {
description: 'Teleport everyone',
usage: '<hash> <player>',
trusted: 1,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.core.run(`minecraft:execute unless entity @s[name= run ] run tp @a ${args.slice(1).join(' ')}`);
},
};
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.core.run(`minecraft:execute unless entity @s[name= run ] run tp @a ${args.slice(1).join(' ')}`)
}
}

View file

@ -1,34 +1,34 @@
/* eslint-disable max-len */
const {MessageEmbed} = require('discord.js');
const translate = require('@vitalets/google-translate-api');
const { MessageEmbed } = require('discord.js')
const translate = require('@vitalets/google-translate-api')
module.exports = {
name: 'translate',
alias: [],
description: 'Translate a message from any language to any language using Google Translate',
usage: '<language 1> <language 2> <message>',
trusted: 0,
execute: async function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
execute: async function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
try {
const res = await translate(args.slice(2).join(' '), {from: args[0], to: args[1]});
bot.tellraw(selector, [{text: 'Result: ', color: 'gold'}, {text: res.text, color: 'green'}]);
const res = await translate(args.slice(2).join(' '), { from: args[0], to: args[1] })
bot.tellraw(selector, [{ text: 'Result: ', color: 'gold' }, { text: res.text, color: 'green' }])
} catch (e) {
bot.tellraw(selector, {text: String(e), color: 'red'});
bot.tellraw(selector, { text: String(e), color: 'red' })
}
},
discordExecute: async function(bot, username, usernameraw, sender, prefix, args, channeldc, message) {
discordExecute: async function (bot, username, usernameraw, sender, prefix, args, channeldc, message) {
try {
const res = await translate(args.slice(2).join(' '), {from: args[0], to: args[1]});
const res = await translate(args.slice(2).join(' '), { from: args[0], to: args[1] })
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Result')
.setDescription(res.text);
channeldc.send({embeds: [Embed]});
.setDescription(res.text)
channeldc.send({ embeds: [Embed] })
} catch (e) {
const Embed = new MessageEmbed()
.setColor('#FF0000')
.setTitle('Error')
.setDescription(`\`\`\`${e}\`\`\``);
channeldc.send({embeds: [Embed]});
.setDescription(`\`\`\`${e}\`\`\``)
channeldc.send({ embeds: [Embed] })
}
},
};
}
}

View file

@ -1,20 +1,20 @@
/* eslint-disable max-len */
const {MessageEmbed} = require('discord.js');
const {secondsToHms} = require('../util/secondToHms');
const { MessageEmbed } = require('discord.js')
const { secondsToHms } = require('../util/secondToHms')
module.exports = {
name: 'uptime',
alias: [],
description: 'Shows the bot\'s uptime',
usage: '',
trusted: 0,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.tellraw(selector, [{text: 'The bot\'s uptime is ', color: 'white'}, {text: `${secondsToHms(Math.floor(performance.now() / 1000))}`, color: 'green'}]);
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.tellraw(selector, [{ text: 'The bot\'s uptime is ', color: 'white' }, { text: `${secondsToHms(Math.floor(performance.now() / 1000))}`, color: 'green' }])
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message) {
discordExecute: function (bot, username, usernameraw, sender, prefix, args, channeldc, message) {
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Bot\'s Uptime')
.setDescription(`The bot\'s uptime is ${secondsToHms(Math.floor(performance.now() / 1000))}`);
channeldc.send({embeds: [Embed]});
},
};
.setDescription(`The bot's uptime is ${secondsToHms(Math.floor(performance.now() / 1000))}`)
channeldc.send({ embeds: [Embed] })
}
}

View file

@ -1,20 +1,20 @@
/* eslint-disable max-len */
const urban = require('urban-dictionary');
const urban = require('urban-dictionary')
module.exports = {
name: 'urban',
alias: [],
description: 'Working Urban Dictionary',
usage: '<word>',
trusted: 0,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
urban.autocompleteExtra(args[0], (error, results) => {
if (error) {
bot.tellraw(selector, [{text: '[', color: 'dark_red'}, {text: 'Urban', color: 'red'}, {text: '] ', color: 'dark_red'}, {text: error.message, color: 'red'}]);
return;
bot.tellraw(selector, [{ text: '[', color: 'dark_red' }, { text: 'Urban', color: 'red' }, { text: '] ', color: 'dark_red' }, { text: error.message, color: 'red' }])
return
}
results.forEach(({preview, term}) => {
bot.tellraw(selector, [{text: '[', color: 'dark_red'}, {text: 'Urban', color: 'red'}, {text: '] ', color: 'dark_red'}, {text: term, color: 'white'}, {text: ' - ', color: 'white'}, {text: preview, color: 'white'}]);
});
});
},
};
results.forEach(({ preview, term }) => {
bot.tellraw(selector, [{ text: '[', color: 'dark_red' }, { text: 'Urban', color: 'red' }, { text: '] ', color: 'dark_red' }, { text: term, color: 'white' }, { text: ' - ', color: 'white' }, { text: preview, color: 'white' }])
})
})
}
}

View file

@ -1,83 +1,83 @@
/* eslint-disable max-len */
const {MessageEmbed} = require('discord.js');
const { MessageEmbed } = require('discord.js')
module.exports = {
name: 'uuid',
alias: [],
description: 'Gets the UUID of a player. If no player specified it will show your UUID instead',
usage: '',
trusted: 0,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
if (args[0]) {
const playername = args.join(' ');
const player = bot.playersAddedPlayers[playername];
if (player === undefined) throw new SyntaxError('Invalid Username');
const playername = args.join(' ')
const player = bot.playersAddedPlayers[playername]
if (player === undefined) throw new SyntaxError('Invalid Username')
bot.tellraw(selector,
[
{
text: `${playername}'s UUID: `,
color: 'green',
color: 'green'
},
{
text: player,
color: 'aqua',
clickEvent: {
action: 'copy_to_clipboard',
value: player,
value: player
},
hoverEvent: {
action: 'show_text',
contents: [
{
text: 'Click here to copy the UUID to your clipboard',
color: 'green',
},
],
},
},
]);
color: 'green'
}
]
}
}
])
} else {
bot.tellraw(selector,
[
{
text: `Your UUID: `,
color: 'green',
text: 'Your UUID: ',
color: 'green'
},
{
text: sender,
color: 'aqua',
clickEvent: {
action: 'copy_to_clipboard',
value: sender,
value: sender
},
hoverEvent: {
action: 'show_text',
contents: [
{
text: 'Click here to copy the uuid to your clipboard',
color: 'green',
},
],
},
},
]);
color: 'green'
}
]
}
}
])
}
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message) {
discordExecute: function (bot, username, usernameraw, sender, prefix, args, channeldc, message) {
if (args[0]) {
const playername = args.join(' ');
const player = bot.playersAddedPlayers[playername];
if (player === undefined) throw new SyntaxError('Invalid UUID');
const playername = args.join(' ')
const player = bot.playersAddedPlayers[playername]
if (player === undefined) throw new SyntaxError('Invalid UUID')
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('UUID')
.setDescription(`${playername}'s UUID: ${player}`);
channeldc.send({embeds: [Embed]});
.setDescription(`${playername}'s UUID: ${player}`)
channeldc.send({ embeds: [Embed] })
} else {
const Embed = new MessageEmbed()
.setColor('#FF0000')
.setTitle('Error')
.setDescription('Invalid player name');
channeldc.send({embeds: [Embed]});
.setDescription('Invalid player name')
channeldc.send({ embeds: [Embed] })
}
},
};
}
}

View file

@ -5,13 +5,13 @@ module.exports = {
alias: [],
usage: '<hash>',
trusted: 1,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
execute: function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
if (args[0] === hash) {
bot.tellraw(selector, {text: 'Valid hash', color: 'green'});
bot.tellraw(selector, { text: 'Valid hash', color: 'green' })
} else if (args[0] === ownerhash) {
bot.tellraw(selector, {text: 'Valid OwnerHash', color: 'green'});
bot.tellraw(selector, { text: 'Valid OwnerHash', color: 'green' })
} else {
bot.tellraw(selector, {text: 'Invalid hash', color: 'red'});
bot.tellraw(selector, { text: 'Invalid hash', color: 'red' })
}
},
};
}
}

View file

@ -1,37 +1,37 @@
/* eslint-disable max-len */
const wiki = require('wikipedia');
const util = require('util');
const {MessageEmbed} = require('discord.js');
const wiki = require('wikipedia')
const util = require('util')
const { MessageEmbed } = require('discord.js')
module.exports = {
name: 'wikipedia',
alias: ['wiki'],
description: 'Working Wikipedia!',
usage: '<page>',
trusted: 0,
execute: async function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
execute: async function (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
try {
const page = await wiki.page(args.join(' '));
const summary = await page.summary();
bot.tellraw(selector, {text: summary.extract, color: 'green'});
const page = await wiki.page(args.join(' '))
const summary = await page.summary()
bot.tellraw(selector, { text: summary.extract, color: 'green' })
} catch (e) {
bot.tellraw(selector, {text: e.toString(), color: 'red'});
bot.tellraw(selector, { text: e.toString(), color: 'red' })
}
},
discordExecute: async function(bot, username, usernameraw, sender, prefix, args, channeldc) {
discordExecute: async function (bot, username, usernameraw, sender, prefix, args, channeldc) {
try {
const page = await wiki.page(args.join(' '));
const summary = await page.summary();
const page = await wiki.page(args.join(' '))
const summary = await page.summary()
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Output')
.setDescription(summary.extract);
channeldc.send({embeds: [Embed]});
.setDescription(summary.extract)
channeldc.send({ embeds: [Embed] })
} catch (e) {
const Embed = new MessageEmbed()
.setColor('#FF0000')
.setTitle('Error')
.setDescription(`\`\`\`${util.inspect(e)}\`\`\``);
channeldc.send({embeds: [Embed]});
.setDescription(`\`\`\`${util.inspect(e)}\`\`\``)
channeldc.send({ embeds: [Embed] })
}
},
};
}
}

View file

@ -4,12 +4,12 @@ module.exports = {
prefixes: [
'*',
'cbot ',
'/cbot ',
'/cbot '
],
commandsDir: '../commands', // this will be used by the commands.js in the plugins folder so it needs ../
keys: {
normalKey: '<27>iB_D<5F><44><EFBFBD>k<EFBFBD><6B>j8H<38>{?[/ڭ<>f<EFBFBD><>^-=<3D>Ț<EFBFBD><C89A>v]<5D><>g><3E><>=c',
ownerHashKey: 'b)R<><52>nF<6E>CW<43><57><EFBFBD>#<23>\\[<5B>S*8"t^eia<69>Z<EFBFBD><5A>k<EFBFBD><6B><EFBFBD><EFBFBD>K1<4B>8zȢ<7A>',
ownerHashKey: 'b)R<><52>nF<6E>CW<43><57><EFBFBD>#<23>\\[<5B>S*8"t^eia<69>Z<EFBFBD><5A>k<EFBFBD><6B><EFBFBD><EFBFBD>K1<4B>8zȢ<7A>'
},
console: true,
useChat: false,
@ -19,13 +19,13 @@ module.exports = {
customName: [
{
text: 'ChomeNS Bot ',
color: 'yellow',
color: 'yellow'
},
{
text: 'Core',
color: 'green',
},
],
color: 'green'
}
]
},
self_care: {
prefix: true,
@ -34,10 +34,10 @@ module.exports = {
vanish: true,
gamemode: true,
mute: true,
endCredits: true,
endCredits: true
},
eval: {
serverUrl: 'http://192.168.1.105:4445/',
serverUrl: 'http://192.168.1.105:4445/'
},
reconnectTimeout: 1000 * 2,
self_care_check_interval: 2000,
@ -50,35 +50,35 @@ module.exports = {
'192.168.1.103': '1002806756885413978',
'kitsune.icu': '1004006678460637315',
'mc.chomens41793.ga': '1010734897796763758',
'real.chipmunk.land': '1042590315464364032',
'real.chipmunk.land': '1042590315464364032'
},
prefix: '!',
prefix: '!'
},
servers: [
{
host: 'play.kaboom.pw',
port: 25565,
kaboom: true,
kaboom: true
},
{
host: 'sus.shhnowisnottheti.me',
port: 25565,
kaboom: true,
kaboom: true
},
{
host: 'kitsune.icu',
port: 25565,
kaboom: true,
kaboom: true
},
{
host: 'real.chipmunk.land',
port: 25565,
kaboom: true,
kaboom: true
},
{
host: 'mc.chomens41793.ga',
port: 25565,
kaboom: true,
},
],
};
kaboom: true
}
]
}

View file

@ -1,36 +1,36 @@
/* eslint-disable max-len */
const readline = require('node:readline');
const {stdin: input, stdout: output} = require('node:process');
const rl = readline.createInterface({input, output});
const config = require('./config');
const {createBot} = require('./bot');
const readline = require('node:readline')
const { stdin: input, stdout: output } = require('node:process')
const rl = readline.createInterface({ input, output })
const config = require('./config')
const { createBot } = require('./bot')
const {
Client,
Intents,
} = require('discord.js');
const intents = new Intents(['GUILDS', 'GUILD_MESSAGES']);
Intents
} = require('discord.js')
const intents = new Intents(['GUILDS', 'GUILD_MESSAGES'])
const dcclient = new Client({
intents,
});
intents
})
let bots = [];
let bots = []
dcclient.on('ready', () => {
config.servers.forEach(async (server) => {
const getBots = () => bots;
const getBots = () => bots
const setNewBot = (server, bot) => {
bots = bots.filter((eachBot) => eachBot !== server);
bots.push(bot);
};
bots = bots.filter((eachBot) => eachBot !== server)
bots.push(bot)
}
// await is important cuz the function is async
// VVVVV
const bot = await createBot(server, config, getBots, setNewBot, dcclient, rl);
bots.push(bot);
});
});
const bot = await createBot(server, config, getBots, setNewBot, dcclient, rl)
bots.push(bot)
})
})
dcclient.login(config.discord.token);
dcclient.login(config.discord.token)
process.on('uncaughtException', (e) => {
console.log('uncaught ' + e);
});
console.log('uncaught ' + e)
})

View file

@ -23,6 +23,7 @@
"moment": "^2.29.3",
"moment-timezone": "^0.5.34",
"prismarine-block": "^1.16.3",
"prismarine-chat": "^1.7.2",
"prismarine-chunk": "^1.32.0",
"prismarine-item": "^1.11.5",
"prismarine-registry": "^1.3.0",
@ -39,6 +40,6 @@
},
"devDependencies": {
"eslint": "^8.20.0",
"eslint-config-google": "^0.14.0"
"eslint-config-standard": "^17.0.0"
}
}

View file

@ -2,40 +2,40 @@
/* eslint-disable require-jsdoc */
// eslint-disable-next-line no-undef
// const parse = require('../util/text_parser');
const {containsIllegalCharacters} = require('../util/containsIllegalCharacters');
const {chatPacketListener, parsePlayerMessages} = require('../util/chat');
const { containsIllegalCharacters } = require('../util/containsIllegalCharacters')
const { chatPacketListener, parsePlayerMessages } = require('../util/chat')
function inject(bot) {
bot.chatQueue = [];
function inject (bot) {
bot.chatQueue = []
const chatQueue = setInterval(function() {
const chatQueue = setInterval(function () {
if (bot.chatQueue[0] || bot.chatQueue[0] === '') {
try {
if (containsIllegalCharacters(bot.chatQueue[0])) {
bot.chatQueue.shift();
return;
bot.chatQueue.shift()
return
};
bot.write('chat', {message: bot.chatQueue[0]});
bot.chatQueue.shift();
bot.write('chat', { message: bot.chatQueue[0] })
bot.chatQueue.shift()
} catch (e) {
bot.console.error(e);
bot.console.error(e)
}
}
}, 450);
}, 450)
bot.chat = (message) => {
bot.chatQueue.push(String(message));
};
bot.chatQueue.push(String(message))
}
bot.once('end', () => {
clearInterval(chatQueue);
});
clearInterval(chatQueue)
})
const ChatMessage = require('prismarine-chat')(bot.version);
const ChatMessage = require('prismarine-chat')(bot.version)
bot._client.on('chat', (packet) => chatPacketListener(packet, ChatMessage, bot));
bot._client.on('chat', (packet) => chatPacketListener(packet, ChatMessage, bot))
bot.on('parsed_chat', (message, packet) => parsePlayerMessages(message, packet, bot));
bot.on('parsed_chat', (message, packet) => parsePlayerMessages(message, packet, bot))
}
module.exports = {inject};
module.exports = { inject }

View file

@ -1,101 +1,102 @@
/* eslint-disable require-jsdoc */
/* eslint-disable max-len */
const path = require('path');
const {MessageEmbed} = require('discord.js');
function inject(bot, dcclient, config) {
const loadFiles = require('../util/load_files');
const channeldc = dcclient.channels.cache.get(config.discord.servers[bot.options.host]);
bot.command_handler = {};
bot.command_handler.commands = {};
bot.command_handler.reload = async function() {
bot.command_handler.commands = await loadFiles(path.join(__dirname, config.commandsDir));
};
bot.command_handler.reload();
bot.command_handler.main = function(prefix, username, usernameraw, message, sender, channeldc, hash, ownerhash, selector) {
bot.command_handler.reload();
let raw;
let command;
const discord = message.content ? true : false;
const path = require('path')
const { MessageEmbed } = require('discord.js')
function inject (bot, dcclient, config) {
const loadFiles = require('../util/load_files')
const channeldc = dcclient.channels.cache.get(config.discord.servers[bot.options.host])
bot.command_handler = {}
bot.command_handler.commands = {}
bot.command_handler.reload = async function () {
bot.command_handler.commands = await loadFiles(path.join(__dirname, config.commandsDir))
}
bot.command_handler.reload()
bot.command_handler.main = function (prefix, username, usernameraw, message, sender, channeldc, hash, ownerhash, selector) {
bot.command_handler.reload()
let raw
let command
const discord = !!message.content
discord ? raw = message.content.substring(prefix.length) :
raw = message.substring(prefix.length);
discord
? raw = message.content.substring(prefix.length)
: raw = message.substring(prefix.length)
const [commandName, ...args] = raw.split(' ');
command = bot.command_handler.commands.find((command) => command.name === commandName.toLowerCase());
const [commandName, ...args] = raw.split(' ')
command = bot.command_handler.commands.find((command) => command.name === commandName.toLowerCase())
try {
const alias = bot.command_handler.commands.find((command) => command.alias.includes(commandName.toLowerCase()));
if (alias) command = bot.command_handler.commands.find((command) => command.alias.includes(commandName.toLowerCase()));
if (prefix === '*' && message.endsWith('*') && message !== '*') return;
if (!command) throw new Error(`Unknown command: "${commandName}"`);
const alias = bot.command_handler.commands.find((command) => command.alias.includes(commandName.toLowerCase()))
if (alias) command = bot.command_handler.commands.find((command) => command.alias.includes(commandName.toLowerCase()))
if (prefix === '*' && message.endsWith('*') && message !== '*') return
if (!command) throw new Error(`Unknown command: "${commandName}"`)
if (command.name !== 'validate' && command.trusted === 1) {
if (discord && !message.member?.roles?.cache?.some((role) => role.name === 'Trusted')) throw new Error('You\'re not in the trusted role!');
else if (!discord && args[0] !== hash) throw new Error(`Invalid hash`);
if (discord && !message.member?.roles?.cache?.some((role) => role.name === 'Trusted')) throw new Error('You\'re not in the trusted role!')
else if (!discord && args[0] !== hash) throw new Error('Invalid hash')
} else if (command.name !== 'validate' && command.trusted === 2) {
if (discord && !message.member?.roles?.cache?.some((role) => role.name === 'Trusted')) throw new Error('You\'re not in the trusted role!');
else if (!discord && args[0] !== ownerhash) throw new Error(`Invalid OwnerHash`);
if (discord && !message.member?.roles?.cache?.some((role) => role.name === 'Trusted')) throw new Error('You\'re not in the trusted role!')
else if (!discord && args[0] !== ownerhash) throw new Error('Invalid OwnerHash')
}
if (prefix === config.discord.prefix) {
if (!command.discordExecute) throw new Error('This command is not yet supported on discord!');
command.discordExecute(bot, username, usernameraw, sender, prefix, args, channeldc, message, config);
if (!command.discordExecute) throw new Error('This command is not yet supported on discord!')
command.discordExecute(bot, username, usernameraw, sender, prefix, args, channeldc, message, config)
} else {
command.execute(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector);
command.execute(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector)
}
} catch (e) {
if (prefix === config.discord.prefix) {
const Embed = new MessageEmbed()
.setColor('#FF0000')
.setTitle('Error')
.setDescription(`\`\`\`${e}\`\`\``);
channeldc.send({embeds: [Embed]});
.setDescription(`\`\`\`${e}\`\`\``)
channeldc.send({ embeds: [Embed] })
} else {
bot.tellraw(selector, {text: String(e), color: 'red'});
bot.tellraw(selector, { text: String(e), color: 'red' })
}
}
};
bot.command_handler.run = function(username, usernameraw, message, sender, channeldc, hash, ownerhash, selector = '@a') {
}
bot.command_handler.run = function (username, usernameraw, message, sender, channeldc, hash, ownerhash, selector = '@a') {
for (const prefix of config.prefixes) {
if (!message.startsWith(prefix)) continue;
bot.command_handler.main(prefix, username, usernameraw, message, sender, channeldc, hash, ownerhash, selector);
if (!message.startsWith(prefix)) continue
bot.command_handler.main(prefix, username, usernameraw, message, sender, channeldc, hash, ownerhash, selector)
}
}
};
bot.on('message', async (_username, _message, _sender) => {
// try catch cuz TypeError: Cannot read properties of undefined (reading 'replace')
try {
const usernameraw = _username.replace(/§.?/g, '');
const sender = _sender !== '00000000-0000-0000-0000-000000000000' ? _sender : bot.playersAddedPlayers[usernameraw];
let username;
if (!bot.getplayerusername[sender]) username = usernameraw;
else username = bot.getplayerusername[sender];
const message = _message.replace(/* /§r/g */ /§.?/g, '')/* .replace(/§/g, '')*/;
bot.command_handler.run(username, usernameraw, message, sender, channeldc, bot.hash, bot.ownerHash);
const usernameraw = _username.replace(/§.?/g, '')
const sender = _sender !== '00000000-0000-0000-0000-000000000000' ? _sender : bot.playersAddedPlayers[usernameraw]
let username
if (!bot.getplayerusername[sender]) username = usernameraw
else username = bot.getplayerusername[sender]
const message = _message.replace(/* /§r/g */ /§.?/g, '')/* .replace(/§/g, '') */
bot.command_handler.run(username, usernameraw, message, sender, channeldc, bot.hash, bot.ownerHash)
} catch (e) {
bot.console.error(e);
bot.console.error(e)
}
});
bot.on('cspy', async function(_username, _message) {
const username = _username.replace(/§.?/g, '');
const message = _message.replace(/§.?/g, '');
const sender = bot.playersAddedPlayers[username];
bot.command_handler.run(username, username, message, sender, channeldc, bot.hash, bot.ownerHash, username);
});
function handleDiscordMessages(message) {
})
bot.on('cspy', async function (_username, _message) {
const username = _username.replace(/§.?/g, '')
const message = _message.replace(/§.?/g, '')
const sender = bot.playersAddedPlayers[username]
bot.command_handler.run(username, username, message, sender, channeldc, bot.hash, bot.ownerHash, username)
})
function handleDiscordMessages (message) {
try {
// ignores the message that comes from the bot itself
if (message.author.id === dcclient.user.id) return;
if (message.author.id === dcclient.user.id) return
// only receive messages in SPECIFIC channel
if (message.channel.id !== channeldc.id) return;
if (!message.content.startsWith(config.discord.prefix)) return;
bot.command_handler.main(config.discord.prefix, message.member.displayName, message.member.displayName, message, 'no sender for discord', channeldc);
if (message.channel.id !== channeldc.id) return
if (!message.content.startsWith(config.discord.prefix)) return
bot.command_handler.main(config.discord.prefix, message.member.displayName, message.member.displayName, message, 'no sender for discord', channeldc)
} catch (e) {
return;
return
};
}
bot.once('end', () => {
dcclient.off('messageCreate', handleDiscordMessages);
});
dcclient.on('messageCreate', handleDiscordMessages);
dcclient.off('messageCreate', handleDiscordMessages)
})
dcclient.on('messageCreate', handleDiscordMessages)
};
module.exports = {inject};
module.exports = { inject }

View file

@ -1,72 +1,73 @@
/* eslint-disable no-eval */
/* eslint-disable require-jsdoc */
/* eslint-disable max-len */
const moment = require('moment-timezone');
const util = require('util');
const moment = require('moment-timezone')
const util = require('util')
function inject(bot, _dcclient, config, rl) {
if (!config.console) return;
function inject (bot, _dcclient, config, rl) {
if (!config.console) return
// readline > fix on log
function log(...args) {
rl.output.write('\x1b[2K\r');
console.log(args.toString());
rl._refreshLine();
function log (...args) {
rl.output.write('\x1b[2K\r')
console.log(args.toString())
rl._refreshLine()
};
const chatMessage = require('prismarine-chat')(bot.version);
const chatMessage = require('prismarine-chat')(bot.version)
function prefix(prefix, _message) {
const message = `[${moment().format('HH:mm:ss')} ${prefix}§r] [${bot.options.host}] `;
const component = chatMessage.MessageBuilder.fromString(message).toJSON();
return chatMessage.fromNotch(component).toAnsi() + _message;
function prefix (prefix, _message) {
const message = `[${moment().format('HH:mm:ss')} ${prefix}§r] [${bot.options.host}] `
const component = chatMessage.MessageBuilder.fromString(message).toJSON()
return chatMessage.fromNotch(component).toAnsi() + _message
}
bot.console = {};
bot.console.host = 'all';
bot.console.log = function(message) {
log(prefix('&6LOG', message));
};
bot.console.info = function(message) {
log(prefix('&aINFO', message));
};
bot.console.error = function(error) {
log(prefix('&cERROR', typeof error === 'string' ? error : error.stack));
};
bot.console = {}
bot.console.host = 'all'
bot.console.log = function (message) {
log(prefix('&6LOG', message))
}
bot.console.info = function (message) {
log(prefix('&aINFO', message))
}
bot.console.error = function (error) {
log(prefix('&cERROR', typeof error === 'string' ? error : error.stack))
}
bot.on('parsed_chat', (message) => {
bot.console.log(message.toAnsi());
});
bot.console.log(message.toAnsi())
})
function handleLine(line) {
function handleLine (line) {
try {
if (line.toLowerCase() === '' ||
line.toLowerCase().startsWith(' ')) return;
line.toLowerCase().startsWith(' ')) return
if (line.startsWith('.csvr ')) {
const host = line.substring(6);
bot.getBots().forEach((eachBot) => eachBot.console.host = host);
bot.console.info(`Host set to: ${host}`);
return;
const host = line.substring(6)
bot.getBots().forEach((eachBot) => { eachBot.console.host = host })
bot.console.info(`Host set to: ${host}`)
return
}
if (bot.options.host !== bot.console.host && bot.console.host !== 'all') return;
if (bot.options.host !== bot.console.host && bot.console.host !== 'all') return
if (line.toLowerCase() === '.exit' || line.toLowerCase() === '.end') {
bot.end('end command');
return;
bot.end('end command')
return
}
if (line.toLowerCase().startsWith('.servereval ')) {
try {
bot.tellraw('@a', {
text: `${util.inspect(eval(`${line.substring(12)}`))}`,
color: 'green',
});
return;
color: 'green'
})
return
} catch (err) {
bot.tellraw('@a', {text: `${util.inspect(err)}`, color: 'red'});
return;
bot.tellraw('@a', { text: `${util.inspect(err)}`, color: 'red' })
return
}
}
if (line === '.kill') process.exit();
if (line === '.kill') process.exit()
if (line.startsWith('.')) {
return bot.command_handler.run(
@ -76,42 +77,42 @@ function inject(bot, _dcclient, config, rl) {
bot.uuid,
null,
'h',
'o',
);
'o'
)
}
bot.tellraw('@a', [
{
text: '[',
color: 'dark_gray',
color: 'dark_gray'
},
{
text: `${bot.username} Console`,
color: 'gray',
color: 'gray'
},
{
text: '] ',
color: 'dark_gray',
color: 'dark_gray'
},
{
text: 'chayapak ',
color: 'green',
color: 'green'
},
{
text: '\u203a ',
color: 'dark_gray',
color: 'dark_gray'
},
chatMessage.MessageBuilder.fromString('&7' + line),
]);
chatMessage.MessageBuilder.fromString('&7' + line)
])
} catch (e) {
bot.console.error(e);
bot.console.error(e)
}
}
rl.on('line', handleLine);
rl.on('line', handleLine)
bot.once('end', () => {
rl.off('line', handleLine);
});
rl.off('line', handleLine)
})
}
module.exports = {inject};
module.exports = { inject }

View file

@ -1,84 +1,84 @@
/* eslint-disable max-len */
/* eslint-disable require-jsdoc */
const nbt = require('prismarine-nbt');
const Vec3 = require('vec3');
const nbt = require('prismarine-nbt')
const Vec3 = require('vec3')
const relativePosition = new Vec3(0, 0, 0);
const relativePosition = new Vec3(0, 0, 0)
function inject(bot, dcclient, config) {
const mcData = require('minecraft-data')(bot.version);
const chatMessage = require('prismarine-chat')(bot.version);
function inject (bot, dcclient, config) {
const mcData = require('minecraft-data')(bot.version)
const chatMessage = require('prismarine-chat')(bot.version)
const core = {
isCore(position) {
return position.x >= core.start.x && position.x <= core.end.x && position.y >= core.start.y && position.y <= core.end.y && position.z >= core.start.z && position.z <= core.end.z;
isCore (position) {
return position.x >= core.start.x && position.x <= core.end.x && position.y >= core.start.y && position.y <= core.end.y && position.z >= core.start.z && position.z <= core.end.z
},
run(command) {
run (command) {
try {
if (config.useChat &&
command.startsWith('minecraft:tellraw @a ') &&
!command.includes('Console') &&
!command.includes('Discord')
) {
bot.chat(chatMessage.fromNotch(command.replace('minecraft:tellraw @a ', '')).toMotd().replaceAll('\xa7', '&'));
return;
bot.chat(chatMessage.fromNotch(command.replace('minecraft:tellraw @a ', '')).toMotd().replaceAll('\xa7', '&'))
return
}
relativePosition.x++;
relativePosition.x++
if (relativePosition.x >= 16) {
relativePosition.x = 0;
relativePosition.y++;
relativePosition.x = 0
relativePosition.y++
}
if (relativePosition.y >= config.core.layers) {
relativePosition.y = 0;
relativePosition.z++;
relativePosition.y = 0
relativePosition.z++
}
if (relativePosition.z >= 16) {
relativePosition.z = 0;
relativePosition.z = 0
}
const impulseMode = !bot.options.kaboom;
const impulseMode = !bot.options.kaboom
const location = {
x: core.start.x + relativePosition.x,
y: core.start.y + relativePosition.y,
z: core.start.z + relativePosition.z,
};
z: core.start.z + relativePosition.z
}
if (impulseMode) bot.write('update_command_block', {location, command: '', mode: 0, flags: 0});
bot.write('update_command_block', {location, command: String(command).substring(0, 32767), mode: impulseMode ? 2 : 1, flags: 0b100});
if (impulseMode) bot.write('update_command_block', { location, command: '', mode: 0, flags: 0 })
bot.write('update_command_block', { location, command: String(command).substring(0, 32767), mode: impulseMode ? 2 : 1, flags: 0b100 })
} catch (e) {
bot.console.error(e);
bot.console.error(e)
}
},
async loopPlace() {
async loopPlace () {
try {
const fillCommand = `/minecraft:fill ${core.start.x} ${core.start.y} ${core.start.z} ${core.end.x} ${core.end.y} ${core.end.z} command_block{CustomName:'${JSON.stringify(config.core.customName)}'}`;
const location = {x: Math.floor(bot.position.x), y: Math.floor(bot.position.y) - 1, z: Math.floor(bot.position.z)};
const fillCommand = `/minecraft:fill ${core.start.x} ${core.start.y} ${core.start.z} ${core.end.x} ${core.end.y} ${core.end.z} command_block{CustomName:'${JSON.stringify(config.core.customName)}'}`
const location = { x: Math.floor(bot.position.x), y: Math.floor(bot.position.y) - 1, z: Math.floor(bot.position.z) }
bot.write('set_creative_slot', {
slot: 36,
item: {
present: true,
itemId: mcData.itemsByName['repeating_command_block'].id,
itemId: mcData.itemsByName.repeating_command_block.id,
itemCount: 64,
nbtData: nbt.comp({
BlockEntityTag: nbt.comp({
Command: nbt.string(fillCommand),
auto: nbt.byte(1),
TrackOutput: nbt.byte(0),
}),
}),
},
});
TrackOutput: nbt.byte(0)
})
})
}
})
bot.write('block_dig', {
status: 0,
location,
face: 1,
});
face: 1
})
bot.write('block_place', {
location,
@ -87,34 +87,34 @@ function inject(bot, dcclient, config) {
cursorX: 0.5,
cursorY: 0.5,
cursorZ: 0.5,
insideBlock: false,
});
insideBlock: false
})
} catch (e) {
bot.console.error(e);
bot.console.error(e)
}
}
}
},
};
function fillCore() {
function fillCore () {
core.start = new Vec3(
Math.floor(bot.position.x / 16) * 16,
0 /* bot.position.y */,
Math.floor(bot.position.z / 16) * 16,
).floor();
core.end = core.start.clone().translate(16, config.core.layers, 16).subtract(new Vec3(1, 1, 1));
Math.floor(bot.position.z / 16) * 16
).floor()
core.end = core.start.clone().translate(16, config.core.layers, 16).subtract(new Vec3(1, 1, 1))
bot.core.loopPlace();
bot.core.loopPlace()
}
bot.on('position', fillCore);
bot.on('position', fillCore)
const interval = setInterval(() => fillCore(), config.core.refillInterval);
const interval = setInterval(() => fillCore(), config.core.refillInterval)
bot.once('end', () => {
clearInterval(interval);
});
clearInterval(interval)
})
bot.core = core;
bot.core = core
}
module.exports = {inject};
module.exports = { inject }

View file

@ -1,43 +1,44 @@
/* eslint-disable require-jsdoc */
/* eslint-disable max-len */
const {escapeMarkdown} = require('../util/escapeMarkdown');
async function inject(bot, dcclient, config) {
const channel = dcclient.channels.cache.get(config.discord.servers[bot.options.host]);
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.options.host])
let queue = '';
let queue = ''
const queueInterval = setInterval(() => {
if (queue === '') return;
if (queue === '') return
channel.send({
content: '```ansi\n' + queue.substring(0, 1986) + '\n```',
allowedMentions: {
parse: [],
},
});
queue = '';
}, 1000);
parse: []
}
})
queue = ''
}, 1000)
bot.on('parsed_chat', (message) => {
const cleanMessage = escapeMarkdown(message.toAnsi(), true);
const cleanMessage = escapeMarkdown(message.toAnsi(), true)
const discordMsg = cleanMessage
.replaceAll('@', '@\u200b')
.replaceAll('http', 'http\u200b')
.replaceAll('\u001b[9', '\u001b[3');
if (message.toMotd().startsWith('§8[§eChomeNS §9Discord§8] §c')) return;
queue += '\n' + discordMsg;
});
.replaceAll('\u001b[9', '\u001b[3')
if (message.toMotd().startsWith('§8[§eChomeNS §9Discord§8] §c')) return
queue += '\n' + discordMsg
})
// handle discord messages!!!
async function handleDiscordMessages(message) {
async function handleDiscordMessages (message) {
// Ignore messages from the bot itself
if (message.author.id === dcclient.user.id) return;
if (message.author.id === dcclient.user.id) return
// Only handle messages in specified channel
if (message.channel.id !== channel.id) return;
if (message.content.startsWith(config.discord.prefix)) return;
if (message.channel.id !== channel.id) return
if (message.content.startsWith(config.discord.prefix)) return
try {
const attachmentsComponent = [];
const attachmentsComponent = []
if (message.attachments) {
message.attachments.forEach((value) => {
attachmentsComponent.push({
@ -45,70 +46,76 @@ async function inject(bot, dcclient, config) {
color: 'green',
clickEvent: {
action: 'open_url',
value: value.proxyURL,
},
});
});
value: value.proxyURL
}
})
})
}
const component = [
{text: '[', color: 'dark_gray'},
{text: 'ChomeNS ', color: 'yellow',
{ text: '[', color: 'dark_gray' },
{
text: 'ChomeNS ',
color: 'yellow',
clickEvent: {
action: 'open_url',
value: 'https://discord.gg/xdgCkUyaA4',
value: 'https://discord.gg/xdgCkUyaA4'
}
},
},
{text: 'Discord', color: 'blue',
{
text: 'Discord',
color: 'blue',
clickEvent: {
action: 'open_url',
value: 'https://discord.gg/xdgCkUyaA4',
value: 'https://discord.gg/xdgCkUyaA4'
}
},
},
{text: '] ', color: 'dark_gray'},
{text: `${message.member.displayName}`, color: 'red',
{ text: '] ', color: 'dark_gray' },
{
text: `${message.member.displayName}`,
color: 'red',
clickEvent: {
action: 'copy_to_clipboard',
value: `${message.author.username}#${message.author.discriminator}`,
value: `${message.author.username}#${message.author.discriminator}`
},
hoverEvent: {
action: 'show_text',
value: [
{
text: message.author.username,
color: 'white',
color: 'white'
},
{
text: '#',
color: 'dark_gray',
color: 'dark_gray'
},
{
text: message.author.discriminator,
color: 'gray',
color: 'gray'
},
'\n',
{
text: 'Click here to copy the tag to your clipboard',
color: 'green',
color: 'green'
}
]
}
},
],
},
},
{text: ' ', color: 'dark_gray'},
{ text: ' ', color: 'dark_gray' },
chatMessage.MessageBuilder.fromString('&7' + message.content),
attachmentsComponent.length === 0 ? '' : attachmentsComponent,
];
bot.tellraw('@a', component);
attachmentsComponent.length === 0 ? '' : attachmentsComponent
]
bot.tellraw('@a', component)
} catch (e) {
return;
}
}
bot.once('end', () => {
clearInterval(queueInterval);
dcclient.off('messageCreate', handleDiscordMessages);
});
clearInterval(queueInterval)
dcclient.off('messageCreate', handleDiscordMessages)
})
dcclient.on('messageCreate', handleDiscordMessages);
dcclient.on('messageCreate', handleDiscordMessages)
};
module.exports = {inject};
module.exports = { inject }

View file

@ -1,54 +1,54 @@
/* eslint-disable max-len */
const convert = require('color-convert');
const convert = require('color-convert')
// eslint-disable-next-line require-jsdoc
function inject(bot) {
function inject (bot) {
/**
* draw which is totallynotskidded from ybot
* @param {buffer} data data buffer
* @param {*} info idk bout this
* @param {object} prefix prefix in the output compoenent
*/
function draw(data, info, prefix = {}) {
const pixels = [];
function draw (data, info, prefix = {}) {
const pixels = []
// Data Buffer -> RGB Array
for (let i = 0; i < data.length; i += info.channels) {
pixels.push([
data[i + 0],
data[i + 1],
data[i + 2],
]);
data[i + 2]
])
}
const rows = [];
const rows = []
// RGB Array -> Rows Array
for (let i = 0; i < pixels.length; i += info.width) {
const row = pixels.slice(i, i + info.width);
const row = pixels.slice(i, i + info.width)
rows.push(row);
rows.push(row)
}
const messages = [];
const messages = []
for (const row of rows) {
const message = [{...prefix, text: ''}];
const message = [{ ...prefix, text: '' }]
for (const rgb of row) {
message.push({
text: '⎮',
color: `#${convert.rgb.hex(rgb)}`,
});
color: `#${convert.rgb.hex(rgb)}`
})
}
messages.push(message);
messages.push(message)
}
for (const message of messages) bot.tellraw('@a', message);
for (const message of messages) bot.tellraw('@a', message)
}
bot.draw = draw;
bot.draw = draw
}
module.exports = {inject};
module.exports = { inject }

View file

@ -1,15 +1,15 @@
/* eslint-disable max-len */
const crypto = require('crypto');
const crypto = require('crypto')
module.exports = {
inject: function(bot, dcclient, config) {
bot.hash = '';
inject: function (bot, dcclient, config) {
bot.hash = ''
const interval = setInterval(() => {
bot.hash = crypto.createHash('sha256').update(Math.floor(Date.now() / 10000) + config.keys.normalKey).digest('hex').substring(0, 16);
bot.ownerHash = crypto.createHash('sha256').update(Math.floor(Date.now() / 10000) + config.keys.ownerHashKey).digest('hex').substring(0, 16);
}, 2000);
bot.hash = crypto.createHash('sha256').update(Math.floor(Date.now() / 10000) + config.keys.normalKey).digest('hex').substring(0, 16)
bot.ownerHash = crypto.createHash('sha256').update(Math.floor(Date.now() / 10000) + config.keys.ownerHashKey).digest('hex').substring(0, 16)
}, 2000)
bot.once('end', () => {
clearInterval(interval);
});
},
};
clearInterval(interval)
})
}
}

View file

@ -1,7 +1,7 @@
/* eslint-disable require-jsdoc */
/* eslint-disable max-len */
const {Midi} = require('@tonejs/midi');
const {convertMidi} = require('../util/midi_converter');
const { Midi } = require('@tonejs/midi')
const { convertMidi } = require('../util/midi_converter')
const soundNames = {
harp: 'minecraft:block.note_block.harp',
@ -19,130 +19,129 @@ const soundNames = {
didgeridoo: 'minecraft:block.note_block.didgeridoo',
bit: 'minecraft:block.note_block.bit',
banjo: 'minecraft:block.note_block.banjo',
pling: 'minecraft:block.note_block.pling',
};
pling: 'minecraft:block.note_block.pling'
}
function inject(bot) {
bot.music = function() {};
bot.music.song = null;
bot.music.loop = 0;
bot.music.queue = [];
let time = 0;
let startTime = 0;
let noteIndex = 0;
bot.music.skip = function() {
function inject (bot) {
bot.music = function () {}
bot.music.song = null
bot.music.loop = 0
bot.music.queue = []
let time = 0
let startTime = 0
let noteIndex = 0
bot.music.skip = function () {
if (bot.music.loop === 2) {
bot.music.queue.push(bot.music.queue.shift());
bot.music.play(bot.music.queue[0]);
bot.music.queue.push(bot.music.queue.shift())
bot.music.play(bot.music.queue[0])
} else {
bot.music.queue.shift();
bot.music.queue.shift()
}
resetTime()
}
resetTime();
};
const interval = setInterval(async () => {
try {
if (!bot.music.queue.length) return;
bot.music.song = bot.music.queue[0];
time = Date.now() - startTime;
if (!bot.music.queue.length) return
bot.music.song = bot.music.queue[0]
time = Date.now() - startTime
while (bot.music.song.notes[noteIndex]?.time <= time) {
const note = bot.music.song.notes[noteIndex];
const floatingPitch = 2 ** ((note.pitch - 12) / 12.0);
bot.core.run(`minecraft:execute as @a[tag=!nomusic] at @s run playsound ${soundNames[note.instrument]} record @s ~ ~ ~ ${note.volume} ${floatingPitch}`);
noteIndex++;
bot.core.run('minecraft:title @a[tag=!nomusic] actionbar ' + JSON.stringify(toComponent()));
const note = bot.music.song.notes[noteIndex]
const floatingPitch = 2 ** ((note.pitch - 12) / 12.0)
bot.core.run(`minecraft:execute as @a[tag=!nomusic] at @s run playsound ${soundNames[note.instrument]} record @s ~ ~ ~ ${note.volume} ${floatingPitch}`)
noteIndex++
bot.core.run('minecraft:title @a[tag=!nomusic] actionbar ' + JSON.stringify(toComponent()))
if (noteIndex >= bot.music.song.notes.length) {
if (bot.music.loop === 1) {
resetTime();
return;
resetTime()
return
}
if (bot.music.loop === 2) {
resetTime();
bot.music.queue.push(bot.music.queue.shift());
bot.music.play(bot.music.queue[0]);
return;
resetTime()
bot.music.queue.push(bot.music.queue.shift())
bot.music.play(bot.music.queue[0])
return
}
bot.music.queue.shift();
bot.music.queue.shift()
if (!bot.music.queue[0]) {
bot.tellraw('@a', {text: 'Finished playing every song in the queue'});
bot.music.stop();
return;
bot.tellraw('@a', { text: 'Finished playing every song in the queue' })
bot.music.stop()
return
}
if (bot.music.queue[0].notes.length > 0) {
if (bot.music.queue.length !== 1) resetTime();
bot.music.play(bot.music.queue[0]);
return;
if (bot.music.queue.length !== 1) resetTime()
bot.music.play(bot.music.queue[0])
return
}
}
}
} catch (e) {}
}, 50);
}, 50)
bot.once('end', () => {
clearInterval(interval);
});
clearInterval(interval)
})
bot.music.load = function(buffer, fallbackName = '[unknown]') {
bot.music.load = function (buffer, fallbackName = '[unknown]') {
// TODO: NBS Support
const midi = new Midi(buffer);
const song = convertMidi(midi);
if (song.name === '') song.name = fallbackName;
return song;
};
bot.music.play = function(song) {
loop = song.loop;
if (bot.music.queue.length === 1) resetTime();
};
bot.music.stop = function() {
bot.music.song = null;
bot.music.loop = 0;
bot.music.queue = [];
resetTime();
};
function resetTime() {
time = 0;
startTime = Date.now();
noteIndex = 0;
const midi = new Midi(buffer)
const song = convertMidi(midi)
if (song.name === '') song.name = fallbackName
return song
}
function formatTime(time) {
const seconds = Math.floor(time / 1000);
return `${Math.floor(seconds / 60)}:${(seconds % 60).toString().padStart(2, '0')}`;
bot.music.play = function () {
if (bot.music.queue.length === 1) resetTime()
}
function toComponent() {
bot.music.stop = function () {
bot.music.song = null
bot.music.loop = 0
bot.music.queue = []
resetTime()
}
function resetTime () {
time = 0
startTime = Date.now()
noteIndex = 0
}
function formatTime (time) {
const seconds = Math.floor(time / 1000)
return `${Math.floor(seconds / 60)}:${(seconds % 60).toString().padStart(2, '0')}`
}
function toComponent () {
const component = [
{text: '[', color: 'dark_gray'},
{text: 'ChomeNS Bot', color: 'yellow'},
{text: '] ', color: 'dark_gray'},
{text: 'Now Playing', color: 'gold'},
{text: ' | ', color: 'dark_gray'},
{text: bot.music.song.name, color: 'green'},
{text: ' | ', color: 'dark_gray'},
{text: formatTime(time), color: 'gray'},
{text: ' / ', color: 'dark_gray'},
{text: formatTime(bot.music.song.length), color: 'gray'},
{text: ' | ', color: 'dark_gray'},
{text: noteIndex, color: 'gray'},
{text: ' / ', color: 'dark_gray'},
{text: bot.music.song.notes.length, color: 'gray'},
];
{ text: '[', color: 'dark_gray' },
{ text: 'ChomeNS Bot', color: 'yellow' },
{ text: '] ', color: 'dark_gray' },
{ text: 'Now Playing', color: 'gold' },
{ text: ' | ', color: 'dark_gray' },
{ text: bot.music.song.name, color: 'green' },
{ text: ' | ', color: 'dark_gray' },
{ text: formatTime(time), color: 'gray' },
{ text: ' / ', color: 'dark_gray' },
{ text: formatTime(bot.music.song.length), color: 'gray' },
{ text: ' | ', color: 'dark_gray' },
{ text: noteIndex, color: 'gray' },
{ text: ' / ', color: 'dark_gray' },
{ text: bot.music.song.notes.length, color: 'gray' }
]
if (bot.music.loop === 1) {
component.push({text: ' | ', color: 'dark_gray'});
component.push({text: 'Looping Current', color: 'green'});
component.push({ text: ' | ', color: 'dark_gray' })
component.push({ text: 'Looping Current', color: 'green' })
}
if (bot.music.loop === 2) {
component.push({text: ' | ', color: 'dark_gray'});
component.push({text: 'Looping All', color: 'green'});
component.push({ text: ' | ', color: 'dark_gray' })
component.push({ text: 'Looping All', color: 'green' })
}
return component;
return component
}
}
module.exports = {inject};
module.exports = { inject }

View file

@ -1,157 +1,157 @@
/* eslint-disable max-len */
/* eslint-disable require-jsdoc */
class PlayerList {
list = [];
list = []
addPlayer(player) {
this.removePlayer(player);
addPlayer (player) {
this.removePlayer(player)
this.list.push(player);
this.list.push(player)
}
hasPlayer(player) {
return this.getPlayer(player) !== undefined;
hasPlayer (player) {
return this.getPlayer(player) !== undefined
}
getPlayer(player) {
let identifier;
getPlayer (player) {
let identifier
switch (typeof player) {
case 'object':
identifier = player.UUID;
break;
identifier = player.UUID
break
case 'string':
identifier = player;
break;
identifier = player
break
default:
throw new Error(`Get player called with ${player}`);
throw new Error(`Get player called with ${player}`)
}
return this.list.find((player) => [player.UUID, player.name].some((item) => item === identifier));
return this.list.find((player) => [player.UUID, player.name].some((item) => item === identifier))
}
getPlayers() {
return Array.from(this.list);
getPlayers () {
return Array.from(this.list)
}
removePlayer(player) {
this.list = this.list.filter(({UUID}) => UUID !== player.UUID);
removePlayer (player) {
this.list = this.list.filter(({ UUID }) => UUID !== player.UUID)
}
}
class TabCompletePlayerRequester {
id = 0;
queue = {};
bot;
id = 0
queue = {}
bot
constructor(bot) {
this.bot = bot;
constructor (bot) {
this.bot = bot
bot._client.on('target_packet', (name, data) => {
if (name !== 'tab_complete') return;
if (name !== 'tab_complete') return
const players = data.matches
.filter((match) => !match.tooltip)
.map((match) => match.match);
.map((match) => match.match)
this.returnPlayerList(data.transactionId, players);
});
this.returnPlayerList(data.transactionId, players)
})
}
getPlayerList() {
getPlayerList () {
return new Promise((resolve) => {
this.id++;
this.id %= 256;
this.id++
this.id %= 256
this.queue[this.id] = resolve;
this.queue[this.id] = resolve
setTimeout(() => this.returnPlayerList(this.id, this.getPlayerList()), 1000 * 5);
setTimeout(() => this.returnPlayerList(this.id, this.getPlayerList()), 1000 * 5)
this.bot.write('tab_complete', {transactionId: this.id, text: '/scoreboard players add '});
});
this.bot.write('tab_complete', { transactionId: this.id, text: '/scoreboard players add ' })
})
}
returnPlayerList(id, players) {
if (!this.queue[id]) return;
returnPlayerList (id, players) {
if (!this.queue[id]) return
this.queue[id](players);
this.queue[id](players)
delete this.queue[id];
delete this.queue[id]
}
}
function inject(bot, dcclient, config) {
bot.players = new PlayerList();
bot.requester = new TabCompletePlayerRequester(bot);
function inject (bot, dcclient, config) {
bot.players = new PlayerList()
bot.requester = new TabCompletePlayerRequester(bot)
bot._client.on('player_info', (packet) => {
for (const player of packet.data) {
switch (packet.action) {
case 0:
addPlayer(player, packet);
break;
addPlayer(player, packet)
break
case 1:
updateGamemode(player, packet);
break;
updateGamemode(player, packet)
break
case 2:
updatePing(player, packet);
break;
updatePing(player, packet)
break
case 3:
updateDisplayName(player, packet);
break;
updateDisplayName(player, packet)
break
case 4:
removePlayer(player, packet);
break;
removePlayer(player, packet)
break
}
}
});
})
function addPlayer(player, packet) {
function addPlayer (player, packet) {
// if (bot.players.getPlayer(player)) bot.emit('player_unvanished', player, packet);
/* else */bot.emit('player_added', player, packet);
/* else */bot.emit('player_added', player, packet)
bot.players.addPlayer(player);
bot.players.addPlayer(player)
}
function updateGamemode(player, packet) {
const fullPlayer = bot.players.getPlayer(player);
function updateGamemode (player, packet) {
const fullPlayer = bot.players.getPlayer(player)
bot.emit('onPlayerGamemodeUpdate', player, packet);
bot.emit('onPlayerGamemodeUpdate', player, packet)
if (fullPlayer === undefined) return;
if (fullPlayer === undefined) return
fullPlayer.gamemode = player.gamemode;
fullPlayer.gamemode = player.gamemode
}
function updatePing(player, packet) {
const fullPlayer = bot.players.getPlayer(player);
function updatePing (player, packet) {
const fullPlayer = bot.players.getPlayer(player)
bot.emit('player_ping_updated', player, packet);
bot.emit('player_ping_updated', player, packet)
if (fullPlayer === undefined) return;
if (fullPlayer === undefined) return
fullPlayer.ping = player.ping;
fullPlayer.ping = player.ping
}
function updateDisplayName(player, packet) {
const fullPlayer = bot.players.getPlayer(player);
function updateDisplayName (player, packet) {
const fullPlayer = bot.players.getPlayer(player)
bot.emit('player_display_name_updated', player, packet);
bot.emit('player_display_name_updated', player, packet)
if (fullPlayer === undefined) return;
if (fullPlayer === undefined) return
fullPlayer.displayName = player.displayName;
fullPlayer.displayName = player.displayName
}
async function removePlayer(player, packet) {
async function removePlayer (player, packet) {
// const fullPlayer = bot.players.getPlayer(player);
// const players = await bot.requester.getPlayerList();
//
// if (fullPlayer && players.some((name) => name === fullPlayer.name)) bot.emit('player_vanished', player);
/* else */bot.emit('player_removed', player, packet);
/* else */bot.emit('player_removed', player, packet)
bot.players.removePlayer(player);
bot.players.removePlayer(player)
}
}
module.exports = {inject};
module.exports = { inject }

View file

@ -1,10 +1,10 @@
/* eslint-disable require-jsdoc */
function inject(bot) {
function inject (bot) {
bot._client.on('position', (position) => {
bot.position = position;
bot.write('teleport_confirm', {teleportId: position.teleportId});
bot.emit('position', position);
});
bot.position = position
bot.write('teleport_confirm', { teleportId: position.teleportId })
bot.emit('position', position)
})
}
module.exports = {inject};
module.exports = { inject }

View file

@ -1,78 +1,78 @@
/* eslint-disable require-jsdoc */
/* eslint-disable max-len */
function inject(bot, dcclient, config) {
let vanish = false;
let cspy = false;
let op = true;
let gameMode = 1;
let prefix = false;
let muted = false;
let endCredits = false;
function inject (bot, dcclient, config) {
let vanish = false
let cspy = false
let op = true
let gameMode = 1
let prefix = false
let muted = false
let endCredits = false
bot.on('parsed_chat', (data) => {
if (data.toString() === 'You are now completely invisible to normal users, and hidden from in-game commands.') vanish = true;
if (data.toString() === 'You are now completely invisible to normal users, and hidden from in-game commands.') vanish = true
if (!bot.visibility &&
data.toString().startsWith('Vanish for ') &&
data.toString().endsWith('disabled')
) vanish = false;
if (data.toString() === 'Successfully enabled CommandSpy' || data.toString() === ' Enabled your command spy.' || data.toString() === ' Your command spy is already enabled.') cspy = true;
if (data.toString() === 'Successfully disabled CommandSpy' || data.toString() === ' Disabled your command spy.') cspy = false;
) vanish = false
if (data.toString() === 'Successfully enabled CommandSpy' || data.toString() === ' Enabled your command spy.' || data.toString() === ' Your command spy is already enabled.') cspy = true
if (data.toString() === 'Successfully disabled CommandSpy' || data.toString() === ' Disabled your command spy.') cspy = false
if (data.toString() === 'You now have the tag: [ChomeNS Bot]') {
prefix = true;
return;
prefix = true
return
}
if (data.toString().startsWith('You no longer have a tag')) prefix = false;
if (data.toString().startsWith('You now have the tag: ')) prefix = false;
if (data.toString().startsWith('You have been muted')) muted = true;
if (data.toString() === 'You have been unmuted.') muted = false;
});
if (data.toString().startsWith('You no longer have a tag')) prefix = false
if (data.toString().startsWith('You now have the tag: ')) prefix = false
if (data.toString().startsWith('You have been muted')) muted = true
if (data.toString() === 'You have been unmuted.') muted = false
})
bot._client.on('entity_status', (data) => {
if (data.entityId !== bot.entityId) return;
if (data.entityId !== bot.entityId) return
switch (data.entityStatus) {
case 24:
op = false;
op = false
bot.emit('deop');
break;
bot.emit('deop')
break
case 28:
op = true;
op = true
bot.emit('op');
break;
bot.emit('op')
break
}
bot.emit('entity_status', data);
});
bot.emit('entity_status', data)
})
bot._client.on('game_state_change', (data) => {
if (data.reason === 4) endCredits = true;
if (data.reason === 4) endCredits = true
if (data.reason !== 3) return;
if (data.reason !== 3) return
gameMode = data.gameMode;
});
gameMode = data.gameMode
})
bot._client.once('login', (data) => {
gameMode = data.gameMode;
});
gameMode = data.gameMode
})
const interval = setInterval(() => {
if (bot.options.kaboom) {
if (!prefix && config.self_care.prefix) bot.chat('/extras:prefix &8[&eChomeNS Bot&8]');
if (!op && config.self_care.op) bot.chat('/minecraft:op @s[type=player]');
if (!cspy && config.self_care.cspy) bot.chat('/commandspy:commandspy on');
if (!prefix && config.self_care.prefix) bot.chat('/extras:prefix &8[&eChomeNS Bot&8]')
if (!op && config.self_care.op) bot.chat('/minecraft:op @s[type=player]')
if (!cspy && config.self_care.cspy) bot.chat('/commandspy:commandspy on')
}
if (!vanish && config.self_care.vanish) bot.chat('/essentials:vanish enable');
if (gameMode !== 1 && config.self_care.gamemode) bot.chat('/minecraft:gamemode creative @s[type=player]');
if (muted && config.self_care.mute) bot.chat('/essentials:mute ' + bot.uuid);
if (endCredits && config.self_care.endCredits) bot.write('client_command', {payload: 0});
}, config.self_care_check_interval);
if (!vanish && config.self_care.vanish) bot.chat('/essentials:vanish enable')
if (gameMode !== 1 && config.self_care.gamemode) bot.chat('/minecraft:gamemode creative @s[type=player]')
if (muted && config.self_care.mute) bot.chat('/essentials:mute ' + bot.uuid)
if (endCredits && config.self_care.endCredits) bot.write('client_command', { payload: 0 })
}, config.self_care_check_interval)
bot.once('end', () => {
clearInterval(interval);
});
clearInterval(interval)
})
};
module.exports = {inject};
module.exports = { inject }

View file

@ -1,9 +1,9 @@
/* eslint-disable require-jsdoc */
/* eslint-disable max-len */
function inject(bot) {
bot.tellraw = function(selector, message) {
bot.core.run(`minecraft:tellraw ${selector} ${typeof message === 'string' ? message : JSON.stringify(message)}`);
};
function inject (bot) {
bot.tellraw = function (selector, message) {
bot.core.run(`minecraft:tellraw ${selector} ${typeof message === 'string' ? message : JSON.stringify(message)}`)
}
};
module.exports = {inject};
module.exports = { inject }

View file

@ -5,9 +5,9 @@ module.exports = {
* @param {Number} max
* @return {Number}
*/
between: function(min, max) {
between: function (min, max) {
return Math.floor(
Math.random() * (max - min) + min,
);
},
};
Math.random() * (max - min) + min
)
}
}

View file

@ -5,30 +5,30 @@
* @param {object} ChatMessage basically just require prismarine-chat
* @param {object} bot bot
*/
function chatPacketListener(packet, ChatMessage, bot) {
function chatPacketListener (packet, ChatMessage, bot) {
// try catch prevents hi % exploit (it uses prismarine-chat)
// and try catch also prevents json parse error
try {
const parsedMessage = JSON.parse(packet.message);
const parsedMessage = JSON.parse(packet.message)
if (parsedMessage.translate === 'translation.test.invalid' ||
parsedMessage.translate === 'translation.test.invalid2') return;
parsedMessage.translate === 'translation.test.invalid2') return
// down here it prevents command set message
// for ayunboom cuz its 1.17.1
// VVVVVVVVVVVVVVVVVVVVVVVVVVVV
if (parsedMessage.extra) {
if (parsedMessage.extra[0].text === 'Command set: ') return;
if (parsedMessage.extra[0].text === 'Command set: ') return
}
// for 1.18 or newer(?)
// VVVVVVVVVVVVVVVVVVVVV
if (parsedMessage.translate === 'advMode.setCommand.success') return;
if (parsedMessage.translate === 'advMode.setCommand.success') return
const message = ChatMessage.fromNotch(packet.message);
const message = ChatMessage.fromNotch(packet.message)
bot.emit('parsed_chat', message, packet);
bot.emit('parsed_chat', message, packet)
} catch (e) {
return;
}
};
@ -38,53 +38,53 @@ function chatPacketListener(packet, ChatMessage, bot) {
* @param {object} packet chat packet
* @param {object} bot bot
*/
function parsePlayerMessages(message, packet, bot) {
function parsePlayerMessages (message, packet, bot) {
try {
// prevent braille cuz it CRASHES THE ENTIRE LAPTOP
// but sometimes this may not work
if (message.toString().includes('⣿')) return;
if (message.toString().includes('⣿')) return
// then here is all the player message parsing thing
const raw = message.toMotd().substring(0, 32767);
const raw = message.toMotd().substring(0, 32767)
if (raw.match(/.* .*: .*/g)) {
const username = raw.replace(/.*?\[.*?\] /g, '').replace(/:.*/g, '').replace(/§#....../gm, '');
const message = raw.split(': ')[1];
bot.emit('message', username, message, packet.sender);
const username = raw.replace(/.*?\[.*?\] /g, '').replace(/:.*/g, '').replace(/§#....../gm, '')
const message = raw.split(': ')[1]
bot.emit('message', username, message, packet.sender)
} else if (raw.match(/.* .*\u203a .*/g)) {
const username = raw.replace(/.*?\[.*?\] /g, '').replace(/\u203a.*/g, '').replace(/§#....../gm, '').split(' ')[0];
const message = raw.split('\u203a ')[1].substring(2);
bot.emit('message', username, message, packet.sender);
const username = raw.replace(/.*?\[.*?\] /g, '').replace(/\u203a.*/g, '').replace(/§#....../gm, '').split(' ')[0]
const message = raw.split('\u203a ')[1].substring(2)
bot.emit('message', username, message, packet.sender)
} else if (raw.match(/.* .*\u00BB .*/g)) {
const username = raw.replace(/.*?\[.*?\] /g, '').replace(/\u00BB.*/g, '').replace(/§#....../gm, '').split(' ')[0];
const message = raw.split('\u00BB ')[1].substring(2);
bot.emit('message', username, message, packet.sender);
const username = raw.replace(/.*?\[.*?\] /g, '').replace(/\u00BB.*/g, '').replace(/§#....../gm, '').split(' ')[0]
const message = raw.split('\u00BB ')[1].substring(2)
bot.emit('message', username, message, packet.sender)
} else if (raw.match(/<.*> .*/g)) {
const username = raw.substring(1).split('>')[0];
const message = raw.split('> ')[1];
const username = raw.substring(1).split('>')[0]
const message = raw.split('> ')[1]
bot.emit('message', username, message, packet.sender);
bot.emit('message', username, message, packet.sender)
} else if (raw.match(/§.*§b: §b\/.*/g)) {
const username = raw.split('§b: §b')[0];
const command = raw.split('§b: §b')[1];
const username = raw.split('§b: §b')[0]
const command = raw.split('§b: §b')[1]
bot.emit('cspy', username, command);
bot.emit('cspy', username, command)
} else if (raw.match(/§.*§e: §e\/.*/g)) {
const username = raw.split('§e: §e')[0];
const command = raw.split('§e: §e')[1];
bot.emit('cspy', username, command);
const username = raw.split('§e: §e')[0]
const command = raw.split('§e: §e')[1]
bot.emit('cspy', username, command)
} else if (raw.match(/§.*§b: \/.*/g)) {
const username = raw.split('§b: ')[0];
const command = raw.split('§b: ')[1];
const username = raw.split('§b: ')[0]
const command = raw.split('§b: ')[1]
bot.emit('cspy', username, command);
bot.emit('cspy', username, command)
} else if (raw.match(/§.*§e: \/.*/g)) {
const username = raw.split('§e: ')[0];
const command = raw.split('§e: ')[1];
bot.emit('cspy', username, command);
const username = raw.split('§e: ')[0]
const command = raw.split('§e: ')[1]
bot.emit('cspy', username, command)
}
} catch (e) {
return;
}
};
module.exports = {chatPacketListener, parsePlayerMessages};
module.exports = { chatPacketListener, parsePlayerMessages }

View file

@ -11,13 +11,13 @@ const styles = {
special: '\xa73',
string: '\xa72',
symbol: '\xa72',
undefined: '\xa78',
};
function stylize(str, styleType) {
const style = styles[styleType];
if (style !== undefined) return `${style}${str}\xa7r`;
return str;
undefined: '\xa78'
}
module.exports = {stylize, styles};
function stylize (str, styleType) {
const style = styles[styleType]
if (style !== undefined) return `${style}${str}\xa7r`
return str
}
module.exports = { stylize, styles }

View file

@ -4,16 +4,16 @@
* @param {String} character the character
* @return {boolean} allowed
*/
function isAllowedCharacter(character) {
return character !== '\xa7' && character >= ' ' && character !== '\x7f';
function isAllowedCharacter (character) {
return character !== '\xa7' && character >= ' ' && character !== '\x7f'
}
/**
* mc chat check if contains illegal chars.
* @param {String} string the string
* @return {boolean} if contains then true else false
*/
function containsIllegalCharacters(string) {
for (let i = 0; i < string.length; i++) if (!isAllowedCharacter(string[i])) return true;
function containsIllegalCharacters (string) {
for (let i = 0; i < string.length; i++) if (!isAllowedCharacter(string[i])) return true
}
module.exports = {containsIllegalCharacters};
module.exports = { containsIllegalCharacters }

View file

@ -4,19 +4,19 @@
* @param {Boolean} zwsp
* @return {String}
*/
function escapeMarkdown(text, zwsp) {
let unescaped;
let escaped;
function escapeMarkdown (text, zwsp) {
let unescaped
let escaped
try {
unescaped = text.replace(/\\(\*|@|_|`|~|\\)/g, '$1');
escaped = unescaped.replace(/(\*|@|_|`|~|\\)/g, zwsp ?
'\u200b\u200b$1' :
'\\$1',
);
unescaped = text.replace(/\\(\*|@|_|`|~|\\)/g, '$1')
escaped = unescaped.replace(/(\*|@|_|`|~|\\)/g, zwsp
? '\u200b\u200b$1'
: '\\$1'
)
} catch (e) {
return unescaped;
return unescaped
}
return escaped;
return escaped
}
module.exports = {escapeMarkdown};
module.exports = { escapeMarkdown }

View file

@ -1,19 +1,19 @@
const fs = require('fs/promises');
const fs = require('fs/promises')
/**
* check if file exists
* @param {String} filepath the file path
* @return {boolean} if file exists true else false
*/
async function fileExists(filepath) {
async function fileExists (filepath) {
try {
await fs.access(filepath);
return true;
await fs.access(filepath)
return true
} catch (error) {
if (error.code !== 'ENOENT') throw error;
if (error.code !== 'ENOENT') throw error
return false;
return false
}
}
module.exports = fileExists;
module.exports = fileExists

View file

@ -1,18 +1,18 @@
const fs = require('fs/promises');
const fs = require('fs/promises')
/**
* just list the files
* @param {String} filepath file path
* @return {Array} component.
*/
async function list(filepath = '.') {
const files = await fs.readdir(filepath);
async function list (filepath = '.') {
const files = await fs.readdir(filepath)
const component = [];
const component = []
files.forEach((filename, index) => {
component.push(filename);
});
return component;
component.push(filename)
})
return component
}
module.exports = list;
module.exports = list

View file

@ -3,21 +3,21 @@ const profanityNames = ['Eagler', 'Eagler', 'Bitch', 'Cock', 'Milf', 'Milf', 'Ye
'Eag', 'Deevis', 'Chode', 'Deev', 'Deev', 'Fucker', 'Fucking',
'Dumpster', 'Dumpster', 'Cum', 'Chad', 'Egg', 'Fudgler', 'Fudgli',
'Yee', 'Yee', 'Yee', 'Yeet', 'Flumpter', 'Darvy', 'Darver', 'Darver',
'Fuck', 'Fuck', 'Frick', 'Eagler', 'Vigg', 'Vigg', 'Cunt', 'Darvig',
];
'Fuck', 'Fuck', 'Frick', 'Eagler', 'Vigg', 'Vigg', 'Cunt', 'Darvig'
]
const names = ['Yeeish', 'Yeeish', 'Yee', 'Yee', 'Yeer', 'Yeeler', 'Eagler', 'Eagl',
'Darver', 'Darvler', 'Vool', 'Vigg', 'Vigg', 'Deev', 'Yigg', 'Yeeg'];
'Darver', 'Darvler', 'Vool', 'Vigg', 'Vigg', 'Deev', 'Yigg', 'Yeeg']
/**
* gets a random item in an array
* @param {Array} arr the array
* @return {*} the item in the array
*/
function getRandomItem(arr) {
const randomIndex = Math.floor(Math.random() * arr.length);
const item = arr[randomIndex];
function getRandomItem (arr) {
const randomIndex = Math.floor(Math.random() * arr.length)
const item = arr[randomIndex]
return item;
return item
}
/**
@ -25,15 +25,15 @@ function getRandomItem(arr) {
* @param {boolean} profanity bad words.
* @return {String} the output of the generated eagler username
*/
function genUsername(profanity) {
let username;
function genUsername (profanity) {
let username
if (profanity) {
username = getRandomItem(profanityNames) + getRandomItem(profanityNames) + (10 + Math.floor(Math.random() * 90));
username = getRandomItem(profanityNames) + getRandomItem(profanityNames) + (10 + Math.floor(Math.random() * 90))
} else {
username = getRandomItem(names) + getRandomItem(names) + (10 + Math.floor(Math.random() * 90));
username = getRandomItem(names) + getRandomItem(names) + (10 + Math.floor(Math.random() * 90))
}
return username;
return username
}
module.exports = genUsername;
module.exports = genUsername

View file

@ -4,24 +4,24 @@
* @param {number} height height
* @return {object} width and height
*/
function resize(width, height) {
const aspectRatio = width / height;
function resize (width, height) {
const aspectRatio = width / height
let optimalWidth = Math.round(aspectRatio * 20 * (27 / 3));
let optimalHeight = 20;
let optimalWidth = Math.round(aspectRatio * 20 * (27 / 3))
let optimalHeight = 20
if (optimalWidth > 320) {
const reduction = optimalWidth / 320;
const reduction = optimalWidth / 320
optimalWidth = 320;
optimalWidth = 320
optimalHeight *= reduction;
optimalHeight *= reduction
}
return {
width: Math.floor(optimalWidth),
height: Math.floor(optimalHeight),
};
height: Math.floor(optimalHeight)
}
}
module.exports = {resize};
module.exports = { resize }

View file

@ -1,7 +1,7 @@
/* eslint-disable max-len */
const fs = require('fs/promises');
const util = require('util');
const path = require('path');
const fs = require('fs/promises')
const util = require('util')
const path = require('path')
/**
* load plugins
@ -10,19 +10,19 @@ const path = require('path');
* @param {object} config the config
* @param {object} rl readline.
*/
async function loadPlugins(bot, dcclient, config, rl) {
const dir = path.join(__dirname, '..', 'plugins');
const plugins = await fs.readdir(dir);
async function loadPlugins (bot, dcclient, config, rl) {
const dir = path.join(__dirname, '..', 'plugins')
const plugins = await fs.readdir(dir)
plugins.forEach((plugin) => {
if (!plugin.endsWith('.js')) return;
if (!plugin.endsWith('.js')) return
try {
const plug = require(path.join(dir, plugin));
plug.inject(bot, dcclient, config, rl);
const plug = require(path.join(dir, plugin))
plug.inject(bot, dcclient, config, rl)
} catch (e) {
console.log(`Plugin ${plugin} is having exception loading the plugin:`);
console.log(util.inspect(e));
console.log(`Plugin ${plugin} is having exception loading the plugin:`)
console.log(util.inspect(e))
}
});
})
};
module.exports = {loadPlugins};
module.exports = { loadPlugins }

View file

@ -1,25 +1,25 @@
const fs = require('fs/promises');
const path = require('path');
const fs = require('fs/promises')
const path = require('path')
/**
* loads js files
* @param {string} directory the directory that contains the js files
* @return {Array} an array of require()ed js files
*/
async function loadPlugins(directory) {
const plugins = [];
async function loadPlugins (directory) {
const plugins = []
for (const filename of await fs.readdir(directory)) {
if (!filename.endsWith('.js')) continue;
if (!filename.endsWith('.js')) continue
const filepath = path.join(directory, filename);
const filepath = path.join(directory, filename)
const plugin = require(filepath);
const plugin = require(filepath)
plugins.push(plugin);
plugins.push(plugin)
}
return plugins;
return plugins
}
module.exports = loadPlugins;
module.exports = loadPlugins

View file

@ -3,15 +3,15 @@
* @param {Number} d seconds
* @return {String} X hour, X minute, X second
*/
function secondsToHms(d) {
d = Number(d);
const h = Math.floor(d / 3600);
const m = Math.floor(d % 3600 / 60);
const s = Math.floor(d % 3600 % 60);
const hDisplay = h > 0 ? h + (h == 1 ? ' hour, ' : ' hours, ') : '';
const mDisplay = m > 0 ? m + (m == 1 ? ' minute, ' : ' minutes, ') : '';
const sDisplay = s > 0 ? s + (s == 1 ? ' second' : ' seconds') : '';
return hDisplay + mDisplay + sDisplay;
function secondsToHms (d) {
d = Number(d)
const h = Math.floor(d / 3600)
const m = Math.floor(d % 3600 / 60)
const s = Math.floor(d % 3600 % 60)
const hDisplay = h > 0 ? h + (h === 1 ? ' hour, ' : ' hours, ') : ''
const mDisplay = m > 0 ? m + (m === 1 ? ' minute, ' : ' minutes, ') : ''
const sDisplay = s > 0 ? s + (s === 1 ? ' second' : ' seconds') : ''
return hDisplay + mDisplay + sDisplay
}
module.exports = {secondsToHms};
module.exports = { secondsToHms }