Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 172 additions & 0 deletions features/emojiMod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
const cooldown = require("./cooldown").default;

const staffRoles = ["mvp", "moderator", "admin", "admins"];

const isStaff = member =>
(member.roles || []).some(role =>
staffRoles.includes(role.name.toLowerCase())
);

const config = {
// This is how many ️️warning reactions a post must get until it's considered an official warning
warningThreshold: 1,
// This is how many ️️warning reactions a post must get until mods are alerted
thumbsDownThreshold: 2,
// This is how many ️️warning reactions a post must get the message is deleted
deletionThreshold: Infinity
};

const warningMessages = {};

const thumbsDownEmojis = ["👎", "👎🏻", "👎🏼", "👎🏽", "👎🏾", "👎🏿"];

const reactionHandlers = {
"⚠️": (bot, reaction, message, member) => {
if (!isStaff(member)) {
return;
}
const usersWhoReacted = reaction.users.map(user =>
message.guild.members.get(user.id)
);
const numberOfTotalReactions = usersWhoReacted.length;
const numberOfStaffReactions = usersWhoReacted.filter(isStaff).length;

const modLogChannel = bot.channels.find(
channel =>
channel.name === "mod-log" || channel.id === "257930126145224704"
);

const userNames = usersWhoReacted
.filter(user => !isStaff(user))
.map(member => member.user.username)
.join(", ");

const staffNames = usersWhoReacted
.filter(isStaff)
.map(member => member.user.username)
.join(", ");

let logMessage = "";
const logMessageEnding = [
"\n\n",
`\`${message.content}\``,
"\n\n",
`Link: https://discordapp.com/channels/${message.guild.id}/${message.channel.id}/${message.id}`,
"\n\n",
userNames && `Reactors: \`${userNames}\``,
staffNames && userNames && "\n",
staffNames && `Staff: \`${staffNames}\``
]
.filter(Boolean)
.join("");

if (numberOfTotalReactions >= config.warningThreshold) {
logMessage = `<@${message.author.id}> has met the warning threshold in <#${message.channel.id}> for the message:`;
}

if (numberOfStaffReactions >= config.deletionThreshold) {
logMessage = `<@${message.author.id}> has met the deletion threshold in <#${message.channel.id}> for the message:`;

message.delete();
}

if (logMessage) {
logMessage += logMessageEnding;

if (warningMessages[message.id]) {
warningMessages[message.id].edit(logMessage);
} else {
modLogChannel.send(logMessage).then(warningMessage => {
warningMessages[message.id] = warningMessage;
});
}
}
},
"👎": (bot, reaction, message, member) => {
if (cooldown.hasCooldown(member.id, "thumbsdown")) {
return;
}
cooldown.addCooldown(member.id, "thumbsdown", 60); // 1 minute

const reactions = thumbsDownEmojis.reduce(
(acc, emoji) => {
if (message.reactions.get(emoji)) {
acc.count += message.reactions.get(emoji).count;

// todo: figure out how to do this
// acc.users.push(Object.values(message.reactions.get(emoji).users));
}

return acc;
},
{
count: 0,
users: []
}
);

const numberOfTotalReactions = reactions.count;

const modLogChannel = bot.channels.find(
channel => channel.name === "mod-log"
);

let logMessage = "";
const logMessageEnding = [
"\n\n",
`\`${message.content}\``,
"\n\n",
`Link: https://discordapp.com/channels/${message.guild.id}/${message.channel.id}/${message.id}`
]
.filter(Boolean)
.join("");

if (numberOfTotalReactions >= config.thumbsDownThreshold) {
logMessage = `<@&102870499406647296> - <@${message.author.id}> has met the warning threshold in <#${message.channel.id}> for the message:`;
}

if (logMessage) {
logMessage += logMessageEnding;

if (warningMessages[message.id]) {
warningMessages[message.id].edit(logMessage);
} else {
modLogChannel.send(logMessage).then(warningMessage => {
warningMessages[message.id] = warningMessage;
});
}
}
}
};

const emojiMod = bot => ({
handleReaction: ({ reaction, user }) => {
const { message } = reaction;
const { member } = message;
if (user.id === bot.user.id) {
return;
}
if (message.author.id === bot.user.id) {
return;
}
let emoji = reaction.emoji.toString();

if (thumbsDownEmojis.includes(emoji)) {
emoji = "👎";
}

const reactionHandler = reactionHandlers[emoji];
if (reactionHandler) {
reactionHandler(
bot,
reaction,
message,
message.guild.members.get(user.id)
);
}
}
});

module.exports = {
default: emojiMod
};
10 changes: 9 additions & 1 deletion features/jobs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
const cooldown = require("./cooldown").default;

const staffRoles = ["mvp", "moderator", "admin", "admins"];

const isStaff = member =>
member.roles.some(role => staffRoles.includes(role.name.toLowerCase()));

const jobs = {
tags: ["forhire", "for hire", "hiring", "remote", "local"],
handleMessage: ({ msg, user }) => {
Expand All @@ -9,6 +14,9 @@ const jobs = {
});
if (!hasTags && msg.mentions.members.array().length === 0) {
if (cooldown.hasCooldown(msg.author.id, "user.jobs")) return;
if (isStaff(msg.guild.members.get(msg.author.id))) {
return;
}

cooldown.addCooldown(msg.author.id, "user.jobs");
msg.author
Expand All @@ -21,7 +29,7 @@ I noticed that you've not added any tags - please consider adding some of the fo
[INTERN] - this is an intern position, no experience required
[REMOTE] - only remote work is possible
[LOCAL] - only local work is possible (please remember to provide the country / city!)
[VISA] - Your company will help with the visa process in case of successfull hire
[VISA] - Your company will help with the visa process in case of successful hire

Thank you :)

Expand Down
23 changes: 19 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ const autoban = require("./features/autoban").default;
const commands = require("./features/commands").default;
const witInvite = require("./features/wit-invite").default;
const stats = require("./features/stats").default;
const emojiMod = require("./features/emojiMod").default;

const bot = new discord.Client();
const bot = new discord.Client({ partials: ["MESSAGE", "CHANNEL"] });
bot.login(process.env.DISCORD_HASH);

const channelHandlers = {
Expand Down Expand Up @@ -94,8 +95,17 @@ channelHandlers.addHandler("479862475047567361", qna); // #general
channelHandlers.addHandler("*", commands);
// channelHandlers.addHandler('*', codeblock);
channelHandlers.addHandler("*", autoban);
channelHandlers.addHandler("*", emojiMod(bot));

bot.on("messageReactionAdd", async (reaction, user) => {
if (reaction.message.partial) {
try {
await reaction.message.fetch();
} catch (error) {
console.log("Something went wrong when fetching the message: ", error);
}
}

bot.on("messageReactionAdd", (reaction, user) => {
channelHandlers.handleReaction(reaction, user);
});

Expand All @@ -105,10 +115,15 @@ bot.on("message", msg => {
});

logger.log("INI", "Bootstrap complete");

bot.on("ready", () => {
logger.log("INI", "Bot connected to Discord server");
bot.user.setActivity('for !commands', { type: "WATCHING" });
Array.from(bot.guilds.values()).forEach(guild => {
logger.log("INI", `Bot connected to Discord server: ${guild.name}`);
});

bot.user.setActivity("for !commands", { type: "WATCHING" });
});

bot.on("error", err => {
try {
logger.log("ERR", err.message);
Expand Down
80 changes: 49 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading