Esempio n. 1
0
def echo_winkstats(message):
    chats = dbase["chats"]
    chat = message.chat
    participants = [(i, participant["personal_id"], participant["wink_count"])
                    for i, participant in enumerate(
                        chats.find({
                            "chat_id": chat.id
                        }).sort("wink_count", DESCENDING))]

    if not participants:
        sending_message, parse_mode = get_standard_answer(
            "no_one_is_registered")
        bot.send_message(chat.id, sending_message, parse_mode=parse_mode)
        return

    stats_messages = dbase["statsMessages"]
    stats_message = get_random_file(stats_messages, {"game": "wink"})

    stats_list = "\n".join([
        stats_message["list_format"].format(
            i + 1,
            username_with_emoji(
                bot.get_chat_member(chat.id, personal_id).user, chat), score,
            declination_count(score, "раз", "раза", "раз"))
        for i, personal_id, score in participants
    ])

    leaders = [
        username_with_emoji(
            bot.get_chat_member(chat.id, personal_id).user, chat)
        for i, personal_id, score in participants
        if score == participants[0][2]
    ]

    if participants[0][2] == 0:
        conclusion = stats_message["draft"]
    elif len(leaders) == 1:
        conclusion = stats_message["congratulation_one"].format(
            ", ".join(leaders))
    else:
        conclusion = stats_message["congratulation_many"].format(
            ", ".join(leaders))

    bot.send_message(chat.id,
                     stats_message["tab"].join(
                         (stats_message["message"], stats_list, conclusion)),
                     parse_mode=stats_message["parse_mode"])
Esempio n. 2
0
def echo_puastats(message):
    chats = dbase["chats"]
    chat = message.chat
    participants = [(i, participant["personal_id"], participant["pua_count"])
                    for i, participant in enumerate(
                        chats.find({
                            "chat_id": chat.id
                        }).sort("pua_count", DESCENDING))]

    if not participants:
        sending_message, parse_mode = get_standard_answer(
            "no_one_is_registered")
        bot.send_message(chat.id, sending_message, parse_mode=parse_mode)
        return

    stats_messages = dbase["statsMessages"]
    stats_message = get_random_file(stats_messages, {"game": "pua"})

    stats_list = "\n".join([
        stats_message["list_format"].format(
            i + 1,
            username_with_emoji(
                bot.get_chat_member(chat.id, personal_id).user, chat), score)
        for i, personal_id, score in participants
    ])

    if len([
            1 for i, personal_id, score in participants
            if score == participants[0][2]
    ]) > 1:
        conclusion = stats_message["draft"]
    else:
        conclusion = stats_message["congratulation"].format(
            username_with_emoji(
                bot.get_chat_member(chat.id, participants[0][1]).user, chat))

    bot.send_message(chat.id,
                     stats_message["tab"].join(
                         (stats_message["message"], stats_list, conclusion)),
                     parse_mode=stats_message["parse_mode"])
Esempio n. 3
0
def get_random_personal_sticker(user):
    personal_stickers = dbase["personalStickers"]
    if personal_stickers.find_one({"personal_id": user.id}) is None:
        return None
    return get_random_file(personal_stickers, {"personal_id": user.id})
