|
| 1 | +// loosely based on https://github.com/hackclub/scrappy |
| 2 | +// |
| 3 | +import { type Message } from "discord.js"; |
| 4 | + |
| 5 | +const SHIP_CHANNEL_ID = "904896819165814794"; |
| 6 | +const CHECKPOINTS_CHANNEL_ID = "1052236377338683514"; |
| 7 | + |
| 8 | +const AUTO_THREAD_CHANNELS = [SHIP_CHANNEL_ID, CHECKPOINTS_CHANNEL_ID]; |
| 9 | +// TODO(@rayhanadev): this is honestly shitty but breaks less |
| 10 | +// than requiring people to add an image like Scrappy does. Look |
| 11 | +// into phasing this out or doing something different. |
| 12 | +const VALID_PROJECT_LINKS = ["https://github.com/"]; |
| 13 | + |
| 14 | +const CHECKPOINT_RESPONSE_MESSAGES = [ |
| 15 | + "Great checkpoint! :D", |
| 16 | + "Nice progress! :D", |
| 17 | + "Awesome update! :D", |
| 18 | + "Yay thanks for sharing! :D", |
| 19 | + "Yippie!! Keep it up! :D", |
| 20 | +]; |
| 21 | + |
| 22 | +const SHIP_RESPONSE_MESSAGES = [ |
| 23 | + "Congrats on shipping! :D", |
| 24 | + "You shipped it! :D", |
| 25 | + "That’s a wrap! :D", |
| 26 | + "Yay thanks for sharing! :D", |
| 27 | + "Yippie!! Great work! :D", |
| 28 | + "Launched and loved! :D", |
| 29 | + "Woohoo, it's live now! :D", |
| 30 | + "Done and dusted! :D", |
| 31 | + "High-five on the ship! :D", |
| 32 | + "Boom, nice ship! :D", |
| 33 | +]; |
| 34 | + |
| 35 | +export default async function handler(message: Message) { |
| 36 | + if (message.author.bot) return; |
| 37 | + if (message.channel.isDMBased()) return; |
| 38 | + |
| 39 | + if (!AUTO_THREAD_CHANNELS.includes(message.channelId)) return; |
| 40 | + |
| 41 | + const hasProjectLink = containsValidProjectLink(message.content); |
| 42 | + const hasAttachment = message.attachments.size > 0; |
| 43 | + |
| 44 | + if (!hasProjectLink && !hasAttachment) { |
| 45 | + await message.delete(); |
| 46 | + return; |
| 47 | + } |
| 48 | + |
| 49 | + // NOTE: add a condition when updating AUTO_THREAD_CHANNELS |
| 50 | + const type = |
| 51 | + message.channelId === CHECKPOINTS_CHANNEL_ID |
| 52 | + ? "checkpoint" |
| 53 | + : message.channelId === SHIP_CHANNEL_ID |
| 54 | + ? "ship" |
| 55 | + : "something???"; |
| 56 | + |
| 57 | + // TODO(@rayhanadev): use groq to generate title? |
| 58 | + const thread = await message.startThread({ |
| 59 | + name: `${message.author.displayName}'s ship!`, |
| 60 | + }); |
| 61 | + |
| 62 | + if (message.channelId === CHECKPOINTS_CHANNEL_ID) { |
| 63 | + await thread.send( |
| 64 | + CHECKPOINT_RESPONSE_MESSAGES[ |
| 65 | + Math.floor(Math.random() * CHECKPOINT_RESPONSE_MESSAGES.length) |
| 66 | + ], |
| 67 | + ); |
| 68 | + // TODO(@rayhanadev): integrate potential scrapbook |
| 69 | + // TODO(@rayhanadev): add auto-emoji behavior |
| 70 | + } |
| 71 | + |
| 72 | + if (message.channelId === SHIP_CHANNEL_ID) { |
| 73 | + await message.react("🎉"); |
| 74 | + await message.react("✨"); |
| 75 | + await message.react("🚀"); |
| 76 | + await thread.send( |
| 77 | + SHIP_RESPONSE_MESSAGES[ |
| 78 | + Math.floor(Math.random() * SHIP_RESPONSE_MESSAGES.length) |
| 79 | + ], |
| 80 | + ); |
| 81 | + |
| 82 | + // TODO(@rayhanadev): integrate potential scrapbook |
| 83 | + // TODO(@rayhanadev): add auto-emoji behavior |
| 84 | + // TODO(@rayhanadev): add hook for SIGHORSE |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +function containsValidProjectLink(text: string): boolean { |
| 89 | + return VALID_PROJECT_LINKS.some((host) => text.includes(host)); |
| 90 | +} |
0 commit comments