<commit_before>/* Lottery Plug-in
 * A chat plug-in for a lottery system for PS
 * by: panpawn
 */

var moment = require('moment');

exports.commands = {
    loto: 'lottery',
    lotto: 'lottery',
    lottery: function(target, room, user) {
        var parts = target.split(',');
	for (var u in parts) parts[u] = parts[u].trim();
	if (room.id !== 'gamechamber') return this.errorReply("You must be in Game Chamber to use this command.");
	if (!Rooms.get('gamechamber')) return this.errorReply("You must have the room \"Game Chamber\" in order to use this script.");
	if (!room.lottery) room.lottery = {};   
        switch (toId(parts[0])) {
            case 'buy':
            case 'join':
                if (!room.lottery.gameActive) return this.errorReply("The game of lottery is not currently running.");
                if (economy.readMoney(toId(user.name)) < room.lottery.ticketPrice) return this.errorReply("You do not have enough bucks to partake in this game of Lottery.  Sorry.");
                if (room.lottery.playerIPS.length > 1) {
                    var filteredPlayerArray = room.lottery.playerIPS.filter(function(ip) {
                        return ip === user.latestIp;
                    });
                    if (filteredPlayerArray.length >= room.lottery.maxTicketsPerUser)  return this.errorReply("You cannot get more than " + room.lottery.maxTicketsPerUser + " tickets for this game of lotto.");
                }
                economy.writeMoney('money', toId(user.name), -room.lottery.ticketPrice);
                room.lottery.pot = room.lottery.pot + (room.lottery.ticketPrice * 2);
                Rooms.get('gamechamber').add("|raw|<b><font color=" + Gold.hashColor(toId(user.name)) + ">" + user.name + "</font></b> has bought a lottery ticket.");
                room.lottery.players.push(toId(user.name));
                room.lottery.playerIPS.push(user.latestIp);
                break;
            case 'new':
            case 'create':
                if (!this.can('ban', null, room)) return this.errorReply("Access denied.");
                if (room.lottery.gameActive) return this.errorReply("There is a game of Lottery already currently running.");
                if (!parts[1]) return this.errorReply("Usage: /lottery create, [ticket cost]");
                room.lottery.maxTicketsPerUser = 10; //default max tickets per user
                room.lottery.maxTicketPrice = 20;
                if (isNaN(Number(parts[1]))) return this.errorReply('The pot must be a number greater than 0');
                if (parts[1] > room.lottery.maxTicketPrice) return this.errorReply("Lottery tickets cannot cost more than " + room.lottery.maxTicketPrice + " bucks.");
                room.lottery.startTime = Date.now();
                room.lottery.ticketPrice = parts[1];
                room.lottery.gameActive = true;
                room.lottery.pot = 0;
                room.lottery.players = [];
                room.lottery.playerIPS = [];
                room.lottery.createdBy = user.name;
                var room_notification = 
                    "<div class=\"broadcast-gold\"><center><b><font size=4 color=red>Lottery Game!</font></b><br />" +
                    "<i><font color=gray>(Started by: " + Tools.escapeHTML(user.name) + ")</font></i><br />" +
                    "A game of lottery has been started!  Cost to join is <b>" + room.lottery.ticketPrice + "</b> Gold bucks.<br />" +
                    "To buy a ticket, do <code>/lotto join</code>. (Max tickets per user: " + room.lottery.maxTicketsPerUser + ")</center></div>";
                if (parts[2] === 'pmall') {
                    if (!this.can('hotpatch')) return this.errorReply("Access denied.");
                    var loto_notification =
                        "<center><font size=5 color=red><b>Lottery Game!</b></font><br />" +
                        "A game of Lottery has started in <button name=\"send\" value=\"/join gamechamber\">Game Chamber</button>!<br />" +
                        "The ticket cost to join is <b> " + room.lottery.ticketPrice + "</b> Gold Bucks.  For every ticket bought, the server automatically matches that price towards the pot.<br />" +
                        "(For more information, hop in the room and do /lotto or ask for help!)</center>";
                    var pmName = '~Gold Lottery';
		            for (var i in Users.users) {
		            	var message = '|pm|' + pmName + '|' + Users.users[i].getIdentity() + '|/html ' + loto_notification;
		            	Users.users[i].send(message);
		            }
                    Rooms.get('gamechamber').add('|raw|' + room_notification);
                } else {
                    Rooms.get('gamechamber').add('|raw|' + room_notification);
                }
                break;
            case 'end':
                if (!this.can('ban', null, room)) return this.errorReply("Access denied.");
                if (!room.lottery.gameActive) return this.errorReply("There is no active game of lottery currently running.");
                var winner = room.lottery.players[Math.floor(Math.random() * room.lottery.players.length)];
                var jackpot = Math.floor(100 * Math.random()) + 1;
                if (!room.lottery.pot == 0) {
                    if (jackpot == 100) {
                        Rooms.get("gamechamber").add('|raw|<b><font size="7" color="green"><blink>JACKPOT!</blink></font></b>');
                        Rooms.get("gamechamber").add('|raw|<b><font size="4" color="' + Gold.hashColor(winner) + '">' + winner + '</b></font><font size="4"> has won the game of lottery for <b>' + (room.lottery.pot * 2) + '</b> bucks!</font>');
                        economy.writeMoney('money', toId(winner), room.lottery.pot*2);
                    } else {
                        economy.writeMoney('money', toId(winner), room.lottery.pot);
                        Rooms.get("gamechamber").add('|raw|<b><font size="4" color="' + Gold.hashColor(winner) + '">' + winner + '</b></font><font size="4"> has won the game of lottery for <b>' + room.lottery.pot + '</b> bucks!</font>');
                        room.lottery = {};
                    }
                } else if (room.lottery.pot === 0) {
                    this.add('|raw|<b><font size="4">This game has been cancelled due to a lack of players by ' + Tools.escapeHTML(toId(user.name)) + '.');
                    room.lottery = {};
                }
                this.privateModCommand("(" + Tools.escapeHTML(user.name) + " has ended the game of lottery.)");
                break;
            case 'setlimit':
                if (!this.can('hotpatch')) return this.errorReply("Access denied.");
                if (!room.lottery.gameActive) return this.errorReply("The game of lottery is not currently running.");
                if (!parts[1]) return this.errorReply("Usage: /lotto setlimit, [limit of tickets per user].");
                if (isNaN(Number(parts[1]))) return this.errorReply('The pot must be a number greater than 0');
                room.lottery.maxTicketsPerUser = parts[1];
                this.add('|raw|<b><font size="4" color="' + Gold.hashColor(toId(user.name)) + '">' + Tools.escapeHTML(user.name) + '</font><font size="4"> has changed the lottery ticket cap to: ' + room.lottery.maxTicketsPerUser + '.</font></b>');
                break;
            case 'limit':
                return this.sendReply("The current cap of lottery tickets per user is: " + room.lottery.maxTicketsPerUser);
                break;
            case 'tickets':
                if (!this.canBroadcast()) return;
                if (!room.lottery.gameActive) return this.errorReply("There is no active game of lottery currently running.");
                return this.sendReplyBox("<b>Current tickets: (" + room.lottery.players.length + ")</b><br /> " + room.lottery.players);
                break;
            case 'odds':
                if (!this.canBroadcast()) return;
                if (!parts[1]) parts[1] = user.name;
                if (room.lottery.players.length > 1) {
                    var filteredPlayerArray = room.lottery.players.filter(function(username) {
                        return username === toId(parts[1])
                    });
                    var chance = ((filteredPlayerArray.length / room.lottery.players.length) * 100).toFixed(1);
                }
                if (!chance) return this.sendReplyBox("This user is not in the current game of lottery.  Check spelling?");
                return this.sendReplyBox("<b><font color=" + Gold.hashColor(toId(parts[1])) + ">" + Tools.escapeHTML(parts[1]) + "</font></b> has a " + chance + "% chance of winning the game of lottery right now.");
                break;
            case 'status':
                if (!this.canBroadcast()) return;
                if (!room.lottery.gameActive) return this.errorReply("There is no active game of lottery currently running.");
                return this.sendReplyBox(
                    "<div style=\"max-height: 125px; overflow-y: auto; overflow-x: hidden;\" target=\"_blank\">" +
                    "<u>Lottery Game Status:</u><br />" +<commit_msg>Change check in /lotto odds<commit_after>/* Lottery Plug-in
 * A chat plug-in for a lottery system for PS
 * by: panpawn
 */

var moment = require('moment');

exports.commands = {
    loto: 'lottery',
    lotto: 'lottery',
    lottery: function(target, room, user) {
        var parts = target.split(',');
	for (var u in parts) parts[u] = parts[u].trim();
	if (room.id !== 'gamechamber') return this.errorReply("You must be in Game Chamber to use this command.");
	if (!Rooms.get('gamechamber')) return this.errorReply("You must have the room \"Game Chamber\" in order to use this script.");
	if (!room.lottery) room.lottery = {};   
        switch (toId(parts[0])) {
            case 'buy':
            case 'join':
                if (!room.lottery.gameActive) return this.errorReply("The game of lottery is not currently running.");
                if (economy.readMoney(toId(user.name)) < room.lottery.ticketPrice) return this.errorReply("You do not have enough bucks to partake in this game of Lottery.  Sorry.");
                if (room.lottery.playerIPS.length > 1) {
                    var filteredPlayerArray = room.lottery.playerIPS.filter(function(ip) {
                        return ip === user.latestIp;
                    });
                    if (filteredPlayerArray.length >= room.lottery.maxTicketsPerUser)  return this.errorReply("You cannot get more than " + room.lottery.maxTicketsPerUser + " tickets for this game of lotto.");
                }
                economy.writeMoney('money', toId(user.name), -room.lottery.ticketPrice);
                room.lottery.pot = room.lottery.pot + (room.lottery.ticketPrice * 2);
                Rooms.get('gamechamber').add("|raw|<b><font color=" + Gold.hashColor(toId(user.name)) + ">" + user.name + "</font></b> has bought a lottery ticket.");
                room.lottery.players.push(toId(user.name));
                room.lottery.playerIPS.push(user.latestIp);
                break;
            case 'new':
            case 'create':
                if (!this.can('ban', null, room)) return this.errorReply("Access denied.");
                if (room.lottery.gameActive) return this.errorReply("There is a game of Lottery already currently running.");
                if (!parts[1]) return this.errorReply("Usage: /lottery create, [ticket cost]");
                room.lottery.maxTicketsPerUser = 10; //default max tickets per user
                room.lottery.maxTicketPrice = 20;
                if (isNaN(Number(parts[1]))) return this.errorReply('The pot must be a number greater than 0');
                if (parts[1] > room.lottery.maxTicketPrice) return this.errorReply("Lottery tickets cannot cost more than " + room.lottery.maxTicketPrice + " bucks.");
                room.lottery.startTime = Date.now();
                room.lottery.ticketPrice = parts[1];
                room.lottery.gameActive = true;
                room.lottery.pot = 0;
                room.lottery.players = [];
                room.lottery.playerIPS = [];
                room.lottery.createdBy = user.name;
                var room_notification = 
                    "<div class=\"broadcast-gold\"><center><b><font size=4 color=red>Lottery Game!</font></b><br />" +
                    "<i><font color=gray>(Started by: " + Tools.escapeHTML(user.name) + ")</font></i><br />" +
                    "A game of lottery has been started!  Cost to join is <b>" + room.lottery.ticketPrice + "</b> Gold bucks.<br />" +
                    "To buy a ticket, do <code>/lotto join</code>. (Max tickets per user: " + room.lottery.maxTicketsPerUser + ")</center></div>";
                if (parts[2] === 'pmall') {
                    if (!this.can('hotpatch')) return this.errorReply("Access denied.");
                    var loto_notification =
                        "<center><font size=5 color=red><b>Lottery Game!</b></font><br />" +
                        "A game of Lottery has started in <button name=\"send\" value=\"/join gamechamber\">Game Chamber</button>!<br />" +
                        "The ticket cost to join is <b> " + room.lottery.ticketPrice + "</b> Gold Bucks.  For every ticket bought, the server automatically matches that price towards the pot.<br />" +
                        "(For more information, hop in the room and do /lotto or ask for help!)</center>";
                    var pmName = '~Gold Lottery';
		            for (var i in Users.users) {
		            	var message = '|pm|' + pmName + '|' + Users.users[i].getIdentity() + '|/html ' + loto_notification;
		            	Users.users[i].send(message);
		            }
                    Rooms.get('gamechamber').add('|raw|' + room_notification);
                } else {
                    Rooms.get('gamechamber').add('|raw|' + room_notification);
                }
                break;
            case 'end':
                if (!this.can('ban', null, room)) return this.errorReply("Access denied.");
                if (!room.lottery.gameActive) return this.errorReply("There is no active game of lottery currently running.");
                var winner = room.lottery.players[Math.floor(Math.random() * room.lottery.players.length)];
                var jackpot = Math.floor(100 * Math.random()) + 1;
                if (!room.lottery.pot == 0) {
                    if (jackpot == 100) {
                        Rooms.get("gamechamber").add('|raw|<b><font size="7" color="green"><blink>JACKPOT!</blink></font></b>');
                        Rooms.get("gamechamber").add('|raw|<b><font size="4" color="' + Gold.hashColor(winner) + '">' + winner + '</b></font><font size="4"> has won the game of lottery for <b>' + (room.lottery.pot * 2) + '</b> bucks!</font>');
                        economy.writeMoney('money', toId(winner), room.lottery.pot*2);
                    } else {
                        economy.writeMoney('money', toId(winner), room.lottery.pot);
                        Rooms.get("gamechamber").add('|raw|<b><font size="4" color="' + Gold.hashColor(winner) + '">' + winner + '</b></font><font size="4"> has won the game of lottery for <b>' + room.lottery.pot + '</b> bucks!</font>');
                        room.lottery = {};
                    }
                } else if (room.lottery.pot === 0) {
                    this.add('|raw|<b><font size="4">This game has been cancelled due to a lack of players by ' + Tools.escapeHTML(toId(user.name)) + '.');
                    room.lottery = {};
                }
                this.privateModCommand("(" + Tools.escapeHTML(user.name) + " has ended the game of lottery.)");
                break;
            case 'setlimit':
                if (!this.can('hotpatch')) return this.errorReply("Access denied.");
                if (!room.lottery.gameActive) return this.errorReply("The game of lottery is not currently running.");
                if (!parts[1]) return this.errorReply("Usage: /lotto setlimit, [limit of tickets per user].");
                if (isNaN(Number(parts[1]))) return this.errorReply('The pot must be a number greater than 0');
                room.lottery.maxTicketsPerUser = parts[1];
                this.add('|raw|<b><font size="4" color="' + Gold.hashColor(toId(user.name)) + '">' + Tools.escapeHTML(user.name) + '</font><font size="4"> has changed the lottery ticket cap to: ' + room.lottery.maxTicketsPerUser + '.</font></b>');
                break;
            case 'limit':
                return this.sendReply("The current cap of lottery tickets per user is: " + room.lottery.maxTicketsPerUser);
                break;
            case 'tickets':
                if (!this.canBroadcast()) return;
                if (!room.lottery.gameActive) return this.errorReply("There is no active game of lottery currently running.");
                return this.sendReplyBox("<b>Current tickets: (" + room.lottery.players.length + ")</b><br /> " + room.lottery.players);
                break;
            case 'odds':
                if (!this.canBroadcast()) return;
                if (!parts[1]) parts[1] = user.name;
                if (room.lottery.players.length > 1) {
                    var filteredPlayerArray = room.lottery.players.filter(function(username) {
                        return username === toId(parts[1])
                    });
                    var chance = ((filteredPlayerArray.length / room.lottery.players.length) * 100).toFixed(1);
                }
                if (chance == 0) return this.sendReplyBox("This user is not in the current game of lottery.  Check spelling?");
                return this.sendReplyBox("<b><font color=" + Gold.hashColor(toId(parts[1])) + ">" + Tools.escapeHTML(parts[1]) + "</font></b> has a " + chance + "% chance of winning the game of lottery right now.");
                break;
            case 'status':
                if (!this.canBroadcast()) return;
                if (!room.lottery.gameActive) return this.errorReply("There is no active game of lottery currently running.");
                return this.sendReplyBox(
                    "<div style=\"max-height: 125px; overflow-y: auto; overflow-x: hidden;\" target=\"_blank\">" +
                    "<u>Lottery Game Status:</u><br />" +
{'fraction_non_alphanumeric': 0.14825676115998696, 'fraction_numerical': 0.005702183121537961, 'mean_word_length': 2.0158860137569605, 'pattern_counts': {'":': 0, '<': 159, '<?xml version=': 0, '>': 165, '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': '4703088', 'n_tokens_mistral': 5364, 'n_tokens_neox': 5026, 'n_words': 1309}