Example #1
0
        '~alias': function(event) {
            var knownUsers = this.getServerUsers(event.server),
                alias = event.params[1].trim();

            if(_.include(knownUsers.users, alias)) {
                var aliases = this.api.getAliases(event.server, alias);
                var aliasCount = aliases.length;

                if(aliasCount != 0) {
                    var aliases = _.first(aliases, 10);
                    var including = 'including: ';
                    for(var i=0;i<aliases.length;i++) {
                        including += aliases[i] + ', ';
                    }
                    including = including.slice(0, -2) + '.';

                    event.reply(dbot.t('primary', { 
                        'user': alias, 
                        'count': aliasCount 
                    }) + including); 
                } else {
                    event.reply(dbot.t('primary', { 
                        'user': alias, 
                        'count': aliasCount 
                    })); 
                }
            } else if(_.has(knownUsers.aliases, alias)) {
                event.reply(dbot.t('alias', { 
                    'alias': alias, 
                    'user': knownUsers.aliases[alias] 
                }));
            } else {
                event.reply(dbot.t('unknown_alias', { 'alias': alias }));
            }
        },
Example #2
0
Game.prototype.removePlayer = function(player) {
  player.game = null;
  delete this.players[player.id];
  if (this.creator.id == player.id && _.size(this.players) > 0) {
    this.creator = _.first(_.toArray(this.players));
  }
}
Example #3
0
		}, _.bind(function(err, res) {
			if(err) {
				winston.error("error loading matches: " + err);
				return;
			}

			if(_.isUndefined(res)) {
				winston.error("Empty response getting recent matches for: " + league.name);
				return;
			}

			if(res.total_results == 0) {
				winston.warn("No matches returned for league_id: " + league.name);
				return;
			} else {
				// winston.info(res.matches.length + " matches found for " + league.name);
			}

			if(this.isDemo) {
				res.matches = _.first(res.matches, 2);
			}

			_.each(res.matches, _.bind(function(match) {
				this.logRecentMatch(match, this.leagues[leagueId]);
			}, this));

			this.leagues[leagueId].init = false;

			// run the callback if present.
			cb && cb(res.matches);
		}, this));
Example #4
0
exports.getReportingViewArgs = function (dates) {
    var startdate = _.first(dates.list),
        enddate = _.last(dates.list),
        startkey = [dates.form],
        endkey = [dates.form, enddate.year()];

    if (dates.reporting_freq === 'week') {
        startkey.push(startdate.year());
        startkey.push(getWeek(startdate));

        endkey.push(getWeek(enddate));
    } else {
        startdate = nextMonth(startdate);
        startkey.push(startdate.year());
        startkey.push(startdate.month() + 1);

        endkey.push(enddate.month() + 1);
    }
    startkey.push({});
    endkey.push('');

    return {
        startkey: startkey,
        endkey: endkey,
        descending: true
    };
};
Example #5
0
            this.api.resolveUser(event.server, nick, function(user) {
                if(user) {
                    if(nick == user.primaryNick) {
                        var aliases = _.first(user.aliases, 10);
                        var including = 'including: ' + aliases.join(', ') + '.';

                        if(user.aliases.length != 0) {
                            event.reply(dbot.t('primary', { 
                                'user': nick,
                                'currentNick': user.currentNick,
                                'count': user.aliases.length,
                            }) + including);
                        } else {
                            event.reply(dbot.t('primary', { 
                                'user': nick, 
                                'currentNick': user.currentNick,
                                'count': user.aliases.length 
                            }).slice(0, -2) + ".");
                        }
                    } else {
                        event.reply(dbot.t('alias', { 
                            'alias': nick, 
                            'user': user.primaryNick
                        }));
                    }
                } else {
                    event.reply(dbot.t('unknown_alias', { 'alias': nick }));
                }
            });
Example #6
0
 table.insert(thing, {conflict : "update"}).run(conn,function(err,result){
   assert.ok(err === null,err);
   if(result.generated_keys && result.generated_keys.length > 0){
     thing.id = _.first(result.generated_keys);
   }
   conn.close();
   next(err,thing);
 });
