def get_buttons(chat_id, keyword):
    try:
        return SESSION.query(Buttons).filter(
            Buttons.chat_id == str(chat_id),
            Buttons.keyword == keyword).order_by(Buttons.id).all()
    finally:
        SESSION.close()
Exemple #2
0
def __load_log_channels():
    global CHANNELS
    try:
        all_chats = SESSION.query(GroupLogs).all()
        CHANNELS = {chat.chat_id: chat.log_channel for chat in all_chats}
    finally:
        SESSION.close()
def get_note(chat_id, note_name):
    try:
        return SESSION.query(Notes).filter(
            func.lower(Notes.name) == note_name,
            Notes.chat_id == str(chat_id)).first()
    finally:
        SESSION.close()
def is_locked(chat_id, lock_type):
    curr_perm = SESSION.query(Permissions).get(str(chat_id))
    SESSION.close()

    if not curr_perm:
        return False

    elif lock_type == "sticker":
        return curr_perm.sticker
    elif lock_type == "photo":
        return curr_perm.photo
    elif lock_type == "audio":
        return curr_perm.audio
    elif lock_type == "voice":
        return curr_perm.voice
    elif lock_type == "contact":
        return curr_perm.contact
    elif lock_type == "video":
        return curr_perm.video
    elif lock_type == "videonote":
        return curr_perm.videonote
    elif lock_type == "document":
        return curr_perm.document
    elif lock_type == "gif":
        return curr_perm.gif
    elif lock_type == "url":
        return curr_perm.url
    elif lock_type == "bots":
        return curr_perm.bots
    elif lock_type == "forward":
        return curr_perm.forward
    elif lock_type == "game":
        return curr_perm.game
    elif lock_type == "location":
        return curr_perm.location
def get_buttons(chat_id, note_name):
    try:
        return SESSION.query(Buttons).filter(
            Buttons.chat_id == str(chat_id),
            Buttons.note_name == note_name).order_by(Buttons.id).all()
    finally:
        SESSION.close()
Exemple #6
0
def chat_should_report(chat_id: Union[str, int]) -> bool:
    try:
        chat_setting = SESSION.query(ReportingChatSettings).get(str(chat_id))
        if chat_setting:
            return chat_setting.should_report
        return True
    finally:
        SESSION.close()
Exemple #7
0
def __load_all_feds_settings():
    global FEDERATION_NOTIFICATION
    try:
        getuser = SESSION.query(FedsUserSettings).all()
        for x in getuser:
            FEDERATION_NOTIFICATION[str(x.user_id)] = x.should_report
    finally:
        SESSION.close()
def get_rules(chat_id):
    rules = SESSION.query(Rules).get(str(chat_id))
    ret = ""
    if rules:
        ret = rules.rules

    SESSION.close()
    return ret
def get_chat_filters(chat_id):
    try:
        return SESSION.query(CustomFilters).filter(
            CustomFilters.chat_id == str(chat_id)).order_by(
                func.length(CustomFilters.keyword).desc()).order_by(
                    CustomFilters.keyword.asc()).all()
    finally:
        SESSION.close()
Exemple #10
0
def user_should_report(user_id: int) -> bool:
    try:
        user_setting = SESSION.query(ReportingUserSettings).get(user_id)
        if user_setting:
            return user_setting.should_report
        return True
    finally:
        SESSION.close()
Exemple #11
0
def __load_gban_stat_list():
    global GBANSTAT_LIST
    try:
        GBANSTAT_LIST = {
            x.chat_id
            for x in SESSION.query(AntispamSettings).all() if not x.setting
        }
    finally:
        SESSION.close()
Exemple #12
0
def __load_gbanned_userid_list():
    global GBANNED_LIST
    try:
        GBANNED_LIST = {
            x.user_id
            for x in SESSION.query(GloballyBannedUsers).all()
        }
    finally:
        SESSION.close()
