Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added !patchnotes command #121

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/commands/implementations/patchnotes.js
Original file line number Diff line number Diff line change
@@ -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);
2 changes: 2 additions & 0 deletions lib/configuration/configure-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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']);
Expand Down
11 changes: 10 additions & 1 deletion lib/configuration/sample.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"cookieToken": "yourCookieToken",
"botNick": "yourBotNick"
},
"scheduledCommands":["!youtube", "!schedule"],
"scheduledCommands": ["!youtube", "!schedule"],
"logger": {
"logToFile": false
},
Expand Down Expand Up @@ -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"
}
}
20 changes: 20 additions & 0 deletions lib/services/github.js
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 2 additions & 0 deletions lib/services/service-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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();
Expand Down