mirror of
https://github.com/Ninluc/Dat_Boi.git
synced 2025-08-09 23:26:13 +02:00
Initial commit
This commit is contained in:
28
handlers/command.js
Executable file
28
handlers/command.js
Executable file
@ -0,0 +1,28 @@
|
||||
const { readdirSync } = require("fs");
|
||||
const ascii = require("ascii-table");
|
||||
let table = new ascii("Commands");
|
||||
table.setHeading("Command", "Load status");
|
||||
console.log("Welcome to SERVICE HANDLER".yellow);
|
||||
module.exports = (client) => {
|
||||
try{
|
||||
readdirSync("./commands/").forEach((dir) => {
|
||||
const commands = readdirSync(`./commands/${dir}/`).filter((file) => file.endsWith(".js"));
|
||||
for (let file of commands) {
|
||||
let pull = require(`../commands/${dir}/${file}`);
|
||||
if (pull.name) {
|
||||
client.commands.set(pull.name, pull);
|
||||
table.addRow(pull.name, "Ready");
|
||||
} else {
|
||||
table.addRow(file, `error->missing a help.name,or help.name is not a string.`);
|
||||
continue;
|
||||
}
|
||||
if (pull.aliases && Array.isArray(pull.aliases)) pull.aliases.forEach((alias) => client.aliases.set(alias, pull.name));
|
||||
}
|
||||
});
|
||||
console.log(table.toString().cyan);
|
||||
}catch (e){
|
||||
console.log(String(e.stack).bgRed)
|
||||
}
|
||||
};
|
||||
|
||||
/** Template by Tomato#6966 | https://github.com/Tomato6966/Discord-Js-Handler-Template */
|
29
handlers/dmCommand.js
Normal file
29
handlers/dmCommand.js
Normal file
@ -0,0 +1,29 @@
|
||||
const { readdirSync } = require("fs");
|
||||
const ascii = require("ascii-table");
|
||||
let table = new ascii("DM Commands");
|
||||
table.setHeading("Command", "Load status");
|
||||
module.exports = (client) => {
|
||||
try {
|
||||
const command = readdirSync(`./dmCommands/`).filter((file) =>
|
||||
file.endsWith(".js")
|
||||
); // Get all the js files
|
||||
for (let file of command) {
|
||||
let pull = require(`../dmCommands/${file}`);
|
||||
if (pull.name) {
|
||||
client.dmCommands.set(pull.name, pull);
|
||||
table.addRow(pull.name, "Ready");
|
||||
} else {
|
||||
table.addRow(
|
||||
file,
|
||||
`error->missing a help.name,or help.name is not a string.`
|
||||
);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
console.log(table.toString().cyan);
|
||||
} catch (e) {
|
||||
console.log(String(e.stack).bgRed);
|
||||
}
|
||||
};
|
||||
|
||||
/** Template by Tomato#6966 | https://github.com/Tomato6966/Discord-Js-Handler-Template */
|
40
handlers/events.js
Executable file
40
handlers/events.js
Executable file
@ -0,0 +1,40 @@
|
||||
const fs = require("fs");
|
||||
const ascii = require("ascii-table");
|
||||
let table = new ascii("Events");
|
||||
table.setHeading("Events", "Load status");
|
||||
const allevents = [];
|
||||
module.exports = async (client) => {
|
||||
try{
|
||||
const load_dir = (dir) => {
|
||||
const event_files = fs.readdirSync(`./events/${dir}`).filter((file) => file.endsWith(".js"));
|
||||
for (const file of event_files){
|
||||
const event = require(`../events/${dir}/${file}`)
|
||||
let eventName = file.split(".")[0];
|
||||
allevents.push(eventName);
|
||||
client.on(eventName, event.bind(null, client));
|
||||
}
|
||||
}
|
||||
await ["client", "guild"].forEach(e=>load_dir(e));
|
||||
for (let i = 0; i < allevents.length; i++) {
|
||||
try {
|
||||
table.addRow(allevents[i], "Ready");
|
||||
} catch (e) {
|
||||
console.log(String(e.stack).red);
|
||||
}
|
||||
}
|
||||
console.log(table.toString().cyan);
|
||||
try{
|
||||
const stringlength2 = 69;
|
||||
console.log("\n")
|
||||
console.log(` ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓`.bold.yellow)
|
||||
console.log(` ┃ `.bold.yellow + " ".repeat(-1+stringlength2-` ┃ `.length)+ "┃".bold.yellow)
|
||||
console.log(` ┃ `.bold.yellow + `Logging into the BOT...`.bold.yellow + " ".repeat(-1+stringlength2-` ┃ `.length-`Logging into the BOT...`.length)+ "┃".bold.yellow)
|
||||
console.log(` ┃ `.bold.yellow + " ".repeat(-1+stringlength2-` ┃ `.length)+ "┃".bold.yellow)
|
||||
console.log(` ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛`.bold.yellow)
|
||||
}catch{ /* */ }
|
||||
}catch (e){
|
||||
console.log(String(e.stack).bgRed)
|
||||
}
|
||||
};
|
||||
|
||||
/** Template by Tomato#6966 | https://github.com/Tomato6966/Discord-Js-Handler-Template */
|
130
handlers/functions.js
Executable file
130
handlers/functions.js
Executable file
@ -0,0 +1,130 @@
|
||||
module.exports = {
|
||||
//get a member lol
|
||||
getMember: function(message, toFind = "") {
|
||||
try{
|
||||
toFind = toFind.toLowerCase();
|
||||
let target = message.guild.members.get(toFind);
|
||||
if (!target && message.mentions.members) target = message.mentions.members.first();
|
||||
if (!target && toFind) {
|
||||
target = message.guild.members.find((member) => {
|
||||
return member.displayName.toLowerCase().includes(toFind) || member.user.tag.toLowerCase().includes(toFind);
|
||||
});
|
||||
}
|
||||
if (!target) target = message.member;
|
||||
return target;
|
||||
}catch (e){
|
||||
console.log(String(e.stack).bgRed)
|
||||
}
|
||||
},
|
||||
//changeging the duration from ms to a date
|
||||
duration: function(ms) {
|
||||
const sec = Math.floor((ms / 1000) % 60).toString();
|
||||
const min = Math.floor((ms / (60 * 1000)) % 60).toString();
|
||||
const hrs = Math.floor((ms / (60 * 60 * 1000)) % 60).toString();
|
||||
const days = Math.floor((ms / (24 * 60 * 60 * 1000)) % 60).toString();
|
||||
return `\`${days}Days\`,\`${hrs}Hours\`,\`${min}Minutes\`,\`${sec}Seconds\``;
|
||||
},
|
||||
//function for awaiting reactions
|
||||
promptMessage: async function(message, author, time, validReactions) {
|
||||
try{
|
||||
time *= 1000;
|
||||
for (const reaction of validReactions) await message.react(reaction);
|
||||
const filter = (reaction, user) => validReactions.includes(reaction.emoji.name) && user.id === author.id;
|
||||
return message.awaitReactions(filter, {
|
||||
max: 1,
|
||||
time: time
|
||||
}).then((collected) => collected.first() && collected.first().emoji.name);
|
||||
}catch (e){
|
||||
console.log(String(e.stack).bgRed)
|
||||
}
|
||||
},
|
||||
//Function to wait some time
|
||||
delay: function(delayInms) {
|
||||
try{
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve(2);
|
||||
}, delayInms);
|
||||
});
|
||||
}catch (e){
|
||||
console.log(String(e.stack).bgRed)
|
||||
}
|
||||
},
|
||||
//random number between 0 and x
|
||||
getRandomInt: function(max) {
|
||||
try{
|
||||
return Math.floor(Math.random() * Math.floor(max));
|
||||
}catch (e){
|
||||
console.log(String(e.stack).bgRed)
|
||||
}
|
||||
},
|
||||
//random number between y and x
|
||||
getRandomNum: function(min, max) {
|
||||
try{
|
||||
return Math.floor(Math.random() * Math.floor((max - min) + min));
|
||||
}catch (e){
|
||||
console.log(String(e.stack).bgRed)
|
||||
}
|
||||
},
|
||||
//function for creating a bar
|
||||
createBar: function(maxtime, currenttime, size = 25, line = "▬", slider = "🔶") {
|
||||
try{
|
||||
let bar = currenttime > maxtime ? [line.repeat(size / 2 * 2), (currenttime / maxtime) * 100] : [line.repeat(Math.round(size / 2 * (currenttime / maxtime))).replace(/.$/, slider) + line.repeat(size - Math.round(size * (currenttime / maxtime)) + 1), currenttime / maxtime];
|
||||
if (!String(bar).includes("🔶")) return `**[🔶${line.repeat(size - 1)}]**\n**00:00:00 / 00:00:00**`;
|
||||
return `**[${bar[0]}]**\n**${new Date(currenttime).toISOString().substr(11, 8)+" / "+(maxtime==0?" ◉ LIVE":new Date(maxtime).toISOString().substr(11, 8))}**`;
|
||||
}catch (e) {
|
||||
console.log(String(e.stack).bgRed)
|
||||
}
|
||||
},
|
||||
format: function(millis) {
|
||||
try{
|
||||
var h = Math.floor(millis / 3600000),
|
||||
m = Math.floor(millis / 60000),
|
||||
s = ((millis % 60000) / 1000).toFixed(0);
|
||||
if (h < 1) return (m < 10 ? "0" : "") + m + ":" + (s < 10 ? "0" : "") + s + " | " + (Math.floor(millis / 1000)) + " Seconds";
|
||||
else return (h < 10 ? "0" : "") + h + ":" + (m < 10 ? "0" : "") + m + ":" + (s < 10 ? "0" : "") + s + " | " + (Math.floor(millis / 1000)) + " Seconds";
|
||||
}catch (e){
|
||||
console.log(String(e.stack).bgRed)
|
||||
}
|
||||
},
|
||||
escapeRegex: function(str) {
|
||||
try{
|
||||
return str.replace(/[.*+?^${}()|[\]\\]/g, `\\$&`);
|
||||
}catch (e){
|
||||
console.log(String(e.stack).bgRed)
|
||||
}
|
||||
},
|
||||
arrayMove: function(array, from, to) {
|
||||
try{
|
||||
array = [...array];
|
||||
const startIndex = from < 0 ? array.length + from : from;
|
||||
if (startIndex >= 0 && startIndex < array.length) {
|
||||
const endIndex = to < 0 ? array.length + to : to;
|
||||
const [item] = array.splice(from, 1);
|
||||
array.splice(endIndex, 0, item);
|
||||
}
|
||||
return array;
|
||||
}catch (e){
|
||||
console.log(String(e.stack).bgRed)
|
||||
}
|
||||
},
|
||||
sendNinluc: function (client, text) {
|
||||
client.users.fetch('417731861033385985', false).then(u => {
|
||||
u.send({ content : text})
|
||||
})
|
||||
},
|
||||
isNinluc: function (id) {
|
||||
return id == "417731861033385985";
|
||||
},
|
||||
/**
|
||||
* Gives an random element from the array given.
|
||||
* @param {array} array The array to choose an element from
|
||||
* @returns An element from the array
|
||||
*/
|
||||
choose: function (array) {
|
||||
return array[Math.floor(Math.random() * array.length)]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Template by Tomato#6966 | https://github.com/Tomato6966/Discord-Js-Handler-Template */
|
25
handlers/keywords.js
Normal file
25
handlers/keywords.js
Normal file
@ -0,0 +1,25 @@
|
||||
const { readdirSync } = require("fs");
|
||||
const ascii = require("ascii-table");
|
||||
let table = new ascii("Keyword triggers");
|
||||
table.setHeading("Keyword", "Load status");
|
||||
module.exports = (client) => {
|
||||
try{
|
||||
const keywords = readdirSync(`./keywords/`).filter((file) => file.endsWith(".js")); // Get all the js files
|
||||
for (let file of keywords) {
|
||||
let pull = require(`../keywords/${file}`);
|
||||
if (pull.keyword) {
|
||||
client.keywords.set(pull.regex, pull);
|
||||
table.addRow(pull.keyword, "Ready");
|
||||
} else {
|
||||
table.addRow(file, `error->missing a help.keyword,or help.keyword is not a string.`);
|
||||
continue;
|
||||
}
|
||||
if (pull.aliases && Array.isArray(pull.aliases)) pull.aliases.forEach((alias) => client.keywords.set(alias, pull));
|
||||
}
|
||||
console.log(table.toString().cyan);
|
||||
}catch (e){
|
||||
console.log(String(e.stack).bgRed)
|
||||
}
|
||||
};
|
||||
|
||||
/** Template by Tomato#6966 | https://github.com/Tomato6966/Discord-Js-Handler-Template */
|
Reference in New Issue
Block a user