Example #1
0
 'applyRegex': function(commandName, event) {
     var applies = false;
     if(_.has(dbot.commands[commandName], 'regex')) {
         var cRegex = dbot.commands[commandName].regex;
         var q = event.message.valMatch(cRegex[0], cRegex[1]);
         if(q) {
             applies = true;
             event.input = q;
         }
     } else {
         applies = true;
     }
     return applies;
 },
Example #2
0
        '~rmdeny': function(event) {
            var rmCache = this.rmCache;
            var rmCacheCount = rmCache.length;
            for(var i=0;i<rmCacheCount;i++) {
                if(!_.has(quotes, rmCache[i].key)) {
                    quotes[rmCache[i].key] = [];
                }
                quotes[rmCache[i].key].push(rmCache[i].quote);
            }
            rmCache.length = 0;

            event.reply(dbot.t('quote_cache_reinstated', 
                { 'count': rmCacheCount }));
        },
Example #3
0
      spashttp.request(shadowed, credentials, function ( err, videos ) {
        if (_.has(videos, 'feed') && videos.feed.entry) {
          // Save meta data outside.
          if (!data) data = videos;

          async.each(videos.feed.entry, getVideoDetails(credentials), function (err) {
            callback(err, videos.feed.entry);
          });
          
        } else {
          callback( err, [] );
        }
        
      });
