Exemplo n.º 1
0
def pay_prizes(sender, channel, roll, prizes, symbols):
    for index, symbol in enumerate(symbols):
        if set(roll) == set([symbol]):
            prize = prizes[index]
            irc.say(channel, f'{sumbol}x3, won {price} chips')
            chips[sender] += prize
            return
Exemplo n.º 2
0
def play(sender, channel):
    global game_status, last_roll
    
    if game_status is not GrassStatus.ROLLING:
        irc.say(channel, 'not your turn yet')
        return

    if sender != current_player:
        return

    roll = random.randint(1, 6)

    if roll in (1, 6):
        irc.say(channel, f'{current_player} rolls {roll} and puts one chip on the table')
        put_chips(current_player, 1)
        if chips[current_player] <= 0:
            irc.say(channel, f'{current_player} is poor now lol')
            kick(current_player, channel)
        next_turn(channel)
    elif roll == 5:
        irc.say(channel, f'{current_player} rolls {roll} and takes one chip from the table')
        take_chips(current_player, 1)
        next_turn(channel)
    elif roll in (2, 3, 4):
        irc.say(channel, f'{current_player} rolls {roll}, place a bet and roll again or pass')
        game_status = GrassStatus.WAITING_FOR_BET
        last_roll = roll
Exemplo n.º 3
0
def buy_chips(sender, channel, amount):
    if bank.transfer_money(sender, config.nickname, amount * CHIP_VALUE):
        slots_logger.info(f'{sender} bought {amount} chips')
        irc.say(channel, f'{sender} bought {amount} chips')
    else:
        return

    chips[sender] += amount
Exemplo n.º 4
0
def cash_out(sender, channel):
    if chips[sender] == 0:
        irc.say(channel, 'nothing to cash out')
        return

    current_chips = chips[sender]
    amount = current_chips * CHIP_VALUE
    bank.transfer_money(config.nickname, sender, amount)
    chips[sender] = 0
    slots_logger.info(
        f'{sender} cashed out {current_chips} chips, {amount:.2f} bux')
    irc.say(sender, f'you got {amount:.2f} newbux from slots')
Exemplo n.º 5
0
def add_player(sender, channel):
    if game_status is not GrassStatus.WAITING_FOR_PLAYERS:
        return

    if bank.transfer_money(sender, config.nickname, INITIAL_CHIPS * chip_value):
        irc.say(channel, f'{sender} joins the game')
    else:
        return

    chips.update({sender: INITIAL_CHIPS})
    turns.insert(counter, sender)
    put_chips(sender, INITIAL_CHIPS_ON_TABLE)
Exemplo n.º 6
0
def start(sender, channel):
    global game_status, turns
    
    if game_status is not GrassStatus.WAITING_FOR_PLAYERS:
        irc.say(channel, 'create a game first')
        return
    
    if sender != owner:
        irc.say(channel, f'wait for {owner} to start the game')
        return

    game_status = GrassStatus.ROLLING
    random.shuffle(turns)
    next_turn(channel)
Exemplo n.º 7
0
def new_game(sender, channel, value):
    global game_status, chips, turns, counter, current_player, owner
    global chip_value, chips_on_table

    if game_status is not GrassStatus.FINISHED:
        irc.say(channel, 'finish this game first before starting a new one')
        return
    
    game_status = GrassStatus.WAITING_FOR_PLAYERS
    chips = {}
    turns = []
    counter = 0
    current_player = ''
    chips_on_table = 0
    last_roll = 0
    owner = sender
    chip_value = value
    add_player(sender, channel)
Exemplo n.º 8
0
def next_turn(channel):
    global counter, current_player
    
    if len(turns) == 1:
        finish(channel)
        return

    if game_status == GrassStatus.FINISHED:
        return
    
    counter = (counter + 1) % len(turns) 
    current_player = turns[counter]
    print_chips(channel)

    if chips_on_table == 0:
        irc.say(channel, 'no chips left')
        abort(channel)

    if current_player == config.nickname:
        bot_play(channel)
Exemplo n.º 9
0
def start(sender, channel, game, auto=False):
    if game == Games.EASY:
        reels, symbols, prizes, bet = EASY_REELS, EASY_SYMBOLS, EASY_PRIZES, EASY_BET
    elif game == Games.HARD:
        reels, symbols, prizes, bet = HARD_REELS, HARD_SYMBOLS, HARD_PRIZES, HARD_BET
    else:
        irc.say(channel, 'that game does not exist')
        return

    current_chips = chips[sender]
    if chips[sender] < bet:
        irc.say(
            channel,
            f'you only have {current_chips} chips, this game requires {bet} per play'
        )
        return

    if sender in ongoing_games:
        irc.say(channel, 'calm down')
        return

    if auto:
        player_thread = threading.Thread(target=auto_play,
                                         args=(sender, channel, reels, symbols,
                                               prizes, bet))
        ongoing_games.add(sender)
        player_thread.start()
    else:
        single_play(sender, channel, reels, symbols, prizes, bet)