Esempio n. 4
0
def echo_wink(message):
    wink_messages = dbase["winkMessages"]
    chats = dbase["chats"]
    chat = message.chat
    sender = message.from_user

    if timings.find_one({
            "chat_id": chat.id,
            "game": "wink",
            "personal_id": sender.id
    }) is None:
        timings.insert_one({
            "game": "wink",
            "chat_id": chat.id,
            "personal_id": sender.id,
            "last_run": None,
            "delta_hours": 0,
            "delta_minutes": 7,
            "label_hours": ["час", "часа", "часов"],
            "label_minutes": ["минуту", "минуты", "минут"],
            "label_seconds": ["секунду", "секунды", "секунд"]
        })

    if wink_messages.find_one({
            "context": "last_wink",
            "chat_id": chat.id
    }) is None:
        wink_messages.insert_one({
            "context": "last_wink",
            "chat_id": chat.id,
            "status": False,
            "personal_id": None,
            "last_wink": None,
            "delta_minutes": 1
        })

    current_date = datetime.datetime.now()
    last_wink = wink_messages.find_one({
        "context": "last_wink",
        "chat_id": chat.id
    })
    if last_wink["status"] and (last_wink["personal_id"] != sender.id):
        delta = datetime.timedelta(minutes=last_wink["delta_minutes"])
        if datetime.datetime(*last_wink["last_wink"]) + delta > current_date:
            wink_message = get_random_file(wink_messages, {"type": "multi"})
            sending_message, parse_mode = wink_message[
                "message"], wink_message["parse_mode"]
            bot.send_message(chat.id,
                             sending_message.format(
                                 username_with_emoji(
                                     bot.get_chat_member(
                                         chat.id,
                                         last_wink["personal_id"]).user, chat),
                                 username_with_emoji(sender, chat)),
                             parse_mode=parse_mode)

            for pers_id in [sender.id, last_wink["personal_id"]]:
                chats.update_one({
                    "chat_id": chat.id,
                    "personal_id": pers_id
                }, {"$inc": {
                    "wink_count": 1
                }})

            wink_messages.update_one(
                {
                    "context": "last_wink",
                    "chat_id": chat.id
                }, {"$set": {
                    "status": False
                }})
            return
        else:
            wink_messages.update_one(
                {
                    "context": "last_wink",
                    "chat_id": chat.id
                }, {"$set": {
                    "status": False
                }})

    timing = timings.find_one({
        "chat_id": chat.id,
        "personal_id": sender.id,
        "game": "wink"
    })

    if timing["last_run"] is None:
        timings.update_one(
            {
                "chat_id": chat.id,
                "personal_id": sender.id,
                "game": "wink"
            }, {"$set": {
                "last_run": date_to_tuple(current_date)
            }})
    else:
        last_run = datetime.datetime(*timing["last_run"])
        delta = datetime.timedelta(hours=timing["delta_hours"],
                                   minutes=timing["delta_minutes"])

        if last_run + delta > current_date:
            sending_message, parse_mode = get_standard_answer(
                "still_early_wink")
            bot.send_message(chat.id,
                             sending_message.format(
                                 date_representation(
                                     last_run + delta - current_date, timing)),
                             parse_mode=parse_mode)
            return
        else:
            timings.update_one(
                {
                    "chat_id": chat.id,
                    "personal_id": sender.id,
                    "game": "wink"
                }, {"$set": {
                    "last_run": date_to_tuple(current_date)
                }})

    wink_message = get_random_file(wink_messages, {"type": "single"})
    sending_message, parse_mode = wink_message["message"], wink_message[
        "parse_mode"]
    wink_messages.update_one({
        "context": "last_wink",
        "chat_id": chat.id
    }, {
        "$set": {
            "status": True,
            "personal_id": sender.id,
            "last_wink": date_to_tuple(current_date)
        }
    })

    bot.send_message(chat.id,
                     sending_message.format(username_with_emoji(sender, chat)),
                     parse_mode=parse_mode)
Esempio n. 5
0
def get_random_intro_sticker():
    intro_stickers = dbase["introStickers"]
    return get_random_file(intro_stickers, {})
