Better notifications

This commit is contained in:
Raicuparta 2023-03-14 14:06:32 +01:00
parent 021cc3de9b
commit b939191d26
3 changed files with 122 additions and 37 deletions

14
scripts/src/mod.d.ts vendored
View File

@ -14,6 +14,13 @@ export interface BaseMod {
downloadUrl: string;
downloadCount: number;
version: string;
tags: string[];
thumbnail: {
main?: string;
openGraph?: string;
};
latestReleaseDescription?: string;
latestPrereleaseDescription?: string;
alpha?: boolean;
required?: boolean;
utility?: boolean;
@ -28,13 +35,6 @@ export interface BaseMod {
downloadUrl: string;
date: string;
};
tags: string[];
thumbnail: {
main?: string;
openGraph?: string;
};
latestReleaseDescription: string;
latestPrereleaseDescription: string;
}
export interface OutputMod extends BaseMod {

View File

@ -3,41 +3,44 @@ import { THUMBNAIL_URL_BASE } from "../constants.js";
import { DiffItem } from "./get-diff.js";
function getNotificationTitle(diffItem: DiffItem) {
const author = diffItem.nextMod.authorDisplay ?? diffItem.nextMod.author;
switch (diffItem.diffType) {
case "add":
return `Added ${diffItem.nextMod.name} by ${author}`;
case "update":
return `Updated ${diffItem.nextMod.name} by ${author}`;
case "update-prerelease":
return `Updated prerelease of ${diffItem.nextMod.name} by ${author}`;
return `New ${
diffItem.nextMod.parent
? `addon for \`${diffItem.nextMod.parent}\``
: "mod"
}`;
case "update": {
return `Update ${diffItem.previousMod.version} → **${diffItem.nextMod.version}**`;
}
case "update-prerelease": {
return `Prerelease **${diffItem.nextMod.prerelease?.version}**`;
}
}
}
function getNotificationDescription(diffItem: DiffItem) {
switch (diffItem.diffType) {
function getNotificationDescription({ diffType, nextMod }: DiffItem) {
let description: string | undefined = "";
switch (diffType) {
case "add":
return `${
diffItem.nextMod.parent
? `Addon for \`${diffItem.nextMod.parent}\`. `
: ""
}${diffItem.nextMod.description}`;
description = nextMod.description;
break;
case "update": {
const nextReleaseDescription = diffItem.nextMod.latestReleaseDescription;
return `${diffItem.previousMod.version} → **${
diffItem.nextMod.version
}**.${nextReleaseDescription ? "\n >>> " : ""}${nextReleaseDescription}`;
description = nextMod.latestReleaseDescription || nextMod.description;
break;
}
case "update-prerelease": {
const prereleaseDescription =
diffItem.nextMod.latestPrereleaseDescription;
return `Prerelease **${diffItem.nextMod.prerelease?.version}**.${
prereleaseDescription ? "\n >>> " : ""
}${prereleaseDescription}`;
description = nextMod.latestPrereleaseDescription || nextMod.description;
break;
}
}
return (
description ||
`Mod tagged as ${
nextMod.tags.length > 0 ? nextMod.tags.join(",") : "ABSOLUTELY NOTHING"
}`
);
}
function getNotificationColor(diffItem: DiffItem) {
@ -55,13 +58,40 @@ function getNotificationImageKey(diffItem: DiffItem) {
return diffItem.diffType === "add" ? "image" : "thumbnail";
}
function getUrlParams(diffItem: DiffItem) {
switch (diffItem.diffType) {
case "add":
return "?linked-from-notification=true";
case "update-prerelease":
return "?prerelease=true";
default:
return "";
}
}
function getEmbed(diffItem: DiffItem) {
const description = getNotificationDescription(diffItem);
return {
title: getNotificationTitle(diffItem),
description: `${getNotificationDescription(diffItem)}\n[source code](${
diffItem.nextMod.repo
})`,
url: `https://outerwildsmods.com/mods/${diffItem.nextMod.slug}?linked-from-notification=true`,
type: "rich",
title: diffItem.nextMod.name,
fields: [
{
name: getNotificationTitle(diffItem),
value: description ? `>>> ${description}` : "\u200B",
},
{
name: "\u200B",
value: `[<:github:1085179483784499260> Source Code](${diffItem.nextMod.repo})`,
},
],
author: {
name: diffItem.nextMod.authorDisplay ?? diffItem.nextMod.author,
icon_url: `https://github.com/${diffItem.nextMod.author}.png`,
},
url: `https://outerwildsmods.com/mods/${
diffItem.nextMod.slug
}${getUrlParams(diffItem)}`,
color: getNotificationColor(diffItem),
[getNotificationImageKey(diffItem)]: {
url: `${THUMBNAIL_URL_BASE}/${

View File

@ -1,8 +1,63 @@
import { fetchMods } from "../update-database/fetch-mods.js";
import modsJson from "./mods.json" assert { type: "json" };
import secrets from "./secrets.json" assert { type: "json" };
import { BaseMod } from "../mod.js";
import { getDiff } from "../send-notifications/get-diff.js";
import { sendDiscordNotifications } from "../send-notifications/send-discord-notifications.js";
async function test() {
fetchMods(JSON.stringify(modsJson), "output", []);
const mod: BaseMod = {
name: "NomaiVR",
uniqueName: "Raicuparta.NomaiVR",
slug: "nomaivr",
description:
"Outer Wilds VR Mod with 6DOF tracking and full motion control support",
author: "Raicuparta",
authorDisplay: "Raicuparta & Artum",
repo: "https://github.com/Raicuparta/nomai-vr",
latestReleaseDate: "latestReleaseDate",
firstReleaseDate: "firstReleaseDate",
repoUpdatedAt: "repoUpdatedAt",
databaseEntryUpdatedAt: "databaseEntryUpdatedAt",
downloadUrl: "downloadUrl",
downloadCount: 0,
version: "0.0.1",
tags: [],
thumbnail: {
main: "nomaivr-static.webp",
},
latestReleaseDescription: `- Stereoscopic view in post credits sequence
- Input prompts are now unaffected by the texture resolution setting
- Additional settings for flashlight gesture, look arrow and markers opacity
- Disable walking when holding a tool or when concealing the lantern`,
};
const diff = getDiff(
[mod],
[
{ ...mod, version: "0.0.2" },
{
...mod,
description: "",
parent: "daddy",
tags: ["funny"],
prerelease: {
version: "0.0.3",
downloadUrl: "https://haha",
date: "",
},
},
{
...mod,
parent: "daddy",
uniqueName: "Raicuparta.NomaiVR2",
slug: "nomaivr2",
},
]
);
sendDiscordNotifications(secrets.discordHookUrl, "", "", diff, {});
// fetchMods(JSON.stringify(modsJson), "output", []);
}
test();