generated from nhcarrigan/template
feat: initial commit
This commit is contained in:
37
src/modules/images/generateBanner.ts
Normal file
37
src/modules/images/generateBanner.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import { AttachmentData } from "../../interfaces/commands/AttachmentData";
|
||||
import { WeatherForecast } from "../../interfaces/weather/WeatherForecast";
|
||||
|
||||
import { getBannerImage } from "./getBannerImage";
|
||||
import { getOverlayImage } from "./getOverlayImage";
|
||||
import { overlayImages } from "./overlayImages";
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
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) {
|
||||
return background;
|
||||
}
|
||||
|
||||
const overlayPath = getOverlayImage(overlayQuery);
|
||||
|
||||
if (!overlayPath) {
|
||||
return background;
|
||||
}
|
||||
|
||||
const overlay = await overlayImages(background.filePath, overlayPath);
|
||||
|
||||
return overlay;
|
||||
};
|
Reference in New Issue
Block a user