Skip to content
This repository has been archived by the owner on Jan 23, 2018. It is now read-only.

Commit

Permalink
Version 0.0.3 (#60)
Browse files Browse the repository at this point in the history
* 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
Dougley authored Jul 15, 2017
1 parent b78a831 commit b56e272
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 9 deletions.
38 changes: 38 additions & 0 deletions Commands/Commands/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,44 @@ commands.registerVote = {
return
}
switch (doc.type) {
case 'upvoteOnly' : {
if (reaction.id === '302138464986595339') {
getMail(uv, user.id).then(f => {
uv.v1.loginAs(f).then(c => {
c.post(`forums/${config.uservoice.forumId}/suggestions/${doc.UvId}/votes.json`, {
to: 1
}).then((s) => {
if (user !== null) {
genlog.log(bot, user, {
message: 'Top10-voted',
affected: doc.UvId
})
}
}).catch(e => {
if (e.statusCode !== 404) {
logger.log(bot, {
cause: 'top10_vote_apply',
message: (e.message !== undefined) ? e.message : JSON.stringify(e)
}, e)
}
})
}).catch(e => {
logger.log(bot, {
cause: 'login_as',
message: (e.message !== undefined) ? e.message : JSON.stringify(e)
}, e).catch(e => {
if (e !== 'Not found') {
logger.log(bot, {
cause: 'email_search',
message: (e.message !== undefined) ? e.message : JSON.stringify(e)
}, e)
}
})
})
})
}
break
}
case 'chatVote': {
if (reaction.id === '302137374920671233') {
checker.getLevel(user.memberOf('268811439588900865'), function (l) {
Expand Down
107 changes: 107 additions & 0 deletions Commands/Commands/top10.js
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
6 changes: 3 additions & 3 deletions Commands/Commands/uservoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ commands.info = {
}).then(response => {
latestSuggLink = response.suggestions[0].url
latestSuggTitle = response.suggestions[0].title
let moment = require('moment')
return msg.channel.sendMessage(`Information for User ${data.user.name}:`, false, {
color: 0xfc9822,
title: `${data.user.name} - UserVoice`,
Expand Down Expand Up @@ -292,9 +291,10 @@ commands.info = {
}
],
footer: {
text: 'User created on ' + moment(data.user.created_at).format("dddd, MMMM Do YYYY, k:mm:ss"),
text: 'User created on',
icon_url: data.user.avatar_url
}
},
timestamp: new Date(data.user.created_at)
})
}).catch(() => {}) // Make bugsnag ignore it, error handling below
}).catch(() => {
Expand Down
2 changes: 1 addition & 1 deletion Commands/Commands/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,4 @@ commands.shutdown = {
}
}

exports.Commands = commands
exports.Commands = commands
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ bot.Dispatcher.on(Events.GATEWAY_READY, () => {
bot.Users.fetchMembers() // Hacky way to cache offline users, #blamelazyloading
}, 600000)
console.log('Feedback bot is ready!')
Commands['initializeTop'].fn(bot, uvClient)
})

process.on('unhandledRejection', (reason, p) => {
Expand Down
6 changes: 2 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "discord-feedback",
"version": "0.0.2",
"version": "0.0.3",
"description": "Bot for the Discord Feedback server",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit b56e272

Please sign in to comment.