Exemplo n.º 10
0
def abort(channel):
    global game_status
    
    if game_status == GrassStatus.FINISHED:
        irc.say(channel, 'no games to cancel')
        return

    for player, current_chips in chips.items():
        amount = current_chips * chip_value
        bank.transfer_money(config.nickname, player, amount)
        irc.say(player, f'you got {amount:.2f} newbux from grass')
    
    irc.say(channel, 'forced end of game')
    game_status = GrassStatus.FINISHED
Exemplo n.º 11
0
def finish(channel):
    global game_status, chips, turns
    
    if game_status == GrassStatus.FINISHED:
        irc.say(channel, 'no games to finish')
        return

    winner = turns[0]
    irc.say(channel, '{winner} takes all {chips_on_table} chips from the table')
    take_chips(winner, chips_on_table)
    bank.transfer_money(config.nickname, winner, chips[winner] * chip_value)
    chips = {}
    turns = []
    irc.say(channel, 'end of game')
    game_status = GrassStatus.FINISHED
Exemplo n.º 12
0
def stop(sender, channel):
    if sender in ongoing_games:
        ongoing_games.remove(sender)
        slots_logger.info(
            f'{sender} stopped auto-play with {chips[sender]} chips')
        irc.say(channel, 'why\'d you stop, gentile')
Exemplo n.º 13
0
def slot_roll(sender, channel, reels, symbols):
    chips_left = chips[sender]
    roll = [random.choices(symbols, reel_probs)[0] for reel_probs in reels]
    text_roll = ' - '.join(roll)
    irc.say(channel, f'[{text_roll}], {chips_left} chips left')
    return roll
