generated from nhcarrigan/template
Reviewed-on: https://codeberg.org/nhcarrigan/tingle-bot/pulls/2 Co-authored-by: Naomi Carrigan <commits@nhcarrigan.com> Co-committed-by: Naomi Carrigan <commits@nhcarrigan.com>
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
/**
|
|
* @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 forecast - The weather forecast.
|
|
* @returns The banner image attachment data.
|
|
*/
|
|
export const generateBanner = async(
|
|
forecast: WeatherForecast,
|
|
): Promise<AttachmentData> => {
|
|
const background = getBannerImage(forecast.region);
|
|
const overlayQuery
|
|
= forecast.special?.name === "Blight Rain"
|
|
? "Blight Rain"
|
|
: forecast.precipitation?.name;
|
|
|
|
if (overlayQuery === undefined) {
|
|
return background;
|
|
}
|
|
|
|
const overlayPath = getOverlayImage(overlayQuery);
|
|
|
|
if (overlayPath === null) {
|
|
return background;
|
|
}
|
|
|
|
const overlay = await overlayImages(background.filePath, overlayPath);
|
|
|
|
return overlay;
|
|
};
|