Exemplo n.º 1
0
def query_text_main(inline_query):
    text_result = translate_query(inline_query)
    output = types.InlineQueryResultArticle(
        id='1', title=locales.get_text_inline(inline_query, "inlineTitle"),
        description=text_result,
        input_message_content=types.InputTextMessageContent
        (message_text=text_result + ad_module.add_ad("", inline_query.from_user.id)))
    utils.bot.answer_inline_query(inline_query.id, [output])
Exemplo n.º 2
0
def auto_engine(message):

    chat_info = sql_worker.get_chat_info(message.chat.id)
    if not chat_info:
        return

    if chat_info[0][6] == "disable" or chat_info[0][
            6] == "" or chat_info[0][6] is None:
        return

    if message.text is not None:
        inputtext = message.text
    elif message.caption is not None:
        inputtext = message.caption
    elif hasattr(message, 'poll'):
        inputtext = message.poll.question + "\n\n"
        for option in message.poll.options:
            inputtext += "☑️ " + option.text + "\n"
    else:
        return

    if logger.logger_message is True:
        logging.info("user " + logger.username_parser(message) +
                     " sent an AUTO translated message: " + inputtext)
    elif logger.logger is True:
        logging.info("user " + logger.username_parser(message) +
                     " sent an AUTO translated message")

    try:
        text_lang = interlayer.extract_lang(inputtext)
    except interlayer.UnkTransException:
        utils.bot.reply_to(message,
                           locales.get_text(message.chat.id, "langDetectErr"))
        return

    if text_lang != chat_info[0][6]:
        try:
            utils.bot.reply_to(
                message,
                interlayer.get_translate(inputtext, chat_info[0][6]) +
                ad_module.add_ad(message.chat.id))
        except interlayer.BadTrgLangException:
            utils.bot.reply_to(
                message,
                locales.get_text(message.chat.id, "badTrgLangException"))
        except interlayer.TooManyRequestException:
            utils.bot.reply_to(
                message,
                locales.get_text(message.chat.id, "tooManyRequestException"))
        except interlayer.TooLongMsg:
            utils.bot.reply_to(message,
                               locales.get_text(message.chat.id, "tooLongMsg"))
        except interlayer.UnkTransException:
            utils.bot.reply_to(
                message, locales.get_text(message.chat.id,
                                          "unkTransException"))
Exemplo n.º 3
0
def translate(message):

    if botname_checker(message):
        inputtext = utils.textparser(message)
        if inputtext is None:
            logger.write_log(message, "none")
            return

        logger.write_log(message, inputtext)
        src_lang = None
        message.text = utils.lang_autocorr(message.text)

        if utils.extract_arg(message.text, 2) is not None:
            src_lang = utils.extract_arg(message.text, 1)
            lang = utils.extract_arg(message.text, 2)
        elif utils.extract_arg(message.text, 1) is not None:
            lang = utils.extract_arg(message.text, 1)
        else:
            utils.bot.reply_to(
                message, locales.get_text(message.chat.id, "specifyLang"))
            return

        try:
            utils.bot.reply_to(
                message,
                interlayer.get_translate(inputtext, lang, src_lang=src_lang) +
                add_ad(message.chat.id))
        except interlayer.BadTrgLangException:
            utils.bot.reply_to(
                message,
                locales.get_text(message.chat.id, "badTrgLangException"))
        except interlayer.BadSrcLangException:
            utils.bot.reply_to(
                message,
                locales.get_text(message.chat.id, "badSrcLangException"))
        except interlayer.TooManyRequestException:
            utils.bot.reply_to(
                message,
                locales.get_text(message.chat.id, "tooManyRequestException"))
        except interlayer.TooLongMsg:
            utils.bot.reply_to(message,
                               locales.get_text(message.chat.id, "tooLongMsg"))
        except interlayer.EqualLangsException:
            utils.bot.reply_to(
                message,
                locales.get_text(message.chat.id, "equalLangsException"))
        except interlayer.UnkTransException:
            utils.bot.reply_to(
                message, locales.get_text(message.chat.id,
                                          "unkTransException"))
