Skip to content

Commit

Permalink
feat: quote id effect output (#2822) (#2823)
Browse files Browse the repository at this point in the history
* feat: quote id effect output (#2822)

* chore: rename to model
  • Loading branch information
dennisrijsdijk authored Sep 24, 2024
1 parent d78fe8d commit 954a9e3
Showing 1 changed file with 29 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
"use strict";
import twitchApi from "../../twitch-api/api";
import quotesManager from "../../quotes/quotes-manager";
import { EffectCategory } from '../../../shared/effect-constants';
import moment from "moment";
import { EffectType } from "../../../types/effects";

const TwitchApi = require("../../twitch-api/api");
const quotesManager = require("../../quotes/quotes-manager");
const { EffectCategory } = require('../../../shared/effect-constants');
const moment = require("moment");

const addQuoteEffect = {
const model: EffectType<{
creator: string;
originator: string;
text: string;
}> = {
definition: {
id: "firebot:add-quote",
name: "Add Quote",
description: "Adds a quote to the quote database.",
icon: "fad fa-quote-right",
categories: [EffectCategory.FUN],
dependencies: []
dependencies: [],
outputs: [
{
label: "Quote ID",
description: "ID of the created quote",
defaultName: "quoteId"
}
]
},
globalSettings: {},
optionsTemplate: `
<eos-container header="Quote Creator">
<p class="muted">This is the name of the person who is creating the quote entry.</p>
Expand All @@ -32,7 +41,7 @@ const addQuoteEffect = {
</eos-container>
`,
optionsController: () => {},
optionsValidator: effect => {
optionsValidator: (effect) => {
const errors = [];
if (effect.creator == null || effect.creator === "") {
errors.push("Please provide a quote creator.");
Expand All @@ -47,10 +56,10 @@ const addQuoteEffect = {
}
return errors;
},
onTriggerEvent: async event => {
onTriggerEvent: async (event) => {
const { effect } = event;

const channelData = await TwitchApi.channels.getChannelInformation();
const channelData = await twitchApi.channels.getChannelInformation();

const currentGameName = channelData && channelData.gameName ? channelData.gameName : "Unknown game";

Expand All @@ -62,10 +71,15 @@ const addQuoteEffect = {
createdAt: moment().toISOString()
};

quotesManager.addQuote(newQuote);
const id = await quotesManager.addQuote(newQuote);

return true;
return {
success: true,
outputs: {
quoteId: id
}
};
}
};

module.exports = addQuoteEffect;
export = model;

0 comments on commit 954a9e3

Please sign in to comment.