generated from nhcarrigan/template
feat: update this highly outdated app to use latest packages and custom configs (#1)
Reviewed-on: https://codeberg.org/nhcarrigan/tingle-bot/pulls/1 Co-authored-by: Naomi Carrigan <commits@nhcarrigan.com> Co-committed-by: Naomi Carrigan <commits@nhcarrigan.com>
This commit is contained in:
@ -1,37 +1,34 @@
|
||||
import { AttachmentData } from "../../interfaces/commands/AttachmentData";
|
||||
import { WeatherForecast } from "../../interfaces/weather/WeatherForecast";
|
||||
|
||||
import { getBannerImage } from "./getBannerImage";
|
||||
import { getOverlayImage } from "./getOverlayImage";
|
||||
import { overlayImages } from "./overlayImages";
|
||||
/**
|
||||
* @copyright nhcarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
import { getBannerImage } from "./getBannerImage.js";
|
||||
import { getOverlayImage } from "./getOverlayImage.js";
|
||||
import { overlayImages } from "./overlayImages.js";
|
||||
import type { AttachmentData }
|
||||
from "../../interfaces/commands/attachmentData.js";
|
||||
import type { WeatherForecast }
|
||||
from "../../interfaces/weather/weatherForecast.js";
|
||||
|
||||
/**
|
||||
* Generates the banner image. If an overlay is available, constructs a new banner image by overlaying the overlay on the banner.
|
||||
* Otherwise, returns the banner itself.
|
||||
*
|
||||
* @param {WeatherForecast} forecast The weather forecast.
|
||||
* @returns {AttachmentData} The banner image attachment data.
|
||||
* @param forecast - The weather forecast.
|
||||
* @returns The banner image attachment data.
|
||||
*/
|
||||
export const generateBanner = async (
|
||||
forecast: WeatherForecast
|
||||
export const generateBanner = async(
|
||||
forecast: WeatherForecast,
|
||||
): Promise<AttachmentData> => {
|
||||
const background = getBannerImage(forecast.region);
|
||||
const overlayQuery =
|
||||
forecast.special?.name === "Blight Rain"
|
||||
const overlayQuery
|
||||
= forecast.special?.name === "Blight Rain"
|
||||
? "Blight Rain"
|
||||
: forecast.precipitation?.name;
|
||||
|
||||
if (!overlayQuery) {
|
||||
return background;
|
||||
}
|
||||
const overlayPath = getOverlayImage(overlayQuery ?? null);
|
||||
|
||||
const overlayPath = getOverlayImage(overlayQuery);
|
||||
|
||||
if (!overlayPath) {
|
||||
return background;
|
||||
}
|
||||
|
||||
const overlay = await overlayImages(background.filePath, overlayPath);
|
||||
const overlay = await overlayImages(background.filePath, overlayPath ?? "");
|
||||
|
||||
return overlay;
|
||||
};
|
||||
|
@ -1,16 +1,21 @@
|
||||
import { join } from "path";
|
||||
|
||||
import { AttachmentData } from "../../interfaces/commands/AttachmentData";
|
||||
import { RegionName } from "../../interfaces/weather/names/RegionName";
|
||||
/**
|
||||
* @copyright nhcarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
import { join } from "node:path";
|
||||
import type { AttachmentData }
|
||||
from "../../interfaces/commands/attachmentData.js";
|
||||
import type { RegionName } from "../../interfaces/weather/names/regionName.js";
|
||||
|
||||
/**
|
||||
* Selects one of the random banner images from the banner folder.
|
||||
*
|
||||
* @param {RegionName} region The name of the region.
|
||||
* @returns {AttachmentData} The banner image attachment data.
|
||||
* @param region - The name of the region.
|
||||
* @returns The banner image attachment data.
|
||||
*/
|
||||
export const getBannerImage = (region: RegionName): AttachmentData => {
|
||||
const fileName = `${region}${Math.ceil(Math.random() * 3)}.png`;
|
||||
const fileName
|
||||
= `${region}${String(Math.ceil(Math.random() * 3))}.png`;
|
||||
const filePath = join(process.cwd(), "src", "assets", "banners", fileName);
|
||||
return {
|
||||
attachmentString: `attachment://${fileName}`,
|
||||
|
@ -1,18 +1,23 @@
|
||||
import { join } from "path";
|
||||
|
||||
import { PrecipitationName } from "../../interfaces/weather/names/PrecipitationName";
|
||||
import { SpecialName } from "../../interfaces/weather/names/SpecialName";
|
||||
/**
|
||||
* @copyright nhcarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
import { join } from "node:path";
|
||||
import type { PrecipitationName }
|
||||
from "../../interfaces/weather/names/precipitationName.js";
|
||||
import type { SpecialName }
|
||||
from "../../interfaces/weather/names/specialName.js";
|
||||
|
||||
/**
|
||||
* Checks if the current weather conditions have an overlay.
|
||||
*
|
||||
* @param {SpecialName | PrecipitationName} name The name of the weather condition to look for.
|
||||
* @returns {string | null} The file path to the overlay, or null if there is no overlay.
|
||||
* @param name - The name of the weather condition to look for.
|
||||
* @returns The file path to the overlay, or null if there is no overlay.
|
||||
*/
|
||||
export const getOverlayImage = (
|
||||
name: SpecialName | PrecipitationName
|
||||
name: SpecialName | PrecipitationName | null,
|
||||
): string | null => {
|
||||
let fileName = null;
|
||||
let fileName: string | null = null;
|
||||
switch (name) {
|
||||
case "Blight Rain":
|
||||
fileName = "ROOTS-blightrain.png";
|
||||
@ -58,8 +63,10 @@ export const getOverlayImage = (
|
||||
case "Thunderstorm":
|
||||
fileName = "ROOTS-thunderstorm.png";
|
||||
break;
|
||||
default:
|
||||
fileName = null;
|
||||
}
|
||||
if (!fileName) {
|
||||
if (fileName === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,17 @@
|
||||
import { join } from "path";
|
||||
|
||||
import { AttachmentData } from "../../interfaces/commands/AttachmentData";
|
||||
import { Season } from "../../interfaces/weather/names/Season";
|
||||
/**
|
||||
* @copyright nhcarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
import { join } from "node:path";
|
||||
import type { AttachmentData } from "../../interfaces/commands/attachmentData.js";
|
||||
import type { Season }
|
||||
from "../../interfaces/weather/names/season.js";
|
||||
|
||||
/**
|
||||
* Module to generate the season icon attachment.
|
||||
*
|
||||
* @param {Season} season The season.
|
||||
* @returns {AttachmentData} The icon attachment data.
|
||||
* @param season - The season for which to get the icon.
|
||||
* @returns The icon attachment data.
|
||||
*/
|
||||
export const getSeasonIcon = (season: Season): AttachmentData => {
|
||||
const fileName = `${season.toLowerCase()}.png`;
|
||||
|
@ -1,25 +1,28 @@
|
||||
import { join } from "path";
|
||||
|
||||
/**
|
||||
* @copyright nhcarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
import { join } from "node:path";
|
||||
import sharp from "sharp";
|
||||
|
||||
import { AttachmentData } from "../../interfaces/commands/AttachmentData";
|
||||
import type { AttachmentData }
|
||||
from "../../interfaces/commands/attachmentData.js";
|
||||
|
||||
/**
|
||||
* Module to combine an overlay and a banner.
|
||||
*
|
||||
* @param {string} banner The file path for the banner.
|
||||
* @param {string} overlay The file path for the overlay.
|
||||
* @returns {AttachmentData} The attachment data for the new banner.
|
||||
* @param banner - The file path for the banner.
|
||||
* @param overlay - The file path for the overlay.
|
||||
* @returns The attachment data for the new banner.
|
||||
*/
|
||||
export const overlayImages = async (
|
||||
export const overlayImages = async(
|
||||
banner: string,
|
||||
overlay: string
|
||||
overlay: string,
|
||||
): Promise<AttachmentData> => {
|
||||
await sharp(banner)
|
||||
.composite([{ input: overlay, gravity: "center" }])
|
||||
.toFile(join(process.cwd(), "src", "assets", "overlay.png"));
|
||||
await sharp(banner).
|
||||
composite([ { gravity: "center", input: overlay } ]).
|
||||
toFile(join(process.cwd(), "src", "assets", "overlay.png"));
|
||||
return {
|
||||
attachmentString: `attachment://overlay.png`,
|
||||
filePath: join(process.cwd(), "src", "assets", "overlay.png"),
|
||||
filePath: join(process.cwd(), "src", "assets", "overlay.png"),
|
||||
};
|
||||
};
|
||||
|
Reference in New Issue
Block a user