From 80a40291d232028878bc1565d6ea49da69a8ba5b Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Fri, 13 Feb 2015 21:49:04 +0000 Subject: [PATCH 01/42] first commit of new bot --- .gitignore | 1 + README.md | 87 ++++++-------------------------- your-bot-here.js => bootstrap.js | 17 ++++--- 3 files changed, 27 insertions(+), 78 deletions(-) rename your-bot-here.js => bootstrap.js (67%) diff --git a/.gitignore b/.gitignore index 9477fc3..5364073 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *-profile.js node_modules/ +config.json \ No newline at end of file diff --git a/README.md b/README.md index e573678..0ec0f4c 100644 --- a/README.md +++ b/README.md @@ -1,79 +1,24 @@ -oftn-bot +bot [Working Title] ======== -This is the repository for both of the IRC bots oftn-bot (in #oftn on freenode) and ecmabot (in ##javascript on freenode). This was originally created as a replacement for v8bot (http://github.com/eisd/v8bot). Over time, it changed to include a full-featured IRC bot library. +Why a new bot, whats wrong with Natasha? +------ +Time has come for us to re-think what our bot of the future is going to look like and how it will suit our needs. +Natasha (who was once called Olga) has done a great job over the years but we wish to change the infrastructure and how people can contribute. +Natasha has stored a whole heap of information (I think from 2011 onwards, maybe earlier) but we want to move logs and stats to the main database we already have running. -Features --------- +Here are our reasons for building a new bot: -* Manages bot commands with an easy API -* Support for "intents" which is when you append "@ user" after a bot command, so the bot can reply to that person -* Context object provides information about bot command invocations, including: - * Who invoked the command - * Who was it "intended" for - * Was this invoked in the channel or in a private message? -* Can listen for regular expression matches -* Control logging amount to standard out -* Inherits from Node.js's built-in EventEmitter -* Manages user lists and recognizes mode changes -* Don't worry about flooding the channel with built-in support for truncation -* Default option is to strip control codes and colors -* Each channel and user is represented as a unique JavaScript object with extra information, e.g. channel topic, or user op status -* Includes extra optional libraries: - * FactoidServ: Manages a list of factoids which are saved and loaded to disk automatically - * FeelingLucky: Performs a quick Google "I'm Feeling Lucky" search - * JSONSaver: Saves and loads arbitrary JavaScript objects to disk automatically (used by FactoidServ) - * Sandbox: Runs JavaScript in a seperate process to allow for users to run code. (Uses v8, but a compiled SpiderMonkey "shovel" is available that uses js185 shared libraries) +* We want to seperate data from the bot, we now have a hashweb API (currently being used by [Hashweb Stats](http://stats.hashweb.org). +* Leaving things like logs and statistics to the main database means we can let the bot to make API calls and data comes from the same place. This also means we can open it up to the public (as its not directly communicating with a database) +* Development on Natasha is quite slow, as she is closed off with only 1 person maintaining her. We don't want a single point of entry. +* We fancied using a new platform, the old bot was wrote in Python (a fork of limnoria) and does a great job. But if users are going to contribute we want a low barrier to entry, and thus decided Node JS was the best solution for that. +* I want to learn Node JS.... +* By Moving to Github means we aremore open and users can view and learn about how the new bot will work. -API +Commands --- -The underlying IRCBot library has methods which make it easy to add functionality. - -### Bot(profile) -@profile: An array of objects representing each server to connect to. - -This is the main constructor for the bot. It is suggested that you inherit from this object when creating your bot, but you don't have to. - -A profile is an array of objects. Each object has the properties: - -* host: The domain name or IP of an IRC server to connect to. Default: "localhost" -* port: A port number. Default: 6667. -* nick: A string nick name to try to connect as. Default: "guest" -* password: The password used to connect (This is not NickServ). Default: null -* user: Your IRC username -* real: Your 'real name' on IRC -* channels: An array of channel names to connect to. (e.g. ["#stuff", "##mychannel", "#yomama"]) - - -### bot.init() -Goes through each server in the profile and begins connecting and registering event listeners. - -### bot.register_listener(regex, callback) -Adds a regular expression listeners to incoming traffic on all servers. When the messages match, callback is called with the arguments: - -* context: A context object -* text: The full message -* 1st subpattern -* 2nd subpattern -* ... - -### bot.register_command(command, callback, options) -Adds a command. - -* command: A string value for the command -* callback: A function to call when the command is run -* options: An object with the keys: allow_intentions and hidden. - -When the command is called, the callback is called with the arguments: - -* context: A context object -* text: The command arguments - - -Additional Documentation ------------------------- - -This bot AND/OR bot library is still being developed, but those are some of the basic commands. Look at your-bot-here.js for a simple example of an IRC bot using this API, or ecmabot.js for a more complex and featured example. - +Currently.... +None \ No newline at end of file diff --git a/your-bot-here.js b/bootstrap.js similarity index 67% rename from your-bot-here.js rename to bootstrap.js index 66fce2d..d756197 100644 --- a/your-bot-here.js +++ b/bootstrap.js @@ -1,5 +1,6 @@ var Util = require("util"); var Bot = require("./lib/irc"); +var fs = require("fs"); var YourBot = function(profile) { Bot.call(this, profile); @@ -25,14 +26,16 @@ YourBot.prototype.unrecognized = function(cx, text) { cx.channel.send_reply(cx.sender, "There is no command: "+text); }; +// config.json will be a hidden (gitignored) file for obvious reasons.... +var config = JSON.parse(fs.readFileSync('config.json', 'utf8')); var profile = [{ - host: "irc.freenode.net", - port: 6667, - nick: "mybot", - password: "password_to_authenticate", - user: "username", - real: "Real Name", - channels: ["#channels", "#to", "#join"] + host: config.host, + port: config.port, + nick: config.nick, + password: config.password, + user: config.user, + real: config.real, + channels: config.channels }]; (new YourBot(profile)).init(); From a9082261a444f7843b972c1876b972befddf9e49 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Sat, 14 Feb 2015 00:42:02 +0000 Subject: [PATCH 02/42] adding commands and updating readme --- README.md | 82 +++++++++++++- bootstrap.js | 252 ++++++++++++++++++++++++++++++++++++++++-- ecmabot-factoids.json | 18 ++- 3 files changed, 332 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 0ec0f4c..b53f176 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,82 @@ Here are our reasons for building a new bot: * I want to learn Node JS.... * By Moving to Github means we aremore open and users can view and learn about how the new bot will work. -Commands ---- +### !commands +Retrieves a list of current commands. +Usage: `!commands` -Currently.... -None \ No newline at end of file + !commands + eboyjr: Valid commands are: !commands, !ecma, !find, !forget, !g, !google, !help, !learn, !mdc, !mdn, !re + +### !ecma +Searches the ECMA-262 specification table of contents. Links to the section as found in http://es5.github.com/ +Usage: `!ecma ` + + !ecma null value + eboyjr: Found: 4.3.11 null value + +### !find +Performs a search of a factoid in the database. +Usage: `!find ` + + !find frame + eboyjr: No factoid/command named `frame`. Did you mean: iframe, or cross-domain? See !commands for a list of commands. + +### !forget +Removes a factoid from the database. +Usage: `!forget ` + +### !g +Returns the first Google result for the query. +Usage: `!g ` + + !g v8 javascript engine + eboyjr: v8 - V8 JavaScript Engine - Google Project Hosting + +### !google +Returns a link to a Google search page of the search term. +Usage: `!google ` + + !google opencourseware computational complexity + eboyjr: Google search: "opencourseware computational complexity" + +### !help +Gives help for a specific command. +Usage: `!help ` + + !help help + eboyjr: No help for `help` + +### !learn +Adds a factoid to the bot. +Usage: `!learn = ` +Usage: `!learn alias = ` +Usage: `!learn =~ s///` + +### !mdn +Searches the Mozilla Developer Network. +Usage: `!mdn ` + + !mdn bitwise operators + eboyjr: Bitwise Operators - MDN Docs + +### !re +Performs a regular expression match. +Usage: `!re //` + + !re Hannah Hannah Bo Banana, Fe Fi Fo Fana /.[an]+/g + eboyjr: Matches: 'Hanna', 'Hanna', 'Banana', 'Fana' + + +## Factoids + +The factoid system in ecmabot is designed to store simple key/value pairs. Accessing a factoid from the database is as simple as: + + !help + eboyjr: In order to get help, paste the relevant portions JavaScript in a pastebin (see !paste), and tell us 1) what you want to happen, 2) what is actually happening, and 3) any error messages you find (see !debug). + +You can direct the responses of your command with the `@` character, followed by a nick. + + HAI GUYS ... uh havin a bit of trubble with this script... i get TypeError: document.crateElenemt is not a function how do i fixx this?? + !spelling @ phpman3000 + phpman3000: Spelling and capitalization are important in programming, unless you are using PHP. \ No newline at end of file diff --git a/bootstrap.js b/bootstrap.js index d756197..d18a3ca 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -1,29 +1,259 @@ -var Util = require("util"); +var file = require('fs'); +var path = require('path'); +var util = require("util"); +var http = require("http"); +var fs = require("fs"); + +var Sandbox = require("./lib/sandbox"); +var FactoidServer = require("./lib/factoidserv"); +var FeelingLucky = require("./lib/feelinglucky"); +var CanIUseServer = require("./lib/caniuse"); + var Bot = require("./lib/irc"); -var fs = require("fs"); +var Shared = require("./shared"); + + +var JSBot = function(profile) { + this.sandbox = new Sandbox(path.join(__dirname, "ecmabot-utils.js")); + this.factoids = new FactoidServer(path.join(__dirname, "ecmabot-factoids.json")); + this.caniuse_server = new CanIUseServer; + this.executeRegex = /^((?:sm|v8|js|>>?|\|)>)([^>].*)+/; -var YourBot = function(profile) { Bot.call(this, profile); this.set_log_level(this.LOG_ALL); this.set_trigger("!"); // Exclamation }; -Util.inherits(YourBot, Bot); -YourBot.prototype.init = function() { +util.inherits(JSBot, Bot); + + +JSBot.prototype.init = function() { Bot.prototype.init.call(this); - + + this.register_listener(this.executeRegex, Shared.execute_js); + + //this.register_listener(/^(\S+)(\+\+|--);?$/, this.do_beers); + + this.register_command("g", Shared.google, { + help: "Run this command with a search query to return the first Google result. Usage: !g kitten images"}); + + this.register_command("google", this.google, { + help: "Returns a link to a Google search page of the search term. Usage: !google opencourseware computational complexity"}); + + this.register_command("mdn", this.mdn, { + help: "Search the Mozilla Developer Network. Usage: !mdn bitwise operators"}); + this.register_command("mdc", "mdn"); + + this.register_command("ecma", this.ecma, { + help: "Lookup a section from the ECMAScript spec. Usage: !ecma null value"}); + + this.register_command("re", this.re, { + help: "Usage: !re Your text here /expression/gi || FLAGS: (g: global match, i: ignore case)"}); + + this.register_command("caniuse", this.caniuse, { + help: "Search the caniuse.com database. Usage: !caniuse webgl"}); + this.register_command("ciu", "caniuse"); + + this.register_command("find", Shared.find); + + this.register_command("help", this.help); + + this.register_command("auth", Shared.reauthenticate, { + allow_intentions: false, + help: "Attempt to re-authenticate with NickServ."}); + + this.register_command("learn", Shared.learn, { + allow_intentions: false, + help: "Add factoid to bot. Usage: !learn ( [alias] foo = bar | foo =~ s/expression/replace/gi )"}); + + this.register_command("forget", Shared.forget, { + allow_intentions: false, + help: "Remove factoid from bot. Usage: !forget foo"}); + + this.register_command("commands", Shared.commands); + this.register_command("ping", this.ping); - this.on('command_not_found', this.unrecognized); + + this.on('command_not_found', this.command_not_found); + + this.load_ecma_ref(); + }; -YourBot.prototype.ping = function(cx, text) { +JSBot.prototype.google = function(context, text) { + + if (!text) { + context.channel.send_reply (context.sender, this.get_command_help("google")); + return; + } + + context.channel.send_reply (context.intent, "Google search: \""+text+"\" "); +}; + + +JSBot.prototype.there_is_no_try = function(context, text) { + var hours = 1000*60*60; + var now = +new Date(); + + if (now > arguments.callee.last_invocation + 3*hours || + typeof arguments.callee.last_invocation === "undefined") { + + context.channel.send_reply(context.sender, "Do or do not; there is no try. --Yoda"); + arguments.callee.last_invocation = now; + + } +}; + +JSBot.prototype.ping = function(cx, text) { cx.channel.send_reply (cx.sender, "Pong!"); }; -YourBot.prototype.unrecognized = function(cx, text) { - cx.channel.send_reply(cx.sender, "There is no command: "+text); + +JSBot.prototype.do_beers = function(context, text, nick, operation) { + /** + * /(\S+)\s*(?:(\+\+|--)|=\s*(?:\1)\s*(\+|-)\s*1);?/ + * TODO: More advanced beer management + **/ + if (operation === "++") { + if (nick.toLowerCase() !== "c") { + context.channel.send_reply(context.sender, "Even if " + nick + + " deserves any beer, I don't have any to spare."); + } else { + context.channel.send_reply(context.sender, "C doesn't deserve beer."); + } + } else { + context.channel.send_action( + "steals a beer a from " + nick + ", since we're taking 'em."); + } +}; + + +JSBot.prototype.re = function(context, msg) { + // Okay first we need to check for the regex literal at the end + // The regular expression to match a real js regex literal + // is too long, so we need to use a simpler one. + var regexmatches, regexliteral = /\/((?:[^\\\/]|\\.)*)\/([gi]*)$/; + + if (regexmatches = msg.match(regexliteral)) { + try { + var regexpobj = new RegExp(regexmatches[1], regexmatches[2]); + } catch (e) { + /* We have an invalid regular expression */ + context.channel.send_reply(context.sender, e.message); + return; + } + + var texttomatch = msg.slice(0, -regexmatches[0].length).trim(); + var result = texttomatch.match(regexpobj); + if (result === null) { + context.channel.send_reply(context.intent, "No matches found."); + return; + } + + var reply = []; + for (var i = 0, len = result.length; i < len; i++) { + reply.push(typeof result[i] !== "undefined" ? + "'"+result[i]+"'" : + "[undefined]"); + } + + context.channel.send_reply(context.intent, "Matches: "+reply.join(", "), {truncate: true}); + } else { + context.channel.send_reply(context.sender, this.get_command_help("re")); + } +}; + + + +JSBot.prototype.help = function(context, text) { + + try { + if (!text) { + return this.command_not_found (context, "help"); + } + + context.channel.send_reply(context.intent, this.get_command_help(text)); + } catch(e) { + context.channel.send_reply(context.sender, e); + } +}; + + +JSBot.prototype.mdn = function(context, text, command) { + if (!text) { + return Shared.findPlus.call(this, context, command); + } + + Shared.google (context, "site:developer.mozilla.org "+text); +}; + + +JSBot.prototype.command_not_found = function(context, text) { + Shared.findPlus.call(this, context, text, !context.priv); +}; + +// JSON.stringify([].slice.call(document.querySelectorAll('#toc-full a')).map(function(v) {return {title: v.firstChild.textContent, id: v.href.replace(/.+#/, '')};})); +// Use that to generate the required JSON from es5.github.io with Firefox + +JSBot.prototype.ecma = function(context, text) { + try { + + if (typeof this.ecma_ref === "undefined") { + context.channel.send_reply(context.sender, "The ECMA-262 reference is not loaded."); + return; + } + + text = text.toLowerCase(); + var ref = this.ecma_ref, ch = text.charCodeAt(0); + + // If text begins with a number, the search must match at the beginning of the string + var muststart = ch >= 48 && ch <= 57; + + for (var i = 0, len = ref.length; i < len; i++) { + var item = ref[i], title = item.title.toLowerCase(); + if (muststart ? title.substring(0, text.length) === text : ~title.indexOf(text)) { + context.channel.send_reply(context.intent, + "Found: " + item.title + " "); + return; + } + } + + throw new Error("Could not find text '"+text+"' in the ECMAScript 5.1 Table of Contents."); + + } catch (e) { context.channel.send_reply(context.sender, e); } +}; + + +JSBot.prototype.load_ecma_ref = function() { + var filename = path.join(__dirname, "ecmabot-reference.json"); + util.puts("Loading ECMA-262 reference..."); + var bot = this; + file.readFile(filename, function (err, data) { + if (err) util.puts(util.inspect(err)); + try { + bot.ecma_ref = JSON.parse(data); + } catch (e) { + util.puts("ECMA-262 Error: "+e.name+": "+e.message); + } + }); + if (typeof this.ecma_ref_watching === "undefined") { + this.ecma_ref_watching = true; + file.watchFile(filename, function (curr, prev) { + util.puts("ECMA-262 reference file has changed."); + bot.load_ecma_ref(); + }); + } +}; + +JSBot.prototype.caniuse = function(context, text) { + try { + var text = this.caniuse_server.search(text); + context.channel.send_reply(context.intent, text, {color: true}); + } catch(e) { + context.channel.send_reply(context.sender, e); + } }; // config.json will be a hidden (gitignored) file for obvious reasons.... @@ -38,4 +268,4 @@ var profile = [{ channels: config.channels }]; -(new YourBot(profile)).init(); +(new JSBot(profile)).init(); diff --git a/ecmabot-factoids.json b/ecmabot-factoids.json index d6b5ca8..c372528 100644 --- a/ecmabot-factoids.json +++ b/ecmabot-factoids.json @@ -18,7 +18,7 @@ }, "w3schools": { "value": "W3Schools is not related to the W3C and has many problems: http://w3fools.com/", - "popularity": 157 + "popularity": 158 }, "iframe": { "value": "To get the document element of the iframe, use: iframe.contentWindow.document; However, cross-domain access to an iframe is disallowed.", @@ -90,7 +90,7 @@ }, "paste": { "value": "Show some code, but don't paste it on the channel. Sites like http://gist.github.com/ and http://bpaste.net/ are cool. You can also use http://jsbin.com , http://requirebin.com or http://jsfiddle.net/ to provide a test case we can run and help you with your problem.", - "popularity": 915, + "popularity": 916, "editors": [ "niggler", "gkatsev", @@ -404,7 +404,7 @@ }, "debug": { "value": "Browser-based debuggers -- Firefox , Safari , Chrome , Opera , IE ", - "popularity": 232, + "popularity": 233, "editors": [ "j201", "FireFly" @@ -428,7 +428,7 @@ }, "help": { "value": "For help, ask your question. Be patient. Code samples should be pasted in a paste service (see !paste). Tell us 1) what you want to happen, 2) what is actually happening, and 3) any error messages you find (see !describe and !debug).", - "popularity": 2228, + "popularity": 2229, "editors": [ "ashnur" ] @@ -4688,6 +4688,14 @@ "popularity": 1, "editors": [], "changes": [] + }, + "buck": { + "value": "somebody", + "creator": "Jayflux", + "date": "2015-02-14T00:29:40.940Z", + "popularity": 1, + "editors": [], + "changes": [] } }, "delete_log": [ @@ -5315,4 +5323,4 @@ } } ] -} +} \ No newline at end of file From 7c9c26326e909403502ea6d55dd2ca5ff3fd3394 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Wed, 18 Feb 2015 18:54:34 +0000 Subject: [PATCH 03/42] added last seen which now uses API --- bootstrap.js | 26 ++++++++++++++++++++++++-- ecmabot-factoids.json | 4 ++-- hashweb.js | 30 ++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 hashweb.js diff --git a/bootstrap.js b/bootstrap.js index d18a3ca..397921d 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -8,9 +8,12 @@ var Sandbox = require("./lib/sandbox"); var FactoidServer = require("./lib/factoidserv"); var FeelingLucky = require("./lib/feelinglucky"); var CanIUseServer = require("./lib/caniuse"); +var hashwebAPI = require("./hashweb"); var Bot = require("./lib/irc"); var Shared = require("./shared"); +// config.json will be a hidden (gitignored) file for obvious reasons.... +var config = JSON.parse(fs.readFileSync('config.json', 'utf8')); var JSBot = function(profile) { @@ -75,6 +78,12 @@ JSBot.prototype.init = function() { this.register_command("ping", this.ping); + this.register_command("dataja", this.dataja); + + this.register_command("chat", this.chat); + + this.register_command("seen", hashwebAPI.getLastSeen); + this.on('command_not_found', this.command_not_found); this.load_ecma_ref(); @@ -92,6 +101,16 @@ JSBot.prototype.google = function(context, text) { context.channel.send_reply (context.intent, "Google search: \""+text+"\" "); }; +JSBot.prototype.chat = function(context, text, something) { + // loop through admins + for(var i = 0; i < config.users.length; i++) { + if (context.sender.name === config.users[i].name && context.sender.host === config.users[i].host) { + var channel = context.client.get_channel("#web-testing"); + channel.send("megalols"); + } + } +} + JSBot.prototype.there_is_no_try = function(context, text) { var hours = 1000*60*60; @@ -256,8 +275,11 @@ JSBot.prototype.caniuse = function(context, text) { } }; -// config.json will be a hidden (gitignored) file for obvious reasons.... -var config = JSON.parse(fs.readFileSync('config.json', 'utf8')); +JSBot.prototype.dataja = function(ctx, text) { + console.log(ctx); + ctx.channel.send(ctx.intent + " Don't ask to ask, just ask"); +}; + var profile = [{ host: config.host, port: config.port, diff --git a/ecmabot-factoids.json b/ecmabot-factoids.json index c372528..7bff0bc 100644 --- a/ecmabot-factoids.json +++ b/ecmabot-factoids.json @@ -1029,7 +1029,7 @@ }, "lol": { "value": "Thou shalt not type LOL unless you are really laughing out loud.", - "popularity": 21 + "popularity": 22 }, "equivalent of x": { "value": "Instead of asking \"What's the equivalent of language Y's X\", describe the feature you want. Chances are we don't know what language Y is or what feature X does.", @@ -1429,7 +1429,7 @@ }, "hello": { "value": "hello", - "popularity": 79, + "popularity": 80, "editors": [ "PigDude" ] diff --git a/hashweb.js b/hashweb.js new file mode 100644 index 0000000..aea61a1 --- /dev/null +++ b/hashweb.js @@ -0,0 +1,30 @@ +var http = require("http"); + +var userUrl = "http://hashweb.org/api/stats/users/"; + + function callStats(user, callback) { + http.get(userUrl + user, function(res) { + var body = ''; + + res.on('data', function(chunk) { + body += chunk; + }); + + res.on('end', function() { + var response = JSON.parse(body) + callback(response); + }); + }).on('error', function(e) { + console.log("Got error: ", e); + }); +} + +module.exports = { + + getLastSeen: function(context, username) { + callStats(username, function(data) { + context.channel.send_reply(context.sender, data.username + " was last seen " + data.userNotSeenFor.days + " days " + data.userNotSeenFor.hours + " hours " + data.userNotSeenFor.minutes + " minutes ago saying: " + data.lastSeen.message); + }); + + } +} \ No newline at end of file From 15e7b1809d357c7768704c394da64ae7bb8cd225 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Fri, 3 Apr 2015 15:51:48 +0100 Subject: [PATCH 04/42] Fixed #13 --- bootstrap.js | 2 ++ hashweb.js | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/bootstrap.js b/bootstrap.js index 397921d..3436c44 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -84,6 +84,8 @@ JSBot.prototype.init = function() { this.register_command("seen", hashwebAPI.getLastSeen); + this.register_command("ops", hashwebAPI.ops); + this.on('command_not_found', this.command_not_found); this.load_ecma_ref(); diff --git a/hashweb.js b/hashweb.js index aea61a1..72ced45 100644 --- a/hashweb.js +++ b/hashweb.js @@ -1,6 +1,8 @@ var http = require("http"); +var fs = require("fs"); var userUrl = "http://hashweb.org/api/stats/users/"; +var config = JSON.parse(fs.readFileSync('config.json', 'utf8')); function callStats(user, callback) { http.get(userUrl + user, function(res) { @@ -21,10 +23,15 @@ var userUrl = "http://hashweb.org/api/stats/users/"; module.exports = { + // Use the Hashweb API to get the last user seen getLastSeen: function(context, username) { callStats(username, function(data) { context.channel.send_reply(context.sender, data.username + " was last seen " + data.userNotSeenFor.days + " days " + data.userNotSeenFor.hours + " hours " + data.userNotSeenFor.minutes + " minutes ago saying: " + data.lastSeen.message); }); + }, + // Use the config file to get the list of ops + ops: function(context, username) { + context.channel.send_reply(context.sender, config.ops.join(' ')); } } \ No newline at end of file From 66dcec26c391670567dc1c753bfbe9853a42c8c9 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Fri, 3 Apr 2015 16:57:01 +0100 Subject: [PATCH 05/42] added DDG search, fixes #10 --- bootstrap.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/bootstrap.js b/bootstrap.js index 3436c44..46badf8 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -4,6 +4,8 @@ var util = require("util"); var http = require("http"); var fs = require("fs"); +var request = require("request"); + var Sandbox = require("./lib/sandbox"); var FactoidServer = require("./lib/factoidserv"); var FeelingLucky = require("./lib/feelinglucky"); @@ -14,6 +16,7 @@ var Bot = require("./lib/irc"); var Shared = require("./shared"); // config.json will be a hidden (gitignored) file for obvious reasons.... var config = JSON.parse(fs.readFileSync('config.json', 'utf8')); +var ddgAPi = "https://duckduckgo.com/?q=british%20broadcasting%20corporation&format=json"; var JSBot = function(profile) { @@ -86,6 +89,8 @@ JSBot.prototype.init = function() { this.register_command("ops", hashwebAPI.ops); + this.register_command("ddg", this.ddg); + this.on('command_not_found', this.command_not_found); this.load_ecma_ref(); @@ -93,6 +98,33 @@ JSBot.prototype.init = function() { }; +JSBot.prototype.ddg = function(context, text) { + text = encodeURIComponent(text); + request("https://duckduckgo.com/?q="+ text +"&format=json", function(error, response, body) { + if (!error && response.statusCode == 200) { + try { + body = JSON.parse(body); + if (body.Abstract && body.Results && body.Results[0].FirstURL) { + context.channel.send_reply(context.sender, body.Abstract + " : " + body.Results[0].FirstURL); + } + else if (body.Abstract) { + context.channel.send_reply(context.sender, body.Abstract); + } + else if (body.AbstractURL) { + context.channel.send_reply(context.sender, body.AbstractURL); + } + else { + context.channel.send_reply(context.sender, " No results..sorry"); + } + } catch(e) { + context.channel.send_reply(context.sender, " Oops looks like I couldn't parse the response from DDG") + } + } else { + context.channel.send_reply(context.sender, " Oops looks like Duck Duck Go gave a bad response :(") + } + }); +} + JSBot.prototype.google = function(context, text) { if (!text) { From 98dcf05f64833beb8b5bacd7e3a897f77c1afbd3 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Fri, 3 Apr 2015 18:01:52 +0100 Subject: [PATCH 06/42] translations come for free, updated readme, fixed #12 --- README.md | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index b53f176..59ea600 100644 --- a/README.md +++ b/README.md @@ -22,21 +22,21 @@ Retrieves a list of current commands. Usage: `!commands` !commands - eboyjr: Valid commands are: !commands, !ecma, !find, !forget, !g, !google, !help, !learn, !mdc, !mdn, !re + eboyjr: Valid commands are: !commands, !ecma, !find, !forget, !g, !google, !help, !learn, !mdc, !mdn, !re ### !ecma Searches the ECMA-262 specification table of contents. Links to the section as found in http://es5.github.com/ Usage: `!ecma ` !ecma null value - eboyjr: Found: 4.3.11 null value + eboyjr: Found: 4.3.11 null value ### !find Performs a search of a factoid in the database. Usage: `!find ` !find frame - eboyjr: No factoid/command named `frame`. Did you mean: iframe, or cross-domain? See !commands for a list of commands. + eboyjr: No factoid/command named `frame`. Did you mean: iframe, or cross-domain? See !commands for a list of commands. ### !forget Removes a factoid from the database. @@ -47,24 +47,30 @@ Returns the first Google result for the query. Usage: `!g ` !g v8 javascript engine - eboyjr: v8 - V8 JavaScript Engine - Google Project Hosting + eboyjr: v8 - V8 JavaScript Engine - Google Project Hosting ### !google Returns a link to a Google search page of the search term. Usage: `!google ` !google opencourseware computational complexity - eboyjr: Google search: "opencourseware computational complexity" + eboyjr: Google search: "opencourseware computational complexity" +### !ddg +Searches Duck Duck Go. +Usage: `!ddg ` + + !ddg opencourseware computational complexity + ### !help Gives help for a specific command. Usage: `!help ` !help help - eboyjr: No help for `help` + eboyjr: No help for `help` ### !learn -Adds a factoid to the bot. +Adds a factoid to the bot. e Usage: `!learn = ` Usage: `!learn alias = ` Usage: `!learn =~ s///` @@ -74,25 +80,32 @@ Searches the Mozilla Developer Network. Usage: `!mdn ` !mdn bitwise operators - eboyjr: Bitwise Operators - MDN Docs + eboyjr: Bitwise Operators - MDN Docs ### !re Performs a regular expression match. Usage: `!re //` !re Hannah Hannah Bo Banana, Fe Fi Fo Fana /.[an]+/g - eboyjr: Matches: 'Hanna', 'Hanna', 'Banana', 'Fana' + eboyjr: Matches: 'Hanna', 'Hanna', 'Banana', 'Fana' + +### !translate +Transtes a word from 1 language to another +Usage: `!translate [language] to [language] ` + + !translate french to english bonjour + Good morning ## Factoids -The factoid system in ecmabot is designed to store simple key/value pairs. Accessing a factoid from the database is as simple as: +The factoid system in bot is designed to store simple key/value pairs. Accessing a factoid from the database is as simple as: !help - eboyjr: In order to get help, paste the relevant portions JavaScript in a pastebin (see !paste), and tell us 1) what you want to happen, 2) what is actually happening, and 3) any error messages you find (see !debug). + eboyjr: In order to get help, paste the relevant portions JavaScript in a pastebin (see !paste), and tell us 1) what you want to happen, 2) what is actually happening, and 3) any error messages you find (see !debug). You can direct the responses of your command with the `@` character, followed by a nick. HAI GUYS ... uh havin a bit of trubble with this script... i get TypeError: document.crateElenemt is not a function how do i fixx this?? !spelling @ phpman3000 - phpman3000: Spelling and capitalization are important in programming, unless you are using PHP. \ No newline at end of file + phpman3000: Spelling and capitalization are important in programming, unless you are using PHP. \ No newline at end of file From 2770a4ae0075f0da9a7238f699dca1b54299db46 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Wed, 8 Apr 2015 21:06:06 +0100 Subject: [PATCH 07/42] changing readme to reflect bot name change --- README.md | 28 ++++++++++++++-------------- bootstrap.js | 1 - 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 59ea600..c88c3da 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -bot [Working Title] +Ella ======== -Why a new bot, whats wrong with Natasha? +Why Ella?, whats wrong with Natasha? ------ Time has come for us to re-think what our bot of the future is going to look like and how it will suit our needs. Natasha (who was once called Olga) has done a great job over the years but we wish to change the infrastructure and how people can contribute. @@ -22,21 +22,21 @@ Retrieves a list of current commands. Usage: `!commands` !commands - eboyjr: Valid commands are: !commands, !ecma, !find, !forget, !g, !google, !help, !learn, !mdc, !mdn, !re + eboyjr: Valid commands are: !commands, !ecma, !find, !forget, !g, !google, !help, !learn, !mdc, !mdn, !re ### !ecma Searches the ECMA-262 specification table of contents. Links to the section as found in http://es5.github.com/ Usage: `!ecma ` !ecma null value - eboyjr: Found: 4.3.11 null value + eboyjr: Found: 4.3.11 null value ### !find Performs a search of a factoid in the database. Usage: `!find ` !find frame - eboyjr: No factoid/command named `frame`. Did you mean: iframe, or cross-domain? See !commands for a list of commands. + eboyjr: No factoid/command named `frame`. Did you mean: iframe, or cross-domain? See !commands for a list of commands. ### !forget Removes a factoid from the database. @@ -47,14 +47,14 @@ Returns the first Google result for the query. Usage: `!g ` !g v8 javascript engine - eboyjr: v8 - V8 JavaScript Engine - Google Project Hosting + eboyjr: v8 - V8 JavaScript Engine - Google Project Hosting ### !google Returns a link to a Google search page of the search term. Usage: `!google ` !google opencourseware computational complexity - eboyjr: Google search: "opencourseware computational complexity" + eboyjr: Google search: "opencourseware computational complexity" ### !ddg Searches Duck Duck Go. @@ -67,10 +67,10 @@ Gives help for a specific command. Usage: `!help ` !help help - eboyjr: No help for `help` + eboyjr: No help for `help` ### !learn -Adds a factoid to the bot. e +Adds a factoid to the Ella. e Usage: `!learn = ` Usage: `!learn alias = ` Usage: `!learn =~ s///` @@ -80,21 +80,21 @@ Searches the Mozilla Developer Network. Usage: `!mdn ` !mdn bitwise operators - eboyjr: Bitwise Operators - MDN Docs + eboyjr: Bitwise Operators - MDN Docs ### !re Performs a regular expression match. Usage: `!re //` !re Hannah Hannah Bo Banana, Fe Fi Fo Fana /.[an]+/g - eboyjr: Matches: 'Hanna', 'Hanna', 'Banana', 'Fana' + eboyjr: Matches: 'Hanna', 'Hanna', 'Banana', 'Fana' ### !translate Transtes a word from 1 language to another Usage: `!translate [language] to [language] ` !translate french to english bonjour - Good morning + Good morning ## Factoids @@ -102,10 +102,10 @@ Usage: `!translate [language] to [language] ` The factoid system in bot is designed to store simple key/value pairs. Accessing a factoid from the database is as simple as: !help - eboyjr: In order to get help, paste the relevant portions JavaScript in a pastebin (see !paste), and tell us 1) what you want to happen, 2) what is actually happening, and 3) any error messages you find (see !debug). + eboyjr: In order to get help, paste the relevant portions JavaScript in a pastebin (see !paste), and tell us 1) what you want to happen, 2) what is actually happening, and 3) any error messages you find (see !debug). You can direct the responses of your command with the `@` character, followed by a nick. HAI GUYS ... uh havin a bit of trubble with this script... i get TypeError: document.crateElenemt is not a function how do i fixx this?? !spelling @ phpman3000 - phpman3000: Spelling and capitalization are important in programming, unless you are using PHP. \ No newline at end of file + phpman3000: Spelling and capitalization are important in programming, unless you are using PHP. \ No newline at end of file diff --git a/bootstrap.js b/bootstrap.js index 46badf8..0ff019d 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -310,7 +310,6 @@ JSBot.prototype.caniuse = function(context, text) { }; JSBot.prototype.dataja = function(ctx, text) { - console.log(ctx); ctx.channel.send(ctx.intent + " Don't ask to ask, just ask"); }; From 4bf7e6206af77ca9eb856a2b5c20bbf0ea4e820b Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Thu, 7 May 2015 00:15:50 +0100 Subject: [PATCH 08/42] major updates --- bootstrap.js | 48 +++++++++++++++++++++++++++++++------------ ecmabot-factoids.json | 4 ++-- hashweb.js | 30 +++++++++++++-------------- lib/irc/index.js | 2 +- package.json | 4 +++- 5 files changed, 55 insertions(+), 33 deletions(-) diff --git a/bootstrap.js b/bootstrap.js index 0ff019d..7ddd2e2 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -5,6 +5,7 @@ var http = require("http"); var fs = require("fs"); var request = require("request"); +var cheerio = require('cheerio'); var Sandbox = require("./lib/sandbox"); var FactoidServer = require("./lib/factoidserv"); @@ -17,6 +18,7 @@ var Shared = require("./shared"); // config.json will be a hidden (gitignored) file for obvious reasons.... var config = JSON.parse(fs.readFileSync('config.json', 'utf8')); var ddgAPi = "https://duckduckgo.com/?q=british%20broadcasting%20corporation&format=json"; +var urlRegex = new RegExp("^(http[s]?:\\/\\/(www\\.)?|ftp:\\/\\/(www\\.)?|www\\.){1}([0-9A-Za-z-\\.@:%_\+~#=]+)+((\\.[a-zA-Z]{2,3})+)(/(.)*)?(\\?(.)*)?"); var JSBot = function(profile) { @@ -35,6 +37,7 @@ util.inherits(JSBot, Bot); JSBot.prototype.init = function() { + var that = this; Bot.prototype.init.call(this); this.register_listener(this.executeRegex, Shared.execute_js); @@ -83,16 +86,46 @@ JSBot.prototype.init = function() { this.register_command("dataja", this.dataja); - this.register_command("chat", this.chat); - this.register_command("seen", hashwebAPI.getLastSeen); this.register_command("ops", hashwebAPI.ops); this.register_command("ddg", this.ddg); + this.register_command("beers", this.do_beers); + this.on('command_not_found', this.command_not_found); + this.on("pm", function(context, text) { + channel = text.match(/^(\#[a-zA-Z0-9-]+)/); + for (var i=0;i < config.users.length ; i++) { + /* Check the config if its a valid user */ + if (config.users[i].host === context.host && channel) { + channel = context.client.get_channel(channel); + text = text.replace(/^(\#[a-zA-Z0-9-]+) /, ""); + channel.send(text.trim()); + } + } + }); + + /* scan messages for links and print titles */ + this.on("message", function(context, text, msg) { + channel = context.client.get_channel(context.name); + /* request only deals with urls which begin with http(s) */ + if (msg.match(urlRegex) && msg.match(/^http[s]?/)) { + /* Make request to URl and get the title */ + var url = msg.match(urlRegex)[0]; + request(url, function(error, response, body) { + if (!error && response.statusCode == 200) { + $ = cheerio.load(body); + var title = $("title").text(); + channel.send("Title: " + title); + } + }); + + }; + }); + this.load_ecma_ref(); }; @@ -135,17 +168,6 @@ JSBot.prototype.google = function(context, text) { context.channel.send_reply (context.intent, "Google search: \""+text+"\" "); }; -JSBot.prototype.chat = function(context, text, something) { - // loop through admins - for(var i = 0; i < config.users.length; i++) { - if (context.sender.name === config.users[i].name && context.sender.host === config.users[i].host) { - var channel = context.client.get_channel("#web-testing"); - channel.send("megalols"); - } - } -} - - JSBot.prototype.there_is_no_try = function(context, text) { var hours = 1000*60*60; var now = +new Date(); diff --git a/ecmabot-factoids.json b/ecmabot-factoids.json index 7bff0bc..491f1b0 100644 --- a/ecmabot-factoids.json +++ b/ecmabot-factoids.json @@ -1029,7 +1029,7 @@ }, "lol": { "value": "Thou shalt not type LOL unless you are really laughing out loud.", - "popularity": 22 + "popularity": 24 }, "equivalent of x": { "value": "Instead of asking \"What's the equivalent of language Y's X\", describe the feature you want. Chances are we don't know what language Y is or what feature X does.", @@ -1429,7 +1429,7 @@ }, "hello": { "value": "hello", - "popularity": 80, + "popularity": 89, "editors": [ "PigDude" ] diff --git a/hashweb.js b/hashweb.js index 72ced45..76cdb08 100644 --- a/hashweb.js +++ b/hashweb.js @@ -1,24 +1,17 @@ var http = require("http"); var fs = require("fs"); +var request = require("request"); var userUrl = "http://hashweb.org/api/stats/users/"; var config = JSON.parse(fs.readFileSync('config.json', 'utf8')); - function callStats(user, callback) { - http.get(userUrl + user, function(res) { - var body = ''; - - res.on('data', function(chunk) { - body += chunk; - }); - - res.on('end', function() { - var response = JSON.parse(body) - callback(response); - }); - }).on('error', function(e) { - console.log("Got error: ", e); - }); +function callStats(user, callback) { + request(userUrl + user, function(error, response, body) { + if (!error && response.statusCode == 200) { + var response = JSON.parse(body) + callback(response); + } + }) } module.exports = { @@ -26,7 +19,12 @@ module.exports = { // Use the Hashweb API to get the last user seen getLastSeen: function(context, username) { callStats(username, function(data) { - context.channel.send_reply(context.sender, data.username + " was last seen " + data.userNotSeenFor.days + " days " + data.userNotSeenFor.hours + " hours " + data.userNotSeenFor.minutes + " minutes ago saying: " + data.lastSeen.message); + var msg = ""; + days = (data.userNotSeenFor.days) ? data.userNotSeenFor.days + " days " : ""; + hours = (data.userNotSeenFor.hours) ? data.userNotSeenFor.hours + " hours " : ""; + minutes = (data.userNotSeenFor.minutes) ? data.userNotSeenFor.minutes + " minutes" : ""; + msg = msg + data.username + " was last seen in #web " + days + hours + minutes + " ago: <" + data.username + "> " + data.lastSeen.message; + context.channel.send_reply(context.sender, msg); }); }, diff --git a/lib/irc/index.js b/lib/irc/index.js index 9f18cbb..9bcd0d3 100644 --- a/lib/irc/index.js +++ b/lib/irc/index.js @@ -283,7 +283,7 @@ Bot.prototype.listeners = { if (this.__commands.hasOwnProperty(command)) { this.__commands[command].callback.call(this, context, parameters, command); } else { - this.emit('command_not_found', context, full); + // this.emit('command_not_found', context, full); } return; } diff --git a/package.json b/package.json index ed02666..0250ac0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,9 @@ { "repository": "https://github.com/oftn/oftn-bot", "dependencies": { - "twitter": "~0.1.19" + "twitter": "~0.1.19", + "request": "~2.55.0", + "cheerio": "~0.19.0" } } From 82f48d8c948e3d4e0a4fd37f06b80fd1c6dbc3af Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Thu, 7 May 2015 00:46:52 +0100 Subject: [PATCH 09/42] adding wolfram --- bootstrap.js | 17 ++++++++++++++++- package.json | 3 ++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/bootstrap.js b/bootstrap.js index 7ddd2e2..6b13902 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -4,8 +4,11 @@ var util = require("util"); var http = require("http"); var fs = require("fs"); +var config = JSON.parse(fs.readFileSync('config.json', 'utf8')); + var request = require("request"); var cheerio = require('cheerio'); +var wolfram = require('wolfram-alpha').createClient(config.wolframAPI, opts); var Sandbox = require("./lib/sandbox"); var FactoidServer = require("./lib/factoidserv"); @@ -13,10 +16,11 @@ var FeelingLucky = require("./lib/feelinglucky"); var CanIUseServer = require("./lib/caniuse"); var hashwebAPI = require("./hashweb"); + var Bot = require("./lib/irc"); var Shared = require("./shared"); // config.json will be a hidden (gitignored) file for obvious reasons.... -var config = JSON.parse(fs.readFileSync('config.json', 'utf8')); + var ddgAPi = "https://duckduckgo.com/?q=british%20broadcasting%20corporation&format=json"; var urlRegex = new RegExp("^(http[s]?:\\/\\/(www\\.)?|ftp:\\/\\/(www\\.)?|www\\.){1}([0-9A-Za-z-\\.@:%_\+~#=]+)+((\\.[a-zA-Z]{2,3})+)(/(.)*)?(\\?(.)*)?"); @@ -94,6 +98,10 @@ JSBot.prototype.init = function() { this.register_command("beers", this.do_beers); + this.register_command("calc", this.calc, { + help: "Wolfram Alpha calculations. Usage !calc [query]" + }); + this.on('command_not_found', this.command_not_found); this.on("pm", function(context, text) { @@ -158,6 +166,13 @@ JSBot.prototype.ddg = function(context, text) { }); } + +JSBot.prototype.calc = function(context, text) { + wolfram.query(text, function (err, result) { + if (err) throw err; + context.channel.send_reply(context.sender, result); + }); +} JSBot.prototype.google = function(context, text) { if (!text) { diff --git a/package.json b/package.json index 0250ac0..01a44b1 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,8 @@ "dependencies": { "twitter": "~0.1.19", "request": "~2.55.0", - "cheerio": "~0.19.0" + "cheerio": "~0.19.0", + "wolfram-alpha": "~0.2.0" } } From b6b5738d8d0b28af51926e9ad85e95e2169102d5 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Thu, 7 May 2015 00:51:57 +0100 Subject: [PATCH 10/42] removing opts --- bootstrap.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap.js b/bootstrap.js index 6b13902..899cab7 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -8,7 +8,7 @@ var config = JSON.parse(fs.readFileSync('config.json', 'utf8')); var request = require("request"); var cheerio = require('cheerio'); -var wolfram = require('wolfram-alpha').createClient(config.wolframAPI, opts); +var wolfram = require('wolfram-alpha').createClient(config.wolframAPI); var Sandbox = require("./lib/sandbox"); var FactoidServer = require("./lib/factoidserv"); From 417196a93b352db991e594a3d7a59597ca6b7a95 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Thu, 7 May 2015 00:57:06 +0100 Subject: [PATCH 11/42] removing calc for now --- bootstrap.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bootstrap.js b/bootstrap.js index 899cab7..32fcf99 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -98,9 +98,9 @@ JSBot.prototype.init = function() { this.register_command("beers", this.do_beers); - this.register_command("calc", this.calc, { - help: "Wolfram Alpha calculations. Usage !calc [query]" - }); + // this.register_command("calc", this.calc, { + // help: "Wolfram Alpha calculations. Usage !calc [query]" + // }); this.on('command_not_found', this.command_not_found); From fc9c6a233ccbbbd88242f982cbfff863796606b0 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Sat, 9 May 2015 17:50:47 +0100 Subject: [PATCH 12/42] fixed !calc --- bootstrap.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bootstrap.js b/bootstrap.js index 32fcf99..45fd880 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -170,9 +170,14 @@ JSBot.prototype.ddg = function(context, text) { JSBot.prototype.calc = function(context, text) { wolfram.query(text, function (err, result) { if (err) throw err; - context.channel.send_reply(context.sender, result); + if (result.length >= 1 && ("subpods" in result[1])) { + context.channel.send_reply(context.sender, result[1].subpods[0].text); + } else { + context.channel.send_reply(context.sender, "Sorry, couldn't find a result for that :("); + } }); -} +}; + JSBot.prototype.google = function(context, text) { if (!text) { From 466cdd117b4323e38025516f403fe58958e06d85 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Sat, 9 May 2015 17:50:47 +0100 Subject: [PATCH 13/42] fixed !calc --- bootstrap.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/bootstrap.js b/bootstrap.js index 32fcf99..f592c32 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -98,9 +98,9 @@ JSBot.prototype.init = function() { this.register_command("beers", this.do_beers); - // this.register_command("calc", this.calc, { - // help: "Wolfram Alpha calculations. Usage !calc [query]" - // }); + this.register_command("calc", this.calc, { + help: "Wolfram Alpha calculations. Usage !calc [query]" + }); this.on('command_not_found', this.command_not_found); @@ -170,9 +170,14 @@ JSBot.prototype.ddg = function(context, text) { JSBot.prototype.calc = function(context, text) { wolfram.query(text, function (err, result) { if (err) throw err; - context.channel.send_reply(context.sender, result); + if (result.length >= 1 && ("subpods" in result[1])) { + context.channel.send_reply(context.sender, result[1].subpods[0].text); + } else { + context.channel.send_reply(context.sender, "Sorry, couldn't find a result for that :("); + } }); -} +}; + JSBot.prototype.google = function(context, text) { if (!text) { From 5d5f22772a7ecd8b6ded7d0bf5937bed6b290b2d Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Sat, 9 May 2015 17:50:47 +0100 Subject: [PATCH 14/42] fixed !calc --- bootstrap.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bootstrap.js b/bootstrap.js index 32fcf99..45fd880 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -170,9 +170,14 @@ JSBot.prototype.ddg = function(context, text) { JSBot.prototype.calc = function(context, text) { wolfram.query(text, function (err, result) { if (err) throw err; - context.channel.send_reply(context.sender, result); + if (result.length >= 1 && ("subpods" in result[1])) { + context.channel.send_reply(context.sender, result[1].subpods[0].text); + } else { + context.channel.send_reply(context.sender, "Sorry, couldn't find a result for that :("); + } }); -} +}; + JSBot.prototype.google = function(context, text) { if (!text) { From e87d98acdbf4f9d76319219372b7a23b1d739e6f Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Sat, 9 May 2015 18:06:39 +0100 Subject: [PATCH 15/42] updating documentation to add calc --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index c88c3da..b5b2ed0 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,14 @@ Usage: `!ecma ` !ecma null value eboyjr: Found: 4.3.11 null value + + +### !calc +Do a calculation using Wolfram Alpha +Usage: `!calc 27 hex to dec` + + !calc Prime Minister of England + eboyjr: David Cameron ### !find Performs a search of a factoid in the database. From ad8ef412687360d2ed0881bc3c9983c0271eebaf Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Mon, 11 May 2015 18:52:38 +0100 Subject: [PATCH 16/42] trim page titles - fixes #18 --- bootstrap.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bootstrap.js b/bootstrap.js index f592c32..e04e251 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -127,6 +127,8 @@ JSBot.prototype.init = function() { if (!error && response.statusCode == 200) { $ = cheerio.load(body); var title = $("title").text(); + // Trim title! + title = title.trim(); channel.send("Title: " + title); } }); From b6a5bafdea18e6352427d604dce510571f525d81 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Mon, 11 May 2015 18:58:40 +0100 Subject: [PATCH 17/42] don't show title if its empty --- bootstrap.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bootstrap.js b/bootstrap.js index e04e251..6dd4385 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -126,10 +126,8 @@ JSBot.prototype.init = function() { request(url, function(error, response, body) { if (!error && response.statusCode == 200) { $ = cheerio.load(body); - var title = $("title").text(); - // Trim title! - title = title.trim(); - channel.send("Title: " + title); + var title = $("title").text().trim(); + if (title) channel.send("Title: " + title); // Don't bother showing a title if its empty } }); From cb62f431b2f313bd54b5aa8da84070728131ba1e Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Tue, 12 May 2015 17:47:08 +0100 Subject: [PATCH 18/42] added First Seen --- bootstrap.js | 2 ++ hashweb.js | 13 +++++++++++++ package.json | 3 ++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/bootstrap.js b/bootstrap.js index 6dd4385..7181934 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -92,6 +92,8 @@ JSBot.prototype.init = function() { this.register_command("seen", hashwebAPI.getLastSeen); + this.register_command("seen", hashwebAPI.getFirstSeen); + this.register_command("ops", hashwebAPI.ops); this.register_command("ddg", this.ddg); diff --git a/hashweb.js b/hashweb.js index 76cdb08..0d3a1b4 100644 --- a/hashweb.js +++ b/hashweb.js @@ -31,5 +31,18 @@ module.exports = { // Use the config file to get the list of ops ops: function(context, username) { context.channel.send_reply(context.sender, config.ops.join(' ')); + }, + + getFirstSeen: function(context, username) { + callStats(username, function(data) { + var today = moment(), + joinedDate = moment(data.firstSeen.timestamp), + joinedDateString = joinedDate.format("dddd, MMMM Do YYYY"); + + var msg = data.username + " was first seen here " + joinedDate.from(today) + " (" + joinedDateString + "): "; + msg = msg + "<" + data.username + ">" + " " + data.firstSeen.message; + + context.channel.send_reply(context.sender, msg); + }); } } \ No newline at end of file diff --git a/package.json b/package.json index 01a44b1..2ff1064 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "twitter": "~0.1.19", "request": "~2.55.0", "cheerio": "~0.19.0", - "wolfram-alpha": "~0.2.0" + "wolfram-alpha": "~0.2.0", + "moment": "~2.10.2" } } From 654f5b8754ecef72d62f2d33ad6d4b59edb09f76 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Tue, 12 May 2015 17:47:52 +0100 Subject: [PATCH 19/42] first seen --- bootstrap.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap.js b/bootstrap.js index 7181934..8d1c2cf 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -92,7 +92,7 @@ JSBot.prototype.init = function() { this.register_command("seen", hashwebAPI.getLastSeen); - this.register_command("seen", hashwebAPI.getFirstSeen); + this.register_command("fseen", hashwebAPI.getFirstSeen); this.register_command("ops", hashwebAPI.ops); From c3824fac8acad5dd56b0759e48a8a8d2271303aa Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Tue, 12 May 2015 17:50:44 +0100 Subject: [PATCH 20/42] adding moment --- hashweb.js | 1 + 1 file changed, 1 insertion(+) diff --git a/hashweb.js b/hashweb.js index 0d3a1b4..b64e132 100644 --- a/hashweb.js +++ b/hashweb.js @@ -1,6 +1,7 @@ var http = require("http"); var fs = require("fs"); var request = require("request"); +var moment = require("moment"); var userUrl = "http://hashweb.org/api/stats/users/"; var config = JSON.parse(fs.readFileSync('config.json', 'utf8')); From faba1e72ab89ac75aa510c780ca72a3f8531e23c Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Thu, 11 Jun 2015 17:58:11 +0100 Subject: [PATCH 21/42] changes to support the rest backend --- bootstrap.js | 2 ++ hashweb.js | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/bootstrap.js b/bootstrap.js index 8d1c2cf..78c4181 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -96,6 +96,8 @@ JSBot.prototype.init = function() { this.register_command("ops", hashwebAPI.ops); + this.register_command("baninfo", hashwebAPI.modifyBansObject); + this.register_command("ddg", this.ddg); this.register_command("beers", this.do_beers); diff --git a/hashweb.js b/hashweb.js index b64e132..3dab50a 100644 --- a/hashweb.js +++ b/hashweb.js @@ -45,5 +45,28 @@ module.exports = { context.channel.send_reply(context.sender, msg); }); + }, + + modifyBansObject: function(context, bansText) { + bansText = bansText.trim(); + id = bansText.match(/^\d+/)[0] + key = bansText.match(/\:(\w*)/)[1] + value = bansText.match(/^\d+\:\w+\s(.+)/)[1] + bansOBject{} + banObject.id = id; + + if (key === "reason") { + bansObject.reason = value + bansObject.reminderTime = false + } + + if (key === "reminderTime") { + bansObject.reminderTime = value + bansObject.reason = false + } + request.post("http://192.168.1.5:8000/stats/bans/" + bansObject.id, {form:{reminderTime: bansObject.reminderTime, reason: bansObject.reason}}, function(err,httpResponse,body) { + console.log(httpResponse); + console.log(body); + }) } } \ No newline at end of file From e434214064bcca8de5754ae2541aecbb75e98054 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Thu, 11 Jun 2015 18:00:01 +0100 Subject: [PATCH 22/42] changes to support the rest backend --- hashweb.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hashweb.js b/hashweb.js index 3dab50a..8126e19 100644 --- a/hashweb.js +++ b/hashweb.js @@ -52,7 +52,7 @@ module.exports = { id = bansText.match(/^\d+/)[0] key = bansText.match(/\:(\w*)/)[1] value = bansText.match(/^\d+\:\w+\s(.+)/)[1] - bansOBject{} + bansOBject = {} banObject.id = id; if (key === "reason") { From 10f98b2e95ebbabd6a8f323b016596a9dc64045e Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Thu, 11 Jun 2015 18:02:00 +0100 Subject: [PATCH 23/42] small change --- hashweb.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hashweb.js b/hashweb.js index 8126e19..9bdd6d6 100644 --- a/hashweb.js +++ b/hashweb.js @@ -52,7 +52,7 @@ module.exports = { id = bansText.match(/^\d+/)[0] key = bansText.match(/\:(\w*)/)[1] value = bansText.match(/^\d+\:\w+\s(.+)/)[1] - bansOBject = {} + bansObject = {} banObject.id = id; if (key === "reason") { From 18712430daa48a1e91bbc07b5942374cc3cfbc63 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Thu, 11 Jun 2015 18:04:46 +0100 Subject: [PATCH 24/42] gahh spelling... --- hashweb.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hashweb.js b/hashweb.js index 9bdd6d6..f020144 100644 --- a/hashweb.js +++ b/hashweb.js @@ -53,7 +53,7 @@ module.exports = { key = bansText.match(/\:(\w*)/)[1] value = bansText.match(/^\d+\:\w+\s(.+)/)[1] bansObject = {} - banObject.id = id; + bansObject.id = id; if (key === "reason") { bansObject.reason = value From 0665fde04321c59a1294fa0178c488bc3e91243c Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Thu, 11 Jun 2015 18:09:36 +0100 Subject: [PATCH 25/42] adding error state for testing --- hashweb.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hashweb.js b/hashweb.js index f020144..d9a749e 100644 --- a/hashweb.js +++ b/hashweb.js @@ -64,7 +64,8 @@ module.exports = { bansObject.reminderTime = value bansObject.reason = false } - request.post("http://192.168.1.5:8000/stats/bans/" + bansObject.id, {form:{reminderTime: bansObject.reminderTime, reason: bansObject.reason}}, function(err,httpResponse,body) { + request.post("http://hashweb.org/api/stats/bans/" + bansObject.id, {form:{reminderTime: bansObject.reminderTime, reason: bansObject.reason}}, function(err,httpResponse,body) { + console.log(err) console.log(httpResponse); console.log(body); }) From 28ef564e479396178d1c1ddc496760b96c0f10da Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Thu, 11 Jun 2015 18:10:28 +0100 Subject: [PATCH 26/42] removing api from url --- hashweb.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hashweb.js b/hashweb.js index d9a749e..c17adae 100644 --- a/hashweb.js +++ b/hashweb.js @@ -64,7 +64,7 @@ module.exports = { bansObject.reminderTime = value bansObject.reason = false } - request.post("http://hashweb.org/api/stats/bans/" + bansObject.id, {form:{reminderTime: bansObject.reminderTime, reason: bansObject.reason}}, function(err,httpResponse,body) { + request.post("http://hashweb.org/stats/bans/" + bansObject.id, {form:{reminderTime: bansObject.reminderTime, reason: bansObject.reason}}, function(err,httpResponse,body) { console.log(err) console.log(httpResponse); console.log(body); From 9e811fa744eecf998ac0c41aa5fdf785ac684164 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Thu, 11 Jun 2015 18:15:28 +0100 Subject: [PATCH 27/42] some modifications to the response --- hashweb.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/hashweb.js b/hashweb.js index c17adae..1346050 100644 --- a/hashweb.js +++ b/hashweb.js @@ -53,21 +53,16 @@ module.exports = { key = bansText.match(/\:(\w*)/)[1] value = bansText.match(/^\d+\:\w+\s(.+)/)[1] bansObject = {} - bansObject.id = id; if (key === "reason") { bansObject.reason = value - bansObject.reminderTime = false } if (key === "reminderTime") { bansObject.reminderTime = value - bansObject.reason = false } - request.post("http://hashweb.org/stats/bans/" + bansObject.id, {form:{reminderTime: bansObject.reminderTime, reason: bansObject.reason}}, function(err,httpResponse,body) { - console.log(err) - console.log(httpResponse); - console.log(body); - }) + request.post("http://hashweb.org/stats/bans/" + id, {form:bansObject}, function(err,httpResponse,body) { + context.channel.send_reply(context.sender, JSON.parse(body.message)); + }); } } \ No newline at end of file From 2a8aeea72f4a90ede5c48c32052effa66e216e71 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Thu, 11 Jun 2015 18:17:28 +0100 Subject: [PATCH 28/42] fixing json problem --- hashweb.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hashweb.js b/hashweb.js index 1346050..45ea328 100644 --- a/hashweb.js +++ b/hashweb.js @@ -62,7 +62,8 @@ module.exports = { bansObject.reminderTime = value } request.post("http://hashweb.org/stats/bans/" + id, {form:bansObject}, function(err,httpResponse,body) { - context.channel.send_reply(context.sender, JSON.parse(body.message)); + // context.channel.send_reply(context.sender, JSON.parse(body.message)); + console.log(body); }); } } \ No newline at end of file From baa52669040cce9c6b6f15e92445844c3f242083 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Thu, 11 Jun 2015 18:17:28 +0100 Subject: [PATCH 29/42] fixing json problem --- hashweb.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hashweb.js b/hashweb.js index 1346050..205d90d 100644 --- a/hashweb.js +++ b/hashweb.js @@ -62,7 +62,7 @@ module.exports = { bansObject.reminderTime = value } request.post("http://hashweb.org/stats/bans/" + id, {form:bansObject}, function(err,httpResponse,body) { - context.channel.send_reply(context.sender, JSON.parse(body.message)); + context.channel.send_reply(context.sender, JSON.parse(body).message) }); } } \ No newline at end of file From 58b73acdecb62b8a7067b82ab598b7bd8cfde93f Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Thu, 11 Jun 2015 18:23:28 +0100 Subject: [PATCH 30/42] fixing merge conflict --- hashweb.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/hashweb.js b/hashweb.js index 1bb5531..205d90d 100644 --- a/hashweb.js +++ b/hashweb.js @@ -62,12 +62,7 @@ module.exports = { bansObject.reminderTime = value } request.post("http://hashweb.org/stats/bans/" + id, {form:bansObject}, function(err,httpResponse,body) { -<<<<<<< HEAD context.channel.send_reply(context.sender, JSON.parse(body).message) -======= - // context.channel.send_reply(context.sender, JSON.parse(body.message)); - console.log(body); ->>>>>>> 2a8aeea72f4a90ede5c48c32052effa66e216e71 }); } } \ No newline at end of file From f385090eddf089e1e6f2826ed47d0f25e50621c7 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Thu, 11 Jun 2015 18:28:47 +0100 Subject: [PATCH 31/42] adding some authorization check --- hashweb.js | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/hashweb.js b/hashweb.js index 205d90d..8d9f80e 100644 --- a/hashweb.js +++ b/hashweb.js @@ -48,21 +48,25 @@ module.exports = { }, modifyBansObject: function(context, bansText) { - bansText = bansText.trim(); - id = bansText.match(/^\d+/)[0] - key = bansText.match(/\:(\w*)/)[1] - value = bansText.match(/^\d+\:\w+\s(.+)/)[1] - bansObject = {} + if (config.users[i].host === context.host && channel) { + bansText = bansText.trim(); + id = bansText.match(/^\d+/)[0] + key = bansText.match(/\:(\w*)/)[1] + value = bansText.match(/^\d+\:\w+\s(.+)/)[1] + bansObject = {} - if (key === "reason") { - bansObject.reason = value - } + if (key === "reason") { + bansObject.reason = value + } - if (key === "reminderTime") { - bansObject.reminderTime = value + if (key === "reminderTime") { + bansObject.reminderTime = value + } + request.post("http://hashweb.org/stats/bans/" + id, {form:bansObject}, function(err,httpResponse,body) { + context.channel.send_reply(context.sender, JSON.parse(body).message) + }); + } else { + context.channel.send_reply(context.sender, "Oops, looks like you're not authorized!"); } - request.post("http://hashweb.org/stats/bans/" + id, {form:bansObject}, function(err,httpResponse,body) { - context.channel.send_reply(context.sender, JSON.parse(body).message) - }); } } \ No newline at end of file From 7b5aaab900e9d8a091afc998ca6a04a02164bb9f Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Thu, 11 Jun 2015 18:31:16 +0100 Subject: [PATCH 32/42] adding some authorization check2 --- hashweb.js | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/hashweb.js b/hashweb.js index 8d9f80e..95f8b33 100644 --- a/hashweb.js +++ b/hashweb.js @@ -48,25 +48,28 @@ module.exports = { }, modifyBansObject: function(context, bansText) { - if (config.users[i].host === context.host && channel) { - bansText = bansText.trim(); - id = bansText.match(/^\d+/)[0] - key = bansText.match(/\:(\w*)/)[1] - value = bansText.match(/^\d+\:\w+\s(.+)/)[1] - bansObject = {} + // TODO: make a isAuth? function + for (var i=0;i < config.users.length ; i++) { + if (config.users[i].host === context.host && channel) { + bansText = bansText.trim(); + id = bansText.match(/^\d+/)[0] + key = bansText.match(/\:(\w*)/)[1] + value = bansText.match(/^\d+\:\w+\s(.+)/)[1] + bansObject = {} - if (key === "reason") { - bansObject.reason = value - } + if (key === "reason") { + bansObject.reason = value + } - if (key === "reminderTime") { - bansObject.reminderTime = value + if (key === "reminderTime") { + bansObject.reminderTime = value + } + request.post("http://hashweb.org/stats/bans/" + id, {form:bansObject}, function(err,httpResponse,body) { + context.channel.send_reply(context.sender, JSON.parse(body).message) + }); + } else { + context.channel.send_reply(context.sender, "Oops, looks like you're not authorized!"); } - request.post("http://hashweb.org/stats/bans/" + id, {form:bansObject}, function(err,httpResponse,body) { - context.channel.send_reply(context.sender, JSON.parse(body).message) - }); - } else { - context.channel.send_reply(context.sender, "Oops, looks like you're not authorized!"); } - } + }); } \ No newline at end of file From fb260dd28429770c45bdba40b435d582c686408d Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Thu, 11 Jun 2015 18:32:37 +0100 Subject: [PATCH 33/42] adding some authorization check3 --- hashweb.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hashweb.js b/hashweb.js index 95f8b33..8e25097 100644 --- a/hashweb.js +++ b/hashweb.js @@ -71,5 +71,5 @@ module.exports = { context.channel.send_reply(context.sender, "Oops, looks like you're not authorized!"); } } - }); + }; } \ No newline at end of file From ddafd32b62155a1de701438f1b5f03f69ccc7be3 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Thu, 11 Jun 2015 18:33:49 +0100 Subject: [PATCH 34/42] adding some authorization check4 --- hashweb.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hashweb.js b/hashweb.js index 8e25097..fc76dd3 100644 --- a/hashweb.js +++ b/hashweb.js @@ -71,5 +71,5 @@ module.exports = { context.channel.send_reply(context.sender, "Oops, looks like you're not authorized!"); } } - }; + } } \ No newline at end of file From 2da41bf349839e65cbad4784a240541cb759ca77 Mon Sep 17 00:00:00 2001 From: Ella Date: Thu, 11 Jun 2015 18:43:10 +0100 Subject: [PATCH 35/42] adjusting authorization check --- ecmabot-factoids.json | 640 +++++++++++++++++++++++++++++++++++++++--- hashweb.js | 4 +- 2 files changed, 607 insertions(+), 37 deletions(-) diff --git a/ecmabot-factoids.json b/ecmabot-factoids.json index 491f1b0..5ea4d3f 100644 --- a/ecmabot-factoids.json +++ b/ecmabot-factoids.json @@ -90,7 +90,7 @@ }, "paste": { "value": "Show some code, but don't paste it on the channel. Sites like http://gist.github.com/ and http://bpaste.net/ are cool. You can also use http://jsbin.com , http://requirebin.com or http://jsfiddle.net/ to provide a test case we can run and help you with your problem.", - "popularity": 916, + "popularity": 918, "editors": [ "niggler", "gkatsev", @@ -247,12 +247,30 @@ "popularity": 14 }, "recursion": { - "value": "See !recursion", - "popularity": 30 + "value": "!learn recursion", + "popularity": 32, + "editors": [ + "inoutput", + "TheHackOPs" + ], + "changes": [ + { + "date": "2015-05-06T23:53:57.950Z", + "editor": "inoutput", + "old-value": "See !recursion", + "new-value": "!learn recursion" + }, + { + "date": "2015-05-19T02:16:54.078Z", + "editor": "TheHackOPs", + "old-value": "!learn recursion", + "new-value": "!learn recursion" + } + ] }, "ask": { "value": "Don't ask to ask, or if anyone is here or alive or uses something. Just ask your question. http://www.mikeash.com/getting_answers.html http://www.catb.org/esr/faqs/smart-questions.html", - "popularity": 406, + "popularity": 408, "editors": [ "hemanth", "eboy", @@ -312,11 +330,11 @@ }, "mdc": { "value": "Mozilla Developer Network @ http://developer.mozilla.org/", - "popularity": 52 + "popularity": 55 }, "mdn": { "alias": "mdc", - "popularity": 41 + "popularity": 43 }, "debugging": { "alias": "console" @@ -428,7 +446,7 @@ }, "help": { "value": "For help, ask your question. Be patient. Code samples should be pasted in a paste service (see !paste). Tell us 1) what you want to happen, 2) what is actually happening, and 3) any error messages you find (see !describe and !debug).", - "popularity": 2229, + "popularity": 2237, "editors": [ "ashnur" ] @@ -474,11 +492,12 @@ "alias": "doesn't work" }, "resources": { - "value": "!books, !es5, !gcu, !mdn, !owsc, !quirksmode, !caniuse, !crockford", - "popularity": 9, + "value": "https://developer.mozilla.org/en-US/ http://www.codecademy.com/ http://www.w3schools.com/ http://hashcss.com/schools/", + "popularity": 10, "editors": [ "Agamemnus", - "Havvy" + "Havvy", + "coachz" ], "changes": [ { @@ -492,6 +511,12 @@ "editor": "Havvy", "old-value": "!eloquent, !es5, !gcu, !mdn, !owsc, !quirksmode, !caniuse", "new-value": "!books, !es5, !gcu, !mdn, !owsc, !quirksmode, !caniuse, !crockford" + }, + { + "date": "2015-05-22T13:51:17.254Z", + "editor": "coachz", + "old-value": "!books, !es5, !gcu, !mdn, !owsc, !quirksmode, !caniuse, !crockford", + "new-value": "https://developer.mozilla.org/en-US/ http://www.codecademy.com/ http://www.w3schools.com/ http://hashcss.com/schools/" } ] }, @@ -695,11 +720,11 @@ }, "js": { "value": "did you mean: recursive acronym for JavaScript is not Java.", - "popularity": 17 + "popularity": 18 }, "comparisons": { "value": "Using == and != should be avoided, since they perform coercion giving unexpected results. Use === and !== instead. See also: http://zero.milosz.ca/ http://es5.github.io/#x11.9.3", - "popularity": 66, + "popularity": 67, "editors": [ "jrajav", "j201", @@ -855,7 +880,7 @@ }, "testcase": { "value": "Show some code, but don't paste it on the channel. Sites like http://gist.github.com/ and http://bpaste.net/ are cool. You can also use http://jsbin.com , http://requirebin.com or http://jsfiddle.net/ to provide a test case we can run and help you with your problem.", - "popularity": 62, + "popularity": 63, "editors": [ "MJCD", "totemizer", @@ -1028,8 +1053,19 @@ "popularity": 4 }, "lol": { - "value": "Thou shalt not type LOL unless you are really laughing out loud.", - "popularity": 24 + "value": "lol", + "popularity": 24, + "editors": [ + "NotTheHackOps" + ], + "changes": [ + { + "date": "2015-05-06T23:53:11.761Z", + "editor": "NotTheHackOps", + "old-value": "Thou shalt not type LOL unless you are really laughing out loud.", + "new-value": "lol" + } + ] }, "equivalent of x": { "value": "Instead of asking \"What's the equivalent of language Y's X\", describe the feature you want. Chances are we don't know what language Y is or what feature X does.", @@ -1547,7 +1583,7 @@ }, "functions": { "value": "See !fe vs fd", - "popularity": 5 + "popularity": 6 }, "ssjs": { "value": "Server-side JavaScript: Node.js and other V8 distributions (C++), Rhino (JVM), Spidermonkey (C).", @@ -1712,10 +1748,19 @@ "alias": "!>>" }, "es6": { - "value": "The next version of JavaScript, slated for completion in late 2013. For ES6 features see http://wiki.ecmascript.org/doku.php?id=harmony:proposals. To experiment with ES6 now see http://benvie.github.com/continuum. For availability in browsers see http://kangax.github.com/es5-compat-table/es6", + "value": "http://kangax.github.io/compat-table/es6/", "popularity": 21, "editors": [ - "Benvie" + "Benvie", + "coachz" + ], + "changes": [ + { + "date": "2015-05-22T14:06:15.088Z", + "editor": "coachz", + "old-value": "The next version of JavaScript, slated for completion in late 2013. For ES6 features see http://wiki.ecmascript.org/doku.php?id=harmony:proposals. To experiment with ES6 now see http://benvie.github.com/continuum. For availability in browsers see http://kangax.github.com/es5-compat-table/es6", + "new-value": "http://kangax.github.io/compat-table/es6/" + } ] }, "concat": { @@ -1803,11 +1848,11 @@ }, "i love you": { "value": "I love you too. <3", - "popularity": 7 + "popularity": 13 }, "<3": { "alias": "i love you", - "popularity": 1 + "popularity": 2 }, "hipsters": { "value": "hipsters use for all their javascript comments. JS: The Hip Parts: https://gist.github.com/3374141", @@ -1834,7 +1879,7 @@ }, "love": { "alias": "i love you", - "popularity": 3 + "popularity": 8 }, "cthuloops": { "value": "I give you, a cthuloop: for (;;) { } … FOR CTHULU", @@ -2335,7 +2380,7 @@ }, "hamster": { "value": "Java is to Javascript like ham is to hamster.", - "popularity": 3, + "popularity": 4, "creator": "ljharb", "editors": [] }, @@ -2384,16 +2429,17 @@ }, "beer": { "value": "Don't mind if I do! Glug glug glug!", - "popularity": 9, + "popularity": 12, "creator": "CoverSlide", "editors": [] }, "stop": { - "value": "hammer time", + "value": "While some offtopic converstation is ok at TIMES, please take this to #web-social if you wish to continue. Thanks. The Management. :-)", "popularity": 7, "creator": "eboy", "editors": [ - "Maxdamantus" + "Maxdamantus", + "coachz" ], "changes": [ { @@ -2401,6 +2447,12 @@ "editor": "Maxdamantus", "old-value": "collaborate and listen", "new-value": "hammer time" + }, + { + "date": "2015-05-22T13:30:03.935Z", + "editor": "coachz", + "old-value": "hammer time", + "new-value": "While some offtopic converstation is ok at TIMES, please take this to #web-social if you wish to continue. Thanks. The Management. :-)" } ] }, @@ -2781,7 +2833,7 @@ }, "fe": { "value": "A function declaration `function declared() {}` & a function expression e.g. `var bar = function expressed() {}`: the former is !hoisted, the latter can be immediately invoked (see !iife) and can be anonymous (eg can omit the name \"expressed\"). \"function\" as the first word of a statement at global scope or directly inside a function starts a function declaration; otherwise, it starts a function expression.", - "popularity": 50, + "popularity": 52, "creator": "ljharb", "editors": [ "ljharb" @@ -2789,7 +2841,7 @@ }, "fd": { "alias": "fe", - "popularity": 1 + "popularity": 2 }, "json object": { "value": "JSON object is an often misused buzzword that does not have a well-defined meaning. See https://github.com/robotlolita/screw-the-buzzwords/wiki/JSON for alternatives to express what you mean.", @@ -2801,7 +2853,7 @@ }, "think": { "value": "\"Give me 6 hours to chop down a tree and I will spend the first 4 sharpening my axe.\" - Abraham Lincoln", - "popularity": 2, + "popularity": 3, "creator": "ljharb", "editors": [ "ljharb" @@ -3084,14 +3136,15 @@ ] }, "fp": { - "value": "Functional programming: A style of programming which uses only pure (mathematical) functions, avoiding side-effects", + "value": "http://code.tutsplus.com/courses/functional-programming-in-javascript", "popularity": 25, "creator": "Sorella", "editors": [ "Sorella", "Maxdamantus", "j201", - "ashnur" + "ashnur", + "coachz" ], "changes": [ { @@ -3113,6 +3166,12 @@ "editor": "ashnur", "old-value": "Functional programming: 1) A style of programming which uses only pure (mathematical) functions, avoiding side-effects; 2) A term used loosely by many to refer to higher-order programming, where functions or procedures are first-class citizens and are passed around to influence the effects of other functions or procedures", "new-value": "Functional programming: A style of programming which uses only pure (mathematical) functions, avoiding side-effects" + }, + { + "date": "2015-05-08T17:57:22.027Z", + "editor": "coachz", + "old-value": "Functional programming: A style of programming which uses only pure (mathematical) functions, avoiding side-effects", + "new-value": "http://code.tutsplus.com/courses/functional-programming-in-javascript" } ] }, @@ -3272,7 +3331,7 @@ }, "important": { "value": "CSS: \"An !important declaration provides a way for a stylesheet author to give a CSS value more weight than it naturally has.\" | More: http://coding.smashingmagazine.com/2010/11/02/the-important-css-declaration-how-and-when-to-use-it/", - "popularity": 1, + "popularity": 2, "creator": "MJCD_", "editors": [] }, @@ -3492,7 +3551,7 @@ "value": "omg", "creator": "urbanizator", "date": "2013-12-23T16:26:17.770Z", - "popularity": 31, + "popularity": 35, "editors": [], "changes": [] }, @@ -4133,7 +4192,7 @@ "alias": "comparisons", "creator": "", "date": "2014-03-23T23:44:47.732Z", - "popularity": 3, + "popularity": 4, "editors": [], "changes": [] }, @@ -4354,7 +4413,7 @@ "value": "I am supposed to say something compromising, because someone told me to when the channel was pretty quiet.", "creator": "Qbix2", "date": "2014-04-24T00:17:29.237Z", - "popularity": 17, + "popularity": 19, "editors": [], "changes": [] }, @@ -4628,7 +4687,7 @@ "value": "jQuery is magical, for example the $ function can be called in any of these ways, and more: $('.a'), $('.a', $(el)) $(el), $([el1, el2]), $({}), $($(el)), $('
'), $('
', document), $('
', {id: 'x'}), $(function(){})", "creator": "GreenJello", "date": "2014-08-20T21:39:11.541Z", - "popularity": 0, + "popularity": 1, "editors": [], "changes": [] }, @@ -4693,9 +4752,437 @@ "value": "somebody", "creator": "Jayflux", "date": "2015-02-14T00:29:40.940Z", + "popularity": 2, + "editors": [], + "changes": [] + }, + "!learn recursion": { + "value": "!learn recursion", + "creator": "inoutput", + "date": "2015-05-06T23:54:03.867Z", + "popularity": 0, + "editors": [], + "changes": [] + }, + "!learn !learn": { + "value": "!learn !learn", + "creator": "inoutput", + "date": "2015-05-06T23:56:32.772Z", + "popularity": 0, + "editors": [], + "changes": [] + }, + "!learn": { + "value": "!learn !learn", + "creator": "inoutput", + "date": "2015-05-06T23:56:47.469Z", + "popularity": 0, + "editors": [ + "inoutput" + ], + "changes": [ + { + "date": "2015-05-06T23:59:45.860Z", + "editor": "inoutput", + "old-value": "!learn !learn", + "new-value": "!learn !learn" + } + ] + }, + "pingu": { + "value": "there are many pingus", + "creator": "Jayflux", + "date": "2015-05-07T09:39:13.478Z", + "popularity": 4, + "editors": [], + "changes": [] + }, + "whatkind": { + "value": "what kind of pingu do you like the most?", + "creator": "pingu3", + "date": "2015-05-07T09:40:12.482Z", + "popularity": 1, + "editors": [], + "changes": [] + }, + "coachz": { + "value": "coachz is the bomb !", + "creator": "Jayflux", + "date": "2015-05-07T13:01:55.178Z", + "popularity": 6, + "editors": [ + "Jayflux", + "coachz" + ], + "changes": [ + { + "date": "2015-05-07T13:02:07.624Z", + "editor": "Jayflux", + "old-value": "is thaifood", + "new-value": "coachz is thaifood" + }, + { + "date": "2015-05-08T13:51:00.321Z", + "editor": "coachz", + "old-value": "coachz is thaifood", + "new-value": "coachz is the bomb !" + } + ] + }, + "jsgrids": { + "value": "http://guriddo.net/ & http://datatables.net/", + "creator": "coachz", + "date": "2015-05-07T13:02:41.666Z", + "popularity": 3, + "editors": [], + "changes": [] + }, + "emailrep": { + "value": "http://blog.mailgun.com/art-of-inboxing/ http://documentation.mailgun.com/faqs.html http://documentation.mailgun.com/best_practices.html", + "creator": "coachz", + "date": "2015-05-07T14:46:26.312Z", + "popularity": 0, + "editors": [], + "changes": [] + }, + "illegal": { + "value": "Please do not help people create illegal websites / applications with the intent of exploiting others", + "creator": "TheHackOps", + "date": "2015-05-07T23:54:05.730Z", + "popularity": 0, + "editors": [], + "changes": [] + }, + "obfusication": { + "value": "We will not help you to obfusicate anything for the purpose of 'security'", + "creator": "TheHackOps", + "date": "2015-05-07T23:56:28.927Z", + "popularity": 0, + "editors": [], + "changes": [] + }, + "sbo": { + "value": "Security by obscurity is not security", + "creator": "TheHackOps", + "date": "2015-05-07T23:56:54.439Z", + "popularity": 1, + "editors": [], + "changes": [] + }, + "trolling": { + "value": "DeltaHeavy", + "creator": "TheHackOps", + "date": "2015-05-07T23:58:36.665Z", + "popularity": 1, + "editors": [], + "changes": [] + }, + "buzzwords": { + "value": "Dont promote them please", + "creator": "TheHackOps", + "date": "2015-05-08T00:48:14.364Z", + "popularity": 1, + "editors": [], + "changes": [] + }, + "evilbug": { + "value": ":D", + "creator": "TheHackOps", + "date": "2015-05-08T05:05:34.674Z", + "popularity": 2, + "editors": [ + "evilbug" + ], + "changes": [ + { + "date": "2015-05-08T05:06:12.523Z", + "editor": "evilbug", + "old-value": "bully", + "new-value": ":D" + } + ] + }, + "thehackops": { + "value": "Hates Asp.net", + "creator": "evilbug", + "date": "2015-05-08T05:07:30.959Z", + "popularity": 3, + "editors": [ + "TheHackOps" + ], + "changes": [ + { + "date": "2015-05-08T13:50:53.220Z", + "editor": "TheHackOps", + "old-value": "asp.net", + "new-value": "Hates Asp.net" + } + ] + }, + "deltaheavy": { + "value": "\"don't wake the borg!\"", + "creator": "coachz", + "date": "2015-05-08T13:01:28.353Z", + "popularity": 2, + "editors": [], + "changes": [] + }, + "emerson": { + "value": "im about 10 seconds away from patching the bot to only allow !learn in #web-social...", + "creator": "coachz", + "date": "2015-05-08T13:52:33.119Z", + "popularity": 1, + "editors": [], + "changes": [] + }, + "xmaddness": { + "value": "<-- what I am doing", + "creator": "coachz", + "date": "2015-05-08T16:10:48.839Z", + "popularity": 0, + "editors": [], + "changes": [] + }, + "billy71": { + "value": "I love the duck", + "creator": "coachz", + "date": "2015-05-08T16:25:28.812Z", + "popularity": 0, + "editors": [], + "changes": [] + }, + "privacy": { + "value": "http://chronicle.com/article/Why-Privacy-Matters-Even-if/127461/", + "creator": "coachz", + "date": "2015-05-08T16:50:45.859Z", + "popularity": 1, + "editors": [], + "changes": [] + }, + "!seen": { + "value": "lol", + "creator": "billy71", + "date": "2015-05-08T17:04:55.957Z", + "popularity": 0, + "editors": [], + "changes": [] + }, + "!seen test": { + "value": "lol", + "creator": "billy71", + "date": "2015-05-08T17:05:09.850Z", + "popularity": 0, + "editors": [], + "changes": [] + }, + "fwotw": { + "value": "http://quinnjs.com/", + "creator": "coachz", + "date": "2015-05-08T18:59:15.887Z", + "popularity": 2, + "editors": [], + "changes": [] + }, + "pingu2": { + "value": "see !pingu3", + "creator": "Buck", + "date": "2015-05-10T11:17:27.868Z", + "popularity": 3, + "editors": [], + "changes": [] + }, + "pingu3": { + "value": "see !pingu4", + "creator": "Buck", + "date": "2015-05-10T11:17:33.720Z", + "popularity": 2, + "editors": [], + "changes": [] + }, + "pingu4": { + "value": "see !pingu5", + "creator": "Buck", + "date": "2015-05-10T11:17:36.650Z", + "popularity": 0, + "editors": [], + "changes": [] + }, + "pingu6": { + "value": "see !pingu7", + "creator": "Buck", + "date": "2015-05-10T11:17:39.223Z", + "popularity": 0, + "editors": [], + "changes": [] + }, + "pingu5": { + "value": "see !pingu6", + "creator": "Buck", + "date": "2015-05-10T11:17:43.310Z", + "popularity": 0, + "editors": [], + "changes": [] + }, + "pingu7": { + "value": "see !pingu8", + "creator": "Buck", + "date": "2015-05-10T11:17:47.855Z", + "popularity": 0, + "editors": [], + "changes": [] + }, + "pingu8": { + "value": "see !pingu9", + "creator": "Buck", + "date": "2015-05-10T11:17:55.463Z", + "popularity": 0, + "editors": [], + "changes": [] + }, + "pingu9": { + "value": "see !pingu10", + "creator": "Buck", + "date": "2015-05-10T11:18:00.190Z", + "popularity": 0, + "editors": [], + "changes": [] + }, + "pingu10": { + "value": "see !pingu11", + "creator": "Buck", + "date": "2015-05-10T11:18:03.967Z", + "popularity": 0, + "editors": [], + "changes": [] + }, + "pingu11": { + "value": "see !pingu12", + "creator": "Buck", + "date": "2015-05-10T11:18:06.960Z", + "popularity": 0, + "editors": [], + "changes": [] + }, + "pingu12": { + "value": "see !pingu2", + "creator": "Buck", + "date": "2015-05-10T11:18:10.031Z", + "popularity": 0, + "editors": [], + "changes": [] + }, + "peace": { + "value": "http://i.huffpost.com/gen/1915222/images/s-PEACE-EARTH-large.jpg", + "creator": "coachz", + "date": "2015-05-12T16:34:12.750Z", + "popularity": 1, + "editors": [], + "changes": [] + }, + "bestsite": { + "value": "http://www.lingscars.com", + "creator": "coachz", + "date": "2015-05-12T17:13:57.573Z", + "popularity": 0, + "editors": [], + "changes": [] + }, + "thependulum": { + "value": "The Poet And The Pendulum (https://www.youtube.com/watch?v=1HYgidYaBl8)", + "creator": "Jayflux", + "date": "2015-05-13T12:24:13.114Z", + "popularity": 1, + "editors": [ + "Jayflux" + ], + "changes": [ + { + "date": "2015-05-13T12:25:36.490Z", + "editor": "Jayflux", + "old-value": "The Poet And The Pendulum", + "new-value": "The Poet And The Pendulum (https://www.youtube.com/watch?v=1HYgidYaBl8)" + } + ] + }, + "basel": { + "value": "(pi^2)/6 = 1.64493406685", + "creator": "festercluck", + "date": "2015-05-13T13:09:55.273Z", + "popularity": 1, + "editors": [], + "changes": [] + }, + "pro": { + "value": "pro bro != pro bono", + "creator": "festercluck", + "date": "2015-05-13T13:12:21.762Z", + "popularity": 1, + "editors": [], + "changes": [] + }, + "probrony": { + "value": "new Rony()", + "creator": "festercluck", + "date": "2015-05-13T13:12:54.952Z", + "popularity": 0, + "editors": [], + "changes": [] + }, + "lw": { + "value": "http://liveweave.com", + "creator": "Buck", + "date": "2015-05-17T12:39:54.759Z", + "popularity": 1, + "editors": [], + "changes": [] + }, + "bwe": { + "value": "The Best Website Ever http://lingscars.com watch the movies in the FAQ top right", + "creator": "coachz", + "date": "2015-05-22T12:09:44.679Z", + "popularity": 4, + "editors": [], + "changes": [] + }, + "wedding": { + "value": "http://yvettesbridalformal.p1r8.net/", + "creator": "coachz", + "date": "2015-05-22T13:40:14.820Z", "popularity": 1, "editors": [], "changes": [] + }, + "calc": { + "value": "js", + "creator": "Buck", + "date": "2015-05-22T15:55:08.387Z", + "popularity": 0, + "editors": [], + "changes": [] + }, + "mars": { + "value": "Mars is populated entirely by robots", + "creator": "Buck", + "date": "2015-05-26T17:38:14.853Z", + "popularity": 0, + "editors": [], + "changes": [] + }, + "diamond": { + "value": "not a metal", + "creator": "TheHackOps", + "date": "2015-06-01T04:51:41.936Z", + "popularity": 1, + "editors": [], + "changes": [] + }, + "die": { + "value": "Even dying can be pretty great ! http://www.lingscars.com FAQ What if I die.", + "creator": "coachz", + "date": "2015-06-01T14:50:33.424Z", + "popularity": 0, + "editors": [], + "changes": [] } }, "delete_log": [ @@ -5321,6 +5808,89 @@ } ] } + }, + { + "date": "2015-05-08T17:08:41.176Z", + "editor": "Obbs", + "key": "i", + "value": { + "value": "Yo", + "creator": "Obbs", + "date": "2015-05-08T17:07:31.753Z", + "popularity": 2, + "editors": [], + "changes": [] + } + }, + { + "date": "2015-05-09T16:36:04.184Z", + "editor": "Obbs", + "key": "triangle", + "value": { + "value": "Δ", + "creator": "Obbs", + "date": "2015-05-09T16:33:54.088Z", + "popularity": 0, + "editors": [], + "changes": [] + } + }, + { + "date": "2015-05-09T16:36:36.016Z", + "editor": "Obbs", + "key": "triangle δ", + "value": { + "value": "b² - 4ac", + "creator": "Obbs", + "date": "2015-05-09T16:36:11.651Z", + "popularity": 0, + "editors": [], + "changes": [] + } + }, + { + "date": "2015-05-15T13:35:47.999Z", + "editor": "emerson", + "key": "experts", + "value": { + "value": "bar", + "creator": "coachz", + "date": "2015-05-15T13:29:28.272Z", + "popularity": 0, + "editors": [ + "Buck" + ], + "changes": [ + { + "date": "2015-05-15T13:35:45.791Z", + "editor": "Buck", + "old-value": "pokk Jayflux emerson buck tjahan", + "new-value": "bar" + } + ] + } + }, + { + "date": "2015-05-19T15:10:56.374Z", + "editor": "emerson", + "key": "op", + "value": { + "value": "Haha, you are alone. Nobody will come to help you.", + "creator": "billy71", + "date": "2015-05-08T00:01:05.722Z", + "popularity": 4, + "editors": [ + "billy71" + ], + "changes": [ + { + "date": "2015-05-08T00:01:52.167Z", + "editor": "billy71", + "old-value": "Haha, nobody will come.", + "new-value": "Haha, you are alone. Nobody will come to help you." + } + ] + } } ] } \ No newline at end of file diff --git a/hashweb.js b/hashweb.js index fc76dd3..ff21c90 100644 --- a/hashweb.js +++ b/hashweb.js @@ -50,7 +50,7 @@ module.exports = { modifyBansObject: function(context, bansText) { // TODO: make a isAuth? function for (var i=0;i < config.users.length ; i++) { - if (config.users[i].host === context.host && channel) { + if (config.users[i].host === context.intent.host && channel) { bansText = bansText.trim(); id = bansText.match(/^\d+/)[0] key = bansText.match(/\:(\w*)/)[1] @@ -72,4 +72,4 @@ module.exports = { } } } -} \ No newline at end of file +} From 29d1a9fdc27c805893c7d00e7ae3389217d3abf3 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Thu, 11 Jun 2015 18:54:04 +0100 Subject: [PATCH 36/42] moving logic to isAuth function --- hashweb.js | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/hashweb.js b/hashweb.js index ff21c90..e50b5b8 100644 --- a/hashweb.js +++ b/hashweb.js @@ -15,6 +15,15 @@ function callStats(user, callback) { }) } +function isAuth(host) { + for (var i=0;i < config.users.length ; i++) { + if (config.users[i].host === host) { + return true + } + } + return false; +} + module.exports = { // Use the Hashweb API to get the last user seen @@ -48,28 +57,25 @@ module.exports = { }, modifyBansObject: function(context, bansText) { - // TODO: make a isAuth? function - for (var i=0;i < config.users.length ; i++) { - if (config.users[i].host === context.intent.host && channel) { - bansText = bansText.trim(); - id = bansText.match(/^\d+/)[0] - key = bansText.match(/\:(\w*)/)[1] - value = bansText.match(/^\d+\:\w+\s(.+)/)[1] - bansObject = {} + if (isAuth(context) { + bansText = bansText.trim(); + id = bansText.match(/^\d+/)[0] + key = bansText.match(/\:(\w*)/)[1] + value = bansText.match(/^\d+\:\w+\s(.+)/)[1] + bansObject = {} - if (key === "reason") { - bansObject.reason = value - } + if (key === "reason") { + bansObject.reason = value + } - if (key === "reminderTime") { - bansObject.reminderTime = value - } - request.post("http://hashweb.org/stats/bans/" + id, {form:bansObject}, function(err,httpResponse,body) { - context.channel.send_reply(context.sender, JSON.parse(body).message) - }); - } else { - context.channel.send_reply(context.sender, "Oops, looks like you're not authorized!"); + if (key === "reminderTime") { + bansObject.reminderTime = value } + request.post("http://hashweb.org/stats/bans/" + id, {form:bansObject}, function(err,httpResponse,body) { + context.channel.send_reply(context.sender, JSON.parse(body).message) + }); + } else { + context.channel.send_reply(context.sender, "Oops, looks like you're not authorized!"); } } -} +} \ No newline at end of file From 7e90c8df3619bc6ca462a309c87287de307df2d7 Mon Sep 17 00:00:00 2001 From: Ella Date: Thu, 11 Jun 2015 18:56:20 +0100 Subject: [PATCH 37/42] small fix --- hashweb.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hashweb.js b/hashweb.js index e50b5b8..655236c 100644 --- a/hashweb.js +++ b/hashweb.js @@ -57,7 +57,7 @@ module.exports = { }, modifyBansObject: function(context, bansText) { - if (isAuth(context) { + if (isAuth(context.intent.host)) { bansText = bansText.trim(); id = bansText.match(/^\d+/)[0] key = bansText.match(/\:(\w*)/)[1] @@ -78,4 +78,4 @@ module.exports = { context.channel.send_reply(context.sender, "Oops, looks like you're not authorized!"); } } -} \ No newline at end of file +} From f9cb2b46fe65ed2e5d23d036157abf694befe8b6 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Thu, 11 Jun 2015 18:59:43 +0100 Subject: [PATCH 38/42] adding update option --- bootstrap.js | 4 +++- hashweb.js | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/bootstrap.js b/bootstrap.js index 78c4181..df12cd0 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -97,7 +97,9 @@ JSBot.prototype.init = function() { this.register_command("ops", hashwebAPI.ops); this.register_command("baninfo", hashwebAPI.modifyBansObject); - + + this.register_command("updatebans", hashwebAPI.updateBansList); + this.register_command("ddg", this.ddg); this.register_command("beers", this.do_beers); diff --git a/hashweb.js b/hashweb.js index 655236c..bde0d25 100644 --- a/hashweb.js +++ b/hashweb.js @@ -57,7 +57,7 @@ module.exports = { }, modifyBansObject: function(context, bansText) { - if (isAuth(context.intent.host)) { + if (isAuth(context) { bansText = bansText.trim(); id = bansText.match(/^\d+/)[0] key = bansText.match(/\:(\w*)/)[1] @@ -77,5 +77,15 @@ module.exports = { } else { context.channel.send_reply(context.sender, "Oops, looks like you're not authorized!"); } + }, + + updateBansList: function(context, bansText) { + if (isAuth(context) { + request.post("http://hashweb.org/stats/bans/update", function(err,httpResponse,body) { + context.channel.send_reply(context.sender, JSON.parse(body).message) + }); + } else { + context.channel.send_reply(context.sender, "Oops, looks like you're not authorized!"); + } } -} +} \ No newline at end of file From 9dad3f8a1aa09206a7dfcf120b4c808def804108 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Thu, 11 Jun 2015 19:00:21 +0100 Subject: [PATCH 39/42] sudih --- hashweb.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hashweb.js b/hashweb.js index bde0d25..7568d26 100644 --- a/hashweb.js +++ b/hashweb.js @@ -57,7 +57,7 @@ module.exports = { }, modifyBansObject: function(context, bansText) { - if (isAuth(context) { + if (isAuth(context)) { bansText = bansText.trim(); id = bansText.match(/^\d+/)[0] key = bansText.match(/\:(\w*)/)[1] From f8652d99e9844aa9bd20b254be1fe31dd7ed2a35 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Thu, 11 Jun 2015 19:00:58 +0100 Subject: [PATCH 40/42] sudih --- hashweb.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hashweb.js b/hashweb.js index 7568d26..248d560 100644 --- a/hashweb.js +++ b/hashweb.js @@ -80,7 +80,7 @@ module.exports = { }, updateBansList: function(context, bansText) { - if (isAuth(context) { + if (isAuth(context)) { request.post("http://hashweb.org/stats/bans/update", function(err,httpResponse,body) { context.channel.send_reply(context.sender, JSON.parse(body).message) }); From c93fb439243878117c3e2b127bcf64b9b764c22a Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Thu, 11 Jun 2015 19:01:35 +0100 Subject: [PATCH 41/42] sudih --- hashweb.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hashweb.js b/hashweb.js index 248d560..229fc6c 100644 --- a/hashweb.js +++ b/hashweb.js @@ -57,7 +57,7 @@ module.exports = { }, modifyBansObject: function(context, bansText) { - if (isAuth(context)) { + if (isAuth(context.intent.host)) { bansText = bansText.trim(); id = bansText.match(/^\d+/)[0] key = bansText.match(/\:(\w*)/)[1] @@ -80,7 +80,7 @@ module.exports = { }, updateBansList: function(context, bansText) { - if (isAuth(context)) { + if (isAuth(context.intent.host)) { request.post("http://hashweb.org/stats/bans/update", function(err,httpResponse,body) { context.channel.send_reply(context.sender, JSON.parse(body).message) }); From 2c470d50143ff06c9a8b2402f0980e39d955d35e Mon Sep 17 00:00:00 2001 From: Ella Date: Thu, 11 Jun 2015 19:06:21 +0100 Subject: [PATCH 42/42] updates --- hashweb.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hashweb.js b/hashweb.js index 229fc6c..e63f167 100644 --- a/hashweb.js +++ b/hashweb.js @@ -82,10 +82,10 @@ module.exports = { updateBansList: function(context, bansText) { if (isAuth(context.intent.host)) { request.post("http://hashweb.org/stats/bans/update", function(err,httpResponse,body) { - context.channel.send_reply(context.sender, JSON.parse(body).message) + context.channel.send_reply(context.sender, JSON.parse(body).message); }); } else { context.channel.send_reply(context.sender, "Oops, looks like you're not authorized!"); } } -} \ No newline at end of file +}