<commit_before>// Description:
//  Beat the sniperino
//  
//
// Commands:
//  sniperino( me)? - start a new game of sniperino 
//
//
// Author:
//  <NAME>

import { Robot } from "tsbot";

interface ISniper {
    name: string;
    gamesPlayed: number;
    gamesWon: number;
    currentSnipe?: number;

    getWinRate(): number;
    generateNewSnipe();
}

class Sniper implements ISniper {
    public name: string;
    public gamesPlayed: number;
    public gamesWon: number;
    public currentSnipe: number;
    
    constructor(n: string) {
        this.name = n.slice(0, n.indexOf(" "));
        this.gamesPlayed = 0;
        this.gamesWon = 0;
    }

    public getWinRate(): number {
        // Calculation with some javascript rounding magic
        return this.gamesPlayed > 0 ? Math.round(this.gamesWon / this.gamesPlayed * 10000) / 100 : 0;
    }

    public generateNewSnipe() {
        this.currentSnipe = Math.floor(Math.random() * 99) + 1;
    }
}

let game = (robot: Robot) => {
    
    // If the brain has no knowledge of sniperino, create it
    if (robot.brain.get("sniperino") == null) {
        robot.brain.set("sniperino", {});
    }
    
    // Create a constant sniperino
    let sniperino = robot.brain.get("sniperino");

    // Get a sniper with a given name. If one doesn't exist, create it.
    let getOrCreateSniper = (name: string) => {
    
        // Check for active sniper, if not, create one
        if (sniperino[name] == null) {
            sniperino[name] = new Sniper(name);
        }
        return sniperino[name];
    }

    // Just get a sniper. Return null on failure.
    let getSniper = (name: string) => {
        return sniperino[name];
    }

    // Respond to a stats message
    robot.respond(/stats( me)?/i, (res) => {
        
        let stats = Object.keys(sniperino)
            .sort((a, b) => sniperino[b].getWinRate() - sniperino[a].getWinRate())
            .map((n) => `${sniperino[n].name}: ${sniperino[n].getWinRate()}%`);
      
        res.send(stats.join("\n"));

    });

    // Respond to a sniperino message
    robot.respond(/sniperino( me)?/i, (res) => {

        // Define instance of our Sniper object from getSniper method
        let name = res.message.user.name;
        let sniper = getOrCreateSniper(name);

        // Deny the play if someone is already actively sniping. Otheriwise, display their roll.
        if (sniper.currentSnipe == undefined) {
            
            // Player isn't playing, start a game for them
            sniper.generateNewSnipe();
        <commit_msg>Fixed Sniperino regex. v0.3.5<commit_after>// Description:
//  Beat the sniperino
//  
//
// Commands:
//  sniperino( me)? - start a new game of sniperino 
//
//
// Author:
//  <NAME>

import { Robot } from "tsbot";

interface ISniper {
    name: string;
    gamesPlayed: number;
    gamesWon: number;
    currentSnipe?: number;

    getWinRate(): number;
    generateNewSnipe();
}

class Sniper implements ISniper {
    public name: string;
    public gamesPlayed: number;
    public gamesWon: number;
    public currentSnipe: number;
    
    constructor(n: string) {
        this.name = n.slice(0, n.indexOf(" "));
        this.gamesPlayed = 0;
        this.gamesWon = 0;
    }

    public getWinRate(): number {
        // Calculation with some javascript rounding magic
        return this.gamesPlayed > 0 ? Math.round(this.gamesWon / this.gamesPlayed * 10000) / 100 : 0;
    }

    public generateNewSnipe() {
        this.currentSnipe = Math.floor(Math.random() * 99) + 1;
    }
}

let game = (robot: Robot) => {
    
    // If the brain has no knowledge of sniperino, create it
    if (robot.brain.get("sniperino") == null) {
        robot.brain.set("sniperino", {});
    }
    
    // Create a constant sniperino
    let sniperino = robot.brain.get("sniperino");

    // Get a sniper with a given name. If one doesn't exist, create it.
    let getOrCreateSniper = (name: string) => {
    
        // Check for active sniper, if not, create one
        if (sniperino[name] == null) {
            sniperino[name] = new Sniper(name);
        }
        return sniperino[name];
    }

    // Just get a sniper. Return null on failure.
    let getSniper = (name: string) => {
        return sniperino[name];
    }

    // Respond to a stats message
    robot.respond(/sniperino stats( me)?/i, (res) => {
        
        let stats = Object.keys(sniperino)
            .sort((a, b) => sniperino[b].getWinRate() - sniperino[a].getWinRate())
            .map((n) => `${sniperino[n].name}: ${sniperino[n].getWinRate()}%`);
      
        res.send(stats.join("\n"));

    });

    // Respond to a sniperino message
    robot.respond(/sniperino( me)?$/i, (res) => {

        // Define instance of our Sniper object from getSniper method
        let name = res.message.user.name;
        let sniper = getOrCreateSniper(name);

        // Deny the play if someone is already actively sniping. Otheriwise, display their roll.
        if (sniper.currentSnipe == undefined) {
            
            // Player isn't playing, start a game for them
            sniper.generateNewSnipe();
        
{'fraction_non_alphanumeric': 0.13172721973965418, 'fraction_numerical': 0.006800077715173888, 'mean_word_length': 2.1738594327990137, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '2454036', 'n_tokens_mistral': 1756, 'n_tokens_neox': 1676, 'n_words': 444}