コード例 #1
0
    def selftimeout(self, bot: Bot, source: User, event: Any, **rest) -> bool:
        if self.settings["subscribers_only"] and not source.subscriber:
            return True

        if self.settings["vip_only"] and not source.vip:
            return True

        if source.moderator is True:
            return True

        random_value = random.randint(self.settings["low_value"],
                                      self.settings["high_value"])
        standard_response = f"You got a {random_value}"

        if random_value == 0 and self.settings["zero_response"] != "":
            bot.send_message_to_user(
                source,
                f"{standard_response}. {self.settings['zero_response']}",
                event,
                method="reply")
        else:
            timeout_length = self.seconds_conversion(random_value)

            # Check if timeout value is over Twitch's maximum
            timeout_length = min(timeout_length, 1209600)

            bot.timeout(source,
                        timeout_length,
                        f"{standard_response}!",
                        once=True)

        return True
コード例 #2
0
 def cmd_link(self, bot: Bot, source: User, message: str, event: Any, **rest: Any) -> None:
     bot.send_message_to_user(
         source,
         self.settings["phrase_room_link"].format(room_name=self.settings["room_name"]),
         event,
         method="reply",
     )
コード例 #3
0
    def bingo_start(self, bot: Bot, source, message: str, event, args) -> bool:
        if self.bingo_running:
            bot.send_message_to_user(source,
                                     "A bingo is already running FailFish",
                                     event,
                                     method="reply")
            return False

        emote_instances = args["emote_instances"]
        known_sets = self.make_known_sets_dict(bot)

        selected_sets: Set[Tuple[str, Tuple[Emote, ...], bool]] = set()
        points_reward: Optional[int] = None
        unparsed_options = []

        words_in_message = [s for s in message.split(" ") if len(s) > 0]
        if len(words_in_message) <= 0:
            bot.send_message_to_user(
                source,
                "You must at least give me some emote sets or emotes to choose from! FailFish",
                event,
                method="reply",
            )
            return False

        emote_index_offset = len("!bingo start ")

        # we can't iterate using words_in_message here because that would mess up the accompanying index
        for index, word in iterate_split_with_index(message.split(" ")):
            if len(word) <= 0:
                continue

            # Is the current word an emote?
            potential_emote_instance = next(
                (e for e in emote_instances
                 if e.start == index + emote_index_offset), None)
            if potential_emote_instance is not None:
                # single-emote set with the name of the emote
                new_set = (potential_emote_instance.emote.code,
                           (potential_emote_instance.emote, ), True)
                selected_sets.add(new_set)
                continue

            parsed_int: Optional[int] = None

            # Is the current word a number?
            try:
                parsed_int = int(word)
            except ValueError:
                pass

            if parsed_int is not None:
                # if points_reward is already set this is the second number in the message
                if points_reward is not None:
                    unparsed_options.append(word)
                    continue
                points_reward = parsed_int
                continue

            # Is the current word a known set?
            cleaned_key = remove_emotes_suffix(word).lower()
            if cleaned_key in known_sets:
                selected_sets.add(known_sets[cleaned_key])
                continue

            unparsed_options.append(word)

        if len(unparsed_options) > 0:
            bot.say(
                "{}, I don't know what to do with the argument{} {} BabyRage".
                format(
                    source,
                    "" if len(unparsed_options) == 1 else "s",  # pluralization
                    join_to_sentence(['"' + s + '"'
                                      for s in unparsed_options]),
                ))
            return False

        default_points = self.settings["default_points"]
        if points_reward is None:
            points_reward = default_points

        max_points = self.settings["max_points"]
        if points_reward > max_points:
            bot.send_message_to_user(
                source,
                f"You can't start a bingo with that many points. FailFish {max_points} are allowed at most.",
                event,
                method="reply",
            )
            return False

        allow_negative_bingo = self.settings["allow_negative_bingo"]
        if points_reward < 0 and not allow_negative_bingo:
            bot.send_message_to_user(
                source,
                "You can't start a bingo with negative points. FailFish",
                event,
                method="reply")
            return False

        min_points = -self.settings["max_negative_points"]
        if points_reward < min_points:
            bot.send_message_to_user(
                source,
                "You can't start a bingo with that many negative points. FailFish {min_points} are allowed at most.",
                event,
                method="reply",
            )
            return False

        if len(selected_sets) <= 0:
            bot.send_message_to_user(
                source,
                "You must at least give me some emotes or emote sets to choose from! FailFish",
                event,
                method="reply",
            )
            return False

        selected_set_names = []
        selected_discrete_emote_codes = []
        selected_emotes: Set[Emote] = set()
        for set_name, set_emotes, is_discrete_emote in selected_sets:
            if is_discrete_emote:
                selected_discrete_emote_codes.append(set_name)
            else:
                selected_set_names.append(set_name)
            selected_emotes.update(set_emotes)

        correct_emote = random.choice(list(selected_emotes))

        user_messages = []
        if len(selected_set_names) > 0:
            user_messages.append(join_to_sentence(selected_set_names))

        if len(selected_discrete_emote_codes) > 0:
            # the space at the end is so the ! from the below message doesn't stop the last emote from showing up in chat
            user_messages.append(
                f"these emotes: {' '.join(selected_discrete_emote_codes)} ")

        bot.me(
            f"A bingo has started! ThunBeast Guess the right emote to win {points_reward} points! B) Only one emote per message! Select from {' and '.join(user_messages)}!"
        )

        log.info(
            f"A Bingo game has begun for {points_reward} points, correct emote is {correct_emote}"
        )
        self.active_game = BingoGame(correct_emote, points_reward)

        return True