From 183b2f5c3c42a3fcc404c4f3c1d6cc4a0a011b75 Mon Sep 17 00:00:00 2001 From: tenacious210 Date: Wed, 21 Dec 2022 08:39:19 -0500 Subject: [PATCH 1/2] Added !patchnotes --- lib/commands/implementations/patchnotes.js | 18 ++++++++++++++++++ lib/configuration/configure-commands.js | 2 ++ lib/configuration/sample.config.json | 16 ++++++++++++++-- lib/services/github.js | 20 ++++++++++++++++++++ lib/services/service-index.js | 2 ++ 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 lib/commands/implementations/patchnotes.js create mode 100644 lib/services/github.js diff --git a/lib/commands/implementations/patchnotes.js b/lib/commands/implementations/patchnotes.js new file mode 100644 index 0000000..2748c44 --- /dev/null +++ b/lib/commands/implementations/patchnotes.js @@ -0,0 +1,18 @@ +const moment = require('moment'); +const formatDuration = require('../../chat-utils/format-duration'); +const Command = require('../command-interface'); +const CommandOutput = require('../command-output'); + +function patchnotes(input, services) { + return services.GithubApi.getGuiReleaseInfo().then((data) => { + const now = moment(); + const releaseVersion = data.name; + const publishedAt = data.published_at; + const releaseUrl = data.html_url; + const publishedDuration = formatDuration(moment.duration(now.diff(publishedAt))); + const reply = `Chat gui ${releaseVersion} released ${publishedDuration} ago. ${releaseUrl}`; + return new CommandOutput(null, reply); + }); +} + +module.exports = new Command(patchnotes, true, false, null); diff --git a/lib/configuration/configure-commands.js b/lib/configuration/configure-commands.js index 5a2f619..21592ea 100644 --- a/lib/configuration/configure-commands.js +++ b/lib/configuration/configure-commands.js @@ -20,6 +20,7 @@ const { addban, addmute } = require('../commands/implementations/banphrase'); const unbanphrase = require('../commands/implementations/unbanphrase'); const live = require('../commands/implementations/live'); const restart = require('../commands/implementations/restart'); +const patchnotes = require('../commands/implementations/patchnotes'); const love = require('../commands/implementations/love'); const { startNewThread, @@ -71,6 +72,7 @@ function registerCommandsFromFiles(commandRegistry, chatConnectedTo, config) { commandRegistry.registerCommand('!deleteban', unbanphrase, ['!deletemute', '!dmute', '!dban']); commandRegistry.registerCommand('!live', live, ['!uptime']); commandRegistry.registerCommand('!restart', restart); + commandRegistry.registerCommand('!patchnotes', patchnotes); commandRegistry.registerCommand('!love', love); commandRegistry.registerCommand('!duo', getDuo); commandRegistry.registerCommand('!ud', updateDuo, ['!updateduo', '!duoupdate']); diff --git a/lib/configuration/sample.config.json b/lib/configuration/sample.config.json index a257ba3..4586662 100644 --- a/lib/configuration/sample.config.json +++ b/lib/configuration/sample.config.json @@ -7,7 +7,10 @@ "cookieToken": "yourCookieToken", "botNick": "yourBotNick" }, - "scheduledCommands":["!youtube", "!schedule"], + "scheduledCommands": [ + "!youtube", + "!schedule" + ], "logger": { "logToFile": false }, @@ -123,5 +126,14 @@ }, "dggApi": { "url": "https://www.destiny.gg/api/info/stream" + }, + "redditVote": { + "enabled": false, + "scriptPath": "", + "threadFilePath": "", + "stateStoreFilePath": "" + }, + "githubApi": { + "gui_url": "https://api.github.com/repos/destinygg/chat-gui/releases/latest" } -} +} \ No newline at end of file diff --git a/lib/services/github.js b/lib/services/github.js new file mode 100644 index 0000000..ca79b75 --- /dev/null +++ b/lib/services/github.js @@ -0,0 +1,20 @@ +const axios = require('axios').default; +const _ = require('lodash'); + +class GithubApi { + constructor(config, logger) { + this.config = config; + this.logger = logger; + } + + getGuiReleaseInfo() { + return axios + .get(this.config.gui_url) + .then((response) => { + return response.data; + }) + .catch((err) => this.logger.error('Error retrieving data from github api.', err)); + } +} + +module.exports = GithubApi; \ No newline at end of file diff --git a/lib/services/service-index.js b/lib/services/service-index.js index 58aa022..b146771 100644 --- a/lib/services/service-index.js +++ b/lib/services/service-index.js @@ -16,6 +16,7 @@ const DggApi = require('./dgg-api'); const TwitterApi = require('./twitter-api'); const FakeScheduler = require('./fake-command-scheduler'); const RedditVote = require('./reddit-vote'); +const GithubApi = require('./github') const MessageRelay = require('./message-relay'); const messageMatchingService = require('./message-matching'); const HTMLMetadata = require('./html-metadata'); @@ -45,6 +46,7 @@ class Services { this.fakeScheduler = new FakeScheduler(serviceConfigurations.schedule); this.dggApi = new DggApi(serviceConfigurations.dggApi, this.logger); this.twitterApi = new TwitterApi(serviceConfigurations.twitter, this.logger); + this.GithubApi = new GithubApi(serviceConfigurations.githubApi, this.logger) this.messageRelay = new MessageRelay(); this.messageMatching = messageMatchingService; this.htmlMetadata = new HTMLMetadata(); From 1e547fb0e567bb82df19a0bda09bcae6e4136357 Mon Sep 17 00:00:00 2001 From: tenacious210 Date: Wed, 21 Dec 2022 09:10:42 -0500 Subject: [PATCH 2/2] Format with Prettier --- lib/commands/implementations/patchnotes.js | 18 +++++++-------- lib/configuration/sample.config.json | 7 ++---- lib/services/github.js | 26 +++++++++++----------- lib/services/service-index.js | 4 ++-- 4 files changed, 26 insertions(+), 29 deletions(-) diff --git a/lib/commands/implementations/patchnotes.js b/lib/commands/implementations/patchnotes.js index 2748c44..94a4274 100644 --- a/lib/commands/implementations/patchnotes.js +++ b/lib/commands/implementations/patchnotes.js @@ -4,15 +4,15 @@ const Command = require('../command-interface'); const CommandOutput = require('../command-output'); function patchnotes(input, services) { - return services.GithubApi.getGuiReleaseInfo().then((data) => { - const now = moment(); - const releaseVersion = data.name; - const publishedAt = data.published_at; - const releaseUrl = data.html_url; - const publishedDuration = formatDuration(moment.duration(now.diff(publishedAt))); - const reply = `Chat gui ${releaseVersion} released ${publishedDuration} ago. ${releaseUrl}`; - return new CommandOutput(null, reply); - }); + return services.GithubApi.getGuiReleaseInfo().then((data) => { + const now = moment(); + const releaseVersion = data.name; + const publishedAt = data.published_at; + const releaseUrl = data.html_url; + const publishedDuration = formatDuration(moment.duration(now.diff(publishedAt))); + const reply = `Chat gui ${releaseVersion} released ${publishedDuration} ago. ${releaseUrl}`; + return new CommandOutput(null, reply); + }); } module.exports = new Command(patchnotes, true, false, null); diff --git a/lib/configuration/sample.config.json b/lib/configuration/sample.config.json index 4586662..00f585c 100644 --- a/lib/configuration/sample.config.json +++ b/lib/configuration/sample.config.json @@ -7,10 +7,7 @@ "cookieToken": "yourCookieToken", "botNick": "yourBotNick" }, - "scheduledCommands": [ - "!youtube", - "!schedule" - ], + "scheduledCommands": ["!youtube", "!schedule"], "logger": { "logToFile": false }, @@ -136,4 +133,4 @@ "githubApi": { "gui_url": "https://api.github.com/repos/destinygg/chat-gui/releases/latest" } -} \ No newline at end of file +} diff --git a/lib/services/github.js b/lib/services/github.js index ca79b75..612ec08 100644 --- a/lib/services/github.js +++ b/lib/services/github.js @@ -2,19 +2,19 @@ const axios = require('axios').default; const _ = require('lodash'); class GithubApi { - constructor(config, logger) { - this.config = config; - this.logger = logger; - } + constructor(config, logger) { + this.config = config; + this.logger = logger; + } - getGuiReleaseInfo() { - return axios - .get(this.config.gui_url) - .then((response) => { - return response.data; - }) - .catch((err) => this.logger.error('Error retrieving data from github api.', err)); - } + getGuiReleaseInfo() { + return axios + .get(this.config.gui_url) + .then((response) => { + return response.data; + }) + .catch((err) => this.logger.error('Error retrieving data from github api.', err)); + } } -module.exports = GithubApi; \ No newline at end of file +module.exports = GithubApi; diff --git a/lib/services/service-index.js b/lib/services/service-index.js index b146771..d546f8e 100644 --- a/lib/services/service-index.js +++ b/lib/services/service-index.js @@ -16,7 +16,7 @@ const DggApi = require('./dgg-api'); const TwitterApi = require('./twitter-api'); const FakeScheduler = require('./fake-command-scheduler'); const RedditVote = require('./reddit-vote'); -const GithubApi = require('./github') +const GithubApi = require('./github'); const MessageRelay = require('./message-relay'); const messageMatchingService = require('./message-matching'); const HTMLMetadata = require('./html-metadata'); @@ -46,7 +46,7 @@ class Services { this.fakeScheduler = new FakeScheduler(serviceConfigurations.schedule); this.dggApi = new DggApi(serviceConfigurations.dggApi, this.logger); this.twitterApi = new TwitterApi(serviceConfigurations.twitter, this.logger); - this.GithubApi = new GithubApi(serviceConfigurations.githubApi, this.logger) + this.GithubApi = new GithubApi(serviceConfigurations.githubApi, this.logger); this.messageRelay = new MessageRelay(); this.messageMatching = messageMatchingService; this.htmlMetadata = new HTMLMetadata();