def drink_command(self, username): if not self.drink_enabled: message = 'Donovan is being responsible for some reason. "drink" command is currently disabled D:' return message try: points = point_utils.get_points(username) except KeyError as exception: message = "No points yet. Your time will come." return message drink_cost = 50 if points < drink_cost: message = "You need at least {} points to me drink!".format( drink_cost) return message points -= drink_cost point_utils.set_points(username, points) self.put_command_in_timeout('drink') message = '{} has purchased a drink token!'.format(username) return message
def enter_bonus_zone(self): self.messages.append('{} has entered the BONUS ZONE PogChamp'.format( self.username)) winner = True number_of_wins = 1 number_of_rolls = 1 while (winner == True or number_of_rolls < 4) and number_of_rolls < 11: roll = self.roll_die() win = self.evaluate_roll(roll, self.gamble_percentage) if win == True: self.points += self.wager bonus_message = 'BONUS role was {}. {} won {} BONUS points{}'.format( roll, self.username, self.wager, '!' * number_of_wins) self.messages.append(bonus_message) number_of_wins += 1 else: bonus_message = 'BONUS role was {} for {}.'.format( roll, self.username) self.messages.append(bonus_message) winner = False number_of_rolls += 1 point_utils.set_points(self.username, self.points) self.messages.append( '{} has left the BONUS ZONE. {} now has {} points!'.format( self.username, self.username, self.points))
def end_game(self, amount_won): message = '' points = point_utils.get_points(self.username) points += amount_won point_utils.set_points(self.username, points) winnings = amount_won - ENTRENCE_FEE if winnings > 0: message += '{} won {} points! PogChamp'.format( self.username, winnings) elif winnings == 0: message += '{} broke even. Could have been worse Kappa'.format( self.username) else: message += '{} lost {} points. Better luck next time!'.format( self.username, winnings) message += '{} now has {} points. The game is over. Thanks for playing!'.format( self.username, points) self.game_over = True return message
def gamble_points(self): # if gambling all set amount to the user's points if isinstance(self.wager, str): self.wager = self.points if self.wager < 1: message = "gambling amount must be positive" return [message] # check if the user has enough points if (self.points < 1) or (self.wager > self.points): message = "{} does not have enough points.".format(self.username) return [message] if self.win == True: self.winnings = self.wager self.apply_bonuses() # if there is a losing roll, there is still a chance that a bonus could # hit so set win to True bonus = False if self.winnings > self.wager: self.win = True bonus = True if self.win == True: self.points += self.winnings else: self.points -= self.wager self.generate_gamble_message(bonus) point_utils.set_points(self.username, self.points) if bonus == True: self.enter_bonus_zone() return self.messages
def select_game(self, game_title, username): message = '' if self.check_active_games(): message = 'A game is currently active. Only one game can be active at a time.' return message if game_title == 'deal': game_manager = deal_or_no_deal.DONDManager(username) points = point_utils.get_points(username) if points >= game_manager.cost: points -= game_manager.cost point_utils.set_points(username, points) else: return 'This game cost {} points. Need more points!'.format( game_manager.cost) self.active_games.append(game_manager) message = game_manager.start_game() else: message = 'Invalid game choice.' return message
def do_command(self, e, cmd): c = self.connection username = e.source.split('!')[0] # remove command from timeout dict if the timeout has passed self.update_commands_in_timeout(cmd) # If command is in time out then dont run command and output message instead if cmd in self.commands_in_timeout.keys(): time_remaining = self.get_time_remaining_in_timeout(cmd) message = '{} command has {} mintues remaining before it can be called again.'.format( cmd, time_remaining) c.privmsg(self.channel, message) # Poll the API to get current game. elif cmd == "game": r = self.get_request() c.privmsg(self.channel, r['display_name'] + ' is currently playing ' + r['game']) # Poll the API the get the current status of the stream elif cmd == "title": r = self.get_request() c.privmsg( self.channel, r['display_name'] + ' channel title is currently ' + r['status']) # cheers! elif cmd == 'cheers': message = 'Cheers! HSCheers HSCheers' c.privmsg(self.channel, message) # output a random fact elif cmd == 'fact': message = self.get_fun_fact() c.privmsg(self.channel, message) # Provide basic information to viewers for specific commands elif cmd == "drink": message = self.drink_command(username) c.privmsg(self.channel, message) # allow drink command to be used elif cmd == 'enable_drink': if username == self.streamer_username: self.drink_enabled = True message = 'drink command has been enabled! 50 points to make Donovan drink (!drink)' c.privmsg(self.channel, message) # prevent drink command from being used elif cmd == 'disable_drink': if username == self.streamer_username: self.drink_enabled = False self.commands_in_timeout.pop('drink', None) message = 'Look at this lightweight... smh. Drink command is now disabled.' c.privmsg(self.channel, message) elif cmd == 'refund': if username == self.streamer_username: message = '' try: cmd_args = e.arguments[0].split() refund_username = cmd_args[1] refund_amount = int(cmd_args[2]) points = point_utils.get_points(refund_username) points += refund_amount point_utils.set_points(refund_username, points) message = '{} has been refunded {} points'.format( refund_username, refund_amount) except: message = "Invalid refund command! Example: !refund username 50" c.privmsg(self.channel, message) elif cmd == "schedule": message = "I stream mostly Thursday-Sunday" c.privmsg(self.channel, message) # Show the number of points a user has elif cmd == "points": try: points = point_utils.get_points(username) message = "{} has {} points!".format(username, points) except KeyError as exception: message = "No points yet. Your time will come." c.privmsg(self.channel, message) elif cmd == "gamble": message = '' amount = '' try: amount_str = e.arguments[0].split()[1] if amount_str != 'all': amount = int(amount_str) else: amount = amount_str except: message = "Invalid gamble command! Example: !gamble 5" # if no error message then gamble points bonus = False if not message: casino = point_casino.PointCasino(username, amount) message = casino.gamble_points() if isinstance(message, list): if len(message) > 1: padded_msg = '' for msg in message[:-1]: padded_msg += (msg + ' ---- ') message = padded_msg + message[-1] else: message = message[0] c.privmsg(self.channel, message) print(message) sys.stdout.flush() # command use to active a game. Game logic is handled in game_manager.py elif cmd == 'play': message = '' try: game = e.arguments[0].split()[1] except: message = "Invalid play command! Example: !play deal" if not message: message = self.game_manager.select_game(game, username) c.privmsg(self.channel, message) print(message) sys.stdout.flush() # commnad used to select a case in deal or no deal game. elif cmd == 'case': message = '' if not self.game_manager.check_game_is_active('deal'): message = 'A Deal or no Deal game is not active right now.' if not message: try: case_number = e.arguments[0].split()[1] except: message = "Invalid case command! Example: !case 3" if not message: message = self.game_manager.enter_game_input(cmd, case_number) c.privmsg(self.channel, message) print(message) sys.stdout.flush() elif cmd == 'deal' or cmd == 'nodeal' or cmd == 'swap' or cmd == 'noswap': message = '' if not self.game_manager.check_game_is_active('deal'): message = 'A Deal or no Deal game is not active right now.' if not message: message = self.game_manager.enter_game_input(cmd, False) c.privmsg(self.channel, message) print(message) sys.stdout.flush() # command used to remove any active games elif cmd == 'gameover': if username == self.streamer_username: message = 'All games canceled' self.game_manager.active_games = [] c.privmsg(self.channel, message) # The command was not recognized else: c.privmsg(self.channel, "Did not understand command: " + cmd)