Exemplo n.º 14
0
def run(sender: str,
        channel: str,
        full_text: str,
        command: Optional[str],
        args: Optional[Tuple[str]]) -> None:
    """Executes the bot commands sent by the user.
    Args:
        sender: The name of the user who sent the command.
        channel: The name of the channel where the message was sent. Same as `sender` if sent through a private message.
        full_text: The message sent by the user. Does not include the command name, if there is any.
        command: The name of the bot command, if any.
        args: The arguments for the bot command, if any.
    """

    def cringe_words(message):
        for w in ['xd', 'spic', 'cring', 'derail']:
            if w in message.replace(' ', '').lower():
                return True
        return False

    if sender == 'eyy' and cringe_words(full_text):
        irc.kick(channel, sender, 'ebin')

    # Refuse to do anything if not well fed by the users
    '''
    if not food.enough(sender):
        irc.say('nah')
        return
    '''

    # Reply to mention with a random quote
    if config.nickname in full_text and sender != config.nickname:
        irc.say(channel, random_quote(sender))
        return

    # Give bux to users
    bank.make_money(sender, full_text)

    if not command:
        return

    elif command == 'help':
        messages = (
            'Grass: grass-new (chip-value), grass-start, grass-join, gr, gb (amount), gp, gs, grass-cancel',
            'Slots: slot-chips (amount), easy-slot <auto>, hard-slot <auto>, slot-stop, slot-cashout',
            'Misc: pick [list], roll (number), ask (query), fetch (wikipedia_article), calc (expression), bux, sendbux (user) (amount), sharia (target) (amount)',
        )
        irc.say(sender, *messages)

    # Random choice
    elif command == 'pick':
        if len(args) > 1:
            irc.say(channel, random.choice(args))

    # Die roll
    elif command == 'roll':
        if not args:
            max_roll = 6
        elif len(args) == 1 and args[0].isdigit():
            max_roll = int(args[0])

        irc.say(channel, random.randint(1, max_roll))

    # Wolfram Alpha query
    elif command == 'ask':
        response = wolfram.ask(full_text)
        irc.say(channel, response)

    # Calculator
    elif command == 'calc':
        result = str(calculate(full_text))
        irc.say(channel, result)

    # Wikipedia fetch
    elif command == 'fetch':
        extract = wikipedia.fetch(full_text)
        irc.say(channel, extract)

    # Check balance
    elif command == 'bux':
        amount = bank.ask_money(sender)
        irc.say(channel, f'{sender} has {amount:.2f} newbux')

    # Transfer money
    elif command == 'sendbux':
        if len(args) != 2:
            irc.say(channel, 'eh')
            return

        source, destination, amount = sender, args[0], args[1]

        if not is_number(amount):
            irc.say(source, 'numbers please')
            return

        bank.transfer_money(source, destination, float(amount))

    # Redistribute wealth
    elif command == 'sharia':
        if len(args) != 2:
            irc.say(channel, 'eh')
            return

        source, target, amount = sender, args[0], args[1]

        if not is_number(amount):
            irc.say(source, 'numbers please')
            return

        bank.islamic_gommunism(source, target, float(amount), channel, users)

    # Grass game
    elif command == 'grass-new':
        if len(args) < 1:
            irc.say(channel, 'how much for each chip')
            return

        chip_value = args[0]

        if not is_number(chip_value):
            irc.say(source, 'numbers please')
            return

        grass.new_game(sender, channel, float(chip_value))

    elif command == 'grass-join':
        grass.add_player(sender, channel)

    elif command == 'grass-start':
        grass.start(sender, channel)

    elif command == 'gr':
        grass.play(sender, channel)

    elif command == 'gb':
        if len(args) < 1:
            irc.say(channel, 'how much are you betting')
            return

        bet = args[0]

        if not is_number(bet):
            irc.say(channel, 'numbers please')
            return

        grass.bet(sender, bet, channel)

    elif command == 'gp':
        grass.pass_turn(sender, channel)

    elif command == 'gs':
        grass.print_chips(channel)

    elif command == 'grass-cancel':
        grass.abort(channel)

    # Slot machine
    elif command == 'slot-chips':
        if len(args) < 1:
            irc.say(channel, 'how many are you buying')
            return

        amount = args[0]

        if not is_number(amount):
            irc.say(channel, 'numbers please')
            return

        slots.buy_chips(sender, channel, int(amount))

    elif command == 'easy-slot':
        auto = False
        if len(args) == 1 and args[0] == 'auto':
            auto = True
        slots.start(sender, channel, slots.Games.EASY, auto=auto)

    elif command == 'hard-slot':
        auto = False
        if len(args) == 1 and args[0] == 'auto':
            auto = True
        slots.start(sender, channel, slots.Games.HARD, auto=auto)

    elif command == 'slot-stop':
        slots.stop(sender, channel)

    elif command == 'slot-cashout':
        slots.cash_out(sender, channel)

    ## Owner commands ##
    if sender == config.owner:
        # Disconnect
        if command == 'quit':
            irc.quit()
            sys.exit(0)

        # Send message from bot
        elif command == 'say':
            if len(args) > 1:
                channel, text = args[0], ' '.join(args[:1])
                irc.say(channel, text)

        # Print userlist
        elif command == 'users':
            irc.say(channel, str(users))

        # Bot joins
        elif command == 'join':
            channel = args[0]
            irc.join(channel)

        # Bot parts
        elif command == 'part':
            part(channel)

        # Bot kicks
        elif command == 'kick':
            user = args[0]
            if len(args) > 1:
                reason = ' '.join(args[1:])
            irc.kick(channel, user, reason)

        # Module reloads
        elif command == 'reload':
            module_name = args[0]
            importlib.reload(sys.modules[module_name])
            irc.say(channel, 'aight')
Exemplo n.º 15
0
def print_chips(channel):
    if game_status in (GrassStatus.ROLLING, GrassStatus.WAITING_FOR_BET):
        all_chips = ', '.join(f'{name[:3]}: {chips} chips' for name, chips in chips.items())
        irc.say(channel, all_chips, f'{current_player} goes next, {chips_on_table} chips on the table')
Exemplo n.º 16
0
def bet(sender, amount, channel):
    global game_status, last_roll
   
    amount = int(amount)
    if game_status != GrassStatus.WAITING_FOR_BET:
        irc.say(channel, 'why are you betting')
        return

    if sender != current_player: 
        irc.say(channel, 'not your turn to bet')
        return

    if amount > chips_on_table:
        irc.say(channel, f'there are only {chips_on_table} chips on the table')
        return

    if amount > chips[sender]:
        irc.say(channel, 'you cannot bet more than what you have')
        return

    roll = random.randrange(1, 6)
    if roll <= last_roll:
        irc.say(channel, f'{current_player} rolls {roll}, loses and puts {amount} chips on the table')
        put_chips(current_player, amount)
        if chips[current_player] <= 0:
            irc.say(channel, f'{current_player} rubbed hands way too hard')
            kick(current_player, channel)
    else:
        irc.say(channel, f'{current_player} rolls {roll}, wins and takes {amount} chips from the table')
        take_chips(current_player, amount)
    
    last_roll = 0
    game_status = GrassStatus.ROLLING
    next_turn(channel)