Example #1
0
        'formatNotify': function(type, server, user, channel, message) {
            var notifier = '[' + user.primaryNick + ']';

            if(_.has(this.config.colours, server)) {
                var colours = this.config.colours[server];

                notifier = '[' + colours['nicks'] + user.primaryNick + '\u000f]';
                if(_.has(colours.type, type)) {
                    type = colours['type'][type] + type + '\u000f';
                }
                if(_.has(colours['channels'], channel)) {
                    channel = colours['channels'][channel] +
                        channel + "\u000f";
                }

                message = message.replace(/(#[\w\-]+)/g, '\u000312$1\u000f');

                _.each(_.union(message.match(/ @([\d\w*|-]+)/g), message.match(/([\d\w*|-]+)@ ?/g)), function(u) {
                    u = u.replace(/\s|@/g, '');
                    message = message.replace(u, colours['nicks'] + u + "\u000f");
                    notifier += '[' + colours['nicks'] + u + '\u000f]';
                });
            }

            return dbot.t('notify', {
                'type': type,
                'channel': channel,
                'notifier': notifier,
                'message': message
            });
        }.bind(this)
Example #2
0
 this.api.resolveUser(event.server, secondaryUser, function(oldUser) {
     if(oldUser) {
         user.aliases.push(oldUser.primaryNick);
         user.aliases = _.union(user.aliases, oldUser.aliases);
         this.internalAPI.mergeChannelUsers(oldUser, user);
         this.db.del('users', oldUser.id, function(err) {
             if(!err) {
                 this.db.save('user_redirs', oldUser.id, user.id, function() {});
                 this.db.save('users', user.id, user, function(err) {
                     if(!err) {
                         if(_.has(this.userCache, event.server) && _.has(this.userCache[event.server], oldUser.currentNick)) {
                             delete this.userCache[event.server][oldUser.currentNick];
                         }
                         event.reply(dbot.t('merged_users', { 
                             'old_user': secondaryUser,
                             'new_user': primaryUser
                         }));
                         dbot.api.event.emit('~mergeusers', [
                             event.server,
                             oldUser,
                             user
                         ]);
                     }
                 }.bind(this));
             }
         }.bind(this));
     } else {
         event.reply(dbot.t('unprimary_error', { 'nick': secondaryUser }));
     }
 }.bind(this));
Example #3
0
module.exports.dispatch = function (command, args, callback) {
    var self = this;
    var spawn_args = [];

    spawn_args.push('--max_new_space_size=5000');
    spawn_args.push('--max_executable_size=3000');
    spawn_args.push('--max_old_space_size=5000');
    spawn_args.push(settings.SCRIPT_PATH);

    /* Looking for the settings file that the current process is using */
    if (settings.CUSTOM) {
        spawn_args.push('-s');
        spawn_args.push(settings.CUSTOM);
    }

    spawn_args.push(command);

    /* Putting all parameters together */
    spawn_args = _.union(spawn_args, args);

    console.log("spawn_args");
    console.log(spawn_args);

    var child = spawn("node", spawn_args);
    child.stdout.on('data', function(data) {
        process.stdout.write(data);
    });
    child.stderr.on('data', function(data) {
        process.stdout.write(data);
    });

    callback(child);
};
Example #4
0
Player.parseValidateAndSaveSpreadsheet = function(dbHandler, spreadsheetList, callback) {
  var players = [];
  var errors = [];
  for ( var i = 0; i < spreadsheetList.length; i++ ) {
    var player = new Player("FCB", spreadsheetList[i]);
    player.parse();
    player.validate();
    errors = _.union(errors, player.validationErrors);
    players.push(player);
  }
  
  if ( errors.length > 0 ) {
    var errorString = "";
    for ( i = 0; i < errors.length; i++ ) {
      errorString = errorString + "validation error:\n" + errors[i] + "\n";
    }

    return callback(errorString, 400);
  } else {
    // redis operations
    dbHandler.del("FCB"); // delete the players hash
    for ( i = 0; i < players.length; i++ ) {
      dbHandler.hset("FCB", players[i].nickname, JSON.stringify(players[i]));
    }
  
    return callback("OK", 200);
  }
};
        it("Split word arrays into graphemes", function() {
                var cumulativeWords = ['one', 'two', 'three'];
                var focusWords = ['four', 'five', 'six'];

                var graphemes = _.uniq(_.union(cumulativeWords, focusWords).join('').split(''));
                console.log(graphemes);
                expect(graphemes.length).toBe(13);
        });
Example #6
0
AppModel.prototype.updateAttributes = function (updates, cb) {
  // delete read-only attributes
  if (updates.id) { delete updates.id}
  if (updates.created_at) { delete updates.created_at}
  if (updates.updated_at) { delete updates.updated_at}

  _.extend(this, updates);
  this.attributes = _.union(_.keys(updates), this.attributes);
  return this.save(cb)
}
Example #7
0
	invalidWord: function(data){
		var words = [],
			pattern = new RegExp("("+words.join('|')+")", "gi"),
			re, result;
		if(re = data.match(pattern)){
			re = us.union(re);
			return {"fatal":'包含非法关键字:' + re.join(",")};
		}else{
			return null;
		}
	},
Example #8
0
 }, function(err) {
     if(secondary) {
         primary.quotes = _.union(primary.quotes, secondary.quotes);
         this.db.save('quote_category', primary.id, primary, function(err) {
             this.db.del('quote_category', secondary.id, function(err) {
                 event.reply(dbot.t('categories_merged', {
                     'from': secondName, 
                     'into': primaryName
                 }));
             });
         }.bind(this));
     } else {
         event.reply(dbot.t('category_not_found', { 'category': secondName }));
     }
 }.bind(this));
