From 86d0a6f31b4a3b5861779d4a1e0e288c11938ab2 Mon Sep 17 00:00:00 2001 From: Scritches Date: Sat, 14 Apr 2018 13:38:28 -0400 Subject: [PATCH 1/4] Link module title regexp fix Fix for sites that use <\/title> instead of to close their title elements. --- modules/link/link.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/link/link.js b/modules/link/link.js index b400680..2d077ab 100644 --- a/modules/link/link.js +++ b/modules/link/link.js @@ -27,7 +27,7 @@ var link = function(dbot) { page = request(link.replace('https', 'http'), function(error, response, body) { if(!error && response.statusCode == 200) { body = body.replace(/(\r\n|\n\r|\n)/gim, " "); - var title = body.valMatch(/(.*?)<\/title>/, 2); + var title = body.valMatch(/<title>(.*?)<\\?\/title>/, 2); if(title && title.length < 140) { callback(ent.decode(title[1]).trim()); } From 11a7f1d20e202f82d2cd5e677e80f485a990e9a6 Mon Sep 17 00:00:00 2001 From: Scritches <dzscritches@gmail.com> Date: Sat, 14 Apr 2018 14:01:36 -0400 Subject: [PATCH 2/4] Fix ~lastfm registered date display --- modules/lastfm/lastfm.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/lastfm/lastfm.js b/modules/lastfm/lastfm.js index 91e6a5b..9aa254d 100644 --- a/modules/lastfm/lastfm.js +++ b/modules/lastfm/lastfm.js @@ -155,7 +155,7 @@ var lastfm = function(dbot) { event.reply(dbot.t('lfm_profile', { 'user': user.currentNick, 'plays': profile.playcount.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"), - 'date': moment(profile.registered['#text']).format('DD/MM/YYYY'), + 'date': moment(profile.registered['#text'] * 1000).format('DD/MM/YYYY'), 'link': profile.url })); } else { From 2d20f19572130c8953e3794ab16bb67f20b3dd5c Mon Sep 17 00:00:00 2001 From: Scritches <dzscritches@gmail.com> Date: Sat, 14 Apr 2018 14:54:23 -0400 Subject: [PATCH 3/4] Fix for lingering votequiets --- modules/kick/commands.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/kick/commands.js b/modules/kick/commands.js index 2e2fd13..71308a3 100644 --- a/modules/kick/commands.js +++ b/modules/kick/commands.js @@ -297,7 +297,7 @@ var commands = function(dbot) { event.reply(orderedKickLeague(dbot.db.kicks, 'Kicked')); event.reply(orderedKickLeague(dbot.db.kickers, 'Kickers')); }, - + '~votequiet': function(event) { var target = event.input[1], reason = event.input[2]; @@ -353,6 +353,11 @@ var commands = function(dbot) { if(vq.yes.length == 4) { event.reply('Attempt to quiet ' + target + ' succeeded. Count: Yes (' + vq.yes.length + '). No (' + vq.no.length + ').'); this.api.quietUser(event.server, event.rUser, '10m', event.channel, target, reason + '[votequiet]', function(response) { + clearTimeout(vq.timer); + vq.spent = true; + setTimeout(function() { + delete this.voteQuiets[user.id]; + }.bind(this), 600000); event.reply(response); }); } @@ -391,6 +396,10 @@ var commands = function(dbot) { event.reply('Attempt to quiet ' + target + ' succeeded. Count: Yes (' + vq.yes.length + '). No (' + vq.no.length + ').'); this.api.quietUser(event.server, event.rUser, '10m', event.channel, target, vq.reason + '[votequiet]', function(response) { clearTimeout(vq.timer); + vq.spent = true; + setTimeout(function() { + delete this.voteQuiets[user.id]; + }.bind(this), 600000); event.reply(response); }); } From 97642f35a9cc94e3d159effa67d1b4449b661e31 Mon Sep 17 00:00:00 2001 From: Scritches <dzscritches@gmail.com> Date: Sat, 14 Apr 2018 15:07:26 -0400 Subject: [PATCH 4/4] Got rid of all the const But muh self-documenting code :'( --- modules/goodreads/goodreads.js | 43 +++++++++++++++++----------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/modules/goodreads/goodreads.js b/modules/goodreads/goodreads.js index 46b2bee..c238052 100644 --- a/modules/goodreads/goodreads.js +++ b/modules/goodreads/goodreads.js @@ -3,12 +3,12 @@ * Description: Interacts with the GoodReads API to provide book-oriented functionality to dbot */ -const util = require('util'), +var util = require('util'), _ = require('underscore')._, rp = require('request-promise-native'), parseString = util.promisify(require('xml2js').parseString); -const GoodReads = function(dbot) { +var GoodReads = function(dbot) { this.apiRoot = 'https://www.goodreads.com'; this.internalAPI = { @@ -37,7 +37,7 @@ const GoodReads = function(dbot) { this.api = { 'findBook': async term => { //https://www.goodreads.com/search/index.xml - const body = await rp({ + var body = await rp({ uri: this.apiRoot + '/search/index.xml', qs: { key: this.config.api_key, @@ -45,10 +45,10 @@ const GoodReads = function(dbot) { } }); - const response = await parseString(body, { explicitArray: false }); + var response = await parseString(body, { explicitArray: false }); if(!_.has(response, 'GoodreadsResponse')) throw 'goodreads-error'; - const result = response.GoodreadsResponse.search.results; + var result = response.GoodreadsResponse.search.results; if(!result || !_.has(result, 'work')) throw 'book-not-found'; if(!result.work[0]) throw 'book-not-found'; @@ -62,7 +62,7 @@ const GoodReads = function(dbot) { 'getSummaryForBook': async id => { //https://www.goodreads.com/book/show.xml - const body = await rp({ + var body = await rp({ uri: this.apiRoot + '/book/show.xml', qs: { key: this.config.api_key, @@ -70,10 +70,10 @@ const GoodReads = function(dbot) { } }); - const response = await parseString(body, { explicitArray: false }); + var response = await parseString(body, { explicitArray: false }); if(!_.has(response, 'GoodreadsResponse')) throw 'goodreads-error'; - const result = response.GoodreadsResponse.book; + var result = response.GoodreadsResponse.book; if(!result) throw 'book-not-found'; if(!_.has(result, 'description')) throw 'no-description'; @@ -82,17 +82,17 @@ const GoodReads = function(dbot) { 'findAuthor': async term => { //https://www.goodreads.com/api/author_url/<ID> - const body = await rp({ + var body = await rp({ url: this.apiRoot + '/api/author_url/' + term, qs: { key: this.config.api_key } }); - const response = await parseString(body, {explicitArray: false }); + var response = await parseString(body, {explicitArray: false }); if(!_.has(response, 'GoodreadsResponse')) throw 'goodreads-error'; - const result = response.GoodreadsResponse.author; + var result = response.GoodreadsResponse.author; if(!result) throw 'author-not-found'; return { @@ -121,10 +121,10 @@ const GoodReads = function(dbot) { throw e; } - const response = await parseString(body, { explicitArray: false }); + var response = await parseString(body, { explicitArray: false }); if(!_.has(response, 'GoodreadsResponse')) throw 'goodreads-error'; - const result = response.GoodreadsResponse.user; + var result = response.GoodreadsResponse.user; if(!result) throw 'user-not-found'; return this.internalAPI.formatProfile(result); @@ -150,10 +150,10 @@ const GoodReads = function(dbot) { throw e; } - const response = await parseString(body, { explicitArray: false }); + var response = await parseString(body, { explicitArray: false }); if(!_.has(response, 'GoodreadsResponse')) throw 'goodreads-error'; - const result = response.GoodreadsResponse.user; + var result = response.GoodreadsResponse.user; if(!result) throw 'user-not-found'; return this.internalAPI.formatProfile(result); @@ -171,7 +171,7 @@ const GoodReads = function(dbot) { } }); - const response = await parseString(body, { explicitArray: false }); + var response = await parseString(body, { explicitArray: false }); if(!_.has(response, 'GoodreadsResponse')) throw 'goodreads-error'; let result = response.GoodreadsResponse.reviews.review; @@ -193,7 +193,7 @@ const GoodReads = function(dbot) { this.commands = { '~book' : async evt => { try { - const book = await this.api.findBook(evt.input[1]); + var book = await this.api.findBook(evt.input[1]); evt.reply(dbot.t('gr_book', { author: book.author, title: book.title, @@ -206,9 +206,8 @@ const GoodReads = function(dbot) { '~booksummary': async evt => { try { - console.log(evt.input[1]); - const book = await this.api.findBook(evt.input[1]); - const summary = await this.api.getSummaryForBook(book.id); + var book = await this.api.findBook(evt.input[1]); + var summary = await this.api.getSummaryForBook(book.id); evt.reply(dbot.t('gr_summary', { title: book.title, summary: summary, @@ -228,7 +227,7 @@ const GoodReads = function(dbot) { '~reading': async (evt, profile) => { try { let books = await this.api.getShelfForUserId(profile.id, 'currently-reading'); - const booksCount = books.length; + var booksCount = books.length; if(!booksCount) { evt.reply(dbot.t('gr_not_reading', { user: evt.rUser.currentNick })); return; @@ -259,7 +258,7 @@ const GoodReads = function(dbot) { _.each(this.commands, ((cmd, cmdName) => { if(cmd.requiresProfile) { this.commands[cmdName] = (async evt => { - const grUsername = evt.rProfile.goodreads; + var grUsername = evt.rProfile.goodreads; if(!grUsername) { evt.reply(evt.rUser.currentNick + ': Set a Goodreads username with "~set goodreads username"');