def give_points(self, bot, source, message, **rest): if message is None or len(message) == 0: # The user did not supply any arguments return False msg_split = message.split(" ") if len(msg_split) < 2: # The user did not supply enough arguments bot.whisper(source, f"Usage: !{self.command_name} USERNAME POINTS") return False input = msg_split[0] try: num_points = utils.parse_points_amount(source, msg_split[1]) except InvalidPointAmount as e: bot.whisper(source, f"{e}. Usage: !{self.command_name} USERNAME POINTS") return False if num_points <= 0: # The user tried to specify a negative amount of points bot.whisper(source, "You cannot give away negative points admiralCute") return True # elif num_points < 250: # bot.whisper(source, "You must give 250 points or more :) Be charitable :)") # return True if not source.can_afford(num_points): # The user tried giving away more points than he owns bot.whisper(source, f"You cannot give away more points than you have. You have {source.points} points.") return False with DBManager.create_session_scope() as db_session: target = User.find_by_user_input(db_session, input) if target is None: # The user tried donating points to someone who doesn't exist in our database bot.whisper(source, "This user does not exist FailFish") return False if target == "admiralbulldog": bot.whisper(source, "But why?") return False if target == source: # The user tried giving points to themselves bot.whisper(source, "You can't give points to yourself Bruh") return True if self.settings["target_requires_sub"] is True and target.subscriber is False: # Settings indicate that the target must be a subscriber, which he isn't bot.whisper(source, "Your target must be a subscriber.") return False source.points -= num_points target.points += num_points bot.whisper(source, f"Successfully gave away {num_points} points to {target}") bot.whisper(target, f"{source} just gave you {num_points} points! You should probably thank them ;-)")
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 command_bet(self, bot, source, message, **rest): if message is None: return False with DBManager.create_session_scope() as db_session: current_game = db_session.query(BetGame).filter( BetGame.is_running).one_or_none() if not current_game: bot.whisper(source, "There is currently no bet") return False if current_game.betting_open is False: bot.whisper( source, "Betting is not currently open. Wait until the next game :\\" ) return False msg_parts = message.split(" ") outcome_input = msg_parts[0].lower() if outcome_input in {"win", "winner", "radiant"}: bet_for = BetGameOutcome.win elif outcome_input in {"lose", "loss", "loser", "loose", "dire"}: bet_for = BetGameOutcome.loss else: bot.whisper(source, "Invalid bet. Usage: !bet win/loss POINTS") return False try: points = utils.parse_points_amount(source, msg_parts[1]) if points > self.settings["max_bet"]: points = self.settings["max_bet"] except InvalidPointAmount as e: bot.whisper(source, f"Invalid bet. Usage: !bet win/loss POINTS. {e}") return False except IndexError: bot.whisper(source, "Invalid bet. Usage: !bet win/loss POINTS") return False if points < 1: bot.whisper( source, "You can't bet less than 1 point you goddamn pleb Bruh") return False if not source.can_afford(points): bot.whisper(source, f"You don't have {points} points to bet") return False user_bet = db_session.query(BetBet).filter_by( game_id=current_game.id, user_id=source.id).one_or_none() if user_bet is not None: bot.whisper( source, "You have already bet on this game. Wait until the next game starts!" ) return False user_bet = BetBet(game_id=current_game.id, user_id=source.id, outcome=bet_for, points=points) db_session.add(user_bet) source.points = source.points - points payload = {"win": 0, "loss": 0, bet_for.name: points} if not self.spectating: bot.websocket_manager.emit("bet_update_data", data=payload) finishString = f"You have bet {points} points on this game resulting in a {'radiant ' if self.spectating else ''}{bet_for.name}" bot.whisper(source, finishString)
def command_bet(self, **options): bot = options["bot"] source = options["source"] message = options["message"] if message is None: return False if not self.betting_open: bot.whisper( source.username, "Betting is not currently open. Wait until the next game :\\") return False msg_parts = message.split(" ") if len(msg_parts) < 2: bot.whisper( source.username, "Invalid bet. You must do !dotabet radiant/dire POINTS (if spectating a game) " "or !dotabet win/loss POINTS (if playing)") return False if source.username in self.bets: bot.whisper( source.username, "You have already bet on this game. Wait until the next game starts!") return False points = 0 try: points = utils.parse_points_amount(source, msg_parts[1]) if points > 1500: points = 1500 except InvalidPointAmount as e: bot.whisper( source.username, "Invalid bet. You must do !dotabet radiant/dire POINTS (if spectating a game) " "or !dotabet win/loss POINTS (if playing) {}".format(e)) return False if points < 1: bot.whisper(source.username, "You can't bet less than 1 point you goddamn pleb Bruh") return False if not source.can_afford(points): bot.whisper( source.username, "You don't have {} points to bet".format(points)) return False outcome = msg_parts[0].lower() bet_for_win = False if "w" in outcome or "radi" in outcome: bet_for_win = True elif "l" in outcome or "dire" in outcome: bet_for_win = False else: bot.whisper( source.username, "Invalid bet. You must do !dotabet radiant/dire POINTS (if spectating a game) " "or !dotabet win/loss POINTS (if playing)") return False if bet_for_win: self.winBetters += 1 self.winPoints += points else: self.lossBetters += 1 self.lossPoints += points source.points -= points self.bets[source.username] = (bet_for_win, points) payload = { "win_betters": self.winBetters, "loss_betters": self.lossBetters, "win_points": self.winPoints, "loss_points": self.lossPoints } if not self.spectating: bot.websocket_manager.emit("dotabet_update_data", data=payload) finishString = "You have bet {} points on this game resulting in a ".format( points) if self.spectating: finishString = finishString + "radiant " bot.whisper( source.username, "{}{}".format( finishString, "win" if bet_for_win else "loss"))
def initiate_duel(self, bot, source, message, **rest): """ Initiate a duel with a user. You can also bet points on the winner. By default, the maximum amount of points you can spend is 420. How to use: !duel USERNAME POINTS_TO_BET """ if message is None: return False msg_split = message.split() input = msg_split[0] with DBManager.create_session_scope() as db_session: user = User.find_by_user_input(db_session, input) if user is None: # No user was found with this username return False duel_price = 1 if len(msg_split) > 1: try: duel_price = utils.parse_points_amount( source, msg_split[1]) if duel_price < 1: # bot.whisper(source, f"Really? {duel_price} points?") # bot.whisper( # user, # f"{source} tried to duel you for {duel_price} points. What a cheapskate EleGiggle", # ) return False except InvalidPointAmount as e: bot.whisper(source, f"{e}. Usage: !duel USERNAME POINTS") return False if source.id in self.duel_requests: currently_duelling = User.find_by_id( db_session, self.duel_requests[source.id]) if currently_duelling is None: del self.duel_requests[source.id] return False bot.whisper( source, f"You already have a duel request active with {currently_duelling}. Type !cancelduel to cancel your duel request.", ) return False if user == source: # You cannot duel yourself return False if user.last_active is None or ( utils.now() - user.last_active) > timedelta(minutes=5): bot.whisper( source, "This user has not been active in chat within the last 5 minutes. Get them to type in chat before sending another challenge", ) return False if user.login in self.blUsers: return True if not user.can_afford(duel_price) or not source.can_afford( duel_price): bot.whisper( source, f"You or your target do not have more than {duel_price} points, therefore you cannot duel for that amount.", ) return False if user.id in self.duel_targets: challenged_by = User.find_by_id(db_session, self.duel_requests[user.id]) bot.whisper( source, f"This person is already being challenged by {challenged_by}. Ask them to answer the offer by typing !deny or !accept", ) return False self.duel_targets[user.id] = source.id self.duel_requests[source.id] = user.id self.duel_request_price[source.id] = duel_price self.duel_begin_time[source.id] = utils.now() bot.whisper( user, f"You have been challenged to a duel by {source} for {duel_price} points. You can either !accept or !deny this challenge.", ) bot.whisper(source, f"You have challenged {user} for {duel_price} points")
def give_points(self, **options): bot = options["bot"] source = options["source"] message = options["message"] if message is None or len(message) == 0: # The user did not supply any arguments return False msg_split = message.split(" ") if len(msg_split) < 2: # The user did not supply enough arguments bot.whisper( source.username, "Usage: !{command_name} USERNAME POINTS".format( command_name=self.command_name)) return False username = msg_split[0] if len(username) < 2: # The username specified was too short. ;-) return False try: num_points = utils.parse_points_amount(source, msg_split[1]) except InvalidPointAmount as e: bot.whisper( source.username, "{error}. Usage: !{command_name} USERNAME POINTS".format( error=e, command_name=self.command_name), ) return False if num_points <= 0: # The user tried to specify a negative amount of points bot.whisper(source.username, "You cannot give away negative points admiralCute") return True elif num_points < 250: bot.whisper( source.username, "You must give 250 points or more :) Be charitable :)") return True if not source.can_afford(num_points): # The user tried giving away more points than he owns bot.whisper( source.username, "You cannot give away more points than you have. You have {} points." .format(source.points), ) return False with bot.users.find_context(username) as target: if target is None: # The user tried donating points to someone who doesn't exist in our database bot.whisper(source.username, "This user does not exist FailFish") return False if target.username == "admiralbulldog": bot.whisper(source.username, "But why?") return False if target == source: # The user tried giving points to themselves bot.whisper(source.username, "You can't give points to yourself OMGScoots") return True if self.settings[ "target_requires_sub"] is True and target.subscriber is False: # Settings indicate that the target must be a subscriber, which he isn't bot.whisper(source.username, "Your target must be a subscriber.") return False source.points -= num_points target.points += num_points bot.whisper( source.username, "Successfully gave away {num_points} points to {target.username_raw}" .format(num_points=num_points, target=target), ) bot.whisper( target.username, "{source.username_raw} just gave you {num_points} points! You should probably thank them ;-)" .format(num_points=num_points, source=source), )