-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ts
61 lines (51 loc) · 1.77 KB
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { AnyThreadChannel, Channel, Collection, Message } from "discord.js";
import "./env.js";
const INDEX_AFTER = 1735527600000; // Tuesday, December 24, 2024 3:00:00 PM (GMT)
export const isForumMessage = (
channel: Channel
): channel is AnyThreadChannel => {
return (
channel.isThread() &&
channel.parentId !== null &&
channel.parentId === process.env.DISCUSSIONS_CHANNEL_ID
);
};
export const isMessageSupported = (message: Message) => {
const isIndexable = message.createdAt.getTime() > INDEX_AFTER;
return !message.author.bot && !message.system && isIndexable;
};
export const isForumThread = (thread: AnyThreadChannel) => {
return (
thread.parentId !== null &&
thread.parentId === process.env.DISCUSSIONS_CHANNEL_ID
);
};
export const isThreadSupported = (thread: AnyThreadChannel) => {
const isIndexable =
thread.createdAt !== null && thread.createdAt.getTime() > INDEX_AFTER;
return isIndexable;
};
export const isMessagePermitted = (message: Message) => {
return !message.author.bot && !message.system;
};
export const isReached = new Collection<string, number>();
if (!process.env.GENERAL_CHANNEL_ID || !process.env.MEMBER_ROLE_ID) {
throw new Error("Missing required environment variables!");
}
export const configuration = {
REQUIRED_MESSAGES: 5,
GENERAL_CHANNEL_ID: process.env.GENERAL_CHANNEL_ID,
MEMBER_ROLE_ID: process.env.MEMBER_ROLE_ID,
};
export const getProposalURL = (title: string) => {
const webURL = process.env.WEB_URL ?? "http://localhost:3000";
if (title) {
const parts = title.split("-");
if (parts.length >= 2) {
const proposalID = parts[0] + "-" + parts[1].split(" ")[0];
return `${webURL}/proposal/${proposalID}`;
}
}
console.error("Invalid proposal title:", title);
return webURL;
};