feat: initial commit

This commit is contained in:
Naomi Carrigan
2024-09-26 11:37:00 -07:00
commit 1339b63378
86 changed files with 12036 additions and 0 deletions

View 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;
};

View File

@ -0,0 +1,19 @@
import { join } from "path";
import { AttachmentData } from "../../interfaces/commands/AttachmentData";
import { RegionName } from "../../interfaces/weather/names/RegionName";
/**
* 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.
*/
export const getBannerImage = (region: RegionName): AttachmentData => {
const fileName = `${region}${Math.ceil(Math.random() * 3)}.png`;
const filePath = join(process.cwd(), "src", "assets", "banners", fileName);
return {
attachmentString: `attachment://${fileName}`,
filePath,
};
};

View File

@ -0,0 +1,68 @@
import { join } from "path";
import { PrecipitationName } from "../../interfaces/weather/names/PrecipitationName";
import { SpecialName } from "../../interfaces/weather/names/SpecialName";
/**
* 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.
*/
export const getOverlayImage = (
name: SpecialName | PrecipitationName
): string | null => {
let fileName = null;
switch (name) {
case "Blight Rain":
fileName = "ROOTS-blightrain.png";
break;
case "Blizzard":
fileName = "ROOTS-blizzard.png";
break;
case "Cinder Storm":
fileName = "ROOTS-cinderstorm.png";
break;
case "Cloudy":
case "Partly Cloudy":
fileName = "ROOTS-cloudy.png";
break;
case "Fog":
fileName = "ROOTS-fog.png";
break;
case "Hail":
fileName = "ROOTS-hail.png";
break;
case "Heat Lightning":
fileName = "ROOTS-heatlightning.png";
break;
case "Rain":
case "Light Rain":
case "Heavy Rain":
fileName = "ROOTS-rain.png";
break;
case "Rainbow":
fileName = "ROOTS-rainbow.png";
break;
case "Sleet":
fileName = "ROOTS-sleet.png";
break;
case "Snow":
case "Light Snow":
case "Heavy Snow":
fileName = "ROOTS-snow.png";
break;
case "Thundersnow":
fileName = "ROOTS-thundersnow.png";
break;
case "Thunderstorm":
fileName = "ROOTS-thunderstorm.png";
break;
}
if (!fileName) {
return null;
}
const filePath = join(process.cwd(), "src", "assets", "overlays", fileName);
return filePath;
};

View File

@ -0,0 +1,19 @@
import { join } from "path";
import { AttachmentData } from "../../interfaces/commands/AttachmentData";
import { Season } from "../../interfaces/weather/names/Season";
/**
* Module to generate the season icon attachment.
*
* @param {Season} season The season.
* @returns {AttachmentData} The icon attachment data.
*/
export const getSeasonIcon = (season: Season): AttachmentData => {
const fileName = `${season.toLowerCase()}.png`;
const filePath = join(process.cwd(), "src", "assets", "seasons", fileName);
return {
attachmentString: `attachment://${fileName}`,
filePath,
};
};

View File

@ -0,0 +1,25 @@
import { join } from "path";
import sharp from "sharp";
import { AttachmentData } from "../../interfaces/commands/AttachmentData";
/**
* 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.
*/
export const overlayImages = async (
banner: string,
overlay: string
): Promise<AttachmentData> => {
await sharp(banner)
.composite([{ input: overlay, gravity: "center" }])
.toFile(join(process.cwd(), "src", "assets", "overlay.png"));
return {
attachmentString: `attachment://overlay.png`,
filePath: join(process.cwd(), "src", "assets", "overlay.png"),
};
};