<commit_before>import random
import re
from src.CommandSuite import CommandSuite

class DiceRollerSuite(CommandSuite):
    """Suite for rolling dice"""

    def __init__(self, name):
        """Initialize some variables"""
        CommandSuite.__init__(self, name)
        self.config = self.config_manager.parse_file('config/defaultLogSuite.config')
        random.seed()
        self.invoke_match_string = '\!([0-9]+)d([0-9]+)'
        self.invoke_modified_match_string = '\![0-9]+d[0-9]+([+]|[-])([0-9]+)'
        self.invoke_coin_match = '\!flip'
    
    def parse(self, data):
        """Parse chat data and log it"""
        self.chat_tuple = self.parse_chat(data, self.config['nick'])
        message = self.chat_tuple[1]
        base_match = re.search(self.invoke_match_string, data)
        modifier_match = re.search(self.invoke_modified_match_string, data)
        coin_flip_match = re.search(self.invoke_coin_match, data)
        number_of_dice = 0
        die_size = 0
        plus_or_minus = ''
        modifier = 0

        if base_match:
            number_of_dice = int(base_match.group(1))
            die_size = int(base_match.group(2))

            if modifier_match:
                plus_or_minus = modifier_match.group(1) 
                modifier = int(modifier_match.group(2))

            total = self.roll_dice(number_of_dice, die_size, plus_or_minus, modifier)

            print(str(total))
        if coin_flip_match:
            heads_or_tails = self.flip_coin()

            print(heads_or_tails)

        
    def roll_dice(self, number_of_dice, die_size, plus_or_minus, modifier):
        """Function to roll a dice pool"""

        total = 0

        for i in range(0,number_of_dice):
            total += random.randint(1,die_size)

        if plus_or_minus == '+':
            total += modifier
        elif plus_or_minus == '-':
            total -= modifier

        return total

    def flip_coin(self):
        """Function to flip a coin"""


        if random.randint(0,1):
            heads_or_tails = 'heads'
        else:
            heads_or_tails = 'tails'

        return heads_or_tails
        <commit_msg>Refactor dice rolling algorithm in DiceRollerSuite<commit_after>import random
import re
from src.CommandSuite import CommandSuite

class DiceRollerSuite(CommandSuite):
    """Suite for rolling dice"""

    def __init__(self, name):
        """Initialize some variables"""
        CommandSuite.__init__(self, name)
        self.config = self.config_manager.parse_file('config/defaultLogSuite.config')
        random.seed()
        self.dice_roll_string = '\!([0-9]+)d([0-9]+)([+]|[-])?([0-9]*)'
        self.invoke_coin_match = '\!flip'
    
    def parse(self, data):
        """Parse chat data and log it"""
        self.chat_tuple = self.parse_chat(data, self.config['nick'])
        message = self.chat_tuple[1]
        dice_roll_match = re.search(self.dice_roll_string, data)
        coin_flip_match = re.search(self.invoke_coin_match, data)
        number_of_dice = 0
        die_size = 0
        plus_or_minus = ''
        modifier = 0

        if dice_roll_match:
            total = self.roll_dice(dice_roll_match)
            print(str(total))

            # print(str(total))
        if coin_flip_match:
            heads_or_tails = self.flip_coin()

            print(heads_or_tails)

        
    def roll_dice(self, dice_roll_match):
        """Function to roll a dice pool"""

        (pool, die, plus_or_minus, modifier) = dice_roll_match.groups()
        pool = int(pool)
        die = int(die)
        if modifier == '':
            modifier = 0
        else:
            modifier = int(modifier)

        total = 0

        for i in range(0, pool):
            total += random.randint(1, die)

        if plus_or_minus == '+':
            total += modifier
        elif plus_or_minus == '-':
            total -= modifier

        return total
        # return 0

    def flip_coin(self):
        """Function to flip a coin"""


        if random.randint(0,1):
            heads_or_tails = 'heads'
        else:
            heads_or_tails = 'tails'

        return heads_or_tails
        
{'fraction_non_alphanumeric': 0.11364728495915426, 'fraction_numerical': 0.009610764055742432, 'mean_word_length': 2.1253753753753752, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3673751', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1268, 'n_words': 265}