Skip to content

Commit

Permalink
Merge pull request #2236 from dennisrijsdijk/v5-quote-date
Browse files Browse the repository at this point in the history
Quotes: Use "Quote Date Format" setting for date output.
  • Loading branch information
itsjesski committed Sep 18, 2023
2 parents f993dad + eb1a359 commit 3f6b586
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/backend/chat/commands/builtin/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const quotesManagement = {
quoteDateFormat: {
type: "enum",
title: "Quote Date Format",
description: "How dates should be formatted for the 'editdate' mod command.",
description: "How dates should be formatted for the '!quote' and '!quote editdate' commands.",
options: [
"MM/DD/YYYY",
"DD/MM/YYYY"
Expand Down Expand Up @@ -210,7 +210,7 @@ const quotesManagement = {
const args = event.userCommand.args;

const getFormattedQuoteString = (quote) => {
const prettyDate = quote.createdAt != null ? moment(quote.createdAt).format('L') : "No Date";
const prettyDate = quote.createdAt != null ? moment(quote.createdAt).format(commandOptions.quoteDateFormat) : "No Date";
return commandOptions.quoteDisplayTemplate
.replace("{id}", quote._id)
.replace("{text}", quote.text)
Expand Down
7 changes: 5 additions & 2 deletions src/backend/variables/builtin/quote-as-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

"use strict";
const quoteManager = require("../../quotes/quotes-manager");
const commandsManager = require("../../chat/commands/CommandManager");
const moment = require("moment");
const logger = require("../../logwrapper");

const { OutputDataType, VariableCategory } = require("../../../shared/variable-constants");
Expand All @@ -28,6 +30,8 @@ const model = {
possibleDataOutput: [OutputDataType.TEXT]
},
evaluator: async (_, quoteId, property) => {
const quoteCommand = commandsManager.getSystemCommandById("firebot:quotesmanagement");
const quoteDateFormat = quoteCommand.definition.options.quoteDateFormat.value;
let quote;
quoteId = parseInt(quoteId);

Expand All @@ -41,10 +45,9 @@ const model = {

if (quote != null) {
logger.debug("Found a quote!");
const ts = new Date(quote.createdAt);
const quoteObject = {
id: quote._id,
createdAt: ts.toLocaleString(),
createdAt: moment(quote.createdAt).format(quoteDateFormat),
creator: quote.creator,
originator: quote.originator,
text: quote.text,
Expand Down
7 changes: 5 additions & 2 deletions src/backend/variables/builtin/quote-as-raw-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

"use strict";
const quoteManager = require("../../quotes/quotes-manager");
const commandsManager = require("../../chat/commands/CommandManager");
const moment = require("moment");
const logger = require("../../logwrapper");

const { OutputDataType, VariableCategory } = require("../../../shared/variable-constants");
Expand All @@ -28,6 +30,8 @@ const model = {
possibleDataOutput: [OutputDataType.TEXT]
},
evaluator: async (_, quoteId, property) => {
const quoteCommand = commandsManager.getSystemCommandById("firebot:quotesmanagement");
const quoteDateFormat = quoteCommand.definition.options.quoteDateFormat.value;
let quote;
quoteId = parseInt(quoteId);

Expand All @@ -41,10 +45,9 @@ const model = {

if (quote != null) {
logger.debug("Found a quote!");
const ts = new Date(quote.createdAt);
const quoteObject = {
id: quote._id,
createdAt: ts.toLocaleString(),
createdAt: moment(quote.createdAt).format(quoteDateFormat),
creator: quote.creator,
originator: quote.originator,
text: quote.text,
Expand Down
9 changes: 6 additions & 3 deletions src/backend/variables/builtin/quote.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

"use strict";
const quoteManager = require("../../quotes/quotes-manager");
const commandsManager = require("../../chat/commands/CommandManager");
const moment = require("moment");
const logger = require("../../logwrapper");

const { OutputDataType, VariableCategory } = require("../../../shared/variable-constants");
Expand All @@ -20,6 +22,8 @@ const model = {
possibleDataOutput: [OutputDataType.TEXT]
},
evaluator: async (_, quoteId) => {
const quoteCommand = commandsManager.getSystemCommandById("firebot:quotesmanagement");
const quoteDateFormat = quoteCommand.definition.options.quoteDateFormat.value;
let quote;
quoteId = parseInt(quoteId);

Expand All @@ -32,10 +36,9 @@ const model = {
}

if (quote != null) {
const ts = new Date(quote.createdAt);
const timestamp = ts.toLocaleString();
const date = moment(quote.createdAt).format(quoteDateFormat);
const quoteText = decodeURIComponent(quote.text);
const quoteString = quoteText + ' - ' + quote.originator + '. [' + quote.game + '] - ' + timestamp;
const quoteString = quoteText + ' - ' + quote.originator + '. [' + quote.game + '] - ' + date;
logger.debug("Found a quote!");
return quoteString;
}
Expand Down

0 comments on commit 3f6b586

Please sign in to comment.