Pepperbot initializing
This commit is contained in:
commit
18c5085262
20 changed files with 2762 additions and 0 deletions
136
src/commands/createreactionrole.js
Normal file
136
src/commands/createreactionrole.js
Normal file
|
@ -0,0 +1,136 @@
|
|||
const { EmbedBuilder } = require("discord.js");
|
||||
const emojiRegex = require("emoji-regex");
|
||||
const irregularsRegex = require("../util/irregularsRegex.js");
|
||||
const irregulars = require("../util/irregulars.json");
|
||||
const fs = require("fs");
|
||||
|
||||
const getEmojis = (message) => {
|
||||
const { content } = message;
|
||||
const result = [];
|
||||
// Normal emojis
|
||||
const normalEmojis = content.match(emojiRegex());
|
||||
if (normalEmojis) {
|
||||
// for (const emoji of normalEmojis) {
|
||||
normalEmojis.forEach((emoji) => {
|
||||
result.push(emoji);
|
||||
});
|
||||
}
|
||||
// Text emojis e.g ♥ ✂ 🗨
|
||||
const textEmojis = content.match(irregularsRegex());
|
||||
if (textEmojis) {
|
||||
textEmojis.forEach((emoji) => {
|
||||
result.push(irregulars[emoji.trim()]);
|
||||
});
|
||||
}
|
||||
// Guild emojis
|
||||
let guildEmojis = content.match(/:[_a-zA-Z0-9]*>/g);
|
||||
if (guildEmojis) {
|
||||
guildEmojis = guildEmojis.map((e) => e.substring(1, e.length - 1));
|
||||
guildEmojis.forEach((e) => {
|
||||
try {
|
||||
const guildEmoji = message.guild.emojis.get(e);
|
||||
if (guildEmoji) {
|
||||
result.push(guildEmoji);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.log("tried using guild emote lmao");
|
||||
}
|
||||
});
|
||||
}
|
||||
// Attempt to sort the results if its not null
|
||||
if (result) {
|
||||
const query = message.content;
|
||||
result.sort((a, b) => {
|
||||
const irregularA = getKeyByValue(irregulars, a);
|
||||
const irregularB = getKeyByValue(irregulars, b);
|
||||
const index1 = irregularA || a;
|
||||
const index2 = irregularB || b;
|
||||
return query.indexOf(index1) - query.indexOf(index2);
|
||||
});
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
let collectors = [];
|
||||
|
||||
const whitelist = ["440163494529073152", "436321340304392222"];
|
||||
|
||||
module.exports = {
|
||||
name: "createreactionrole",
|
||||
description: "creates reaction role, requires whitelist",
|
||||
execute(message, args) {
|
||||
if (whitelist.includes(message.author.id)) {
|
||||
let emojis = getEmojis(message);
|
||||
let emoji = emojis[0];
|
||||
let role = message.mentions.roles.first();
|
||||
if (!role) {
|
||||
console.log("role variable missing");
|
||||
fs.appendFileSync(
|
||||
"../pepperbot/src/logs/failed.log",
|
||||
"role variable missing" +
|
||||
"from: " +
|
||||
message.content +
|
||||
" at " +
|
||||
Date() +
|
||||
"\n"
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (!emoji) {
|
||||
console.log("emoji variable missing");
|
||||
fs.appendFileSync(
|
||||
"../pepperbot/src/logs/failed.log",
|
||||
" emoji variable missing" +
|
||||
"from: " +
|
||||
message.content +
|
||||
" at " +
|
||||
Date() +
|
||||
"\n"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const embed = new EmbedBuilder();
|
||||
|
||||
embed.setThumbnail(
|
||||
"https://cdn.discordapp.com/attachments/755150633191080073/1149152214850469908/Map_Icon.png"
|
||||
);
|
||||
embed.setColor(0xff0000);
|
||||
|
||||
embed.setTitle(role.name);
|
||||
embed.setDescription(
|
||||
"React with " + emoji + " to recieve the " + role.name + " role."
|
||||
);
|
||||
|
||||
message.channel.send({ embeds: [embed] }).then((m) => m.react(emoji));
|
||||
|
||||
const collectorFilter = function (reaction) {
|
||||
return true;
|
||||
};
|
||||
|
||||
const collector = message.createReactionCollector({
|
||||
filter: collectorFilter,
|
||||
});
|
||||
collectors.push(collector);
|
||||
|
||||
collector.on("collect", (reaction, user) => {
|
||||
console.log(`Collected ${reaction.emoji.name} from ${user.tag}`);
|
||||
});
|
||||
} else {
|
||||
message.reply("UNAUTHORIZED");
|
||||
const path = require("path");
|
||||
const scriptName = path.basename(__filename);
|
||||
fs.appendFileSync(
|
||||
"../pepperbot/src/logs/failed.log",
|
||||
"non whitelisted user " +
|
||||
message.author.username +
|
||||
" (" +
|
||||
message.author +
|
||||
") attempted accessing " +
|
||||
scriptName +
|
||||
"\n"
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue