3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-26 20:52:39 +01:00
dbot/modules/quotes/pages.js

44 lines
1.4 KiB
JavaScript
Raw Normal View History

2013-01-15 15:47:46 +01:00
var _ = require('underscore')._;
var pages = function(dbot) {
return {
// Lists quotes in a category
'/quotes/:key': function(req, res) {
2013-04-23 19:26:44 +02:00
this.api.getQuoteCategory(req.params.key, function(category) {
if(category) {
res.render('quotes', {
'name': dbot.config.name,
'quotes': category.quotes,
'url_regex': new RegExp(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig)
2013-04-23 19:26:44 +02:00
});
} else {
res.render('error', {
'name': dbot.config.name,
'message': 'No quotes under that key.'
});
}
});
2013-01-15 15:47:46 +01:00
},
// Show quote list.
'/quotes': function(req, res) {
2013-04-23 19:26:44 +02:00
this.api.getCategoryKeys(function(keys) {
res.render('quotelist', {
'name': dbot.config.name,
'quotelist': keys
});
});
2013-01-15 15:47:46 +01:00
},
'/quoteremovals': function(req, res) {
res.render('quotes', {
'name': dbot.config.name,
'quotes': _.pluck(this.rmCache, 'quote')
});
}
2013-01-15 15:47:46 +01:00
}
};
exports.fetch = function(dbot) {
return pages(dbot);
};