def __load_disabled_commands():
    global DISABLED
    try:
        all_chats = SESSION.query(Disable).all()
        for chat in all_chats:
            DISABLED.setdefault(chat.chat_id, set()).add(chat.command)

    finally:
        SESSION.close()
Exemple #14
0
def is_chat(chat_id):
    try:
        chat = SESSION.query(ChatbotChats).get(str(chat_id))
        if chat:
            return True
        else:
            return False
    finally:
        SESSION.close()
Exemple #15
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()
Exemple #16
0
def __load_afk_users():
    global AFK_USERS
    try:
        all_afk = SESSION.query(AFK).all()
        AFK_USERS = {
            user.user_id: user.reason
            for user in all_afk if user.is_afk
        }
    finally:
        SESSION.close()
Exemple #17
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
Exemple #18
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()
def rm_repo(chat_id, name):
    with GIT_LOCK:
        repo = SESSION.query(GitHub).get((str(chat_id), name))
        if repo:
            SESSION.delete(repo)
            SESSION.commit()
            return True
        else:
            SESSION.close()
            return False
Exemple #20
0
def get_soft_warn(chat_id):
    try:
        setting = SESSION.query(WarnSettings).get(str(chat_id))
        if setting:
            return setting.soft_warn
        else:
            return False

    finally:
        SESSION.close()
Exemple #21
0
def clear_user_bio(user_id):
    with INSERTION_LOCK:
        curr = SESSION.query(UserBio).get(user_id)
        if curr:
            SESSION.delete(curr)
            SESSION.commit()
            return True

        SESSION.close()
    return False
def __load_flood_settings():
    global CHAT_FLOOD
    try:
        all_chats = SESSION.query(FloodControl).all()
        CHAT_FLOOD = {
            chat.chat_id: (None, DEF_COUNT, chat.limit)
            for chat in all_chats
        }
    finally:
        SESSION.close()
def migrate_chat(old_chat_id, new_chat_id):
    with INSERTION_LOCK:
        flood = SESSION.query(FloodControl).get(str(old_chat_id))
        if flood:
            CHAT_FLOOD[str(new_chat_id)] = CHAT_FLOOD.get(
                str(old_chat_id), DEF_OBJ)
            flood.chat_id = str(new_chat_id)
            SESSION.commit()

        SESSION.close()
Exemple #24
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
Exemple #25
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]

            SESSION.delete(curr)
            SESSION.commit()
            return True

        SESSION.close()
        return False
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
def disable_command(chat_id, disable):
    with DISABLE_INSERTION_LOCK:
        disabled = SESSION.query(Disable).get((str(chat_id), disable))

        if not disabled:
            DISABLED.setdefault(str(chat_id), set()).add(disable)

            disabled = Disable(str(chat_id), disable)
            SESSION.add(disabled)
            SESSION.commit()
            return True

        SESSION.close()
        return False
def enable_command(chat_id, enable):
    with DISABLE_INSERTION_LOCK:
        disabled = SESSION.query(Disable).get((str(chat_id), enable))

        if disabled:
            if enable in DISABLED.get(str(chat_id)):  # sanity check
                DISABLED.setdefault(str(chat_id), set()).remove(enable)

            SESSION.delete(disabled)
            SESSION.commit()
            return True

        SESSION.close()
        return False
Exemple #29
0
def rm_from_blacklist(chat_id, trigger):
    with BLACKLIST_FILTER_INSERTION_LOCK:
        blacklist_filt = SESSION.query(BlackListFilters).get(
            (str(chat_id), trigger))
        if blacklist_filt:
            if trigger in CHAT_BLACKLISTS.get(str(chat_id),
                                              set()):  # sanity check
                CHAT_BLACKLISTS.get(str(chat_id), set()).remove(trigger)

            SESSION.delete(blacklist_filt)
            SESSION.commit()
            return True

        SESSION.close()
        return False
Exemple #30
0
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()