def __load_chat_blacklists():
    global CHAT_BLACKLISTS
    try:
        chats = SESSION.query(BlackListFilters.chat_id).distinct().all()
        for (chat_id, ) in chats:  # remove tuple by ( ,)
            CHAT_BLACKLISTS[chat_id] = []

        all_filters = SESSION.query(BlackListFilters).all()
        for x in all_filters:
            CHAT_BLACKLISTS[x.chat_id] += [x.trigger]

        CHAT_BLACKLISTS = {x: set(y) for x, y in CHAT_BLACKLISTS.items()}

    finally:
        SESSION.close()
Example #2
0
def is_nightmode_indb(chat_id: str):
    try:
        s__ = SESSION.query(Nightmode).get(str(chat_id))
        if s__:
            return str(s__.chat_id)
    finally:
        SESSION.close()
def is_data_indb(chat_id: int):
    try:
        s__ = SESSION.query(Cst).get(str(chat_id))
        if s__:
            return s__.sticker_token
    finally:
        SESSION.close()
def is_tracker_in_db(amazon_url: str):
    try:
        s__ = SESSION.query(Anp).get(str(amazon_url))
        if s__:
            return str(s__.budget)
    finally:
        SESSION.close()
Example #5
0
def is_footer(chat_id: int):
    try:
        s__ = SESSION.query(Pa).get(str(chat_id))
        if s__:
            return s__.append_foot
    finally:
        SESSION.close()
Example #6
0
def is_nsfwatch_indb(chat_id: str):
    try:
        s__ = SESSION.query(Nsfwatch).get(str(chat_id))
        if s__:
            return str(s__.chat_id)
    finally:
        SESSION.close()
Example #7
0
def get_all_snips():
    try:
        return SESSION.query(Snips).all()
    except:
        return None
    finally:
        SESSION.close()
Example #8
0
def is_data_indbs(chat_id: int):
    try:
        s__ = SESSION.query(Pa).get(str(chat_id))
        if s__:
            return s__.textto_append
    finally:
        SESSION.close()
def get_filter(chat_id, keyword):
    try:
        return SESSION.query(Filters).get((str(chat_id), keyword))
    except:
        return None
    finally:
        SESSION.close()
Example #10
0
def is_gmuted(sender_id):
    try:
        return SESSION.query(GMute).all()
    except:
        return None
    finally:
        SESSION.close()
def add_filter(
    chat_id,
    keyword,
    reply,
    snip_type,
    media_id,
    media_access_hash,
    media_file_reference,
):
    adder = SESSION.query(Filters).get((str(chat_id), keyword))
    if adder:
        adder.reply = reply
        adder.snip_type = snip_type
        adder.media_id = media_id
        adder.media_access_hash = media_access_hash
        adder.media_file_reference = media_file_reference
    else:
        adder = Filters(
            chat_id,
            keyword,
            reply,
            snip_type,
            media_id,
            media_access_hash,
            media_file_reference,
        )
    SESSION.add(adder)
    SESSION.commit()
def is_fed_indb(feds):
    try:
        return SESSION.query(Fed).filter(Fed.feds == feds).one()
    except:
        return None
    finally:
        SESSION.close()
def is_globelmuted(sender_id):
    try:
        return SESSION.query(GLOBELMute).all()
    except BaseException:
        return None
    finally:
        SESSION.close()
def is_gbanned(user_id: int):
    try:
        s__ = SESSION.query(Gban).get(str(user_id))
        if s__:
            return str(s__.reason)
    finally:
        SESSION.close()
Example #15
0
def get_snips(keyword):
    try:
        return SESSION.query(Snips).get(keyword)
    except:
        return None
    finally:
        SESSION.close()
Example #16
0
def is_ping_indb(url):
    try:
        return SESSION.query(Serverpinger).filter(
            Serverpinger.url == url).one()
    except:
        return None
    finally:
        SESSION.close()
Example #17
0
def get_current_welcome_settings(chat_id):
    try:
        return SESSION.query(Welcome).filter(
            Welcome.chat_id == str(chat_id)).one()
    except:
        return None
    finally:
        SESSION.close()
def add_note(chat_id, keyword, reply):
    adder = SESSION.query(Notes).get((str(chat_id), keyword))
    if adder:
        adder.reply = reply
    else:
        adder = Notes(str(chat_id), keyword, reply)
    SESSION.add(adder)
    SESSION.commit()
