Exemplo n.º 1
0
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
Exemplo n.º 2
0
def get_gp_exit_pref(chat_id):
    getsql = SESSION.query(Welcome).get(str(chat_id))
    SESSION.close()
    if getsql:
        return getsql.should_goodbye
    else:
        # Welcome by default.
        return True
Exemplo n.º 3
0
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()
Exemplo n.º 4
0
def del_user(user_id):
    with INSERTION_LOCK:
        curr = SESSION.query(Users).get(user_id)
        if curr:
            SESSION.delete(curr)
            SESSION.commit()
            return True

        ChatMembers.query.filter(ChatMembers.user == user_id).delete()
        SESSION.commit()
        SESSION.close()
    return False
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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
Exemplo n.º 7
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
Exemplo n.º 8
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()
Exemplo n.º 9
0
def is_restr_locked(chat_id, lock_type):
    curr_restr = SESSION.query(Restrictions).get(str(chat_id))
    SESSION.close()

    if not curr_restr:
        return False

    if lock_type == "messages":
        return curr_restr.messages
    elif lock_type == "media":
        return curr_restr.media
    elif lock_type == "other":
        return curr_restr.other
    elif lock_type == "previews":
        return curr_restr.preview
    elif lock_type == "all":
        return curr_restr.messages and curr_restr.media and curr_restr.other and curr_restr.preview
Exemplo n.º 10
0
def num_blacklist_filters():
    try:
        return SESSION.query(BlackListFilters).count()
    finally:
        SESSION.close()
Exemplo n.º 11
0
def num_blacklist_chat_filters(chat_id):
    try:
        return SESSION.query(BlackListFilters.chat_id).filter(
            BlackListFilters.chat_id == str(chat_id)).count()
    finally:
        SESSION.close()
Exemplo n.º 12
0
def get_name_by_userid(user_id):
    try:
        return SESSION.query(Users).get(Users.user_id == int(user_id)).first()
    finally:
        SESSION.close()
Exemplo n.º 13
0
def get_userid_by_name(username):
    try:
        return SESSION.query(Users).filter(
            func.lower(Users.username) == username.lower()).all()
    finally:
        SESSION.close()
Exemplo n.º 14
0
def num_chats():
    try:
        return SESSION.query(func.count(distinct(Disable.chat_id))).scalar()
    finally:
        SESSION.close()
Exemplo n.º 15
0
def num_disabled():
    try:
        return SESSION.query(Disable).count()
    finally:
        SESSION.close()
Exemplo n.º 16
0
def get_all_chats():
    try:
        return SESSION.query(Chats).all()
    finally:
        SESSION.close()
Exemplo n.º 17
0
def get_chat_members(chat_id):
    try:
        return SESSION.query(ChatMembers).filter(
            ChatMembers.chat == str(chat_id)).all()
    finally:
        SESSION.close()
Exemplo n.º 18
0
def get_restr(chat_id):
    try:
        return SESSION.query(Restrictions).get(str(chat_id))
    finally:
        SESSION.close()
Exemplo n.º 19
0
def get_user_num_chats(user_id):
    try:
        return SESSION.query(ChatMembers).filter(
            ChatMembers.user == int(user_id)).count()
    finally:
        SESSION.close()
Exemplo n.º 20
0
def num_blacklist_filter_chats():
    try:
        return SESSION.query(func.count(distinct(
            BlackListFilters.chat_id))).scalar()
    finally:
        SESSION.close()
Exemplo n.º 21
0
def num_chats():
    try:
        return SESSION.query(Chats).count()
    finally:
        SESSION.close()
Exemplo n.º 22
0
def num_users():
    try:
        return SESSION.query(Users).count()
    finally:
        SESSION.close()
Exemplo n.º 23
0
def get_locks(chat_id):
    try:
        return SESSION.query(Permissions).get(str(chat_id))
    finally:
        SESSION.close()
Exemplo n.º 24
0
def get_gp_exit_buttons(chat_id):
    try:
        return SESSION.query(GoodbyeButtons).filter(GoodbyeButtons.chat_id == str(chat_id)).order_by(
            GoodbyeButtons.id).all()
    finally:
        SESSION.close()