Skip to content

Commit 6053abd

Browse files
Techbot121Meta Construct
authored andcommitted
use an actual map for the server map
1 parent b55ef14 commit 6053abd

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

app/services/discord/modules/webhook-handler.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ const GetGithubChanges = (
5454

5555
const getGitHubDiff = async (url: string) => {
5656
const res = await axios.get<string>(url + ".diff");
57-
if (res) return res.data;
57+
if (res) return res.data
58+
.replaceAll(/(@@ -\d+,\d+ .+\d+,\d+ @@)[^\n]/g, "$1\n")
59+
.replaceAll(/diff.+\nindex.+\n/g, "")
60+
.replaceAll("```", "​`​`​`");
5861
};
5962

6063
const FIELD_REGEX = /^(?:Add|Mod|Del) \[(.+)\]/g;
@@ -64,6 +67,16 @@ const SERVER_EMOJI_MAP = {
6467
"2": "2️⃣",
6568
"3": "3️⃣",
6669
};
70+
71+
const REPO_SERVER_MAP = new Map([
72+
["Lumiens-Map-Vote", [3]],
73+
["MTA-Gamemode", [3]],
74+
["terrortown_modding", [3]],
75+
["ttt_player_tumbler", [3]],
76+
["ttt_ragmod", [3]],
77+
["TTT2", [3]],
78+
]);
79+
6780
const isRemoteMergeCommit = (message: string) =>
6881
message.startsWith("Merge remote-tracking") || message.startsWith("Merge pull request");
6982
const isMergeCommit = (message: string) =>
@@ -225,23 +238,11 @@ export default async (bot: DiscordBot): Promise<void> => {
225238
}
226239
});
227240

228-
const REPO_SERVER_MAP: [repo: string, servers: number[]][] = [
229-
// maybe move this to a config?
230-
["Lumiens-Map-Vote", [3]],
231-
["MTA-Gamemode", [3]],
232-
["terrortown_modding", [3]],
233-
["ttt_player_tumbler", [3]],
234-
["ttt_ragmod", [3]],
235-
["TTT2", [3]],
236-
];
237-
238241
GitHub.on("push", async event => {
239242
if (!webhook) return;
240243
const payload = event.payload;
241244
const repo = payload.repository;
242-
const serverOverride = REPO_SERVER_MAP.filter(r => r[1].length > 0).find(
243-
r => r[0] === repo.name
244-
)?.[1];
245+
const serverOverride = REPO_SERVER_MAP.get(repo.name);
245246
const commits = payload.commits;
246247
const branch = payload.ref.split("/")[2];
247248

@@ -308,11 +309,6 @@ export default async (bot: DiscordBot): Promise<void> => {
308309
}
309310

310311
let diff = isMergeCommit(commit.message) ? undefined : await getGitHubDiff(commit.url);
311-
if (diff) {
312-
diff = diff.replaceAll(/(@@ -\d+,\d+ .+\d+,\d+ @@)[^\n]/g, "$1\n");
313-
diff = diff.replaceAll(/diff.+\nindex.+\n/g, "");
314-
diff = diff.replaceAll("```", "​`​`​`");
315-
}
316312

317313
embeds.push({
318314
title:

0 commit comments

Comments
 (0)