예제 #1
0
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()
예제 #2
0
def _load_chat_blacklist():
    global CHAT_URL_BLACKLISTS
    try:
        chats = SESSION.query(URLBlackListFilters.chat_id).distinct().all()
        for (chat_id, ) in chats:
            CHAT_URL_BLACKLISTS[chat_id] = []

        all_urls = SESSION.query(URLBlackListFilters).all()
        for url in all_urls:
            CHAT_URL_BLACKLISTS[url.chat_id] += [url.domain]
        CHAT_URL_BLACKLISTS = {
            k: set(v)
            for k, v in CHAT_URL_BLACKLISTS.items()
        }
    finally:
        SESSION.close()
예제 #3
0
def get_filter(chat_id, keyword):
    try:
        return SESSION.query(Filters).get((str(chat_id), keyword))
    except BaseException:
        return None
    finally:
        SESSION.close()
예제 #4
0
def rem_chat(chat_id):
    with INSERTION_LOCK:
        autochat = SESSION.query(ChatbotChats).get(str(chat_id))
        if autochat:
            SESSION.delete(autochat)

        SESSION.commit()
예제 #5
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()
예제 #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()
예제 #7
0
def is_chat(chat_id):
    try:
        chat = SESSION.query(ChatbotChats).get(str(chat_id))
        if chat:
            return True
        return False
    finally:
        SESSION.close()
예제 #8
0
def get_all_filters(chat_id):
    try:
        return SESSION.query(Filters).filter(
            Filters.chat_id == str(chat_id)).all()
    except BaseException:
        return None
    finally:
        SESSION.close()
예제 #9
0
def add_channel(chat_id, channel):
    adder = SESSION.query(forceSubscribe).get(chat_id)
    if adder:
        adder.channel = channel
    else:
        adder = forceSubscribe(chat_id, channel)
    SESSION.add(adder)
    SESSION.commit()
예제 #10
0
def fs_settings(chat_id):
    try:
        return (SESSION.query(forceSubscribe).filter(
            forceSubscribe.chat_id == chat_id).one())
    except:
        return None
    finally:
        SESSION.close()
예제 #11
0
def get_ses(chat_id):
    autochat = SESSION.query(ChatbotChats).get(str(chat_id))
    sesh = ""
    exp = ""
    if autochat:
        sesh = str(autochat.ses_id)
        exp = str(autochat.expires)

    SESSION.close()
    return sesh, exp
예제 #12
0
def set_ses(chat_id, ses_id, expires):
    with INSERTION_LOCK:
        autochat = SESSION.query(ChatbotChats).get(str(chat_id))
        if not autochat:
            autochat = ChatbotChats(str(chat_id), str(ses_id), str(expires))
        else:
            autochat.ses_id = str(ses_id)
            autochat.expires = str(expires)

        SESSION.add(autochat)
        SESSION.commit()
예제 #13
0
def set_afk(user_id, reason, start_time=""):
    with INSERTION_LOCK:
        curr = SESSION.query(AFK).get(user_id)
        if not curr:
            curr = AFK(user_id, reason, True, start_time)
        else:
            curr.is_afk = True
            curr.reason = reason
            curr.start_time = time.time()
        AFK_USERS[user_id] = reason
        AFK_USERSS[user_id] = start_time
        SESSION.add(curr)
        SESSION.commit()
예제 #14
0
def rm_afk(user_id):
    with INSERTION_LOCK:
        curr = SESSION.query(AFK).get(user_id)
        if curr:
            if user_id in AFK_USERS:  # sanity check
                del AFK_USERS[user_id]
                del AFK_USERSS[user_id]
            SESSION.delete(curr)
            SESSION.commit()
            return True

        SESSION.close()
        return False
예제 #15
0
def rm_url_from_blacklist(chat_id, domain):
    with URL_BLACKLIST_FILTER_INSERTION_LOCK:
        domain_filt = SESSION.query(URLBlackListFilters).get(
            (str(chat_id), domain))
        if domain_filt:
            if domain in CHAT_URL_BLACKLISTS.get(str(chat_id), set()):
                CHAT_URL_BLACKLISTS.get(str(chat_id), set()).remove(domain)
            SESSION.delete(domain_filt)
            SESSION.commit()
            return True

        SESSION.close()
        return False
예제 #16
0
def __load_afk_users():
    global AFK_USERS
    global AFK_USERSS
    try:
        all_afk = SESSION.query(AFK).all()
        AFK_USERS = {
            user.user_id: user.reason
            for user in all_afk if user.is_afk
        }
        AFK_USERSS = {
            user.user_id: user.start_time
            for user in all_afk if user.is_afk
        }
    finally:
        SESSION.close()
예제 #17
0
def get_all_nsfw_enabled_chat():
    stark = SESSION.query(Nsfwatch).all()
    SESSION.close()
    return stark
예제 #18
0
def rmnsfwatch(chat_id: str):
    nsfwm = SESSION.query(Nsfwatch).get(str(chat_id))
    if nsfwm:
        SESSION.delete(nsfwm)
        SESSION.commit()
예제 #19
0
def get_all_chats():
    try:
        return SESSION.query(ChatbotChats.chat_id).all()
    finally:
        SESSION.close()
예제 #20
0
def disapprove(chat_id):
    rem = SESSION.query(forceSubscribe).get(chat_id)
    if rem:
        SESSION.delete(rem)
        SESSION.commit()
예제 #21
0
def remove_filter(chat_id, keyword):
    saved_filter = SESSION.query(Filters).get((str(chat_id), keyword))
    if saved_filter:
        SESSION.delete(saved_filter)
        SESSION.commit()
예제 #22
0
def remove_all_filters(chat_id):
    saved_filter = SESSION.query(Filters).filter(
        Filters.chat_id == str(chat_id))
    if saved_filter:
        saved_filter.delete()
        SESSION.commit()
예제 #23
0
def check_afk_status(user_id):
    try:
        return SESSION.query(AFK).get(user_id)
    finally:
        SESSION.close()
예제 #24
0
def get_all_chat_id():
    stark = SESSION.query(Nightmode).all()
    SESSION.close()
    return stark
예제 #25
0
def rmnightmode(chat_id: str):
    rmnightmoddy = SESSION.query(Nightmode).get(str(chat_id))
    if rmnightmoddy:
        SESSION.delete(rmnightmoddy)
        SESSION.commit()