2022-07-31 17:08:00 +05:00
|
|
|
const { PermissionsBitField } = require("discord.js"),
|
2022-07-26 17:20:10 +05:00
|
|
|
langs = require("../languages/language-meta.json").map((l) => l.moment).filter((l) => l !== "en");
|
|
|
|
langs.forEach((lang) => {
|
2022-01-04 02:18:28 +05:00
|
|
|
require(`moment/locale/${lang}.js`);
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = {
|
2022-03-01 22:53:05 +05:00
|
|
|
async createInvite(client, guildId) {
|
|
|
|
const guild = client.guilds.cache.get(guildId);
|
2022-07-31 17:08:00 +05:00
|
|
|
const member = guild.members.me;
|
|
|
|
const channel = guild.channels.cache.find((ch) => ch.permissionsFor(member.id).has(PermissionsBitField.Flags.CreateInstantInvite) && ch.type === "GUILD_TEXT" || ch.type === "GUILD_VOICE");
|
2022-01-04 02:18:28 +05:00
|
|
|
if (channel) {
|
2022-07-29 23:31:08 +05:00
|
|
|
const invite = await channel.createInvite();
|
2022-01-04 02:18:28 +05:00
|
|
|
|
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
|
|
|
}
|
|
|
|
};
|