Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block all cryptocurrency/nft/blockchain job postings #237

Merged
merged 3 commits into from
Jul 13, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
114 changes: 106 additions & 8 deletions src/features/jobs-moderation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ import {
differenceInMinutes,
format,
} from "date-fns";
import { Client, Message, TextChannel } from "discord.js";
import {
Client,
Message,
MessageActionRow,
MessageButton,
MessageMentions,
TextChannel,
} from "discord.js";
import { simplifyString } from "../helpers/string";
import { CHANNELS } from "../constants/channels";
import { isStaff } from "../helpers/discord";
import { sleep } from "../helpers/misc";
import { ReportReasons, reportUser } from "../helpers/modLog";
import { ReportReasons, reportUser, modLog } from "../helpers/modLog";
import cooldown from "./cooldown";

const storedMessages: Message[] = [];
Expand Down Expand Up @@ -66,12 +74,73 @@ const removeSpecificJob = (message: Message) => {
storedMessages.splice(storedMessages.findIndex((m) => m === message));
};

const freeflowHiring = "https://discord.gg/gTWTwZPDYT";
const freeflowForHire = "https://vjlup8tch3g.typeform.com/to/T8w8qWzl";

const hiringTest = /hiring/i;
const isHiring = (content: string) => hiringTest.test(content);

const forHireTest = /for ?hire/i;
const isForHire = (content: string) => forHireTest.test(content);

const jobModeration = async (bot: Client) => {
const jobBoard = await bot.channels.fetch(CHANNELS.jobBoard);
if (!jobBoard?.isText() || !(jobBoard instanceof TextChannel)) return;

await loadJobs(bot, jobBoard);

bot.on("interactionCreate", (interaction) => {
if (
interaction.isMessageComponent() &&
interaction.customId === "freeflow-hiring"
) {
if (
!(interaction.message.mentions as MessageMentions).users.has(
interaction.user.id,
)
) {
modLog(`<@${interaction.user.id}> invited to Freeflow by hiring link`);
} else {
modLog(`<@${interaction.user.id}> directed to hire from Freeflow`);
}
interaction.reply({
content: "Join the Freeflow community and start hiring developers",
ephemeral: true,
components: [
new MessageActionRow().addComponents(
new MessageButton()
.setURL(freeflowHiring)
.setLabel("Apply")
.setStyle("LINK"),
),
],
});
}
if (
interaction.isMessageComponent() &&
interaction.customId === "freeflow-for-hire"
) {
if (
!(interaction.message.mentions as MessageMentions).users.has(
interaction.user.id,
)
) {
modLog(
`<@${interaction.user.id}> invited to Freeflow by for hire link`,
);
return interaction.reply({
ephemeral: true,
content: `For more information about Freeflow, visit their website: <https://freeflow.dev/> or apply to join: ${freeflowForHire}`,
});
}
modLog(`<@${interaction.user.id}> directed to apply to Freeflow`);
interaction.reply({
content: `Apply to join Freeflow to get started: ${freeflowForHire}`,
ephemeral: true,
});
}
});

bot.on("messageCreate", async (message) => {
if (
message.channelId !== CHANNELS.jobBoard ||
Expand Down Expand Up @@ -121,6 +190,41 @@ const jobModeration = async (bot: Client) => {
return;
}

const DELETE_DELAY = 90;
const bannedWords = /(blockchain|nft|cryptocurrency|token|web3)/;
if (bannedWords.test(simplifyString(message.content))) {
moderatedMessageIds.add(message.id);
const [reply] = await Promise.all([
message.reply({
content: `Sorry! We don't allow blockchain or related cryptocurrency roles to be advertised in our community. We encourage you to contact our Freeflow, a talent network for the cryptocurrency industry. This message will be deleted in ${DELETE_DELAY} seconds.`,
components: (() => {
const hiring = isHiring(message.content);
const forHire = isForHire(message.content);
const hiringLink = new MessageActionRow().addComponents(
new MessageButton()
.setCustomId("freeflow-hiring")
.setLabel("Start hiring")
.setStyle("PRIMARY"),
);
const forHireLink = new MessageActionRow().addComponents(
new MessageButton()
.setCustomId("freeflow-for-hire")
.setLabel("Request a Freeflow application")
.setStyle("PRIMARY"),
);
if (!hiring && !forHire) {
return [hiringLink, forHireLink];
}
return hiring ? [hiringLink] : [forHireLink];
})(),
}),
reportUser({ reason: ReportReasons.jobCrypto, message }),
]);
await Promise.all([message.delete(), sleep(DELETE_DELAY)]);
await reply.delete();
return;
}

// Handle joining and posting too quickly
const now = new Date();
if (
Expand Down Expand Up @@ -209,12 +313,6 @@ const jobModeration = async (bot: Client) => {
// Last, update the list of tracked messages.
updateJobs(message);
});
const modLog = bot.channels.cache.find(
(channel) => channel.id === CHANNELS.modLog,
);
if (!modLog?.isText()) {
throw new Error("Couldn't find #mod-log");
}
bot.on("messageDelete", async (message) => {
// TODO: look up audit log, early return if member was banned
if (
Expand Down
19 changes: 18 additions & 1 deletion src/helpers/modLog.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { GuildMember, Message } from "discord.js";
import {
GuildMember,
Message,
MessageOptions,
MessagePayload,
} from "discord.js";
import { modRoleId } from "../constants";
import {
constructDiscordLink,
Expand All @@ -8,6 +13,13 @@ import {
import { simplifyString } from "../helpers/string";
import { CHANNELS, getChannel } from "../constants/channels";

export const modLog = async (
message: string | MessagePayload | MessageOptions,
) => {
const logChannel = await getChannel(CHANNELS.jobsLog);
return await logChannel.send(message);
};

const warningMessages = new Map<
string,
{ warnings: number; message: Message }
Expand All @@ -22,6 +34,7 @@ export const enum ReportReasons {
jobAge = "jobAge",
jobFrequency = "jobFrequency",
jobRemoved = "jobRemoved",
jobCrypto = "jobCrypto",
}

interface Report {
Expand Down Expand Up @@ -170,6 +183,10 @@ ${reportedMessage}
return `${preface}, post was deleted:
${extra}
${reportedMessage}
`;
case ReportReasons.jobCrypto:
return `<@${message.author.id}> posted a crypto job:
${reportedMessage}
`;
}
};