def get_all_filters(chat_id):
    try:
        return SESSION.query(Filters).filter(
            Filters.chat_id == str(chat_id)).all()
    except:
        return None
    finally:
        SESSION.close()
def is_approved(chat_id):
    try:
        return SESSION.query(PMPermit).filter(
            PMPermit.chat_id == str(chat_id)).one()
    except:
        return None
    finally:
        SESSION.close()
Example #21
0
def init_locks(chat_id, reset=False):
    curr_restr = SESSION.query(Locks).get(str(chat_id))
    if reset:
        SESSION.delete(curr_restr)
        SESSION.flush()
    restr = Locks(str(chat_id))
    SESSION.add(restr)
    SESSION.commit()
    return restr
Example #22
0
def __load_chat_warn_filters():
    global WARN_FILTERS
    try:
        chats = SESSION.query(WarnFilters.chat_id).distinct().all()
        for (chat_id, ) in chats:  # remove tuple by ( ,)
            WARN_FILTERS[chat_id] = []

        all_filters = SESSION.query(WarnFilters).all()
        for x in all_filters:
            WARN_FILTERS[x.chat_id] += [x.keyword]

        WARN_FILTERS = {
            x: sorted(set(y), key=lambda i: (-len(i), i))
            for x, y in WARN_FILTERS.items()
        }

    finally:
        SESSION.close()
Example #23
0
def get_warns(user_id, chat_id):
    try:
        user = SESSION.query(Warns).get((user_id, str(chat_id)))
        if not user:
            return None
        reasons = user.reasons
        num = user.num_warns
        return num, reasons
    finally:
        SESSION.close()
Example #24
0
def set_warn_limit(chat_id, warn_limit):
    with WARN_SETTINGS_LOCK:
        curr_setting = SESSION.query(WarnSettings).get(str(chat_id))
        if not curr_setting:
            curr_setting = WarnSettings(chat_id, warn_limit=warn_limit)

        curr_setting.warn_limit = warn_limit

        SESSION.add(curr_setting)
        SESSION.commit()
Example #25
0
def set_warn_strength(chat_id, soft_warn):
    with WARN_SETTINGS_LOCK:
        curr_setting = SESSION.query(WarnSettings).get(str(chat_id))
        if not curr_setting:
            curr_setting = WarnSettings(chat_id, soft_warn=soft_warn)

        curr_setting.soft_warn = soft_warn

        SESSION.add(curr_setting)
        SESSION.commit()
Example #26
0
def get_warn_setting(chat_id):
    try:
        setting = SESSION.query(WarnSettings).get(str(chat_id))
        if setting:
            return setting.warn_limit, setting.soft_warn
        else:
            return 3, False

    finally:
        SESSION.close()
Example #27
0
def reset_warns(user_id, chat_id):
    with WARN_INSERTION_LOCK:
        warned_user = SESSION.query(Warns).get((user_id, str(chat_id)))
        if warned_user:
            warned_user.num_warns = 0
            warned_user.reasons = []

            SESSION.add(warned_user)
            SESSION.commit()
        SESSION.close()
Example #28
0
def remove_warn_filter(chat_id, keyword):
    with WARN_FILTER_INSERTION_LOCK:
        warn_filt = SESSION.query(WarnFilters).get((str(chat_id), keyword))
        if warn_filt:
            if keyword in WARN_FILTERS.get(str(chat_id), []):  # sanity check
                WARN_FILTERS.get(str(chat_id), []).remove(keyword)

            SESSION.delete(warn_filt)
            SESSION.commit()
            return True
        SESSION.close()
        return False
Example #29
0
def add_snip(keyword, reply, snip_type, media_id, media_access_hash,
             media_file_reference):
    adder = SESSION.query(Snips).get(keyword)
    if adder:
        adder.reply = reply
        adder.snip_type = snip_type
        adder.media_id = media_id
        adder.media_access_hash = media_access_hash
        adder.media_file_reference = media_file_reference
    else:
        adder = Snips(keyword, reply, snip_type, media_id, media_access_hash,
                      media_file_reference)
    SESSION.add(adder)
    SESSION.commit()
Example #30
0
def remove_warn(user_id, chat_id):
    with WARN_INSERTION_LOCK:
        removed = False
        warned_user = SESSION.query(Warns).get((user_id, str(chat_id)))

        if warned_user and warned_user.num_warns > 0:
            warned_user.num_warns -= 1

            SESSION.add(warned_user)
            SESSION.commit()
            removed = True

        SESSION.close()
        return removed