<commit_before>var irc = require("irc");
var fs = require('fs');

// Make sure requried files exist
var wordlists = JSON.parse(fs.readFileSync('wordlist.json', 'utf8'));
var secrets = JSON.parse(fs.readFileSync('oauthfile.json', 'utf8'));
var inmem = JSON.parse(fs.readFileSync('config.json', 'utf8'));

console.log(secrets);

if (!inmem.joinlist) {
    console.log("Please specifiy a list of channels to join in the config.json file section 'joinlist'");
    process.exit(1);
}

var config = {
    //server: "irc.twitch.tv",
    server: "localhost",
    botName: "repkbot",
    channel: inmem.joinlist
};

console.log("Starting up repbot on irc...");
// Create the bot name
var bot = new irc.Client(config.server, config.botName, {
    channels: config.channel,
    debug: false,
    password: <PASSWORD>,
    username: config.botName
});

bot.addListener('error', function (message) {
    console.log("Error: " + JSON.stringify(message));
});

bot.addListener('end', function (reason) {
    console.log("connection ended!");
});


config.channel.forEach(function (channelName) {
    console.log("Listening in " + channelName);

    // Create a config for this channel if it doesnt exist
    if (!inmem[channelName]) {
        var current = {};
        current.trusted = [];
        current.quotes = [];
        current.deathcount = 0;

        console.log("Creating config entry for " + channelName + ": " + JSON.stringify(current));
        inmem[channelName] = current;
        updateConfig();
    } else {
        console.log("Config entry for " + channelName + " exists");
    }

    // Use this method for any setup needed in the channel
    bot.addListener('join' + channelName, function (nick, message) {
        console.log("" + nick + " joined the channel " + channelName);
    });

    bot.addListener('part' + channelName, function (nick, message) {
        console.log("" + nick + " left the channel " + channelName);
    });

    bot.addListener('message' + channelName, function (from, message) {
        if (message.substring(0, 1) === '!') {
            var msgarray = message.split(" ");
            switch (msgarray[0]) {
                case '!trust': // expects !trusted [name]
                    cmdTrusted(channelName, from, msgarray);
                    break;

                case "!told": // expects !told
                    cmdTold(channelName, from, msgarray);
                    break;

                case "!rekt": // expects !rekt
                    cmdRekt(channelName, from, msgarray);
                    break;

                case "!quote": // expects !quote
                    cmdQuote(channelName, from, msgarray);
                    break;

                case "!death":
                    cmdDeathCount(channelName, from, msgarray);
                    break;

                case "!saveconfig":
                    cmdSaveConfig(channelName, from, msgarray);
                    break;

                case "!printconfig":
                    cmdPrintConfig(channelName, from, msgarray);
                    break;

                case "!" + config.botName:
                    cmdPrintCommands(channelName, from, msgarray);
                    break;

                case "!help":
                    cmdPrintCommands(channelName, from, msgarray);
                    break;

                case "!about":
                    cmdAboutBot(channelName, from, msgarray);
                    break;
                default:
                    conprint(channelName, "Unhandled: " + from + ": " + message);
                    break;
            }
        }
    });
});

function randomInt(low, high) {
    return Math.floor(Math.random() * (high - low) + low);
}

/**
 * Print something to the console. Takes the channel name and a log message
 */
function conprint(channel, logmsg) {
    console.log("[" + channel + "] " + logmsg);
}


/**
 * Say something back into the IRC channel specified. Also log to console
 */
function botprint(channel, logmsg) {
    conprint(channel, config.botName + ": " + logmsg);
    bot.say(channel, logmsg);
}

/**
 * Checks if a user is trusted in the given channel
 * The Owner of the channel is always trusted, and therefore
 * can add other trusted members.
 *
 * If I can find a way to check if someone is a channel mod, this will also
 * give them trusted status.
 */
function isTrusted(channelName, name) {
    if ("#" + name === channelName) {
        // conprint(channelName, "Verified, user " + name + " is the owner of " + channelName);
        return true;
    }

    if (inmem[channelName].trusted.indexOf(name) > -1) {
        //conprint(channelName, "Verified, user " + name + " is trusted in " + channelName);
        return true;
    } else {
        //conprint(channelName, "Rejected, user " + name + " is not trusted in " + channelName);
        return false;
    }
}


