diff --git a/lib/commands/implementations/patchnotes.js b/lib/commands/implementations/patchnotes.js new file mode 100644 index 0000000..94a4274 --- /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..00f585c 100644 --- a/lib/configuration/sample.config.json +++ b/lib/configuration/sample.config.json @@ -7,7 +7,7 @@ "cookieToken": "yourCookieToken", "botNick": "yourBotNick" }, - "scheduledCommands":["!youtube", "!schedule"], + "scheduledCommands": ["!youtube", "!schedule"], "logger": { "logToFile": false }, @@ -123,5 +123,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" } } diff --git a/lib/services/github.js b/lib/services/github.js new file mode 100644 index 0000000..612ec08 --- /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; diff --git a/lib/services/service-index.js b/lib/services/service-index.js index 58aa022..d546f8e 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();