Esempio n. 6
0
def echo_pua(message):
    pua_messages = dbase["puaMessages"]
    chats = dbase["chats"]
    chat = message.chat
    sender = message.from_user

    if timings.find_one({
            "chat_id": chat.id,
            "game": "pua",
            "personal_id": sender.id
    }) is None:
        timings.insert_one({
            "game": "pua",
            "chat_id": chat.id,
            "personal_id": sender.id,
            "last_run": None,
            "delta_hours": 0,
            "delta_minutes": 5,
            "label_hours": ["час", "часа", "часов"],
            "label_minutes": ["минуту", "минуты", "минут"],
            "label_seconds": ["секунду", "секунды", "секунд"]
        })

    timing = timings.find_one({
        "chat_id": chat.id,
        "personal_id": sender.id,
        "game": "pua"
    })
    current_date = datetime.datetime.now()

    if timing["last_run"] is None:
        timings.update_one(
            {
                "chat_id": chat.id,
                "personal_id": sender.id,
                "game": "pua"
            }, {"$set": {
                "last_run": date_to_tuple(current_date)
            }})
    else:
        last_run = datetime.datetime(*timing["last_run"])
        delta = datetime.timedelta(hours=timing["delta_hours"],
                                   minutes=timing["delta_minutes"])

        if last_run + delta > current_date:
            sending_message, parse_mode = get_standard_answer(
                "still_early_pua")
            bot.send_message(chat.id,
                             sending_message.format(
                                 date_representation(
                                     last_run + delta - current_date, timing)),
                             parse_mode=parse_mode)
            return
        else:
            timings.update_one(
                {
                    "chat_id": chat.id,
                    "personal_id": sender.id,
                    "game": "pua"
                }, {"$set": {
                    "last_run": date_to_tuple(current_date)
                }})

    pua_message = get_random_file(pua_messages, {})
    sending_message, parse_mode = pua_message["message"], pua_message[
        "parse_mode"]

    bot.send_message(chat.id,
                     sending_message.format(username_with_emoji(sender, chat)),
                     parse_mode=parse_mode)

    chats.update_one({
        "chat_id": chat.id,
        "personal_id": sender.id
    }, {"$inc": {
        "pua_count": 1
    }})
Esempio n. 7
0
def get_standard_answer(context):
    res = get_random_file(standard_answers, {"context": context})
    return res["message"], res["parse_mode"]
Esempio n. 8
0
def echo_piu(message):
    piu_messages = dbase["piuMessages"]
    chats = dbase["chats"]
    chat = message.chat
    sender = message.from_user

    if timings.find_one({
            "chat_id": chat.id,
            "game": "piu",
            "personal_id": sender.id
    }) is None:
        timings.insert_one({
            "game": "piu",
            "chat_id": chat.id,
            "personal_id": sender.id,
            "last_run": None,
            "delta_hours": 0,
            "delta_minutes": 10,
            "label_hours": ["час", "часа", "часов"],
            "label_minutes": ["минуту", "минуты", "минут"],
            "label_seconds": ["секунду", "секунды", "секунд"]
        })

    timing = timings.find_one({
        "chat_id": chat.id,
        "personal_id": sender.id,
        "game": "piu"
    })
    current_date = datetime.datetime.now()

    if timing["last_run"] is None:
        timings.update_one(
            {
                "chat_id": chat.id,
                "personal_id": sender.id,
                "game": "piu"
            }, {"$set": {
                "last_run": date_to_tuple(current_date)
            }})
    else:
        last_run = datetime.datetime(*timing["last_run"])
        delta = datetime.timedelta(hours=timing["delta_hours"],
                                   minutes=timing["delta_minutes"])

        if last_run + delta > current_date:
            sending_message, parse_mode = get_standard_answer(
                "still_early_piu")
            bot.send_message(chat.id,
                             sending_message.format(
                                 date_representation(
                                     last_run + delta - current_date, timing)),
                             parse_mode=parse_mode)
            return
        else:
            timings.update_one(
                {
                    "chat_id": chat.id,
                    "personal_id": sender.id,
                    "game": "piu"
                }, {"$set": {
                    "last_run": date_to_tuple(current_date)
                }})

    piu_message = get_random_file(piu_messages, {})
    sending_message, parse_mode = piu_message["message"], piu_message[
        "parse_mode"]

    receiver = message.text.split()[1] if len(
        message.text.split()) > 1 else sender.username
    bot.send_message(chat.id,
                     sending_message.format(username_with_emoji(sender, chat),
                                            receiver),
                     parse_mode=parse_mode)

    personal_sticker = get_random_personal_sticker(sender)
    if personal_sticker is not None:
        sleep(piu_message["sleep_time"])
        bot.send_sticker(chat.id,
                         get_random_personal_sticker(sender)["file_id"])

    if receiver != sender.username:
        chats.update_one({
            "chat_id": chat.id,
            "personal_id": sender.id
        }, {"$inc": {
            "piu_count": 1
        }})