/**<commit_msg>Add me as trusted user<commit_after>var irc = require("irc");
var fs = require('fs');

// Make sure requried files exist
var wordlists = JSON.parse(fs.readFileSync('wordlist.json', 'utf8'));
var secrets = JSON.parse(fs.readFileSync('oauthfile.json', 'utf8'));
var inmem = JSON.parse(fs.readFileSync('config.json', 'utf8'));

console.log(secrets);

if (!inmem.joinlist) {
    console.log("Please specifiy a list of channels to join in the config.json file section 'joinlist'");
    process.exit(1);
}

var config = {
    server: "irc.twitch.tv",
    botName: "repkbot",
    channel: inmem.joinlist
};

console.log("Starting up repbot on irc...");
// Create the bot name
var bot = new irc.Client(config.server, config.botName, {
    channels: config.channel,
    debug: false,
    password: <PASSWORD>,
    username: config.botName
});

bot.addListener('error', function (message) {
    console.log("Error: " + JSON.stringify(message));
});

bot.addListener('end', function (reason) {
    console.log("connection ended!");
});


config.channel.forEach(function (channelName) {
    console.log("Listening in " + channelName);

    // Create a config for this channel if it doesnt exist
    if (!inmem[channelName]) {
        var current = {};
        current.trusted = [];
        current.quotes = [];
        current.deathcount = 0;

        console.log("Creating config entry for " + channelName + ": " + JSON.stringify(current));
        inmem[channelName] = current;
        updateConfig();
    } else {
        console.log("Config entry for " + channelName + " exists");
    }

    // Use this method for any setup needed in the channel
    bot.addListener('join' + channelName, function (nick, message) {
        console.log("" + nick + " joined the channel " + channelName);
    });

    bot.addListener('part' + channelName, function (nick, message) {
        console.log("" + nick + " left the channel " + channelName);
    });

    bot.addListener('message' + channelName, function (from, message) {
        if (message.substring(0, 1) === '!') {
            var msgarray = message.split(" ");
            switch (msgarray[0]) {
                case '!trust': // expects !trusted [name]
                    cmdTrusted(channelName, from, msgarray);
                    break;

                case "!told": // expects !told
                    cmdTold(channelName, from, msgarray);
                    break;

                case "!rekt": // expects !rekt
                    cmdRekt(channelName, from, msgarray);
                    break;

                case "!quote": // expects !quote
                    cmdQuote(channelName, from, msgarray);
                    break;

                case "!death":
                    cmdDeathCount(channelName, from, msgarray);
                    break;

                case "!saveconfig":
                    cmdSaveConfig(channelName, from, msgarray);
                    break;

                case "!printconfig":
                    cmdPrintConfig(channelName, from, msgarray);
                    break;

                case "!" + config.botName:
                    cmdPrintCommands(channelName, from, msgarray);
                    break;

                case "!help":
                    cmdPrintCommands(channelName, from, msgarray);
                    break;

                case "!about":
                    cmdAboutBot(channelName, from, msgarray);
                    break;
                default:
                    conprint(channelName, "Unhandled: " + from + ": " + message);
                    break;
            }
        }
    });
});

function randomInt(low, high) {
    return Math.floor(Math.random() * (high - low) + low);
}

/**
 * Print something to the console. Takes the channel name and a log message
 */
function conprint(channel, logmsg) {
    console.log("[" + channel + "] " + logmsg);
}


/**
 * Say something back into the IRC channel specified. Also log to console
 */
function botprint(channel, logmsg) {
    conprint(channel, config.botName + ": " + logmsg);
    bot.say(channel, logmsg);
}

/**
 * Checks if a user is trusted in the given channel
 * The Owner of the channel is always trusted, and therefore
 * can add other trusted members.
 *
 * If I can find a way to check if someone is a channel mod, this will also
 * give them trusted status.
 */
function isTrusted(channelName, name) {
    if ("#" + name === channelName) {
        // conprint(channelName, "Verified, user " + name + " is the owner of " + channelName);
        return true;
    }

    if (name === "repkam09" ) {
	return true;
    }

    if (inmem[channelName].trusted.indexOf(name) > -1) {
        //conprint(channelName, "Verified, user " + name + " is trusted in " + channelName);
        return true;
    } else {
        //conprint(channelName, "Rejected, user " + name + " is not trusted in " + channelName);
        return false;
    }
}


/**
{'fraction_non_alphanumeric': 0.1299256694837593, 'fraction_numerical': 0.0020364524997454436, 'mean_word_length': 2.0751408891671885, 'pattern_counts': {'":': 22, '<': 5, '<?xml version=': 0, '>': 7, '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': '2826751', 'n_tokens_mistral': 2833, 'n_tokens_neox': 2696, 'n_words': 759}