Skip to content

Commit 6d78a2f

Browse files
authored
Merge pull request #8 from purduehackers/ray/thread-ship
2 parents 043b16d + 70982ad commit 6d78a2f

File tree

3 files changed

+97
-2
lines changed

3 files changed

+97
-2
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
}

src/events/message_create/dashboard.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { type Message } from "discord.js";
22
import { connectToApi, sendDashboardMessage } from "../../utils/phack";
3-
import { env } from "../../env";
43

54
const client = await connectToApi();
65

src/events/message_create/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import { Events } from "discord.js";
22

3+
import autoThreadChannels from "./auto-thread-channels";
34
import dashboard from "./dashboard";
45
import evergreenIt from "./evergreen-it";
56
import voiceMessageTranscription from "./voice-transcription";
67

78
export const eventType = Events.MessageCreate;
8-
export { dashboard, evergreenIt, voiceMessageTranscription };
9+
export {
10+
autoThreadChannels,
11+
dashboard,
12+
evergreenIt,
13+
voiceMessageTranscription,
14+
};

0 commit comments

Comments
 (0)