From c5448080bf603a4a10c45908458e3c456f24278b Mon Sep 17 00:00:00 2001 From: reality Date: Sat, 6 Jul 2013 18:45:21 +0000 Subject: [PATCH] record notifies --- modules/report/pages.js | 44 ++++++++++++++++++++++++++++++++++++++ modules/report/report.js | 14 +++++++++++- views/report/channels.jade | 10 +++++++++ views/report/notifies.jade | 21 ++++++++++++++++++ views/report/servers.jade | 10 +++++++++ 5 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 modules/report/pages.js create mode 100644 views/report/channels.jade create mode 100644 views/report/notifies.jade create mode 100644 views/report/servers.jade diff --git a/modules/report/pages.js b/modules/report/pages.js new file mode 100644 index 0000000..8ecc841 --- /dev/null +++ b/modules/report/pages.js @@ -0,0 +1,44 @@ +var _ = require('underscore')._; + +var pages = function(dbot) { + return { + '/notify': function(req, res) { + res.render('servers', { + 'name': dbot.config.name, + 'servers': _.keys(dbot.config.servers) + }); + }, + + '/notify/:server': function(req, res) { + var server = req.params.server; + res.render('channels', { + 'name': dbot.config.name, + 'server': server, + 'channels': _.keys(dbot.instance.servers[server].channels) + }); + }, + + '/notify/:server/:user': function(req, res) { + var server = req.params.server, + channel = req.params.channel, + notifies = []; + + this.db.search('notifies', { + 'server': server, + 'channel': channel + }, function(notify) { + notifies.push(notify); + }, function(err) { + res.render('notifies', { + 'name': dbot.config.name, + 'server': server, + 'notifies': notifies + }); + }); + } + }; +}; + +exports.fetch = function(dbot) { + return pages(dbot); +}; diff --git a/modules/report/report.js b/modules/report/report.js index e123b2e..ceb327c 100644 --- a/modules/report/report.js +++ b/modules/report/report.js @@ -1,4 +1,5 @@ -var _ = require('underscore')._; +var _ = require('underscore')._, + uuid = require('node-uuid'); var report = function(dbot) { this.api = { @@ -56,6 +57,17 @@ var report = function(dbot) { 'notifier': event.user, 'message': message })); + + var id = uuid.v4(); + this.db.save('notifies', id, { + 'id': id, + 'server': event.server, + 'channel': channelName, + 'user': event.user, + 'time': new Date().getTime(), + 'message': message + }, function() {}); + event.reply(dbot.t('notified', { 'user': event.user, 'channel': channelName diff --git a/views/report/channels.jade b/views/report/channels.jade new file mode 100644 index 0000000..b2a0b7e --- /dev/null +++ b/views/report/channels.jade @@ -0,0 +1,10 @@ +extends ../layout + +block content + h3 Channels on #{server} + div#backlink + a(href='/warning') « Server List + ul#quotelist + -each channel in channels + a(href='/notify/'+server+'/'+encodeURIComponent(channel)) + li.quotes #{channel} diff --git a/views/report/notifies.jade b/views/report/notifies.jade new file mode 100644 index 0000000..1b4c04d --- /dev/null +++ b/views/report/notifies.jade @@ -0,0 +1,21 @@ +extends ../layout + +block content + div#backlink + a(href='/notify/'+server) « Server Channels + p + div#profile_datatable + table.table.table-hover.data + thead + tr + th Date + th Channel + th User + th Message + tbody + for notify, key in notifies + tr + td #{new Date(notify.time)} + td #{notify.channel} + td #{notify.user} + td #{notify.message} diff --git a/views/report/servers.jade b/views/report/servers.jade new file mode 100644 index 0000000..924eb19 --- /dev/null +++ b/views/report/servers.jade @@ -0,0 +1,10 @@ +extends ../layout + +block content + h3 Servers + div#backlink + a(href='/') « Home + ul#quotelist + -each server in servers + a(href='/notify/'+server) + li.quotes #{server}