Example #9
0
          campaignProvider.findById(item.campaignId, function (error, campaign) {
            if (error) return next(error);

            // create a list of all bonuses this is associated with
            if (!item.bonuses) item.bonuses = [];
            if (!item.winner) item.winner = [];
            item.bonuses = _.union(item.bonuses, item.winner);

            bonusProvider.findByIds(item.bonuses, function (error, bonuses) {
              if (error) return next(error);

              res.render(null, {locals: {item: item, user: created_user, bonuses: bonuses,
                         teamId: item.teamId, campaignId: item.campaignId, isAdmin: isAdmin, 
                         canFlag: (campaign && campaign.allowflag)}});
            });
          });
Example #10
0
	getWinners: function(){
		var bests = [];

		for(var i = 0; i < this.players.length; i++){
			var currentPlayer = this.players[i];
			var cards = _.union(currentPlayer.getCards(), this.board);
			var evaluation = this.handEvaluator.evaluate(cards);
			var temp = {
				player: currentPlayer, 
				hand: evaluation
			};
			if(bests.length == 0 || evaluation.score > bests[0].hand.score){
				bests = [temp];
			} else if(bests.length > 0 && evaluation.score == bests[0].hand.score){
				bests.push(temp);
			}
		}

		return bests;
	}
Example #11
0
File: api.js Project: Rob-pw/dbot
            dbot.api.users.resolveChannel(server, cName, function(channel) {
                if(channel) {
                    var perOps = channel.op;
                    if(this.config.notifyVoice) perOps = _.union(perOps, channel.voice);

                    this.db.read('nunsubs', channel.id, function(err, nunsubs) {
                        async.eachSeries(ops, function(nick, next) {
                            dbot.api.users.resolveUser(server, nick, function(user) {
                                if(!_.include(user.mobile, user.currentNick)) {
                                    perOps = _.without(perOps, user.id);
                                }
                                if(nunsubs && _.include(nunsubs.users, user.id)) {
                                    ops = _.without(ops, user.currentNick);
                                }
                                next();
                            }); 
                        }, function() {
                            offlineUsers = perOps;
                            if(!_.include(this.config.noMissingChans, cName)) {
                                _.each(offlineUsers, function(id) {
                                    if(!this.pending[id]) this.pending[id] = [];
                                    this.pending[id].push({
                                        'time': new Date().getTime(),
                                        'channel': cName,
                                        'user': user.primaryNick,
                                        'message': message
                                    });
                                    this.pNotify[id] = true;
                                }.bind(this));
                            }
                            
                            message = this.internalAPI.formatNotify(type, server,
                                user, cName, message);
                            this.internalAPI.notify(server, ops, message);
                            if(_.has(this.config.chan_redirs, cName)) {
                                dbot.say(server, this.config.chan_redirs[cName], message);
                            }
                        }.bind(this)); 
                    }.bind(this));
                }
            }.bind(this));
Example #12
0
        'hasAccess': function(server, user, command, callback) {
            var accessNeeded = dbot.commands[command].access;

            if(accessNeeded == 'admin' || accessNeeded == 'moderator') {
                var allowedNicks = dbot.config.admins;
                if(accessNeeded == 'moderator') allowedNicks = _.union(allowedNicks, dbot.config.moderators); 

                if(!_.include(allowedNicks, user)) {
                    callback(false);
                } else {
                    if(_.has(dbot.modules, 'nickserv') && this.config.useNickserv == true) {
                        dbot.api.nickserv.auth(server, user, function(result) {
                            callback(result);
                        });
                    } else {
                        callback(true);
                    }
                }
            } else {
                callback(true);
            }
        },
