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.2 (#53)
Browse files Browse the repository at this point in the history
* Update dependencies

* Update eslint config

Seems that some of the stuff I've set has been borked for awhile, tis' what I get for not reading about it properly. Anyways its fixed now.

* Make bugsnag more useful & easier to use

It's amazing what a bit of configuration can do.

* Actually fix eslint

We all make mistakes, maybe next time it wouldn't be me.

* Fix the indenting

* Fix access_checker (#44)

* Fix eslint conf formatting

* add feature to use previously used link (with "-") (#48)

* add feature to use previously used link (with "-")

* fix

* !info command (#32)

* !info command

So I made a !info command which takes either Username#Discrim, a mention or even a discord ID and gives you info on that user on UV. It even lets you get their UV profile by Discord User ID if they arent on the server.
Even better it shouldn't have syntax errors because I used Visual Studio now
Even better I might add it showing stuff like the latest Upvote and Suggestion
EEEEEven better you get to test it because I can't :^)

* Format since @LW001 can't

* Color thing changed

Lol mobile code editing

* Made the if larger

More mobile editing please

* ESLint Fix some things

It was a christmas tree, still is a bit.

* Fixed the method that's not a method to be no method

https://youtu.be/nX7CeTXoxyU

* Fix the foreach

* Parts rewritten, added last upvoted and submitted

* done teaman

next

* Bump for travis

* shut travis up

* Complete rewrite of !info

Whew laddy. Works on staging now.

* Revert "Merge branch 'develop' into patch-3"

This reverts commit 246bc0f.

* Style fix

* nice typo @LW001

* Update package.json

* Analytics database handler

* Final commit for analytics collection

* heheh

* Don't allow submitting the same card 2 times

* Make the data for info more readable.

I actually tested to ensure it would convert and output correctly.

* Change last submmited suggestion to last touched

Need to reflect what it actually it is.

* Experimental: Calculate consecutive days

* Cache depends on travis

* Properly count consecutive days

* !info username#discrim fix (#52)

* Stats command

This only returns your own stats, an admin version to return the stats of someone else is coming later.

* lookup command

This is for admins to lookup someone elses stats

* Version bump

* Log error body instead

* Make date even more proper using moment

got to make everything pretty,
  • Loading branch information
Dougley committed Jul 10, 2017
1 parent 84a5fad commit 61aaf85
Show file tree
Hide file tree
Showing 9 changed files with 1,225 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: node_js
node_js:
- "7"

install:
- npm install
cache: npm install

script:
- npm run lint
10 changes: 7 additions & 3 deletions Commands/Commands/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ commands.dupe = {
return
}
}
if (id === id2) {
msg.reply('you cannot merge 2 of the same suggestions.')
return
}
uv.v1.loginAsOwner().then(c => {
c.get(`forums/${config.uservoice.forumId}/suggestions/${id}.json`).then((data) => {
c.get(`forums/${config.uservoice.forumId}/suggestions/${id2}.json`).then((data2) => {
Expand Down Expand Up @@ -480,10 +484,10 @@ commands.registerVote = {
bot.Channels.find(c => c.name === 'admin-queue').sendMessage(`The report for ${doc.embed.title} has been approved, the card has been merged.`).then(o => {
setTimeout(() => bot.Messages.deleteMessages([o.id, msg.id], bot.Channels.find(c => c.name === 'admin-queue').id), config.timeouts.messageDelete)
})
merge(doc.UV1, doc.UV2, uv).catch((e) => {
merge(doc.UV1, doc.UV2, uv).catch((e, body) => {
logger.log(bot, {
cause: 'merge_apply',
message: e.message
message: body
}, e)
})
r.db('DFB').table('queue').get(doc.id).delete().run().catch(bugsnag.nofify)
Expand Down Expand Up @@ -518,7 +522,7 @@ function merge (target, dupe, uv) {
.send(`action.notify_supporters=false&action.reply_to=&action.links.to_suggestion=${dupe}&include_ids=${target}`)
.set('Authorization', 'Bearer ' + client.accessToken)
.end((err, res) => {
if (err || res.statusCode !== 200) return reject(err)
if (err || res.statusCode !== 200) return reject(err, res.body)
else return resolve(res)
})
})
Expand Down
16 changes: 8 additions & 8 deletions Commands/Commands/uservoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ 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 All @@ -280,12 +281,7 @@ commands.info = {
inline: true
},
{
name: 'First UserVoice Login',
value: data.user.created_at,
inline: true
},
{
name: 'Last Submitted Suggestion',
name: 'Last Suggestion Interacted with',
value: `[${latestSuggTitle}](${latestSuggLink})`,
inline: true
},
Expand All @@ -294,7 +290,11 @@ commands.info = {
value: dcuser,
inline: false
}
]
],
footer: {
text: 'User created on ' + moment('2015-11-18T23:52:49.000Z').format("dddd, MMMM Do YYYY, k:mm:ss"),
icon_url: data.user.avatar_url
}
})
}).catch(() => {}) // Make bugsnag ignore it, error handling below
}).catch(() => {
Expand All @@ -317,7 +317,7 @@ commands.info = {
} else if (suffix.match(/(.{2,32}#\d{4})/g)) { // NAME#DISCRIM given? Search for user in server and set User ID
let namedisc = suffix.match(/(.{2,32})#(\d{4})/g)[0]
let member = msg.guild.members.find(member => member.username === namedisc[1] && member.discriminator === namedisc[2])
if (userid) {
if (member) {
userid = member.id
} else { // Can't find user by that? Abort mission
return msg.reply(`Unable to find a user named ${suffix}. The user has to be in this server for using NAME#DISCRIM search. Use a Discord or UserVoice ID.`).then(errMsg => {
Expand Down
106 changes: 106 additions & 0 deletions Commands/Commands/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var commands = []
// var checker = require('../../Utils/access_checker')
// var logger = require('../../Utils/error_loggers')
var config = require('../../config.js')
var analytics = require('../../Utils/orwell.js')
var bugsnag = require('bugsnag')

bugsnag.register(config.discord.bugsnag)
Expand All @@ -28,6 +29,111 @@ commands.help = {
}
}

commands.stats = {
adminOnly: false,
modOnly: false,
fn: function (bot, msg) {
msg.channel.sendTyping()
let moment = require('moment') // forgive me father for i have sinned
analytics.getPoints(msg.member.id).then(data => {
if (data === null) return msg.reply("you don't have any stats registered right now.")
let now = new Date()
let today = new Date(now.getFullYear(), now.getUTCMonth(), now.getUTCDate()).getTime()
let messagesField = []
let commandsField = []
for (let date in data.messages) {
if (today - parseInt(date) <= 172800000) {
let parsed = moment(parseInt(date)).format("MMM Do YYYY")
messagesField.push({
name: `Messages on ${parsed}`,
value: data.messages[date],
inline: true
})
}
if (messagesField.length === 3) break
}
for (let date in data.commands) {
if (today - parseInt(date) <= 172800000) {
let parsed = moment(parseInt(date)).format("MMM Do YYYY")
commandsField.push({
name: `Commands on ${parsed}`,
value: data.messages[date],
inline: false
})
if (commandsField.length === 3) break
}
}
commandsField.push({
name: `Consecutive active days`,
value: data.consecutive.length,
inline: true
})
msg.channel.sendMessage('', false, {
color: 0x59f442,
title: `${msg.author.username} - Statistics`,
thumbnail: {
url: msg.author.avatarURL
},
fields: messagesField.concat(commandsField)
})
}).catch(e => {
msg.reply('an unexpected error occured while getting your stats, try again later.')
console.error(e)
})
}
}

commands.lookup = {
adminOnly: true,
modOnly: false,
fn: function (bot, msg, suffix) {
msg.channel.sendTyping()
let moment = require('moment') // forgive me father for i have sinned
analytics.getPoints(suffix).then(data => {
if (data === null) return msg.reply("couldn't find data on this user.")
let now = new Date()
let today = new Date(now.getFullYear(), now.getUTCMonth(), now.getUTCDate()).getTime()
let messagesField = []
let commandsField = []
for (let date in data.messages) {
if (today - parseInt(date) <= 172800000) {
let parsed = moment(parseInt(date)).format("MMM Do YYYY")
messagesField.push({
name: `Messages on ${parsed}`,
value: data.messages[date],
inline: true
})
}
if (messagesField.length === 3) break
}
for (let date in data.commands) {
if (today - parseInt(date) <= 172800000) {
let parsed = moment(parseInt(date)).format("MMM Do YYYY")
commandsField.push({
name: `Commands on ${parsed}`,
value: data.messages[date],
inline: false
})
if (commandsField.length === 3) break
}
}
commandsField.push({
name: `Consecutive active days`,
value: data.consecutive.length,
inline: false
})
msg.channel.sendMessage('', false, {
color: 0x59f442,
title: `Statistics for ${suffix}`,
fields: messagesField.concat(commandsField)
})
}).catch(e => {
msg.reply('an unexpected error occured while getting your stats, try again later.')
console.error(e)
})
}
}

commands.fetch = {
phantom: true,
adminOnly: true,
Expand Down
4 changes: 2 additions & 2 deletions Utils/generic_logger.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// const Analytics = require('./analytics.js')
const Analytics = require('./orwell.js')

exports.log = function (bot, user, cObj) {
var fields = []
if (cObj.result !== undefined) fields.push({name: 'This resulted in the following:', value: cObj.result, inline: false})
if (cObj.affected !== undefined) fields.push({name: 'This affected the following cards:', value: cObj.affected, inline: false})
// if (cObj.awardPoints === true) Analytics.log(cObj)
if (cObj.awardPoints === true) Analytics.awardPoints(user.id, 'commands')
bot.Channels.find((c) => c.name === 'bot-log').sendMessage('', false, {
color: 0x3498db,
author: {
Expand Down
37 changes: 37 additions & 0 deletions Utils/orwell.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const Dash = require('rethinkdbdash')
const r = new Dash()

module.exports = {
awardPoints: (user, type) => {
return new Promise((resolve, reject) => {
let now = new Date()
let today = new Date(now.getFullYear(), now.getUTCMonth(), now.getUTCDate()).getTime()
let consecutive
r.db('DFB').table('analytics').get(user).then(o => {
if (o === null) return r.db('DFB').table('analytics').insert({
id: user,
consecutive: []
})
consecutive = o.consecutive !== undefined ? o.consecutive : [today.toString()]
if (consecutive.indexOf(today.toString()) === -1) {
let last = new Date(parseInt(consecutive[consecutive.length -1]))
let difference = today - last
if (difference === 86400000) { // 1 day difference
consecutive.push(today.toString())
} else {
consecutive = [today.toString()]
}
}
r.db('DFB').table('analytics').get(user).update({
[type]: { [today]: r.row(type)(today.toString()).default(0).add(1) },
consecutive: consecutive
}).run().then(resolve).catch(reject)
})
})
},
getPoints: (user) => {
return new Promise((resolve, reject) => {
r.db('DFB').table('analytics').get(user).run().then(resolve).catch(reject)
})
}
}
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const AccessChecker = require('./Utils/access_checker')
const ErrorLog = require('./Utils/error_loggers')
const GenericLog = require('./Utils/generic_logger')
const woofmeow = require('./Utils/woofmeow')
const Analytics = require('./Utils/orwell')
const bot = new Discordie({
autoReconnect: true
})
Expand Down Expand Up @@ -48,6 +49,7 @@ var uvClient = {
}

bot.Dispatcher.on(Events.MESSAGE_CREATE, (c) => {
if (c.message.isPrivate === true) return
if (c.message.channel.id !== Config.discord.feedChannel && c.message.content.match(UVRegex) !== null && c.message.content.indexOf(Config.discord.prefix) !== 0) {
let parts = c.message.content.match(UVRegex)
Commands['chatVoteInit'].fn(c.message, parts[2], uvClient)
Expand All @@ -56,7 +58,9 @@ bot.Dispatcher.on(Events.MESSAGE_CREATE, (c) => {
Commands['newCardInit'].fn(c.message)
return
}
if (c.message.isPrivate === true) return
if (!c.message.author.bot) {
Analytics.awardPoints(c.message.author.id, 'messages')
}
if (c.message.content.indexOf(Config.discord.prefix) === 0) {
var cmd = c.message.content.substr(Config.discord.prefix.length).split(' ')[0].toLowerCase()
var suffix
Expand All @@ -75,7 +79,8 @@ bot.Dispatcher.on(Events.MESSAGE_CREATE, (c) => {
GenericLog.log(bot, c.message.author, {
message: `Ran the command \`${cmd}\``,
result: res.result,
affected: res.affected
affected: res.affected,
awardPoints: true
})
})
} catch (e) {
Expand Down
Loading

0 comments on commit 61aaf85

Please sign in to comment.