Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now listen to actual irc channels and insert into database
- Loading branch information
1 parent
4c661be
commit fc5d7c5
Showing
12 changed files
with
290 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ standard-app-packages | |
insecure | ||
preserve-inputs | ||
coffeescript | ||
npm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.7.0.1 | ||
0.7.1.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"irc" : "0.3.6" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.build* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
This directory and the files immediately inside it are automatically generated | ||
when you change this package's NPM dependencies. Commit the files in this | ||
directory (npm-shrinkwrap.json, .gitignore, and this README) to source control | ||
so that others run the same versions of sub-dependencies. | ||
|
||
You should NOT check in the node_modules directory that Meteor automatically | ||
creates; if you are using git, the .gitignore file tells git to ignore it. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
var Future = Npm.require('fibers/future'); | ||
Async = {}; | ||
|
||
Meteor.require = function(moduleName) { | ||
var module = Npm.require(moduleName); | ||
return module; | ||
}; | ||
|
||
Async.runSync = Meteor.sync = function(asynFunction) { | ||
var future = new Future(); | ||
var sent = false; | ||
var payload; | ||
|
||
var wrappedAsyncFunction = Meteor.bindEnvironment(asynFunction, function(err) { | ||
console.error('Error inside the Async.runSync: ' + err.message); | ||
returnFuture(err); | ||
}); | ||
|
||
setTimeout(function() { | ||
wrappedAsyncFunction(returnFuture); | ||
}, 0); | ||
|
||
future.wait(); | ||
sent = true; | ||
|
||
function returnFuture(error, result) { | ||
if(!sent) { | ||
payload = { result: result, error: error}; | ||
future.return(); | ||
} | ||
} | ||
|
||
return payload; | ||
}; | ||
|
||
Async.wrap = function(arg1, arg2) { | ||
if(typeof arg1 == 'function') { | ||
var func = arg1; | ||
return wrapFunction(func); | ||
} else if(typeof arg1 == 'object' && typeof arg2 == 'string') { | ||
var obj = arg1; | ||
var funcName = arg2; | ||
return wrapObject(obj, [funcName])[funcName]; | ||
} else if(typeof arg1 == 'object' && arg2 instanceof Array) { | ||
var obj = arg1; | ||
var funcNameList = arg2; | ||
return wrapObject(obj, funcNameList); | ||
} else { | ||
throw new Error('unsupported argument list'); | ||
} | ||
|
||
function wrapObject(obj, funcNameList) { | ||
var returnObj = {}; | ||
funcNameList.forEach(function(funcName) { | ||
if(obj[funcName]) { | ||
var func = obj[funcName].bind(obj); | ||
returnObj[funcName] = wrapFunction(func); | ||
} else { | ||
throw new Error('instance method not exists: ' + funcName); | ||
} | ||
}); | ||
return returnObj; | ||
} | ||
|
||
function wrapFunction(func) { | ||
return function() { | ||
var args = arguments; | ||
response = Meteor.sync(function(done) { | ||
Array.prototype.push.call(args, done); | ||
func.apply(null, args); | ||
}); | ||
|
||
if(response.error) { | ||
//we need to wrap a new error here something throw error object comes with response does not | ||
//print the correct error to the console, if there is not try catch block | ||
var error = new Error(response.error.message); | ||
for(var key in response.error) { | ||
if(error[key] === undefined) { | ||
error[key] = response.error[key]; | ||
} | ||
} | ||
throw error; | ||
} else { | ||
return response.result; | ||
} | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
var path = Npm.require('path'); | ||
var fs = Npm.require('fs'); | ||
var packagesJsonFile = path.resolve('./packages.json'); | ||
|
||
//creating `packages.json` file for the first-time if not exists | ||
if(!fs.existsSync(packagesJsonFile)) { | ||
fs.writeFileSync(packagesJsonFile, '{\n \n}') | ||
} | ||
|
||
try { | ||
var fileContent = fs.readFileSync(packagesJsonFile); | ||
var packages = JSON.parse(fileContent.toString()); | ||
Npm.depends(packages); | ||
} catch(ex) { | ||
console.error('ERROR: packages.json parsing error [ ' + ex.message + ' ]'); | ||
} | ||
|
||
Package.describe({ | ||
summary: "complete npm integration/support for Meteor" | ||
}); | ||
|
||
Package.on_use(function (api, where) { | ||
api.export('Async'); | ||
|
||
var packagesFile = './.meteor/packages'; | ||
if(fs.existsSync(packagesFile) && isNewerMeteor) { | ||
api.add_files(['index.js', '../../packages.json'], 'server'); | ||
} else { | ||
api.add_files(['index.js'], 'server'); | ||
} | ||
|
||
function isNewerMeteor() { | ||
return fs.readFileSync(packagesFile, 'utf8').match(/\nstandard-app-packages/); | ||
} | ||
}); | ||
|
||
Package.on_test(function (api) { | ||
api.use(['tinytest']); | ||
api.add_files(['index.js', 'test.js'], 'server'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
Tinytest.add('Async.runSync - with done()', function(test) { | ||
var output = Async.runSync(function(done) { | ||
setTimeout(function() { | ||
done(null, 10001); | ||
}, 10); | ||
}); | ||
|
||
test.equal(output.result, 10001); | ||
test.equal(output.error, null); | ||
}); | ||
|
||
Tinytest.add('Async.runSync - with error()', function(test) { | ||
var output = Async.runSync(function(done) { | ||
setTimeout(function() { | ||
done({message: 'error-message', code: 402}); | ||
}, 10); | ||
}); | ||
|
||
test.equal(output.result, undefined); | ||
test.equal(output.error.code, 402); | ||
}); | ||
|
||
Tinytest.add('Async.runSync - with error in the callback', function(test) { | ||
var output = Async.runSync(function(done) { | ||
throw new Error('SOME_ERROR'); | ||
}); | ||
|
||
test.equal(output.result, undefined); | ||
test.equal(output.error.message, 'SOME_ERROR'); | ||
}); | ||
|
||
Tinytest.add('Async.wrap function mode - success', function(test) { | ||
function wait(timeout, callback) { | ||
setTimeout(function() { | ||
callback(null, 'okay'); | ||
}, timeout); | ||
}; | ||
|
||
var enclosedWait = Async.wrap(wait); | ||
var output = enclosedWait(100); | ||
|
||
test.equal(output, 'okay'); | ||
}); | ||
|
||
Tinytest.add('Async.wrap function mode - error', function(test) { | ||
function wait(timeout, callback) { | ||
setTimeout(function() { | ||
var error = new Error('THE_ERROR'); | ||
error.code = 500; | ||
callback(error); | ||
}, timeout); | ||
}; | ||
|
||
var enclosedWait = Async.wrap(wait); | ||
try { | ||
enclosedWait(100); | ||
test.fail('there must be an error'); | ||
} catch(err) { | ||
test.ok(err.message.match('THE_ERROR')); | ||
test.equal(err.code, 500); | ||
} | ||
|
||
}); | ||
|
||
Tinytest.add('Async.wrap object mode - success', function(test) { | ||
function Wait() { | ||
this.start = function(timeout, callback) { | ||
setTimeout(function() { | ||
callback(null, 'okay'); | ||
}, timeout); | ||
}; | ||
} | ||
|
||
var wait = new Wait(); | ||
|
||
var enclosedWait = Async.wrap(wait, 'start'); | ||
|
||
var output = enclosedWait(100); | ||
test.equal(output, 'okay'); | ||
}); | ||
|
||
Tinytest.add('Async.wrap object mode - funcName not exists', function(test) { | ||
function Wait() { | ||
this.start = function(timeout, callback) { | ||
setTimeout(function() { | ||
callback(null, 'okay'); | ||
}, timeout); | ||
}; | ||
} | ||
|
||
var wait = new Wait(); | ||
try { | ||
var enclosedWait = Async.wrap(wait, 'startz'); | ||
test.fail('shoud throw an error'); | ||
} catch(ex) { | ||
|
||
} | ||
}); | ||
|
||
Tinytest.add('Async.wrap object mode - multi function mode', function(test) { | ||
function Wait() { | ||
this.start = function(timeout, callback) { | ||
setTimeout(function() { | ||
callback(null, 'okay'); | ||
}, timeout); | ||
}; | ||
|
||
this.start2 = function(timeout, callback) { | ||
setTimeout(function() { | ||
callback(null, 'okay'); | ||
}, timeout); | ||
}; | ||
} | ||
|
||
var wait = new Wait(); | ||
var enclosedWait = Async.wrap(wait, ['start', 'start2']); | ||
enclosedWait.start(100); | ||
enclosedWait.start2(100); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,22 @@ | ||
Messages = new Meteor.Collection('messages') | ||
Meteor.publish 'channel', (channel) -> | ||
if channel | ||
irc = Meteor.require 'irc' | ||
clients = {} | ||
Meteor.publish 'channel', (channel, nick) -> | ||
if channel && nick | ||
listen channel, nick | ||
Messages.find(channel : channel) | ||
listen = (channel, nick) -> | ||
console.log(channel, nick) | ||
client = clients[nick] = new irc.Client 'chat.freenode.net', nick, { | ||
channels : [channel] | ||
} | ||
client.on 'error', console.log | ||
client.on 'message', (from, to, message) -> | ||
console.log(from, to, message) | ||
Fiber(-> | ||
Messages.insert { | ||
from, | ||
message | ||
channel : to, | ||
} | ||
) |