Exemplo n.º 4
0
def qwerty_main(message):

    text = utils.textparser(message)
    if text is None:
        logger.write_log(message, "none")
        return

    logger.write_log(message, text)
    message.text = utils.lang_autocorr(message.text)
    arg1, arg2 = utils.extract_arg(message.text,
                                   1), utils.extract_arg(message.text, 2)

    if arg2 is None:
        tab1 = utils.layouts.get(interlayer.extract_lang(text))
        tab2 = utils.layouts.get(arg1)
    else:
        tab1 = utils.layouts.get(arg1)
        tab2 = utils.layouts.get(arg2)

    if tab1 is None and arg2 is None:
        try:
            recognized_lang = interlayer.get_translate(
                interlayer.lang_list.get(interlayer.extract_lang(text)), "ru")
        except (interlayer.BadTrgLangException, interlayer.UnkTransException,
                interlayer.TooManyRequestException):
            recognized_lang = "Unknown"
        utils.bot.reply_to(
            message,
            locales.get_text(message.chat.id,
                             "unknownSourceLang").format(recognized_lang))
        return

    if tab1 is None or tab2 is None:
        utils.bot.reply_to(message,
                           locales.get_text(message.chat.id, "unknownLayout"))
        return

    try:
        translated_text = text.translate(str.maketrans(tab1, tab2))
        utils.bot.reply_to(message,
                           translated_text + ad_module.add_ad(message.chat.id))
    except Exception as e:
        logging.error(str(e) + "\n" + traceback.format_exc())
        utils.bot.reply_to(message,
                           locales.get_text(message.chat.id, "layoutError"))
Exemplo n.º 5
0
def distort_main(message):

    if max_inits == 0:
        utils.bot.reply_to(
            message, locales.get_text(message.chat.id, "distortDisabled"))
        return

    inputshiz = utils.textparser(message)
    if inputshiz is None:
        logger.write_log(message, "none")
        return

    logger.write_log(message, inputshiz)

    try:
        counter = int(utils.extract_arg(message.text, 1))
    except (ValueError, TypeError):
        utils.bot.reply_to(message,
                           locales.get_text(message.chat.id, "distortNaN"))
        return

    if counter > max_inits or counter < 1:
        utils.bot.reply_to(
            message,
            locales.get_text(message.chat.id,
                             "distortWrongNumber").format(str(max_inits)))
        return

    randlangs_list = ""

    if utils.extract_arg(message.text, 2) is not None:
        endlang = utils.extract_arg(utils.lang_autocorr(message.text), 2)
        if interlayer.lang_list.get(endlang) is None:
            utils.bot.reply_to(
                message, locales.get_text(message.chat.id, "distortWrongLang"))
            return
    else:
        endlang = interlayer.extract_lang(inputshiz)

    tmpmessage = utils.bot.reply_to(
        message, locales.get_text(message.chat.id, "distortStarted"))
    idc = tmpmessage.chat.id
    idm = tmpmessage.message_id
    lastlang = interlayer.extract_lang(inputshiz)
    randlang = random.choice(list(interlayer.lang_list))

    for i in range(counter):
        while randlang == lastlang:
            randlang = random.choice(list(interlayer.lang_list))

        randlangs_list += randlang + "; "

        try:
            inputshiz = interlayer.get_translate(inputshiz, randlang, True)
        except interlayer.TooManyRequestException:
            utils.bot.edit_message_text(
                locales.get_text(message.chat.id, "tooManyRequestException"),
                idc, idm)
            return
        except interlayer.TooLongMsg:
            utils.bot.edit_message_text(
                locales.get_text(message.chat.id, "tooLongMsg"), idc, idm)
            return
        except interlayer.UnkTransException:
            utils.bot.edit_message_text(
                locales.get_text(message.chat.id, "distortUnkTransException"),
                idc, idm)
            return

        lastlang = randlang

    try:
        inputshiz = interlayer.get_translate(inputshiz, endlang)
    except (interlayer.UnkTransException, interlayer.TooLongMsg,
            interlayer.TooManyRequestException,
            interlayer.BadTrgLangException):
        utils.bot.reply_to(
            message, locales.get_text(message.chat.id, "distortEndingError"))

    utils.bot.edit_message_text(
        inputshiz + locales.get_text(message.chat.id, "usedDistortions") +
        randlangs_list + ad_module.add_ad(idc), idc, idm)