Exemplo n.º 1
0
def add_ad(chat_id, user_id=None):
    if enable_ad is False:
        return ""
    lang_chat_code = "en"

    if user_id is None:
        chat_info = sql_worker.get_chat_info(chat_id)
    else:
        chat_info = sql_worker.get_chat_info(user_id)

    if chat_info:
        if chat_info[0][3] == "yes":
            return ""  # Return for premium
        lang_chat_code = chat_info[0][1]
    list_ad = sql_worker.get_tasks(lang_chat_code)
    if not list_ad:
        return ""
    for current_ad in list_ad:
        if int(current_ad[3]) < int(time.time()):
            try:
                sql_worker.rem_task(current_ad[0], current_ad[4])
            except sql_worker.SQLWriteError:
                pass
    percent = random.randint(1, 100)
    if percent > ad_percent:
        return ""
    random_index = random.randint(0, len(list_ad) - 1)
    if list_ad[random_index][2] != lang_chat_code:
        return ""
    return "\n---------------\n" + list_ad[random_index][1]
Exemplo n.º 2
0
def callback_inline_lang_list(call_msg):

    status = utils.bot.get_chat_member(call_msg.message.chat.id,
                                       call_msg.from_user.id).status
    if status != "administrator" and status != "owner" and status != "creator":
        utils.bot.answer_callback_query(callback_query_id=call_msg.id,
                                        text=locales.get_text(
                                            call_msg.message.chat.id,
                                            "adminsOnly"),
                                        show_alert=True)
        return
    chat_info = sql_worker.get_chat_info(call_msg.message.chat.id)
    if not chat_info:
        try:
            sql_worker.write_chat_info(call_msg.message.chat.id, "lang", "en")
        except sql_worker.SQLWriteError:
            return
        chat_info = sql_worker.get_chat_info(call_msg.message.chat.id)
    if chat_info[0][2] == "yes":
        set_lock = "no"
    else:
        set_lock = "yes"
    buttons = types.InlineKeyboardMarkup()
    buttons.add(
        types.InlineKeyboardButton(text=locales.get_text(
            call_msg.message.chat.id, "backBtn"),
                                   callback_data="back"))
    try:
        sql_worker.write_chat_info(call_msg.message.chat.id, "is_locked",
                                   set_lock)
    except sql_worker.SQLWriteError:
        utils.bot.edit_message_text(locales.get_text(call_msg.message.chat.id,
                                                     "configFailed"),
                                    call_msg.message.chat.id,
                                    call_msg.message.id,
                                    reply_markup=buttons,
                                    parse_mode="html")
        return
    if set_lock == "yes":
        utils.bot.edit_message_text(locales.get_text(call_msg.message.chat.id,
                                                     "canSetAdmins"),
                                    call_msg.message.chat.id,
                                    call_msg.message.id,
                                    reply_markup=buttons,
                                    parse_mode="html")
    else:
        utils.bot.edit_message_text(locales.get_text(call_msg.message.chat.id,
                                                     "canSetAll"),
                                    call_msg.message.chat.id,
                                    call_msg.message.id,
                                    reply_markup=buttons,
                                    parse_mode="html")
Exemplo n.º 3
0
def status_premium(message):
    if not enable_ad:
        utils.bot.reply_to(message,
                           locales.get_text(message.chat.id, "adDisabled"))
        return

    chat_user_id = message.chat.id
    is_user = False

    if message.reply_to_message is not None:
        chat_user_id = message.reply_to_message.from_user.id
        is_user = True

    sql_worker.actualize_chat_premium(chat_user_id)
    current_chat = sql_worker.get_chat_info(chat_user_id)
    if not current_chat:
        try:
            sql_worker.write_chat_info(chat_user_id, "premium", "no")
        except sql_worker.SQLWriteError:
            utils.bot.reply_to(message,
                               locales.get_text(chat_user_id, "premiumError"))
            return
        current_chat = sql_worker.get_chat_info(chat_user_id)

    if utils.extract_arg(message.text, 1) == "force":
        # Usage: /premium force [time_in_hours (optional argument)]
        force_premium(message, current_chat, is_user)
        return

    added_text = locales.get_text(message.chat.id, "premiumChat")
    if is_user or message.chat.type == "private":
        added_text = locales.get_text(message.chat.id, "premiumUser")

    if current_chat[0][3] == "no":
        premium_status = locales.get_text(message.chat.id,
                                          "premiumStatusDisabled")
    else:
        if current_chat[0][4] != 0:
            premium_status = locales.get_text(message.chat.id, "premiumStatusTime") + " " + \
                             datetime.datetime.fromtimestamp(current_chat[0][4]).strftime("%d.%m.%Y %H:%M:%S")
        else:
            premium_status = locales.get_text(message.chat.id,
                                              "premiumStatusInfinity")

    utils.bot.reply_to(
        message,
        locales.get_text(message.chat.id, "premiumStatus").format(added_text) +
        " <b>" + premium_status + "</b>",
        parse_mode="html")