Example #4
0
            this.db.scan(key, function(item) {
                var id = item.id;
                for(var i=0;i<pPointer.length;i++) {
                    if(_.has(item, pPointer[i])) {
                        item = item[pPointer[i]]; 
                    } else {
                        item = null; break;
                    }
                }

                if(item) {
                    pList[id] = item;
                }
            }, function() {
Example #5
0
            request(testUrl, function(error, response, body) {
                // 492 is body.length of a removed image
                if(!error && response.statusCode == 200 && body.length != 492) {
                    dbot.db.imgur.totalImages += 1;
                    var hash = crypto.createHash('md5').update(body).digest("hex");
                    if(_.has(dbot.modules, 'quotes')){
                        // autoadd: {"abcdef": "facebookman"}
                        if(_.has(dbot.config.modules.imgur.autoadd,hash)){
				fbman = true;
                            var category = this.config.autoadd[hash];
                            if (_.contains(category, testUrl)){
                                // there's probably less than 62^5 chance of this happening
                            } else {
                                dbot.api.quotes.addQuote(category, testUrl,
                                    dbot.config.name, function() { });
                            }
                        }
                    }
                    callback(testUrl, testSlug, hash, fbman);
                } else {
                    this.api.getRandomImage(callback);
                }
            }.bind(this));
Example #6
0
Connection.prototype.updateNickLists = function() {
    for(var channel in this.channels) {
        if(_.has(this.channels, channel)) {
            this.channels[channel] = {
                'name': channel,
                'nicks': {},
                'toString': function() {
                    return this.name;
                }
            };
            this.send('NAMES ' + channel);
        }
    }
}
Example #7
0
    var getCurrentConfig = function(configKey) {
        var defaultConfigPath = dbot.config;
        var userConfigPath = dbot.db.config;

        if(configKey) {
            var configKey = configKey.split('.');
            for(var i=0;i<configKey.length-1;i++) {
                if(_.has(defaultConfigPath, configKey[i])) {
                    if(!_.has(userConfigPath, configKey[i])) {
                        userConfigPath[configKey[i]] = {};
                    }
                    userConfigPath = userConfigPath[configKey[i]];
                    defaultConfigPath = defaultConfigPath[configKey[i]];
                } else {
                    return false;
                }
            }
        }

        var currentOption;
        if(configKey && configKey.length != 1) {
            configKey = _.last(configKey);
            if(_.has(userConfigPath, configKey) && !_.isUndefined(userConfigPath[configKey])) {
                currentOption = userConfigPath[configKey];
            } else if(_.has(defaultConfigPath, configKey)) {
                currentOption = defaultConfigPath[configKey];
            }
        } else {
            currentOption = defaultConfigPath[configKey];
        }

        return { 
            'user': userConfigPath,
            'default': defaultConfigPath,
            'value': currentOption
        };
   };
Example #8
0
 '~link': function(event) {
     var key = event.input[1].toLowerCase();
     if(_.has(quotes, key)) {
         event.reply(dbot.t('quote_link', {
             'category': key, 
             'url': dbot.t('url', {
                 'host': dbot.config.web.webHost, 
                 'port': dbot.config.web.webPort, 
                 'path': 'quotes/' + key
             })
         }));
     } else {
         event.reply(dbot.t('category_not_found', { 'category': key }));
     }
 },
Example #9
0
 'getUserHost': function(server, nick, callback) {
     if(!_.has(this.userStack, server)) this.userStack[server] = {};
     this.userStack[server][nick] = callback;
     dbot.instance.connections[server].send('USERHOST ' + nick);
     setTimeout(function() {
         if(_.has(this.userStack[server], nick)) {
             dbot.instance.connections[server].send('WHOWAS ' + nick);
             setTimeout(function() {
                 if(_.has(this.userStack[server], nick)) {
                     callback(false); 
                 }
             }.bind(this), 4000);
         }
     }.bind(this), 4000);
 }
Example #10
0
        '~vote': function(event) {
            var name = event.input[1].toLowerCase(),
                vote = event.input[2].toLowerCase(),
                user = dbot.api.users.resolveUser(event.server, event.user);

            if(_.has(polls, name)) {
                if(_.has(polls[name].votes, vote)) {
                    if(_.has(polls[name].votees, user)) {
                        var oldVote = polls[name].votees[user];
                        polls[name].votes[oldVote]--;
                        polls[name].votes[vote]++;
                        polls[name].votees[user] = vote;

                        event.reply(dbot.t('changed_vote', {
                            'vote': vote, 
                            'poll': name,
                            'count': polls[name].votes[vote], 
                            'user': event.user
                        }));
                    } else {
                        polls[name].votes[vote]++;
                        polls[name].votees[user] = vote;
                        event.reply(dbot.t('voted', {
                            'vote': vote, 
                            'poll': name,
                            'count': polls[name].votes[vote], 
                            'user': event.user
                        }));
                    }
                } else {
                    event.reply(dbot.t('invalid_vote', { 'vote': vote }));
                }
            } else {
                event.reply(dbot.t('poll_unexistent', { 'name': name }));
            }
        },
Example #11
0
 '~rmoption': function(event) {
     var name = event.input[1].toLowerCase(),
         option = event.input[2].toLowerCase(),
         user = dbot.api.users.resolveUser(event.server, event.user);
     
     if(_.has(polls, name)) {
         if(polls[name].owner === user) {
             if(_.has(polls[name].votes, option)) {
                 delete polls[name]['votes'][option];
                 event.reply(dbot.t('option_removed', {
                     'user': event.user,
                     'name': name, 
                     'option': option
                 }));
             } else {
                 event.reply(dbot.t('invalid_vote', { 'vote': option }));
             }
         } else {
             event.reply(dbot.t('not_poll_owner', { 'name': name }));
         }
     } else {
         event.reply(dbot.t('poll_unexistent', { 'name': name }));
     }
 },
Example #12
0
 '~setmobilealias': function(event) {
     if(_.include(event.rUser.aliases, event.params[1])) {
         if(!_.has(event.rUser, 'mobile')) event.rUser.mobile = [];
         if(!_.include(event.rUser.mobile, event.params[1])) {
             event.rUser.mobile.push(event.params[1]);
             this.db.save('users', event.rUser.id, event.rUser, function(err) {
                 event.reply(dbot.t('added_mobile_alias', { 'alias': event.params[1] })); 
             });
         } else {
             event.reply(dbot.t('already_mobile', { 'alias': event.params[1] })); 
         }
     } else {
         event.reply(dbot.t('unknown_alias', { 'alias': event.params[1] }));
     }
 },
Example #13
0
_i2p_Handlers['Symbol'] = function(outputQ, stack, token, prev, next) {
    if (next && next.is('LeftParen')) {
        token.type = Types.Function;

        if (!_.has(Functions, token.value)) {
            throw new SyntaxError('Unknown function: ' + token.value);
        }

        token.info = Functions[token.value];

        stack.push(token);
        return;
    }

    if (_.has(Constants, token.value)) {
        token.type = Types.Constant;
        token.info = Constants[token.value];
    }
    else {
        token.type = Types.Variable;
    }

    outputQ.push(token);
};
Example #14
0
File: admin.js Project: amki/dbot
        'getCurrentConfig': function(configKey, callback) {
            var configPath = dbot.config;
            configKey = configKey.split('.');  

            for(var i=0;i<configKey.length;i++) {
                if(_.has(configPath, configKey[i])) {
                    configPath = configPath[configKey[i]]; 
                } else {
                    configPath = null;
                    break;
                }
            }

            callback(configPath);
        },
Example #15
0
        this.db.scan('config', function(config) {
            if(config) {
                var currentPath = configMap,
                    key = config.key.split('.'),
                    value = config.value;

                for(var i=0;i<key.length-1;i++) {
                    if(_.has(currentPath, key[i])) {
                        currentPath = currentPath[key[i]];
                    }
                }

                currentPath[key[i]] = value;
            }
        }, function(err) { });
Example #16
0
File: kick.js Project: reality/dbot
  this.onLoad = function () {
    if (!_.has(dbot.db, 'hosts')) {
      dbot.db.hosts = {};
      _.each(dbot.config.servers, function (v, k) {
        dbot.db.hosts[k] = {};
      }, this);
    }
    if (!_.has(dbot.db, 'tempBans'))
      dbot.db.tempBans = {};
    this.hosts = dbot.db.hosts;
    this.tempBans = dbot.db.tempBans;
    this.voteQuiets = {};

    _.each(this.tempBans, function (bans, server) {
      _.each(bans, function (timeout, nick) {
        timeout = new Date(timeout);
        this.internalAPI.addTempBan(server, nick, timeout);
      }, this);
    }, this);

    if (_.has(dbot.modules, 'web')) {
      dbot.api.web.addIndexLink('/bans', 'Ban List');
    }
  }
 _.each(netDb.db, function(discovery) {
     if(_.has(discovery, 'blades')) {
         _.each(discovery.blades, function(blade) {
             var item = _.find(blade.networks, function(network) {
                 return network.ipv4 === from;
             });
             if(item) {
                 console.log("Found blade to update status for");
                 item.pingVerified = errors.length == 0 ? 1 : 0;
                 item.errors = errors;
                 netDb.triggerUpdate();
             }
         })
     }
 });
Example #18
0
    this.onLoad = function() {
        var routes = _.pluck(dbot.modules.web.app.routes.get, 'path'),
            moduleNames = _.keys(dbot.modules);

        _.each(moduleNames, function(moduleName) {
            var modulePath = '/' + moduleName;
            if(_.include(routes, modulePath)) {
                moduleName = moduleName.charAt(0).toUpperCase() +
                    moduleName.slice(1);
                this.indexLinks[modulePath] = moduleName;
            }
        }.bind(this));

        this.app.get('/', function(req, res) {
            res.render('index', { 
                'name': dbot.config.name,
                'user': req.user,
                'routes': this.indexLinks
            });
        }.bind(this));

        this.app.get('/login', function(req, res) {
            res.render('login', {
                'user': req.user,
                'message': req.flash('error')
            });
        });

        this.app.post('/login', passport.authenticate('local', {
            'failureRedirect': '/login', 
            'failureFlash': true
        }), function(req, res) {
            if(req.body.redirect) {
                res.redirect(req.body.redirect);
            } else {
                res.redirect('/');
            }
        });

        this.app.get('/logout', function(req, res) {
            req.logout(); 
            res.redirect('/');
        });

        if(_.has(dbot.modules, 'log')) {
            dbot.api.log.ignoreCommand('~setwebpass');
        }
    }.bind(this);
Example #19
0
 var each = _.each = _.forEach = function(obj, iterator, context) {
   if (obj == null) return;
   if (nativeForEach && obj.forEach === nativeForEach) {
     obj.forEach(iterator, context);
   } else if (obj.length === +obj.length) {
     for (var i = 0, l = obj.length; i < l; i++) {
       if (i in obj && iterator.call(context, obj[i], i, obj) === breaker) return;
     }
   } else {
     for (var key in obj) {
       if (_.has(obj, key)) {
         if (iterator.call(context, obj[key], key, obj) === breaker) return;
       }
     }
   }
 };
Example #20
0
    this.listener = function(event) {
        if(!_.isNull(this.game) && this.game.channel === event.channel.name) {
            if(_.include(this.game.solutions, event.message) && !_.include(this.game.found, event.message)) {
                if(!_.has(this.game.scores, event.user)) this.game.scores[event.user] = 0;
                this.game.scores[event.user]++;
                this.game.found.push(event.message);
                event.reply(event.user + ': ' + event.message.toUpperCase() + ' IS CORRECT. ' + 
                    this.game.found.length + '/' + this.game.solutions.length + ' WORDS FOUND');

                if(this.game.found.length === this.game.solutions.length) {
                    var winner = _.invert(this.game.scores)[_.max(this.game.scores)];
                    event.reply('ALL WORDS FOUND. THE WINNER IS ' + winner.toUpperCase() + ' WITH ' + this.game.scores[winner]);
                    this.game = null;
                }
            }
        }
    }.bind(this);
Example #21
0
var getVideoDetails = function (credentials) {
  'use strict';
  // If this bundle is using oauth2, add in the access token
  var tokenString = _.isObject(credentials) && _.has(credentials, 'access_token') ? 
    "&access_token=" + credentials.access_token : 
    '';
  return function (obj, cb) {
    spashttp.request({url: "http://gdata.youtube.com/feeds/api/videos/" + obj.media$group.yt$videoid.$t + '?v=2&alt=json' + tokenString }, credentials, function( err, video ) {
      if(video && _.has(video, 'entry')) {
        obj.media$group.media$keywords.$t = video.entry.media$group.media$keywords.$t;
        obj.category = video.entry.category;
      }

      cb(err);
    });
  };
};
Example #22
0
 'albumInfoString': function(albumData) {
     var info = '';
     if(!_.isUndefined(albumData) && _.has(albumData, 'data') && !_.isUndefined(albumData.data.id)) {
         albumData = albumData.data;
         if(albumData.title) {
             info += albumData.title + ' - ';
         }
         if(albumData.description) {
             info += albumData.description.split('\n')[0] + ' is ';
         }
         info += 'an album with ' + albumData.images_count + ' images ';
         info += 'and ' + albumData.views + ' views';
         if(albumData.nsfw) {
             info += ' - NSFW';
         }
     }
     return info;
 }.bind(this),
Example #23
0
 this.api.getUserStats(user.id, function(uStats) {
     if(uStats) {
         var output = dbot.t('sstats_tlines', { 
             'user': user.primaryNick,
             'lines': uStats.lines,
             'date': moment(uStats.creation).format('DD/MM/YYYY')
         });
         if(_.has(uStats.channels, cId)) {
             output += dbot.t('sstats_uclines', { 
                 'channel': event.channel,
                 'lines': uStats.channels[cId].lines 
             });
         }
         event.reply(output);
     } else {
         event.reply(dbot.t('sstats_noustats'));
     }
 });       
Example #24
0
File: api.js Project: treesus/dbot
        'resolveChannel': function(server, channelName, callback) {
            if(_.has(this.chanCache[server], channelName)) {
                return this.api.getChannel(this.chanCache[server][channelName], callback);
            }

            var channel = false;
            this.db.search('channel_users', {
                'server': server,
                'name': channelName
            }, function(result) {
                channel = result;
            }, function(err) {
                if(!err) {
                    this.chanCache[server][channelName] = channel.id;
                    callback(channel);
                }
            }.bind(this));
        },
Example #25
0
                        dbot.api.timers.addTimeout(msTimeout, function() {
                            if(_.has(this.hosts[server], quietee)) {
                                if(_.include(this.config.quietBans, channel)) {
                                    this.api.unban(server, this.hosts[server][quietee], channel);
                                this.api.voice(server, quietee, channel);
                                } else {
                                    this.api.unquiet(server, this.hosts[server][quietee], channel);
                                }

                                dbot.api.users.resolveUser(server, dbot.config.name, function(err, user) {
                                    dbot.api.report.notify('unquiet', server, user, channel,
                                    dbot.t('unquiet_notify', {
                                        'unquieter': dbot.config.name,
                                        'quietee': quietee
                                    }));
                                });
                            }
                        }.bind(this));  
Example #26
0
					spashttp.request({url: params.url}, credentials, function( err, photos ) {
					
						n = n - 1;
						
						if (err) {
							obj["error"] = err;
						} else {
							if (_.has(photos, 'photoset')) {
								sets.photosets.photoset[key].photo = photos.photoset.photo;
								sets.size += photos.size;
							} else {
								console.log('photoset missing: ' + params);
							}
						}
						
						if (n === 0) {
							cb( null, sets );
						}
					});
Example #27
0
 this.api.search(event.input[1], function(body) {
     if(_.isObject(body) && _.has(body, 'items') && body.items.length > 0) {
         request.get(this.ApiRoot + 'playlists' , {
             'qs': {
                 'key': this.config.api_key,
                 'id': body.items[0].id.playlistId,
                 'maxResults': 1,
                 'part': "snippet,contentDetails"
             },
             'json': true
         }, function(error, response, body) {
             if(_.isObject(body) && _.has(body, 'items') && body.items.length > 0) {
                 event.reply(this.internalAPI.formatPlaylistLink(body.items[0]));
             }
         }.bind(this));
     } else {
         event.reply(dbot.t('yt_noresults'));
     }
 }.bind(this), "playlist");
Example #28
0
			work: function(apiResponse) {

				winston.info('manager:finishRequest');

				queriesInThisBundle--;

				if (_.has(apiResponse, 'redirect')) {
					thisResponse["redirect"] = apiResponse.redirect;
					thisResponse["guid"] = apiResponse.guid || '';
					thisResponse["authBundle"] = bid;
					thisResponse["authPart"] = apiResponse.cname;
				}
				thisResponse[apiResponse.cname] = apiResponse;

			  	if (queriesInThisBundle === 0) {
			  		manager.enqueue('composeResponse', bid);
			  	}
				this.finished = true;
			}
Example #29
0
 '~qcount': function(event) {
     var input = event.message.valMatch(/^~qcount ([\d\w\s-]*)/, 2);
     if(input) { // Give quote count for named category
         var key = input[1].trim().toLowerCase();
         if(_.has(quotes, key)) {
             event.reply(dbot.t('quote_count', {
                 'category': key, 
                 'count': quotes[key].length
             }));
         } else {
             event.reply(dbot.t('no_quotes', { 'category': key }));
         }
     } else { // Give total quote count
         var totalQuoteCount = _.reduce(quotes, function(memo, category) {
             return memo + category.length;
         }, 0);
         event.reply(dbot.t('total_quotes', { 'count': totalQuoteCount }));
     }
 },
Example #30
0
 this.reloadPages = function() {
     var pages = dbot.pages;
     for(var p in pages) {
         if(_.has(pages, p)) {
             var func = pages[p];
             var mod = func.module;
             app.get(p, (function(req, resp) {
                 // Crazy shim to seperate module views.
                 var shim = Object.create(resp);
                 shim.render = (function(view, one, two) {
                     // Render with express.js
                     resp.render(this.module + '/' + view, one, two);
                 }).bind(this);
                 shim.render_core = resp.render;
                 this.call(this.module, req, shim);
             }).bind(func));
         }
     }
 }.bind(this);