New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fb-opt-facts

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fb-opt-facts - npm Package Compare versions

Comparing version 0.0.2 to 0.1.0

lang/en.yaml

8

index.js

@@ -17,2 +17,8 @@ var commands = require('./src/commands');

}, {
name : 'Say Fact',
description : 'Force Fritbot to say a given factoid; useful for testing new facts before teaching them.',
usage : 'say factoid',
trigger : /say/i,
func : commands.say
}, {
name : 'Explain Fact',

@@ -39,2 +45,2 @@ description : 'Explains what fact Fritbot just recited.',

}]
};
};

8

package.json
{
"name": "fb-opt-facts",
"version": "0.0.2",
"version": "0.1.0",
"description": "Fritbot Facts Module",
"repository": {
"type": "git",
"url": "git://github.com/Urthen/fb-opt-facts.git"
"url": "git://github.com/fritbot/fb-opt-facts.git"
},

@@ -26,5 +26,5 @@ "dependencies": {

"bugs": {
"url": "https://github.com/Urthen/fb-opt-facts/issues"
"url": "https://github.com/fritbot/fb-opt-facts/issues"
},
"homepage": "https://github.com/Urthen/fb-opt-facts"
"homepage": "https://github.com/fritbot/fb-opt-facts"
}
var _ = require('lodash');
var last_info = [];
var last_info = {};
var rate_limit = {};
function replaceFactoidPlaceholders (factoid, triggered, bot, route) {
// Replace who and what with the triggerer and the match
factoid = factoid.replace(/\$who/ig, route.nick);
if (triggered) factoid = factoid.replace(/\$what/ig, triggered.match[1]);
// Chose random people in the room
var someone = /\$someone/i;
while (someone.test(factoid)) {
factoid = factoid.replace(someone, _.sample(bot.users.getRoomRoster(route.room)).nick);
}
// Some people like using $something instead of $item
var something = /(\$something)/i;
while (something.test(factoid)) {
factoid = factoid.replace(something, bot.db.schemas.word.selectByType('$item'));
}
// Resolve remaining $placeholders
_.forEach(bot.db.schemas.word.getTypes(), function (type) {
// don't forget to add a slash before the $!!
var regex = new RegExp('\\' + type, 'i');
while (regex.test(factoid)) {
factoid = factoid.replace(regex, bot.db.schemas.word.selectByType(type));
}
});
return factoid;
}
module.exports = {

@@ -12,2 +41,7 @@ learn : function (route, args) {

if (!trigger) {
route.send('?facts_trigger_missing');
return;
}
if (trigger === 'alias') {

@@ -20,4 +54,4 @@ alias = true;

if (trigger[0] === '/') {
if (trigger.length < 6) {
route.send('Triggers must be longer than that!');
if (trigger.length < 5) {
route.send('?facts_trigger_short');
return;

@@ -28,4 +62,4 @@ }

} else {
if (trigger.length < 4) {
route.send('Triggers must be longer than that!');
if (trigger.length < 3) {
route.send('?facts_trigger_short');
return;

@@ -47,16 +81,28 @@ }

promise.then(function () {
route.send('Learned "' + trigger + '" -> "' + remainder + '"');
route.send('?facts_learned_fact', trigger, remainder);
}, function (err) {
console.log('Error learning fact:', err);
route.send('Error learning that fact: ' + err);
route.send('?response_error', err);
});
},
say : function (route, message) {
var bot = this;
var output = message.join(' ');
console.log('Forced to say fact:', output);
output = replaceFactoidPlaceholders(output, false, bot, route);
route.indirect().send(output);
},
explain : function (route) {
if (last_info) {
var out = 'That was "' + last_info.factoid + '", triggered by "' + last_info.match + '"';
if (last_info.trigger !== '\\b' + last_info.match + '\\b') {
out += ' matching "' + last_info.trigger + '"';
var channel = last_info[route.room] ? route.room : route.user._id.toString();
if (last_info[channel]) {
var out = 'That was "' + last_info[channel].factoid + '", triggered by "' + last_info[channel].match + '"';
if (last_info[channel].trigger !== '\\b' + last_info[channel].match + '\\b') {
out += ' matching "' + last_info[channel].trigger + '"';
}
if (last_info.author) {
out += ', authored by ' + last_info.author;
if (last_info[channel].author) {
out += ', authored by ' + last_info[channel].author;
}

@@ -77,3 +123,3 @@ route.send(out);

var bot = this;
var triggered = this.db.schemas.factTrigger.checkMessage(message);
var triggered = this.db.schemas.factTrigger.checkMessage(message);

@@ -101,3 +147,3 @@ if (triggered) {

// Save info about last triggered fact
last_info = {
var last_info_obj = {
factoid : factoid.factoid,

@@ -109,26 +155,10 @@ author : factoid.author,

// Replace who and what with the triggerer and the match
output = output.replace(/\$who/ig, route.nick);
output = output.replace(/\$what/ig, triggered.match[1]);
// Chose random people in the room
var someone = /\$someone/i;
while (someone.test(output)) {
output = output.replace(someone, _.sample(bot.users.getRoomRoster(route.room)).nick);
if (route.room) {
last_info[route.room] = last_info_obj;
} else {
last_info[route.user._id.toString()] = last_info_obj;
}
// Some people like using $something instead of $item
var something = /(\$something)/i;
while (something.test(output)) {
output = output.replace(something, bot.db.schemas.word.selectByType('$item'));
}
output = replaceFactoidPlaceholders(output, triggered, bot, route);
_.forEach(bot.db.schemas.word.getTypes(), function (type) {
// don't forget to add a slash before the $!!
var regex = new RegExp('\\' + type, 'i');
while (regex.test(output)) {
output = output.replace(regex, bot.db.schemas.word.selectByType(type));
}
});
route.indirect().send(output);

@@ -135,0 +165,0 @@ }, function (err) {

@@ -162,3 +162,3 @@ var _ = require('lodash');

// Load all existing triggers
// Load all existing words
bot.db.schemas.word.find({}, function (err, words) {

@@ -170,2 +170,2 @@ for (var i = 0; i < words.length; i++) {

});
};
};

@@ -13,5 +13,47 @@ // Simply list all facts

next({ facts : facts });
});
}).done();
}));
app.get('/words', web.render(app, 'words', function (req, next) {
web.bot.db.schemas.word.find({}).then(function (words) {
next({ words : words });
}).done();
}));
function sanityCheck (req, res, next) {
if (!req.query.id) {
web.error(res, 'Needs ID', "Don't mess around with things you don't understand.");
return;
}
if (!(req.session && req.session.user && req.session.user.admin)) {
web.error(res, 'Unauthorized', 'You are not an admin.');
return;
}
next();
}
app.get('/remove', sanityCheck, function (req, res) {
var id = req.query.id;
console.log('Deleting fact:', id);
web.bot.db.schemas.factFactoid.remove({ _id : id })
.then(function () {
res.redirect('/modules/facts/');
}).done();
});
app.get('/words/remove', sanityCheck, function (req, res) {
var id = req.query.id;
console.log('Deleting word:', id);
web.bot.db.schemas.word.remove({ _id : id })
.then(function () {
res.redirect('/modules/facts/words');
}).done();
});
app.locals.module_root = '/modules/facts';
app.use('/static', web.express.static(__dirname + '/../static/'));

@@ -18,0 +60,0 @@

@@ -1,2 +0,2 @@

$('head').append('<link rel="stylesheet" href="//cdn.datatables.net/1.10.5/css/jquery.dataTables.min.css" type="text/css" />');
$('head').append('<link rel="stylesheet" href="//cdn.datatables.net/plug-ins/1.10.7/integration/bootstrap/3/dataTables.bootstrap.css" type="text/css" />');
$(document).ready(function () {

@@ -6,14 +6,30 @@ $('#maintable tfoot th').each( function () {

if (title) {
$(this).html( '<input type="text" placeholder="Search ' + title + '" />' );
$(this).html( '<input type="text" class="form-control" placeholder="Search ' + title + '" />' );
}
} );
// Set all cell heights to value of largest cell height
var maxCellHeight = Math.max.apply(null, $("#maintable td").map(function () {
return $(this).height();
}).get());
$("<style>#maintable td { height: " + maxCellHeight.toString() + "px; }</style>" ).appendTo("head");
var table = $('#maintable').DataTable({
processing : true,
dom : 'lrtip',
dom : 'rtiS',
deferRender: true,
scrollY: "500px",
stateSave: true,
columns : [
null,
null,
{
width : '20%'
},
{
width : 'auto'
},
{
className : 'text-right',
orderable : false,
searchable : false
searchable : false,
width : '60px'
}

@@ -32,8 +48,26 @@ ]

var r = $('#maintable tfoot tr');
r.find('th').each(function () {
$(this).css('padding', 8);
var r = $('.dataTables_scrollFoot tfoot');
$('.dataTables_scrollHead table').append(r);
$('#search_0').css('text-align', 'center');
function resizeDataTable () {
var windowHeight = $(window).height();
var tableBodyOffset = $('.dataTables_scrollBody').offset().top;
var tableInfoHeight = $('.dataTables_info').outerHeight();
var footerHeight = $('.navbar-fixed-bottom').outerHeight();
$('.dataTables_scrollBody').css('height', (windowHeight - tableBodyOffset - (tableInfoHeight * 2) - footerHeight));
}
resizeDataTable();
$(window).resize(function() {
resizeDataTable();
});
$('#maintable thead').append(r);
$('#search_0').css('text-align', 'center');
});
// Force a manual window.resize event; DataTables Scroller plugin won't read proper row heights if we don't
// Delay the event so that the table and all styling has been applied
setTimeout(function () {
$(window).trigger('resize');
}, 500);
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc