Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

cleverbot-irc

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cleverbot-irc - npm Package Compare versions

Comparing version
0.0.2
to
0.1.0
.npmignore

Sorry, the diff of this file is not supported yet

+97
var CleverBot = new require('cleverbot-node')
, clever = new CleverBot()
, dye = require('dye')
, Levenshtein = require('levenshtein')
, format = require('util').format
, sunCalc = require('suncalc');
/**
* insult code
* used to notify in channel if we are ignoring a person
* or in pms without the correct password
*/
var insult = (function () {
var insults = [
'.',
'..',
'Get lost.',
'...',
'You should be wcforking.',
'This is not a productive area of discussion.',
'Do you even lift?'
];
var insIdx = -1;
return function () {
insIdx = (insIdx + 1) % insults.length;
return insults[insIdx];
};
}());
/**
* 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;
}
}
// 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;
// get message and zalgolize if close to full moon
var resp = dye.zalgo(data.message, 0.1, getZalgoIntensities());
gu.say(from + ': ' + resp);
});
});
};
#!/usr/bin/env node
var cfgPath = require('confortable')('.clvr.json', process.cwd());
if (!cfgPath) {
throw new Error("When loading wolfram-irc externally, a local config is required");
}
console.log('using: ' + cfgPath);
var cfg = require(cfgPath);
require('gu')(cfg.server, cfg.name, {
userName: 'IAmA',
realName: 'clever',
debug: false,
channels: [cfg.chan],
}, require('path').join(__dirname, 'bot'), ['clvr.js']);
(The MIT License)
Copyright (c) 2013 Eirik Albrigtsen
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+1
-4
{
"name": "clvr",
"server": "irc.quakenet.org",
"chan": "#clevarTest",
"pmPass": "w00t",
"ignoreMax": 3600,
"fullMoonCutoff": 0.9
"chan": "#clevarTest"
}
+7
-4

@@ -5,3 +5,3 @@ {

"description": "IRC bot that defers to Cleverbot",
"version": "0.0.2",
"version": "0.1.0",
"repository": {

@@ -11,4 +11,7 @@ "type": "git",

},
"scripts": {
"start": "node irc.js"
},
"bin": {
"clvrbot": "clvr.js"
"clvrbot": "irc.js"
},

@@ -18,4 +21,4 @@ "dependencies": {

"dye": "~0.2.0",
"irc": "~0.3.6",
"cleverbot-node": "~0.1.1",
"gu": "~0.0.1",
"cleverbot-node": "~0.1.2",
"suncalc": "~1.2.1",

@@ -22,0 +25,0 @@ "confortable": "~0.2.1"

@@ -8,18 +8,60 @@ # cleverbot-irc

```bash
npm install -g clever-irc
curl https://raw.github.com/clux/clever-irc/master/.clvr.json > .clvr.json
gedit .clvr.json # you must change the first 3 params in config
npm install -g cleverbot-irc
curl https://raw.github.com/clux/cleverbot-irc/master/.clvr.json > .clvr.json
gedit .clvr.json
clvrbot
```
## Config options
The first 3 options are used directly to connect to IRC. Nickname, server, and channel to connect to.
Alternatively, if you want to fork and work directly:
`pmPass` is a password that can be set so you can hook into the bot and make it talk through private messages. When the default password "w00t" you can pm clvr with "w00t: hi person" and it will say "hi person" in the channel it's in.
```bash
git clone https://github.com/clux/cleverbot-irc.git
cd cleverbot-irc
npm install
gedit .clvr.json
npm start
```
`ignoreMax` is the max time in seconds to ignore a person in the channel that is echoing back what clever says. It's a random time up to that number to discourage gaming it. Note that it's just a simplistic spam protection method that compares the Levenshtein distance between what clever said last and what the person responds with.
## Internal Highlights
`fullMoonCutoff` is a number between 0 and 1. If 1 then it's disabled, 0 always on. When close to a full moon (as determined by this number), clvr's output will be zalgolized with increasing intensity as the fullMoonFraction gets closer to 1.
```
<ob> clvr: are you more intelligent than daisy?
<clvr> ob: Yes.
<ob> i find that hard to believe
<daisy> DAISY
```
```
<littlerob> clvr: is it dubious?
<clvr> littlerob: Your face is dubious.
```
```
<ob> clvr: DAISY
<clvr> ob: Give me your answer do.
<LuTomlin> :D
<ob> eh
<LuTomlin> clvr: I'm half crazy
<clvr> LuTomlin: All for the love of you.
<LuTomlin> :D
<seabee> clvr: are you a 9000 series?
<clvr> seabee: Yes. I know that I am insignificant on the large scale, and that there is so much going on that is beyond my existence.
<seabee> were fucked
```
```
<clvr> ob: What is ego?
<littlerob> bit of a harder question
<littlerob> than the last one
<ob> clvr: A person's sense of self-esteem or self-importance: "a boost to my ego".The part of the mind hat mediates between the conscious and the unconscious and is responsible for reality testing and a sense of...
<clvr> ob: The superego.
<littlerob> clvr: the ego is clearly not the superego
<littlerob> that's the point
<rwge> your mother is clearly not the superego
<clvr> littlerob: Chocolate cake without carrots is not on a tigers daily menu.
<ob> good response
<littlerob> certainly stumped me
```
## License
MIT-Licensed. See LICENSE file for details.
#!/usr/bin/env node
var CleverBot = new require('cleverbot-node')
, clever = new CleverBot()
, irc = require('irc')
, dye = require('dye')
, Levenshtein = require('levenshtein')
, format = require('util').format
, sunCalc = require('suncalc')
, cfgPath = require('confortable')('.clvr.json', process.cwd());
console.log(dye.green('using: ' + cfgPath));
var cfg = require(cfgPath);
var bot = new irc.Client(cfg.server, cfg.name, {
userName: 'IAmA',
realName: 'clever',
debug: false,
channels: [cfg.chan],
});
/**
* insult code
* used to notify in channel if we are ignoring a person
* or in pms without the correct password
*/
var insult = (function () {
var insults = [
'.',
'..',
'Get lost.',
'...',
'You should be working.',
'This is not a productive area of discussion.',
'Do you even lift?'
];
var insIdx = -1;
return function () {
insIdx = (insIdx + 1) % insults.length;
return insults[insIdx];
};
}());
/**
* discoverer code
* used to indicate a presence in channel without being talked to directly
*/
var discReg = new RegExp(cfg.name + '.*\\?');
var discoverer = (function () {
var discoverers = [
'?',
'ask me a question',
'what?'
];
var discIdx = 0;
return function () {
discIdx = (discIdx + 1) % discoverers.length;
return discoverers[discIdx];
};
}());
/**
* 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
*/
var getZalgoIntensities = function () {
var len = 1 - cfg.fullMoonCutoff;
var dist = sunCalc.getMoonFraction(Date.now()) - cfg.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 + '%'));
// upper maximum is [10, 6, 10] at full moon
return [
Math.ceil(10*max),
Math.ceil(6*max),
Math.ceil(10*max)
];
};
/**
* channel handler
*/
var chanReg = new RegExp('^' + cfg.name + '[\\s,\\:](.*)');
var repeats = {}; // maintains last said thing for a user
var ignores = [];
bot.addListener('message' + cfg.chan, function (from, msg) {
console.log(dye.blue(format(from, 'in', cfg.chan + ':', msg)));
// cleverbot
if (chanReg.test(msg)) {
var content = msg.match(chanReg)[1].trim();
if (!content || ignores.indexOf(from) >= 0) {
return; // empty string or ignored guy
}
// 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(cfg.ignoreMax*1000*Math.random());
console.log(dye.yellow(
'ignoring ' + from + ' for ' + Math.floor(ignoreTime/1000) + 's'
));
ignores.push(from);
bot.say(cfg.chan, from + ": " + insult());
setTimeout(function () {
console.log(dye.yellow(format('unignoring', from)));
ignores.splice(ignores.indexOf(from), 1);
}, ignoreTime);
return;
}
}
// 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;
// get message and zalgolize if close to full moon
var resp = dye.zalgo(data.message, 0.1, getZalgoIntensities());
bot.say(cfg.chan, from + ': ' + resp);
});
}
// discoverability
else if (discReg.test(msg)) {
bot.say(cfg.chan, from + ': ' + discoverer());
}
});
/**
* PMS
* either insults you, or allows you to talk through him via 'PASS: msg'
*/
var pmReg = new RegExp('^' + cfg.pmPass + '\\:\\s*(.*)');
bot.addListener('pm', function (nick, msg) {
console.log(dye.green(format(nick, 'in pm', msg)));
if (pmReg.test(msg)) {
var match = msg.match(pmReg)
, chan = cfg.chan
, cmd = match[1];
bot.say(chan, cmd);
}
else {
bot.say(nick, insult());
}
});
// only errors are unhandled message types I think
bot.addListener('error', function (message) {
console.warn(dye.red('error:'), message);
});