This repository has been archived by the owner on Jan 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adding a pipe (#55) * adding a pipe * i think i got it? * Fix a Null like mistake, thanks to me misreading discord docs * Fix visual glitch * Remove extra info. * Fix timestamp, was done incorrectly first time through * Top 10 suggestions and version 0.0.3 because why not * i dont trust UV with dates * rip linebreaks again * Respond when regenerating is done * Whoops * Revert discordie requirement rip dev version, you will be missed :c * I suck at grammar * be gone 404 error logging
- Loading branch information
Showing
7 changed files
with
153 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
var Entities = require('html-entities').AllHtmlEntities | ||
var config = require('../../config.js') | ||
const entities = new Entities() | ||
const Dash = require('rethinkdbdash') | ||
const r = new Dash() | ||
|
||
var commands = [] | ||
|
||
commands.initializeTop = { | ||
internal: true, | ||
fn: function (bot, uv) { | ||
setInterval(() => generateTop(bot, uv), 3600000) // update the top 10 hourly | ||
} | ||
} | ||
|
||
commands.regenerate = { | ||
adminOnly: true, | ||
modOnly: false, | ||
fn: function (bot, msg, suffix, uv) { | ||
msg.reply('regenerating the top 10, this could take a while...').then((msg) => { | ||
generateTop(bot, uv).then(() => { | ||
msg.edit('Done! You can check the results at <#268812972401360906>') | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
function generateTop (bot, uv) { | ||
return new Promise(function(resolve, reject) { | ||
let channel = bot.Channels.find(c => c.name === 'top-10-suggestions') | ||
let messages | ||
channel.fetchMessages().then(msgs => { | ||
messages = msgs.messages.filter(y => y.author.id === bot.User.id) | ||
}) | ||
uv.v1.loginAsOwner().then(f => { | ||
f.get(`forums/${config.uservoice.forumId}/suggestions.json`).then(data => { | ||
for (let suggestion of data.suggestions) { | ||
generateEmbed(suggestion).then(embed => { | ||
let message = messages.pop() | ||
if (!message) { | ||
channel.sendMessage('', false, embed).then(msg => { | ||
r.db('DFB').table('queue').insert({ | ||
id: msg.id, | ||
type: 'upvoteOnly', | ||
UvId: suggestion.id | ||
}).then(() => { | ||
msg.addReaction({ | ||
id: '302138464986595339', | ||
name: 'upvote' | ||
}) | ||
}) | ||
}) | ||
} else { | ||
message.edit('', embed).then(msg => { | ||
r.db('DFB').table('queue').get(msg.id).update({ | ||
type: 'upvoteOnly', | ||
UvId: suggestion.id | ||
}) | ||
}) | ||
} | ||
}) | ||
} | ||
return resolve() | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
function generateEmbed (data) { | ||
return new Promise(function(resolve, reject) { | ||
try { | ||
let embedFields = (data.response) ? [{ | ||
name: data.status ? `${entities.decode(data.status_changed_by.name)} set the status to ${entities.decode(data.status.name)}` : `${entities.decode(data.status_changed_by.name)} responded:`, | ||
value: (data.response) ? entities.decode(data.response.text).length > 2000 ? '*Content too long, check the feedback website instead.*' : entities.decode(data.response.text) : 'No comment', | ||
inline: false | ||
}, { | ||
name: "Votes", | ||
value: data.vote_count, | ||
inline: false | ||
}] : [{ | ||
name: "Votes", | ||
value: data.vote_count, | ||
inline: false | ||
}] | ||
return resolve({ | ||
title: entities.decode(data.title), | ||
description: entities.decode(data.text).length > 2000 ? '*Content too long, check the feedback website instead.*' : entities.decode(data.text), | ||
url: data.url, | ||
timestamp: new Date(data.created_at), | ||
color: (data.status) ? parseInt(data.status.hex_color.substr(1), 16) : 0x595f68, | ||
footer: { | ||
text: (data.topic.forum.name) ? entities.decode(data.topic.forum.name) : 'Uncategorised' | ||
}, | ||
author: { | ||
name: entities.decode(data.creator.name), | ||
url: data.creator.url, | ||
icon_url: data.creator.avatar_url | ||
}, | ||
fields: embedFields | ||
}) | ||
} catch (e) { | ||
return reject(e) | ||
} | ||
}) | ||
} | ||
|
||
exports.Commands = commands |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,4 +158,4 @@ commands.shutdown = { | |
} | ||
} | ||
|
||
exports.Commands = commands | ||
exports.Commands = commands |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters