cleverbot-irc
Advanced tools
Comparing version
var CleverBot = new require('cleverbot-node') | ||
, clever = new CleverBot() | ||
, dye = require('dye') | ||
, Levenshtein = require('levenshtein') | ||
, format = require('util').format | ||
, sunCalc = require('suncalc'); | ||
, protection = require('./echo_protection') | ||
, maybeSpiceUp = require('./fullmoon_spiceup'); | ||
@@ -11,4 +9,4 @@ /** | ||
* used to notify in channel if we are ignoring a person | ||
* or in pms without the correct password | ||
*/ | ||
const ignoreMax = 3600; | ||
var insult = (function () { | ||
@@ -32,68 +30,24 @@ var insults = [ | ||
/** | ||
* Full Moon Based Zalgolizer | ||
* when moon is sufficiently full, clvr speaks with the zalgolizer | ||
* the zalgolizer grows more intense the closer to full moon it is | ||
*/ | ||
const fullMoonCutoff = 0.95; | ||
var getZalgoIntensities = function () { | ||
var len = 1 - fullMoonCutoff; | ||
var dist = sunCalc.getMoonFraction(Date.now()) - fullMoonCutoff; | ||
if (dist < 0) { | ||
// not a full moon! | ||
return [0, 0, 0]; | ||
} | ||
// full moon | ||
var max = dist/len; | ||
console.log(dye.magenta('full moon intensity at ' + max + '%')); | ||
// [0, 0, 0] at [0, fullMoonCutoff), [10, 6, 10] at full moon (=1) | ||
// linear interpolation in the range [fullMoonCutoff, 1] | ||
return [ | ||
Math.ceil(10*max), | ||
Math.ceil(6*max), | ||
Math.ceil(10*max) | ||
]; | ||
}; | ||
var repeats = {}; // maintains last said thing for a user | ||
var ignores = []; | ||
const ignoreMax = 3600; | ||
module.exports = function (gu) { | ||
gu.on(/(.*)/, function (content, from) { | ||
if (ignores.indexOf(from) >= 0) { | ||
return; // ignored person | ||
} | ||
// repeat messengers should not echo back 'basically' what cleverbot said | ||
if (repeats[from]) { | ||
var ld = new Levenshtein(repeats[from], content); | ||
if (ld.distance < content.length/8) { | ||
var ignoreTime = Math.ceil(ignoreMax*1000*Math.random()); | ||
console.log(dye.yellow( | ||
'ignoring ' + from + ' for ' + Math.floor(ignoreTime/1000) + 's' | ||
)); | ||
ignores.push(from); | ||
gu.say(from + ": " + insult()); | ||
setTimeout(function () { | ||
console.log(dye.yellow(format('unignoring', from))); | ||
ignores.splice(ignores.indexOf(from), 1); | ||
}, ignoreTime); | ||
return; | ||
gu.on(/(.*)/, function (message, user) { | ||
if (!protection.isIgnored(user)) { | ||
if (protection.isTooSimilar(user, message)) { | ||
gu.say(user + ': ' + insult()); | ||
return protection.ignore(user, ignoreMax); | ||
} | ||
} | ||
// pass data onto cleverbot | ||
clever.write(content, function (data) { | ||
// cache response for user so we can catch if they mime on next message | ||
repeats[from] = data.message; | ||
// pass message on to cleverbot | ||
clever.write(message, function (data) { | ||
var resp = data.message; | ||
// remember the last thing `user` got returned to him | ||
// so we can verify that he doesn't simply echo it back | ||
protection.remember(user, resp); | ||
// get message and zalgolize if close to full moon | ||
var resp = dye.zalgo(data.message, 0.1, getZalgoIntensities()); | ||
gu.say(from + ': ' + resp); | ||
}); | ||
// do fancy things to the message on full moons | ||
gu.say(user + ': ' + maybeSpiceUp(resp)); | ||
}); | ||
} | ||
}); | ||
}; |
@@ -5,3 +5,3 @@ { | ||
"description": "IRC bot that defers to Cleverbot", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"repository": { | ||
@@ -20,5 +20,6 @@ "type": "git", | ||
"dye": "~0.2.0", | ||
"gu": "~0.0.1", | ||
"gu": "~0.0.2", | ||
"cleverbot-node": "~0.1.2", | ||
"suncalc": "~1.2.1", | ||
"irc-colors": "~1.0.3", | ||
"confortable": "~0.2.1" | ||
@@ -25,0 +26,0 @@ }, |
@@ -24,2 +24,8 @@ # cleverbot-irc | ||
## Quirks | ||
Because spare time. | ||
- `clvr` will go a little crazy close to every full moon | ||
- imitating the responses of `clvr` back to her can get you ignored for some time | ||
## Internal Highlights | ||
@@ -26,0 +32,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
8116
20.92%9
28.57%142
36.54%73
8.96%0
-100%7
16.67%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
Updated