def roulette(self, **options): if self.settings['only_roulette_after_sub']: if self.last_sub is None: return False if datetime.datetime.now() - self.last_sub > datetime.timedelta( seconds=self.settings['after_sub_roulette_time']): return False message = options['message'] user = options['source'] bot = options['bot'] if message: bot.whisper( user.username, 'The command is only !roulette and it wagers all your points SmileyFace' ) return False try: bet = pajbot.utils.parse_points_amount(user, 'all') except pajbot.exc.InvalidPointAmount as e: bot.whisper(user.username, str(e)) return False if bet < 500: bot.whisper(user.username, 'You can only roulette for 500+ points FeelsWeirdMan') return False # Calculating the result result = self.rigged_random_result() points = bet if result else -bet user.points += points with DBManager.create_session_scope() as db_session: r = Roulette(user.id, points) db_session.add(r) arguments = { 'bet': bet, 'user': user.username_raw, 'points': user.points_available() } if points > 0: out_message = self.get_phrase('message_won', **arguments) else: out_message = self.get_phrase('message_lost', **arguments) if user.subscriber: bot.me(out_message) else: bot.whisper(user.username, out_message) HandlerManager.trigger('on_roulette_finish', user, points)
def roulette(self, **options): if self.settings["only_roulette_after_sub"]: if self.last_sub is None: return False if utils.now() - self.last_sub > datetime.timedelta( seconds=self.settings["after_sub_roulette_time"]): return False message = options["message"] user = options["source"] bot = options["bot"] if message: bot.whisper( user.username, "The command is only !roulette and it wagers all your points SmileyFace" ) return False try: bet = pajbot.utils.parse_points_amount(user, "all") except pajbot.exc.InvalidPointAmount as e: bot.whisper(user.username, str(e)) return False if bet < 500: bot.whisper(user.username, "You can only roulette for 500+ points FeelsWeirdMan") return False # Calculating the result result = self.rigged_random_result() points = bet if result else -bet user.points += points with DBManager.create_session_scope() as db_session: r = Roulette(user.id, points) db_session.add(r) arguments = { "bet": bet, "user": user.username_raw, "points": user.points_available() } if points > 0: out_message = self.get_phrase("message_won", **arguments) else: out_message = self.get_phrase("message_lost", **arguments) if user.subscriber: bot.me(out_message) else: bot.whisper(user.username, out_message) HandlerManager.trigger("on_roulette_finish", user=user, points=points)
def roulette(self, **options): if self.settings['only_roulette_after_sub']: if self.last_sub is None: return False if datetime.datetime.now() - self.last_sub > datetime.timedelta( seconds=self.settings['after_sub_roulette_time']): return False message = options['message'] user = options['source'] bot = options['bot'] if message is None: bot.whisper( user.username, 'I didn\'t recognize your bet! Usage: !roulette 150 to bet 150 points' ) return False msg_split = message.split(' ') try: bet = pajbot.utils.parse_points_amount(user, msg_split[0]) except pajbot.exc.InvalidPointAmount as e: bot.whisper(user.username, str(e)) return False if not user.can_afford(bet): bot.whisper( user.username, 'You don\'t have enough points to do a roulette for {} points :(' .format(bet)) return False if bet < self.settings['min_roulette_amount']: bot.whisper( user.username, 'You have to bet at least {} point! :('.format( self.settings['min_roulette_amount'])) return False # Calculating the result result = self.rigged_random_result() points = bet if result else -bet user.points += points with DBManager.create_session_scope() as db_session: r = Roulette(user.id, points) db_session.add(r) arguments = { 'bet': bet, 'user': user.username_raw, 'points': user.points_available() } if points > 0: out_message = self.get_phrase('message_won', **arguments) else: out_message = self.get_phrase('message_lost', **arguments) if self.settings['options_output'] == '1. Show results in chat': bot.me(out_message) if self.settings['options_output'] == '2. Show results in whispers': bot.whisper(user.username, out_message) if self.settings[ 'options_output'] == '3. Show results in chat if it\'s over X points else it will be whispered.': if abs(points) >= self.settings['min_show_points']: bot.me(out_message) else: bot.whisper(user.username, out_message) HandlerManager.trigger('on_roulette_finish', user, points)
def roulette(self, bot, source, message, **rest): if self.settings["stream_status"] == "Online" and not bot.is_online: return if self.settings["stream_status"] == "Offline" and bot.is_online: return if self.settings["only_roulette_after_sub"]: if self.last_sub is None: return False if utils.now() - self.last_sub > datetime.timedelta( seconds=self.settings["after_sub_roulette_time"]): return False if message is None: bot.whisper( source, "I didn't recognize your bet! Usage: !" + self.settings["command_name"] + " 150 to bet 150 points", ) return False msg_split = message.split(" ") try: bet = utils.parse_points_amount(source, msg_split[0]) except pajbot.exc.InvalidPointAmount as e: bot.whisper(source, str(e)) return False if not source.can_afford(bet): bot.whisper( source, f"You don't have enough points to do a roulette for {bet} points :(" ) return False if bet < self.settings["min_roulette_amount"]: bot.whisper( source, f"You have to bet at least {self.settings['min_roulette_amount']} point! :(" ) return False # Calculating the result result = self.rigged_random_result() points = bet if result else -bet source.points += points with DBManager.create_session_scope() as db_session: r = Roulette(source.id, points) db_session.add(r) arguments = { "bet": bet, "user": source.name, "points": source.points, "win": points > 0 } if points > 0: out_message = self.get_phrase("message_won", **arguments) else: out_message = self.get_phrase("message_lost", **arguments) if self.settings["options_output"] == "4. Combine output in chat": if bot.is_online: self.add_message(bot, arguments) else: bot.me(out_message) if self.settings["options_output"] == "1. Show results in chat": bot.me(out_message) if self.settings["options_output"] == "2. Show results in whispers": bot.whisper(source, out_message) if (self.settings["options_output"] == "3. Show results in chat if it's over X points else it will be whispered." ): if abs(points) >= self.settings["min_show_points"]: bot.me(out_message) else: bot.whisper(source, out_message) HandlerManager.trigger("on_roulette_finish", user=source, points=points)
def roulette(self, **options): if self.settings['only_roulette_after_sub']: if self.last_sub is None: return False if datetime.datetime.now() - self.last_sub > datetime.timedelta(seconds=self.settings['after_sub_roulette_time']): return False message = options['message'] user = options['source'] bot = options['bot'] if message is None: bot.whisper(user.username, 'I didn\'t recognize your bet! Usage: !roulette 150 to bet 150 points') return False msg_split = message.split(' ') if msg_split[0].lower() in ('all', 'allin'): bet = user.points_available() elif msg_split[0].endswith('%'): try: percentage = int(msg_split[0][:-1]) if percentage < 1 or percentage > 100: bot.whisper(user.username, 'To bet with percentages you need to specify a number between 1 and 100 (like !roulette 50%)') return False bet = math.floor(user.points_available() * (percentage / 100)) except (ValueError, TypeError): bot.whisper(user.username, 'Invalid percentage specified haHAA') return False else: try: message = message.lower() message = message.replace('k', '000') message = message.replace('m', '000000') bet = int(message.split(' ')[0]) except (ValueError, TypeError): bot.whisper(user.username, 'I didn\'t recognize your bet! Usage: !roulette 150 to bet 150 points') return False if not user.can_afford(bet): bot.whisper(user.username, 'You don\'t have enough points to do a roulette for {} points :('.format(bet)) return False if bet < self.settings['min_roulette_amount']: bot.whisper(user.username, 'You have to bet at least {} point! :('.format(self.settings['min_roulette_amount'])) return False # Calculating the result result = self.rigged_random_result() points = bet if result else -bet user.points += points with DBManager.create_session_scope() as db_session: r = Roulette(user.id, points) db_session.add(r) arguments = { 'bet': bet, 'user': user.username_raw, 'points': user.points_available() } if points > 0: out_message = self.get_phrase('message_won', **arguments) else: out_message = self.get_phrase('message_lost', **arguments) if self.settings['options_output'] == '1. Show results in chat': bot.me(out_message) if self.settings['options_output'] == '2. Show results in whispers': bot.whisper(user.username, out_message) if self.settings['options_output'] == '3. Show results in chat if it\'s over X points else it will be whispered.': if abs(points) >= self.settings['min_show_points']: bot.me(out_message) else: bot.whisper(user.username, out_message) HandlerManager.trigger('on_roulette_finish', user, points)