Esempio n. 1
0
    def test_prepare_message(self, update):
        update.set_message("Текст с БОЛЬШИМИ буквами и Ё")
        expected_text = "текст с большими буквами и е"

        edited_text = prepare_message(update)

        assert edited_text == expected_text
Esempio n. 2
0
async def answer_parser(config, bot, update):
    in_text = prepare_message(update)

    with connector(config.engine()) as ses:
        out_text = ses.query(Answers.answer).filter(
            literal(in_text).contains(Answers.match))
    for message in ["".join(i) for i in out_text]:
        bot.send_message(chat_id=update.message.chat_id, text=message)
        log_print("Answer", update.message.from_user.username)
Esempio n. 3
0
async def ping_parser(config, bot, update):
    in_text = prepare_message(update)

    with connector(config.engine()) as ses:
        in_text_list = in_text.split()
        username = update.message.from_user.username
        chat_id = update.message.chat_id

        try:
            ses.query(PingPhrases.phrase).filter(
                PingPhrases.phrase.in_(in_text_list)).limit(1).one()
            usernames = ses.query(Pingers.username).filter(
                and_(Pingers.match.in_(in_text_list),
                     or_(Pingers.chat_id == chat_id,
                         Pingers.chat_id == "all"))).distinct().all()
            usernames = [i for i in usernames for i in i]
            if 'EVERYONE GET IN HERE' in usernames:
                try:
                    ses.query(PingExcludes.match).filter(
                        PingExcludes.match.in_(in_text_list)).one()
                    usernames = ses.query(Pingers.username).filter(
                        and_(
                            Pingers.username.notin_(usernames),
                            Pingers.username != username,
                            or_(Pingers.chat_id == chat_id,
                                Pingers.chat_id == "all"))).distinct().all()
                    usernames = [i for i in usernames for i in i]

                except NoResultFound:
                    if ['EVERYONE GET IN HERE'] == usernames:
                        usernames = ses.query(Pingers.username).filter(
                            and_(
                                Pingers.username != 'EVERYONE GET IN HERE',
                                Pingers.username != username,
                                or_(Pingers.chat_id == chat_id, Pingers.chat_id
                                    == "all"))).distinct().all()
                        usernames = [i for i in usernames for i in i]

            if usernames:
                send_typing_action(bot, update)
                if 'EVERYONE GET IN HERE' in usernames:
                    usernames.remove('EVERYONE GET IN HERE')
                out_text = " ".join(["@" + i for i in usernames])
                bot.send_message(chat_id=update.message.chat_id,
                                 reply_to_message_id=update.message.message_id,
                                 text=out_text)
                log_print("Ping",
                          chat_id=update.message.chat_id,
                          username=username,
                          pinged=out_text.split(),
                          level="INFO",
                          command="ping")
        except NoResultFound:
            pass
Esempio n. 4
0
async def answer_parser(config, bot, update):
    in_text = prepare_message(update)

    with connector(config.engine()) as ses:
        out_text = ses.query(Answers.answer).filter(
            literal(in_text).contains(Answers.match))
    for message in ["".join(i) for i in out_text]:
        send_typing_action(bot, update)
        bot.send_message(chat_id=update.message.chat_id, text=message)
        log_print("Answer",
                  chat_id=update.message.chat_id,
                  username=username,
                  level="INFO",
                  command="answer")
Esempio n. 5
0
async def weather_parser(config, bot, update):
    in_text = prepare_message(update)

    with connector(config.engine()) as ses:
        try:
            phrase = "".join(
                ses.query(WeatherPhrases.match).filter(
                    literal(in_text.lower()).contains(
                        WeatherPhrases.match)).one())
            weather(
                config, bot, update,
                in_text.lower()[in_text.lower().find(phrase) +
                                len(phrase):].split())
            return
        except NoResultFound:
            pass