예제 #1
0
    def start(self):
        WAIFUS_COUNT = 100000
        if self.vk_event.args:
            try:
                self.int_args = [0]
                self.parse_int()
                waifu_number = self.vk_event.args[0]
                self.check_number_arg_range(waifu_number, 0, WAIFUS_COUNT)
            except RuntimeError:
                seed = " ".join(self.vk_event.args)
                waifu_number = get_random_int(WAIFUS_COUNT, seed=seed)
        else:
            waifu_number = get_random_int(WAIFUS_COUNT)
        URL = f"https://www.thiswaifudoesnotexist.net/example-{waifu_number}.jpg"
        attachment = self.vk_bot.upload_photos(URL)

        if self.vk_event.args:
            keyboard = get_inline_keyboard(
                self.names[0],
                "Следующая",
                args={"waifu_number": waifu_number + 1})
        else:
            keyboard = get_inline_keyboard(self.names[0])
        return {
            "msg": waifu_number,
            "attachments": attachment,
            "keyboard": keyboard
        }
예제 #2
0
    def start(self):
        if self.vk_event.msg.lower() in ['идиот?', 'ты идиот?']:
            return "Мне потанцевать нельзя?"
        elif self.vk_event.msg.lower() in ['да?']:
            return {'attachments': 'video162408856_456239566'}

        bad_words = get_bad_words()

        if not check_user_group(self.vk_event.sender, Role.ADMIN):
            min_index_bad = len(self.vk_event.msg)
            max_index_bad = -1
            for word in bad_words:
                ind = self.vk_event.msg.lower().find(word)
                if ind != -1:
                    if ind < min_index_bad:
                        min_index_bad = ind
                    if ind > max_index_bad:
                        max_index_bad = ind

            min_index_bad = self.vk_event.msg.rfind(' ', 0, min_index_bad)
            if min_index_bad == -1:
                min_index_bad = self.vk_event.msg.rfind(',', 0, min_index_bad)
                if min_index_bad == -1:
                    min_index_bad = self.vk_event.msg.rfind(
                        '.', 0, min_index_bad)
                    if min_index_bad == -1:
                        min_index_bad = self.vk_event.msg.find('/')
            min_index_bad += 1
            if max_index_bad != -1:
                len_bad = self.vk_event.msg.find(',', max_index_bad)
                if len_bad == -1:
                    len_bad = self.vk_event.msg.find(' ', max_index_bad)
                    if len_bad == -1:
                        len_bad = self.vk_event.msg.find('?', max_index_bad)
                        if len_bad == -1:
                            len_bad = len(self.vk_event.msg)

                rand_int = get_random_int(len(BAD_ANSWERS) - 1)
                messages = [BAD_ANSWERS[rand_int]]
                name = self.vk_event.sender.name
                if self.vk_event.sender.gender == '1':
                    msg_self = "сама"
                else:
                    msg_self = "сам"
                messages.append(
                    f"{name}, может ты {msg_self} {self.vk_event.msg[min_index_bad: len_bad]}?"
                )
                return messages

        random_events = [["Да", "Ага", "Канеш", "Само собой", "Абсолютно"],
                         ["Нет", "Неа", "Ни за что", "Невозможно", "NO"],
                         [
                             "Ну тут даже я хз", "ДА НЕ ЗНАЮ Я", "Хз",
                             "Спроси у другого бота", "Да нет наверное"
                         ]]
        probability_events1 = [47, 47, 6]
        probability_events2 = [40, 15, 15, 15, 15]
        selected_event = random_event(random_events, probability_events1)
        selected_event2 = random_event(selected_event, probability_events2)
        return selected_event2
예제 #3
0
    def menu_play(self):
        with lock:
            if self.vk_event.from_chat:
                rrs = RouletteRate.objects.filter(chat=self.vk_event.chat)
            else:
                rrs = RouletteRate.objects.filter(chat__isnull=True,
                                                  gamer=self.gamer)
            if len(rrs) == 0:
                return "Ставок нет"
            msg1 = "Ставки сделаны. Ставок больше нет\n"
            roulette_ball = get_random_int(MAX_NUMBERS)
            msg2 = f"Крутим колесо. Выпало - {roulette_ball}\n\n"

            winners = []
            for rr in rrs:
                rate_on = json.loads(rr.rate_on)
                if roulette_ball in rate_on['win_numbers']:
                    win_points = rr.rate * rate_on['coefficient']
                    rr.gamer.roulette_points += win_points
                    rr.gamer.save()
                    winners.append({
                        'user': rr.gamer.user,
                        'points': win_points
                    })
            if len(winners) > 0:
                msg3 = "Победители:\n"
                for winner in winners:
                    msg3 += f"{winner['user']} - {winner['points']}\n"
            else:
                msg3 = "Нет победителей"
            msg = msg1 + msg2 + msg3
            rrs.delete()
            return msg
예제 #4
0
    def start(self):
        with lock:
            MIN_GAMERS = int(len(VkUser.objects.filter(chats=self.vk_event.chat)) / 2)
            if MIN_GAMERS < 2:
                MIN_GAMERS = 2

            gamers = RateModel.objects.filter(chat=self.vk_event.chat).order_by("date")
            if self.vk_event.args and self.vk_event.args[0] == 'f':
                self.check_sender(Role.CONFERENCE_ADMIN)
                if len(gamers) <= 1:
                    return "Ну ты ваще обалдел? Хотя бы один игрок-то пусть будет"
            else:
                if len(gamers) < MIN_GAMERS:
                    return f"Минимальное количество игроков - {MIN_GAMERS}"
            messages = ["Ставки сделаны, ставок больше нет."]

            rnd = get_random_int(1, 100)

            winner_rates = ([abs(rnd - gamer.rate) for gamer in gamers])
            min_val = min(winner_rates)
            winners = []
            for i, winner_rate in enumerate(winner_rates):
                if winner_rate == min_val:
                    winners.append(gamers[i])

            winners_str = ""
            for winner in winners:
                gamer = winner.gamer
                winners_str += f"{gamer}\n"

                if winner.rate != rnd:
                    gamer.points += 1
                else:
                    gamer.points += 5
                    winners_str += "\nБонус x5 за точное попадание\n"

                gamer.save()

            if self.vk_event.command == "казино":
                attachments = []
                photo = self.vk_bot.get_attachment_by_id('photo', None, 457241180)
                attachments.append(photo)
                if len(winners) == 1:
                    msg = {'msg': f"Выпавшее число - {rnd}\nПобедитель этого казино:\n{winners_str}",
                           'attachments': attachments}
                else:
                    msg = {'msg': f"Выпавшее число - {rnd}\nПобедители этого казино:\n{winners_str}",
                           'attachments': attachments}
            else:
                if len(winners) == 1:
                    msg = f"Выпавшее число - {rnd}\nПобедитель:\n{winners_str}"
                else:
                    msg = f"Выпавшее число - {rnd}\nПобедители:\n{winners_str}"

            gamers.delete()
            messages.append(msg)
            return messages
예제 #5
0
    def start(self):
        if self.vk_event.args:
            if len(self.vk_event.args) == 2:
                int1 = self.vk_event.args[0]
                int2 = self.vk_event.args[1]
            else:
                int1 = 1
                int2 = self.vk_event.args[0]
        else:
            int1 = 0
            int2 = 1

        if int1 > int2:
            int1, int2 = int2, int1

        rand_int = get_random_int(int1, int2)
        return str(rand_int)