Example #7
0
function build_search_url(terms) {
    var url = "_search/" + _.first(terms);
    if (terms.length > 1) {
        var first = true;
        _.each(_.rest(terms), function(term){
            var prepend = '/';
            if (!first)  prepend = '+';
            url += prepend + term;
            first = false;
        })
    }
    return url;
}
Example #8
0
Errors.prototype.on = function (fieldPath) {
  var leaf = path.leaf(fieldPath),
      resource = path.resource(fieldPath, this);

  if (!resource) {
    return undefined;
  }

  var errors = resource.errors[leaf] || null;

  if (errors && errors.length === 1) {
    return _.first(errors);
  } else {
    return errors;
  }
};
Example #9
0
 neodb.getIndexedNodes("person", "id", identifyPerson(person), function(err, nodePersons) {
    if(err || _.isEmpty(nodePersons)) {
       var nodePersonGlobal = {};
       async.waterfall([
          function(callback) {
             neodb.createNode(objectifyPerson(person)).save(callback);
          },
          function(nodePerson, callback) {
             nodePersonGlobal = nodePerson;
             nodePerson.index("person", "id", identifyPerson(person), callback);
          }
       ], function(err, result) {
          hop(err, nodePersonGlobal);
       });
    } else {
       hop(null, _.first(nodePersons));
    }
 });
Example #10
0
 neodb.getIndexedNodes("movie", "id", identifyMovie(movie), function(err, nodeMovies) {
    if(err || _.isEmpty(nodeMovies)) {
       var nodeMovieGlobal = {};
       async.waterfall([
          function(callback) {
             neodb.createNode(objectifyMovie(movie)).save(callback);
          },
          function(nodeMovie, callback) {
             nodeMovieGlobal = nodeMovie;
             nodeMovie.index("movie", "id", identifyMovie(movie), callback);
          }
       ], function(err, result) {
          hop(err, nodeMovieGlobal);
       });
    } else {
       hop(null, _.first(nodeMovies));
    }
 });
Example #11
0
 neodb.getIndexedRelationships("person_movie", "id", identifyRelation(person, movie), function(err, relations) {
    if(err || _.isEmpty(relations)) {
       async.waterfall([
          function(callback) {
             personNode.createRelationshipTo(movieNode, 'beIn', {department: person.department}, callback);
          },
          function(relationship, callback) {
             relationship.save(callback); 
          },
          function(relationship, callback) {
             relationship.index("person_movie", "id", identifyRelation(person, movie), callback);
          }
       ], function(err, result) {
          hop(err, result);
       })
    } else {
       hop(null, _.first(relations));
    }
 });
Example #12
0
                    this.api.getUserAliases(user.id, function(err, aliases) {
                        var including = _.first(aliases, 10).join(', ');

                        if(nick !== user.primaryNick) {
                            event.reply(dbot.t('alias', { 
                                'alias': nick, 
                                'user': user.primaryNick
                            }));
                        }

                        if(aliases.length === 0) {
                            event.reply(dbot.t('primary_no_alias', { 
                                'user': user.primaryNick,
                                'currentNick': user.currentNick
                            }));
                        } else {
                            event.reply(dbot.t('primary', { 
                                'user': user.primaryNick,
                                'currentNick': user.currentNick,
                                'count': aliases.length,
                                'including': including
                            }));
                        }
                    });
Example #13
0
	Parser.prototype.getTitle = function () {
		var fileName = _.last(this.filePath.split("/"));
		return _s.titleize(_s.humanize(_.first(fileName.split("."))));
	};
 function getBaseURI () {
     return 'http://' + _.first(serverIPs) + ":" + serverPort;
 }
Example #15
0
module.exports.servicesElement = function(req, res, value) {
  res.send(200, {}, JSON.stringify(_.first(_.select(status.services, function(data){ return data.name == value; }))));
};
Example #16
0
 it( 'prepends arguments to .includes', function () {
   One.prepend(Two);
   assert.equal(_.first(One.includes), Two);
 });
Example #17
0
File: game.js Project: hmac/whist
 var shift = function(array, index) {
   return _.rest(array, index).concat(_.first(array, index));
 };
Example #18
0
 table.query(criteria, function(err,array){
   next(err, _.first(array));
 });