Example #13
0
server.post('/process', function (req, res) {
  console.log('Processing graph...');
  var clusters = req.body.clusters ? 'clusters=' + req.body.clusters : '',
      genes = req.body.genes ? 'genes=' + req.body.genes : '',
      graph = 'graph=' + req.body.graph,
      process = req.body.process,
      visual = req.body.visual,
      options = req.body.options;

  if (process != 'cluster' && process != 'regression') {
    res.end('Error: data sent is not valid');
  }

  var args = _.union(['r/process.r'], graph, clusters, genes, visual, options);
  console.log('Invoking Rscript ' + args.join(' '));
  childProcess.exec('Rscript ' + args.join(' '), function (error, stdout, stderr) {
    if (error) {
      throw error;
    }
    res.end(stdout || stderr);
  });
});
Example #14
0
			redis.flushdb(function(err) {
				if(err) {
					logger.error(err);
					return;
				}

				sync.init(logger, redis);
				sync.setPersist(true);

				logger.info("Starting seed.");

				var events = [];

				events.push(new models.ServerEvent({title:"Writers at Work", organizer: "National Writing Program & ConnectedLearning.tv",
				description: "Throughout July, NWP partnered with Connected Learning TV to host a webinar series called Writers at Work: Making and Connected Learning. As a wrap-up to our series we invite you to regroup here to debrief with us, test and tinker with this new unHangout tool, and continue the great conversations that have been started! We will start with a whole group kick-off and then split up into smaller group discussions, based on themes and topics raised by the seminar series. Please be aware that this is a “beta-test webinar” so your adventurous spirit is welcome!",
				start: new Date().getTime(), end: new Date().getTime()+60*60*2*1000}));

				// events.push(new models.ServerEvent({title:"Open Source Learning Unhangout", organizer: "MIT Media Lab & ConnectedLearning.tv",
				// description: "There are more online resources for education than ever, but how to make sense of them all? Do they have a role in a traditional classroom? For life long learners? Come share your favorite resources, discover new ones, and get inspired about how to bring open educational resources into your classroom.",
				// start: new Date().getTime()+60*60*24*4*1000, end: new Date().getTime()+60*60*24*4*1000 + 60*60*2*1000}));

				var sessions = [];
				
				sessions.push(new models.ServerSession({title:"Writing as Making/Making as Writing", description: "This webinar featured both inside and outside of school educators and media makers to discuss the impact of thinking about what happens when you put the learner front and enter in the role of producer. Facilitated by Elyse Eidman-Aadahl, NWP."}));
				sessions.push(new models.ServerSession({title:"What does interest-driven look like?", description:"This webinar featured both inside and outside of school educators and researchers discussing what interest-driven means and what it looks like in connected learning. Facilitated by Stephanie West-Puckett, TRWP"}));
				sessions.push(new models.ServerSession({title:"What we've been learning in #clmooc", description:"Not yet a webinar but actually a MOOC (“Massively Open Online Collaboration”) that the NWP also hosted throughout the month of July, this webinar is an opportunity to see what’s been made and what’s been learned. Facilitated by Paul Oh, NWP."}));
				sessions.push(new models.ServerSession({title:"From Expression to Impact: Youth Civic Engagement Enacted", description:"This webinar explored how are educators fostering civic engagement in Connected Learning environments, how these contexts are changing and how best to support educators in doing this work with their students. Facilitated by Antero Garcia, CSUWP"}));
				sessions.push(new models.ServerSession({title:"Connected Learning TV now and into the future", description:"Connected Learning TV is in the middle of a 12-month experiment where we take 1 month at a time to focus on key connected learning communities and topics/themes. What have you found most useful about this format? What do you wish was different? What would make it easier for you (and your peers) to get involved in the series and the Connected Learning community? Facilitated by Jon Barilone, CLTV"}));

				events[0].addSession(sessions[0], true);
				events[0].addSession(sessions[1], true);
				events[0].addSession(sessions[2], true);
				events[0].addSession(sessions[3], true);
				events[0].addSession(sessions[4], true);

				// events[0].addSession(sessions[5]);
				// events[0].addSession(sessions[6]);
				// events[0].addSession(sessions[7]);
				// events[0].addSession(sessions[8]);
				// events[0].addSession(sessions[9]);

				// events[1].addSession(sessions[10]);
				// events[1].addSession(sessions[11]);
				// events[1].addSession(sessions[12]);

				_.each(sessions, function(session) {
					if(_.isUndefined(session.collection)) {
						logger.info("found undefined collection for name: " + session.get("name"));
					}
				});

				logger.info("sessions: " + sessions.length);

				async.series(_.map(_.union(events, sessions), function(model) {

					return function(callback) {
						// logger.info("saving " + JSON.stringify(model.collection));
						model.save(null, {success:function() {
							callback();
						}});
					};
				}), function(err, res) {
					callback && callback();
				});
			});