Add image opacity support
This commit is contained in:
parent
4d5dc235d1
commit
ef2ccf95f4
2 changed files with 5 additions and 4 deletions
|
@ -106,6 +106,7 @@ if (!config.token) {
|
||||||
case "simulate":
|
case "simulate":
|
||||||
var electionname = (i.options as CommandInteractionOptionResolver).getSubcommand();
|
var electionname = (i.options as CommandInteractionOptionResolver).getSubcommand();
|
||||||
var overlayimage = (i.options as CommandInteractionOptionResolver).getAttachment('image_overlay');
|
var overlayimage = (i.options as CommandInteractionOptionResolver).getAttachment('image_overlay');
|
||||||
|
var overlayopacity = Number(i.options.get('image_opacity')?.value);
|
||||||
|
|
||||||
var election = structuredClone(Elections[electionname]);
|
var election = structuredClone(Elections[electionname]);
|
||||||
for (const candidate of election.candidates) {
|
for (const candidate of election.candidates) {
|
||||||
|
@ -152,7 +153,7 @@ if (!config.token) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var result = await MakePrediction(election, overlayimage?.url);
|
var result = await MakePrediction(election, overlayimage?.url, overlayopacity ? Math.round((overlayopacity / 100) * 255) : 255);
|
||||||
var embed = new EmbedBuilder()
|
var embed = new EmbedBuilder()
|
||||||
.setTitle(election.title)
|
.setTitle(election.title)
|
||||||
.setDescription(election.description.replace("$WINNER", result.winner))
|
.setDescription(election.description.replace("$WINNER", result.winner))
|
||||||
|
|
|
@ -5,7 +5,7 @@ import crypto from "crypto";
|
||||||
import Election from "./election.js";
|
import Election from "./election.js";
|
||||||
import VoteType from './VoteType.js';
|
import VoteType from './VoteType.js';
|
||||||
|
|
||||||
export function MakePrediction(election : Election, overlay_image?: string) : Promise<Prediction> {
|
export function MakePrediction(election : Election, overlay_image?: string, overlay_opacity?: number) : Promise<Prediction> {
|
||||||
return new Promise(async res => {
|
return new Promise(async res => {
|
||||||
const window = createSVGWindow();
|
const window = createSVGWindow();
|
||||||
registerWindow(window, window.document);
|
registerWindow(window, window.document);
|
||||||
|
@ -50,7 +50,7 @@ export function MakePrediction(election : Election, overlay_image?: string) : Pr
|
||||||
|
|
||||||
const overlay = await sharp(overlayBuffer)
|
const overlay = await sharp(overlayBuffer)
|
||||||
.composite([{
|
.composite([{
|
||||||
input: Buffer.from([0, 0, 0, 255]),
|
input: Buffer.from([0, 0, 0, overlay_opacity !== undefined ? overlay_opacity : 255]),
|
||||||
raw: {
|
raw: {
|
||||||
width: 1,
|
width: 1,
|
||||||
height: 1,
|
height: 1,
|
||||||
|
|
Loading…
Reference in a new issue