From 538a500ca4fe55ef1aebb357974fad3200685836 Mon Sep 17 00:00:00 2001 From: Crypticelo Date: Thu, 19 Dec 2024 12:59:47 +0100 Subject: [PATCH] Testing --- src/events/JobCreate.ts | 27 +++++++++++++++++++++++++++ src/lib/constants.ts | 3 +++ src/lib/helpers.ts | 2 ++ 3 files changed, 32 insertions(+) create mode 100644 src/events/JobCreate.ts diff --git a/src/events/JobCreate.ts b/src/events/JobCreate.ts new file mode 100644 index 00000000..26f795c7 --- /dev/null +++ b/src/events/JobCreate.ts @@ -0,0 +1,27 @@ +import type { ArgsOf, Client } from "discordx"; +import { Discord, On } from "discordx"; +import { JOB_POST_REGEX } from "../lib/helpers.js"; +import { DEV_BOARD_CHANNEL } from "../lib/constants.js"; + +@Discord() +export class MessageCreate { + private readonly JOB_CHANNEL_ID = DEV_BOARD_CHANNEL; + + @On({ event: "messageCreate" }) + async onMessage([message]: ArgsOf<"messageCreate">, client: Client) { + if (message.channelId !== this.JOB_CHANNEL_ID) return; + if (message.author.bot) return; + + if (!JOB_POST_REGEX.test(message.content)) { + await message.delete(); + + try { + await message.author.send({ + content: `Your post in the job board was deleted because it didn't follow the required format` + }); + } catch { + console.log(`Couldn't send DM to ${message.author.tag}`); + } + } + } +} \ No newline at end of file diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 1f1537d3..1ee2f79b 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -122,3 +122,6 @@ export const LEVEL_MESSAGES = { "`ansible-playbook promote-to-principal.yml` ${user} deployment complete as ${role}!", ], }; + +export const DEV_BOARD_CHANNEL = '1300427846342283436'; +export const JOB_BOARD_CHANNEL = '1300427561704226867'; \ No newline at end of file diff --git a/src/lib/helpers.ts b/src/lib/helpers.ts index b18fef40..ff9df426 100644 --- a/src/lib/helpers.ts +++ b/src/lib/helpers.ts @@ -2,6 +2,8 @@ import { ChartConfiguration, ChartDataset } from "chart.js"; import { enUS } from "date-fns/locale"; import { TRANSLATOR } from "./constants.js"; +export const JOB_POST_REGEX = /Project Title:[\s\S]*?(?=Project Description:|$)Project Description:[\s\S]*?(?=Required Skills:|$)Required Skills:[\s\S]*?(?=Budget Range:|$)Budget Range:[\s\S]*?(?=Timeline:|$)Timeline:[\s\S]*?(?=Contact Method:|$)Contact Method:[\s\S]*?(?=Additional Details:|$)Additional Details:[\s\S]*$/; + export function placementSuffix(i: number) { var j = i % 10, k = i % 100;