Exemplo n.º 4
0
def auto_status(message):
    disabled = False
    chat_info = sql_worker.get_chat_info(message.chat.id)
    if not chat_info:
        disabled = True
    if chat_info:
        if chat_info[0][6] == "disable" or chat_info[0][
                6] == "" or chat_info[0][6] is None:
            disabled = True
    if disabled:
        utils.bot.reply_to(
            message,
            locales.get_text(message.chat.id, "autoTransStatus") +
            locales.get_text(message.chat.id, "premiumStatusDisabled"))
        return

    lang = interlayer.lang_list.get(chat_info[0][6])
    try:
        if locales.get_chat_lang(message.chat.id) != "en":
            translated_lang = lang + " (" + interlayer.get_translate(
                lang, chat_info[0][1]) + ")"
        else:
            translated_lang = ""
    except (interlayer.BadTrgLangException, interlayer.UnkTransException):
        utils.bot.reply_to(message,
                           locales.get_text(message.chat.id, "langDetectErr"))
        return

    utils.bot.reply_to(
        message,
        locales.get_text(message.chat.id, "autoTransStatus") +
        locales.get_text(message.chat.id, "autoTransLang") + translated_lang)
Exemplo n.º 5
0
def btn_checker(message, who_id):

    chat_info = sql_worker.get_chat_info(message.chat.id)
    if chat_info:
        if chat_info[0][2] == "yes":
            status = utils.bot.get_chat_member(message.chat.id, who_id).status
            if status != "administrator" and status != "owner" and status != "creator":
                return True
    return False
Exemplo n.º 6
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.º 7
0
def send_welcome(message):

    if botname_checker(message):
        logger.write_log(message, logger.BLOB_TEXT)
        chat_info = sql_worker.get_chat_info(message.chat.id)
        if not chat_info:
            chat_settings_lang(message, "start")
            return
        utils.bot.reply_to(message,
                           locales.get_text(message.chat.id, "startMSG"))
Exemplo n.º 8
0
def get_text(chat_id, string_name):
    chat_info = sql_worker.get_chat_info(chat_id)
    if not chat_info:
        chat_lang = "en"
    else:
        chat_lang = chat_info[0][1]
    try:
        if locale_data.get(chat_lang).get(string_name) is not None:
            return locale_data.get(chat_lang).get(string_name)
        else:
            raise AttributeError("Key isn't found!")
    except AttributeError as e:
        logging.error("lang parsing failed! Lang code - " + chat_lang)
        logging.error(str(e) + "\n" + traceback.format_exc())
        return "Lang parsing failed! Please check bot logs."
Exemplo n.º 9
0
def get_text_inline(message, string_name):
    chat_info = sql_worker.get_chat_info(message.from_user.id)
    if not chat_info:
        lang_code = "en"
    else:
        lang_code = chat_info[0][1]
    try:
        if locale_data.get(lang_code).get(string_name) is not None:
            return locale_data.get(lang_code).get(string_name)
        else:
            raise AttributeError("Key isn't found!")
    except AttributeError as e:
        logging.error("lang parsing failed! (inline). Lang code - " +
                      lang_code)
        logging.error(str(e) + "\n" + traceback.format_exc())
        return "LOCALE_ERR"
Exemplo n.º 10
0
def get_chat_lang(chat_id):
    chat_info = sql_worker.get_chat_info(chat_id)
    if not chat_info:
        return "en"
    else:
        return chat_info[0][1]