def get_name_by_userid(user_id): try: return SESSION.query(Users).get(Users.user_id == int(user_id)).first() finally: SESSION.close()
def get_connected_chat(user_id): try: return SESSION.query(Connection).get((int(user_id))) finally: SESSION.close()
def get_userid_by_name(username): try: return SESSION.query(Users).filter( func.lower(Users.username) == username.lower()).all() finally: SESSION.close()
def get_locks(chat_id): try: return SESSION.query(Permissions).get(str(chat_id)) finally: SESSION.close()
def curr_connection(chat_id): try: return SESSION.query(Connection).get((str(chat_id))) finally: SESSION.close()
def get_all_users(): try: return SESSION.query(Users).all() finally: SESSION.close()
def num_chats(): try: return SESSION.query(Chats).count() finally: SESSION.close()
def num_filters(): try: return SESSION.query(CustomFilters).count() finally: SESSION.close()
def get_warn_filter(chat_id, keyword): try: return SESSION.query(WarnFilters).get((str(chat_id), keyword)) finally: SESSION.close()
def num_chats(): try: return SESSION.query(func.count(distinct( CustomFilters.chat_id))).scalar() finally: SESSION.close()
def get_all_filters(): try: return SESSION.query(CustomFilters).all() finally: SESSION.close()
def num_logchannels(): try: return SESSION.query(func.count(distinct(GroupLogs.chat_id))).scalar() finally: SESSION.close()
def num_notes(): try: return SESSION.query(Notes).count() finally: SESSION.close()
def get_restr(chat_id): try: return SESSION.query(Restrictions).get(str(chat_id)) finally: SESSION.close()
def get_chat_members(chat_id): try: return SESSION.query(ChatMembers).filter( ChatMembers.chat == str(chat_id)).all() finally: SESSION.close()
def num_warns(): try: return SESSION.query(func.sum(Warns.num_warns)).scalar() or 0 finally: SESSION.close()
def get_all_chats(): try: return SESSION.query(Chats).all() finally: SESSION.close()
def num_warn_chats(): try: return SESSION.query(func.count(distinct(Warns.chat_id))).scalar() finally: SESSION.close()
def get_user_num_chats(user_id): try: return SESSION.query(ChatMembers).filter( ChatMembers.user == int(user_id)).count() finally: SESSION.close()
def num_warn_filters(): try: return SESSION.query(WarnFilters).count() finally: SESSION.close()
def num_users(): try: return SESSION.query(Users).count() finally: SESSION.close()
def num_disabled(): try: return SESSION.query(Disable).count() finally: SESSION.close()