Esempio n. 9
0
def echo_pidor(message):
    chats = dbase["chats"]
    cheated = dbase["cheated"]
    chat = message.chat

    cheated_participants = [
        bot.get_chat_member(chat.id, participant["personal_id"])
        for participant in cheated.find({"chat_id": chat.id})
    ]

    participants = [
        bot.get_chat_member(chat.id, participant["personal_id"])
        for participant in chats.find({"chat_id": chat.id})
    ]

    if timings.find_one({"chat_id": chat.id, "game": "pidor"}) is None:
        timings.insert_one({
            "game": "pidor",
            "chat_id": chat.id,
            "last_run": None,
            "delta_hours": 24,
            "delta_minutes": 0,
            "pidor_of_the_day": None,
            "label_hours": ["час", "часа", "часов"],
            "label_minutes": ["минута", "минуты", "минут"],
            "label_seconds": ["секунда", "секунды", "секунд"]
        })

    if len(participants) <= 0:
        sending_message, parse_mode = get_standard_answer("not_enough_players")
        bot.send_message(chat.id, sending_message, parse_mode=parse_mode)
        return

    timing = timings.find_one({"chat_id": chat.id, "game": "pidor"})
    current_date = datetime.datetime.now()

    if timing["last_run"] is None or timing["pidor_of_the_day"] is None:
        timings.update_one({
            "chat_id": chat.id,
            "game": "pidor"
        }, {"$set": {
            "last_run": date_to_tuple(current_date)
        }})
    else:
        last_run = datetime.datetime(*timing["last_run"])
        delta = datetime.timedelta(hours=timing["delta_hours"],
                                   minutes=timing["delta_minutes"])

        if last_run + delta > current_date:
            sending_message, parse_mode = get_standard_answer(
                "still_early_pidor")
            bot.send_message(
                chat.id,
                sending_message.format(
                    username_with_emoji(
                        bot.get_chat_member(chat.id,
                                            timing["pidor_of_the_day"]).user,
                        chat),
                    date_representation(last_run + delta - current_date,
                                        timing)),
                parse_mode=parse_mode)
            return
        else:
            timings.update_one({
                "chat_id": chat.id,
                "game": "pidor"
            }, {"$set": {
                "last_run": date_to_tuple(current_date)
            }})

    pidor_messages = dbase["pidorMessages"]

    pidor_message = get_random_file(pidor_messages, {})

    for text in pidor_message["intro_messages"]:
        if text == "send_intro_sticker":
            bot.send_sticker(chat.id, get_random_intro_sticker()["file_id"])
        else:
            bot.send_message(chat.id,
                             text,
                             parse_mode=pidor_message["parse_mode"])
        sleep(pidor_message["sleep_time"])

    if not cheated_participants:
        winner = choice(participants)
    else:
        winner = choice(cheated_participants)

    chats.update_one({
        "chat_id": chat.id,
        "personal_id": winner.user.id
    }, {"$inc": {
        "score": 1
    }})
    bot.send_message(chat.id,
                     pidor_message["winner_message"].format(
                         username_with_emoji(winner.user, chat)),
                     parse_mode=pidor_message["parse_mode"])

    timings.update_one({
        "chat_id": chat.id,
        "game": "pidor"
    }, {"$set": {
        "pidor_of_the_day": winner.user.id
    }})

    sleep(pidor_message["sleep_time"])

    personal_sticker = get_random_personal_sticker(winner.user)
    if personal_sticker is not None:
        bot.send_sticker(chat.id,
                         get_random_personal_sticker(winner.user)["file_id"])