<commit_before>#!/usr/bin/env node

var grooveshark = require('./core/grooveshark.js');
var manatee = require('./core/manatee.js')
var moduleloader = require('./core/moduleloader.js');
var request = require('./core/request.js');

var GU = {
 user: null,
 pingInterval: null,
 isFollowed: [],
 mods: {},
 
 getLastBroadcast: function(cb) {
    grooveshark.more({method: 'getUserLastBroadcast'}, false, cb);
 },
 
 permissionList: {
    guest: function(userid) {
        return manatee.getQueue().guests.indexOf(userid) != -1;
    },
    isFollowed: function(userid) {
        return GU.isFollowed instanceof Array && GU.isFollowed.indexOf(userid) != -1;
    }
 },

 manateeCallback: {
    OnSocketClose: function() {
        console.log('Matanee socket is down.');
    },
    OnChatMessageRcv: function(userid, msg) {
        var regexp = RegExp('^/([a-zA-Z]*)([ ]+(.+))?$');
        var regResult = regexp.exec(msg);
        if (regResult != null)
        {
            var mod = GU.mods[regResult[1]];
            var req = request.onCall(userid, GU.isFollowed, regResult[3]);
            // TODO: add functionality for eventSilence toggle that when enabled, will silence all non-guest initaiated output, and turn off auto-queuing.
            if (mod && (!mod.permission || mod.permission.some(function(pname){return GU.permissionList[pname](userid)})))
            {
                try {
                    mod.onCall(req);
                } catch (err) {
                    manatee.sendChatMessage("BOT WARNING: The extension " + mod.name + " by " + mod.author + " threw an error...");
                    console.log(err.stack);
                }
            }
            else if (mod)
            {
                manatee.sendChatMessage("You do not meet the following permission: " + mod.permission);
            }
        }
    }
 },

 // Call the callback with the user as a parameter, or null if the login failed.
 login: function(cb) {
    if (GU.user)
    {
        cb(GU.user);
        return;
    }
    var config = require('./config.js');
    var user = config.username;
    var pass = config.password;
    
    if (user == '' || pass == '')
    {
        cb(null);
        return;
    }
    
    var parameters = {method: 'authenticateUser', parameters: {username: user, password: <PASSWORD>}};
    var callback;
    callback = function(message) {
        if (message == undefined)
        {
            grooveshark.more(parameters, true, callback);
        }
        else
        {
            GU.user = message;
            cb(GU.user);
        }
    };
    grooveshark.more(parameters, true, callback);
 },
    
 getFollowing: function() {
        grooveshark.more({method: 'userGetFollowersFollowingExt', parameters: {}},
        false,
        function(alluser)
        {
            alluser.forEach(function(single)
            {
                if (single.IsFavorite === '1')
                {
                    GU.isFollowed.push(parseInt(single.UserID));
                }
            });
        });<commit_msg>userGetFollowersFollowingExt is broken, using getFavorites instead<commit_after>#!/usr/bin/env node

var grooveshark = require('./core/grooveshark.js');
var manatee = require('./core/manatee.js')
var moduleloader = require('./core/moduleloader.js');
var request = require('./core/request.js');

var GU = {
 user: null,
 pingInterval: null,
 isFollowed: [],
 mods: {},
 
 getLastBroadcast: function(cb) {
    grooveshark.more({method: 'getUserLastBroadcast'}, false, cb);
 },
 
 permissionList: {
    guest: function(userid) {
        return manatee.getQueue().guests.indexOf(userid) != -1;
    },
    isFollowed: function(userid) {
        return GU.isFollowed.indexOf(userid) != -1;
    }
 },

 manateeCallback: {
    OnSocketClose: function() {
        console.log('Matanee socket is down.');
    },
    OnChatMessageRcv: function(userid, msg) {
        var regexp = RegExp('^/([a-zA-Z]*)([ ]+(.+))?$');
        var regResult = regexp.exec(msg);
        if (regResult != null)
        {
            var mod = GU.mods[regResult[1]];
            var req = request.onCall(userid, GU.isFollowed, regResult[3]);
            // TODO: add functionality for eventSilence toggle that when enabled, will silence all non-guest initaiated output, and turn off auto-queuing.
            if (mod && (!mod.permission || mod.permission.some(function(pname){return GU.permissionList[pname](userid)})))
            {
                try {
                    mod.onCall(req);
                } catch (err) {
                    manatee.sendChatMessage("BOT WARNING: The extension " + mod.name + " by " + mod.author + " threw an error...");
                    console.log(err.stack);
                }
            }
            else if (mod)
            {
                manatee.sendChatMessage("You do not meet the following permission: " + mod.permission);
            }
        }
    }
 },

 // Call the callback with the user as a parameter, or null if the login failed.
 login: function(cb) {
    if (GU.user)
    {
        cb(GU.user);
        return;
    }
    var config = require('./config.js');
    var user = config.username;
    var pass = config.password;
    
    if (user == '' || pass == '')
    {
        cb(null);
        return;
    }
    
    var parameters = {method: 'authenticateUser', parameters: {username: user, password: <PASSWORD>}};
    var callback;
    callback = function(message) {
        if (message == undefined)
        {
            grooveshark.more(parameters, true, callback);
        }
        else
        {
            GU.user = message;
            cb(GU.user);
        }
    };
    grooveshark.more(parameters, true, callback);
 },
    
 getFollowing: function() {
        grooveshark.more({method: 'getFavorites', parameters: {userID: GU.user.userID, ofWhat: "Users"}},
        false,
        function(alluser) {
            alluser.forEach(function(single) {
                GU.isFollowed.push(parseInt(single.UserID));
            });
        });
{'fraction_non_alphanumeric': 0.14029553378714926, 'fraction_numerical': 0.0014942719574962643, 'mean_word_length': 1.9955246146195922, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3116888', 'n_tokens_mistral': 1833, 'n_tokens_neox': 1771, 'n_words': 387}