2022-01-05 00:24:57 +05:00
|
|
|
const { Permissions } = require("discord.js");
|
2022-01-04 02:18:28 +05:00
|
|
|
const languages = require("../languages/language-meta.json").map((l) => l.moment).filter((l) => l !== "en");
|
|
|
|
languages.forEach((lang) => {
|
|
|
|
require(`moment/locale/${lang}.js`);
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getPrefix(message, data) {
|
2022-01-05 00:24:57 +05:00
|
|
|
if (message.channel.type !== "DM") {
|
2022-01-04 02:18:28 +05:00
|
|
|
const prefixes = [
|
|
|
|
`<@!${message.client.user.id}> `,
|
|
|
|
`<@${message.client.user.id}> `,
|
|
|
|
`<@!${message.client.user.id}>`,
|
|
|
|
`<@${message.client.user.id}>`,
|
|
|
|
message.client.user.username.toLowerCase(),
|
|
|
|
data.guild.prefix
|
|
|
|
];
|
2022-03-01 22:53:05 +05:00
|
|
|
|
2022-01-04 02:18:28 +05:00
|
|
|
let prefix = null;
|
2022-03-01 22:53:05 +05:00
|
|
|
|
2022-01-04 02:18:28 +05:00
|
|
|
prefixes.forEach((p) => {
|
|
|
|
if (message.content.startsWith(p) || message.content.toLowerCase().startsWith(p)) prefix = p;
|
|
|
|
});
|
|
|
|
|
|
|
|
return prefix;
|
2022-03-01 22:53:05 +05:00
|
|
|
} else return true;
|
2022-01-04 02:18:28 +05:00
|
|
|
},
|
|
|
|
|
2022-03-01 22:53:05 +05:00
|
|
|
async createInvite(client, guildId) {
|
|
|
|
const guild = client.guilds.cache.get(guildId);
|
2022-01-04 02:18:28 +05:00
|
|
|
const member = guild.me;
|
2022-01-05 00:24:57 +05:00
|
|
|
const channel = guild.channels.cache.find((ch) => ch.permissionsFor(member.id).has(Permissions.FLAGS.CREATE_INSTANT_INVITE) && ch.type === "GUILD_TEXT" || ch.type === "GUILD_VOICE");
|
2022-01-04 02:18:28 +05:00
|
|
|
if (channel) {
|
|
|
|
const invite = await channel.createInvite({
|
2022-03-01 22:53:05 +05:00
|
|
|
maxAge: 0,
|
|
|
|
maxUses: 5
|
2022-01-04 02:18:28 +05:00
|
|
|
}).catch(() => {});
|
|
|
|
|
2022-03-01 22:53:05 +05:00
|
|
|
return invite ? invite.url : "No URL";
|
2022-07-02 01:17:00 +05:00
|
|
|
} return "No channels found for invite";
|
2022-01-04 02:18:28 +05:00
|
|
|
},
|
|
|
|
|
|
|
|
sortByKey(array, key) {
|
|
|
|
return array.sort(function (a, b) {
|
|
|
|
const x = a[key];
|
|
|
|
const y = b[key];
|
|
|
|
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
shuffle(pArray) {
|
|
|
|
const array = [];
|
|
|
|
pArray.forEach(element => array.push(element));
|
|
|
|
let currentIndex = array.length,
|
|
|
|
temporaryValue, randomIndex;
|
|
|
|
|
|
|
|
// While there remain elements to shuffle...
|
|
|
|
while (0 !== currentIndex) {
|
|
|
|
// Pick a remaining element...
|
|
|
|
randomIndex = Math.floor(Math.random() * currentIndex);
|
|
|
|
currentIndex -= 1;
|
|
|
|
// And swap it with the current element.
|
|
|
|
temporaryValue = array[currentIndex];
|
|
|
|
array[currentIndex] = array[randomIndex];
|
|
|
|
array[randomIndex] = temporaryValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return array;
|
|
|
|
},
|
|
|
|
|
|
|
|
randomNum(min, max) {
|
2022-03-01 22:53:05 +05:00
|
|
|
return Math.floor(Math.random() * (max - min) + min + 1);
|
2022-01-04 02:18:28 +05:00
|
|
|
},
|
|
|
|
|
|
|
|
convertTime(guild, time) {
|
|
|
|
const absoluteSeconds = Math.floor((time / 1000) % 60);
|
|
|
|
const absoluteMinutes = Math.floor((time / (1000 * 60)) % 60);
|
|
|
|
const absoluteHours = Math.floor((time / (1000 * 60 * 60)) % 24);
|
|
|
|
const absoluteDays = Math.floor(time / (1000 * 60 * 60 * 24));
|
|
|
|
|
|
|
|
const d = absoluteDays ?
|
|
|
|
absoluteDays === 1 ?
|
2022-01-13 00:26:23 +05:00
|
|
|
guild.translate("time:ONE_DAY") :
|
|
|
|
guild.translate("time:DAYS", {
|
|
|
|
amount: absoluteDays
|
|
|
|
}) :
|
2022-01-04 02:18:28 +05:00
|
|
|
null;
|
|
|
|
const h = absoluteHours ?
|
|
|
|
absoluteHours === 1 ?
|
2022-01-13 00:26:23 +05:00
|
|
|
guild.translate("time:ONE_HOUR") :
|
|
|
|
guild.translate("time:HOURS", {
|
|
|
|
amount: absoluteHours
|
|
|
|
}) :
|
2022-01-04 02:18:28 +05:00
|
|
|
null;
|
|
|
|
const m = absoluteMinutes ?
|
|
|
|
absoluteMinutes === 1 ?
|
2022-01-13 00:26:23 +05:00
|
|
|
guild.translate("time:ONE_MINUTE") :
|
|
|
|
guild.translate("time:MINUTES", {
|
|
|
|
amount: absoluteMinutes
|
|
|
|
}) :
|
2022-01-04 02:18:28 +05:00
|
|
|
null;
|
|
|
|
const s = absoluteSeconds ?
|
|
|
|
absoluteSeconds === 1 ?
|
2022-01-13 00:26:23 +05:00
|
|
|
guild.translate("time:ONE_SECOND") :
|
|
|
|
guild.translate("time:SECONDS", {
|
|
|
|
amount: absoluteSeconds
|
|
|
|
}) :
|
2022-01-04 02:18:28 +05:00
|
|
|
null;
|
|
|
|
|
|
|
|
const absoluteTime = [];
|
|
|
|
if (d) absoluteTime.push(d);
|
|
|
|
if (h) absoluteTime.push(h);
|
|
|
|
if (m) absoluteTime.push(m);
|
|
|
|
if (s) absoluteTime.push(s);
|
|
|
|
|
|
|
|
return absoluteTime.join(", ");
|
|
|
|
}
|
|
|
|
};
|