mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-14 10:44:55 -05:00
jsdocs
This commit is contained in:
parent
3b0a7ebadb
commit
681fa526e4
14 changed files with 78 additions and 172 deletions
|
@ -11,7 +11,6 @@
|
|||
"sourceType": "module"
|
||||
},
|
||||
"rules": {
|
||||
"linebreak-style": 0,
|
||||
"require-jsdoc": 0
|
||||
"linebreak-style": 0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable require-jsdoc */
|
||||
/* eslint-disable no-var */
|
||||
/* eslint-disable max-len */
|
||||
const {MessageEmbed} = require('discord.js');
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
/* eslint-disable require-jsdoc */
|
||||
/* eslint-disable max-len */
|
||||
/* eslint-disable prefer-rest-params */
|
||||
const moment = require('moment-timezone');
|
||||
const util = require('util');
|
||||
|
||||
function inject(bot, dcclient, config, rl) {
|
||||
function inject(bot, _dcclient, config, rl) {
|
||||
if (!config.console) return;
|
||||
|
||||
const chatMessage = require('prismarine-chat')(bot.version);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable require-jsdoc */
|
||||
/* eslint-disable max-len */
|
||||
function inject(bot) {
|
||||
bot.tellraw = function(selector, message) {
|
||||
|
|
|
@ -1,7 +1,17 @@
|
|||
/* eslint-disable max-len */
|
||||
/**
|
||||
* character allowed in mc chat
|
||||
* @param {String} character the character
|
||||
* @return {boolean} allowed
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
/* eslint-disable no-var */
|
||||
/* eslint-disable max-len */
|
||||
/**
|
||||
* escape markdown so on discord it will be \_ChipMC\_ instead of ChipMC in italic
|
||||
* escape markdown so on discord it will be \_ChipMC\_ instead of _ChipMC_
|
||||
* @param {String} text
|
||||
* @param {Boolean} zwsp
|
||||
* @return {String}
|
||||
*/
|
||||
function escapeMarkdown(text, zwsp) {
|
||||
let unescaped;
|
||||
let escaped;
|
||||
try {
|
||||
var unescaped = text.replace(/\\(\*|@|_|`|~|\\)/g, '$1');
|
||||
var escaped = unescaped.replace(/(\*|@|_|`|~|\\)/g, zwsp ? '\u200b\u200b\u200b\u200b\u200b$1' : '\\$1');
|
||||
unescaped = text.replace(/\\(\*|@|_|`|~|\\)/g, '$1');
|
||||
escaped = unescaped.replace(/(\*|@|_|`|~|\\)/g, zwsp ?
|
||||
'\u200b\u200b$1' :
|
||||
'\\$1',
|
||||
);
|
||||
} catch (e) {
|
||||
return unescaped;
|
||||
}
|
||||
|
|
|
@ -1,14 +1,19 @@
|
|||
const fs = require('fs/promises')
|
||||
const fs = require('fs/promises');
|
||||
|
||||
async function fileExists (filepath) {
|
||||
/**
|
||||
* check if file exists
|
||||
* @param {String} filepath the file path
|
||||
* @return {boolean} if file exists true else false
|
||||
*/
|
||||
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;
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
const fs = require('fs/promises')
|
||||
const fs = require('fs/promises');
|
||||
|
||||
async function list (filepath = '.') {
|
||||
const files = await fs.readdir(filepath)
|
||||
/**
|
||||
* just list the files
|
||||
* @param {String} filepath file path
|
||||
* @return {Array} component.
|
||||
*/
|
||||
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;
|
||||
|
|
|
@ -8,6 +8,11 @@ const profanityNames = ['Eagler', 'Eagler', 'Bitch', 'Cock', 'Milf', 'Milf', 'Ye
|
|||
const names = ['Yeeish', 'Yeeish', 'Yee', 'Yee', 'Yeer', 'Yeeler', 'Eagler', 'Eagl',
|
||||
'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];
|
||||
|
@ -15,6 +20,11 @@ function getRandomItem(arr) {
|
|||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* generates an eaglercraft username (totally not converted from the eaglercraft repo)
|
||||
* @param {boolean} profanity bad words.
|
||||
* @return {String} the output of the generated eagler username
|
||||
*/
|
||||
function genUsername(profanity) {
|
||||
let username;
|
||||
if (profanity) {
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
/**
|
||||
* resize image.
|
||||
* @param {number} width width
|
||||
* @param {number} height height
|
||||
* @return {object} width and height
|
||||
*/
|
||||
function resize(width, height) {
|
||||
const aspectRatio = width / height;
|
||||
|
||||
|
|
|
@ -2,6 +2,13 @@ const fs = require('fs/promises');
|
|||
const util = require('util');
|
||||
const path = require('path');
|
||||
|
||||
/**
|
||||
* load plugins
|
||||
* @param {object} bot the bot object
|
||||
* @param {object} dcclient discord client
|
||||
* @param {object} config the config
|
||||
* @param {object} rl readline
|
||||
*/
|
||||
async function loadPlugins(bot, dcclient, config, rl) {
|
||||
const plugins = await fs.readdir(path.join(__dirname, '..', 'plugins'));
|
||||
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
const fs = require('fs');
|
||||
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
|
||||
*/
|
||||
function loadPlugins(directory) {
|
||||
const plugins = [];
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* from codegrepper
|
||||
* @param {Number} d
|
||||
* @return {String}
|
||||
* @param {Number} d seconds
|
||||
* @return {String} X hour, X minute, X second
|
||||
*/
|
||||
function secondsToHms(d) {
|
||||
d = Number(d);
|
||||
|
|
|
@ -1,147 +0,0 @@
|
|||
/* eslint-disable max-len */
|
||||
const {language} = require('minecraft-data')('1.16.1');
|
||||
|
||||
const colormap = {
|
||||
black: '§0',
|
||||
dark_blue: '§1',
|
||||
dark_green: '§2',
|
||||
dark_aqua: '§3',
|
||||
dark_red: '§4',
|
||||
dark_purple: '§5',
|
||||
gold: '§6',
|
||||
gray: '§7',
|
||||
dark_gray: '§8',
|
||||
blue: '§9',
|
||||
green: '§a',
|
||||
aqua: '§b',
|
||||
red: '§c',
|
||||
light_purple: '§d',
|
||||
yellow: '§e',
|
||||
white: '§f',
|
||||
reset: '§r',
|
||||
};
|
||||
|
||||
const ansimap = {
|
||||
'§0': '\x1b[0m\x1b[30m',
|
||||
'§1': '\x1b[0m\x1b[34m',
|
||||
'§2': '\x1b[0m\x1b[32m',
|
||||
'§3': '\x1b[0m\x1b[36m',
|
||||
'§4': '\x1b[0m\x1b[31m',
|
||||
'§5': '\x1b[0m\x1b[35m',
|
||||
'§6': '\x1b[0m\x1b[33m',
|
||||
'§7': '\x1b[0m\x1b[37m',
|
||||
'§8': '\x1b[0m\x1b[90m',
|
||||
'§9': '\x1b[0m\x1b[94m',
|
||||
'§a': '\x1b[0m\x1b[92m',
|
||||
'§b': '\x1b[0m\x1b[96m',
|
||||
'§c': '\x1b[0m\x1b[91m',
|
||||
'§d': '\x1b[0m\x1b[95m',
|
||||
'§e': '\x1b[0m\x1b[93m',
|
||||
'§f': '\x1b[0m\x1b[97m',
|
||||
'§r': '\x1b[0m',
|
||||
'§l': '\x1b[1m',
|
||||
'§o': '\x1b[3m',
|
||||
'§n': '\x1b[4m',
|
||||
'§m': '\x1b[9m',
|
||||
'§k': '\x1b[6m',
|
||||
};
|
||||
|
||||
/**
|
||||
* Parses a native minecraft text component in string form.
|
||||
* @param {string} string - A text component string, such as the chat packet's "message" property.
|
||||
* @return {object} Parsed message in { raw, clean, ansi } form.
|
||||
*/
|
||||
function parseText(string) {
|
||||
const json = JSON.parse(string);
|
||||
|
||||
let raw = parseJson(json, {color: 'reset'});
|
||||
if (raw.startsWith('§r')) {
|
||||
raw = raw.substring(2);
|
||||
}
|
||||
const clean = raw.replace(/§.?/g, '');
|
||||
const ansi = raw.replace(/§.?/g, (m) => ansimap[m] || '');
|
||||
|
||||
return {raw, clean, ansi};
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a native minecraft text component in JSON form.
|
||||
* @param {object} json - The json message.
|
||||
* @param {object} parent - The parent json.
|
||||
* @return {string} The parsed raw string.
|
||||
*/
|
||||
function parseJson(json, parent) {
|
||||
if (typeof json === 'string') json = {text: json};
|
||||
|
||||
json.color ??= parent.color;
|
||||
json.bold ??= parent.bold;
|
||||
json.italic ??= parent.italic;
|
||||
json.underlined ??= parent.underlined;
|
||||
json.strikethrough ??= parent.strikethrough;
|
||||
json.obfuscated ??= parent.obfuscated;
|
||||
|
||||
let raw = '';
|
||||
let formatting = '';
|
||||
|
||||
raw += colormap[json.color] ?? '';
|
||||
|
||||
if (json.bold) {
|
||||
formatting += '§l';
|
||||
}
|
||||
if (json.italic) {
|
||||
formatting += '§o';
|
||||
}
|
||||
if (json.underlined) {
|
||||
formatting += '§n';
|
||||
}
|
||||
if (json.strikethrough) {
|
||||
formatting += '§m';
|
||||
}
|
||||
if (json.obfuscated) {
|
||||
formatting += '§k';
|
||||
}
|
||||
raw += formatting;
|
||||
|
||||
if (json.text) {
|
||||
raw += json.text;
|
||||
} else if (json.translate) { // I checked with the native minecraft code. This is how Minecraft does the matching and group indexing. -hhhzzzsss
|
||||
if (language[json.translate]) {
|
||||
const _with = json.with ?? [];
|
||||
let i = 0;
|
||||
|
||||
raw += language[json.translate].replace(/%(?:(\d+)\$)?(s|%)/g, (g0, g1) => {
|
||||
if (g0 === '%%') {
|
||||
return '%';
|
||||
} else {
|
||||
const idx = g1 ? parseInt(g1) : i++;
|
||||
if (_with[idx]) {
|
||||
return parseJson(_with[idx], json) + formatting;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
raw += json.translate;
|
||||
}
|
||||
} else if (json.selector) {
|
||||
raw += json.selector;
|
||||
} else if (json.keybind) {
|
||||
raw += json.keybind;
|
||||
}
|
||||
|
||||
// Remove trailing section signs
|
||||
let end = raw.length;
|
||||
while (raw[end - 1] === '§') end--;
|
||||
raw = raw.substring(0, end);
|
||||
|
||||
if (json.extra) {
|
||||
json.extra.forEach((extra) => {
|
||||
raw += parseJson(extra, json);
|
||||
});
|
||||
}
|
||||
|
||||
return raw;
|
||||
}
|
||||
|
||||
module.exports = parseText;
|
Loading…
Reference in a new issue