def get_whitelist(user_id): user = SESSION.query(PMTable).get(user_id) rep = "" if user: rep = str(user.boolvalue) SESSION.close() return rep
def get_antiservice(chat_id): try: x = SESSION.query(AntiService).get(str(chat_id)) if x.is_enabled: return True else: return False finally: SESSION.close()
def get_msg_id(user_id): try: user = SESSION.query(MsgID).get(user_id) msg_id = None if user: msg_id = user.msg_id return msg_id finally: SESSION.close()
def __load_afk(): global MY_AFK try: MY_AFK = {} qall = SESSION.query(AFK).all() for x in qall: MY_AFK[int(x.user_id)] = {"afk": x.is_afk, "reason": x.reason} finally: SESSION.close()
def __load_mychats(): global MY_ALL_CHATS, MY_ADMIN_CHATS try: MY_ALL_CHATS = {} qall = SESSION.query(MyChats).all() for x in qall: MY_ALL_CHATS[x.chat_id] = {"name": x.chat_name, "username": x.chat_username} finally: SESSION.close()
def __load_mychats(): global ANTISERVICE_CHATS try: ANTISERVICE_CHATS = [] qall = SESSION.query(AntiService).all() for x in qall: if x.is_enabled: ANTISERVICE_CHATS.append(x.chat_id) finally: SESSION.close()
def disable_antiservice(chat_id, vbool=False): try: enabled = SESSION.query(AntiService).get(str(chat_id)) if enabled: SESSION.delete(enabled) enabled = AntiService(chat_id, vbool) SESSION.add(enabled) SESSION.commit() finally: SESSION.close()
def del_whitelist(user_id): with INSERTION_LOCK: user = SESSION.query(PMTable).get(user_id) try: if user: SESSION.delete(user) SESSION.commit() finally: SESSION.close() return False
def is_gmuted(sender_id): global GMUTE_USERS with INSERTION_LOCK: try: if sender_id in GMUTE_USERS: return True else: return None finally: SESSION.close() return
def set_last_msg_id(user_id, msg_id): with INSERTION_LOCK: try: user = SESSION.query(MsgID).get(user_id) if not user: user = MsgID(user_id, msg_id) else: user.msg_id = msg_id SESSION.merge(user) SESSION.commit() finally: SESSION.close()
def rm_note(user_id, note_name): global SELF_NOTES with INSERTION_LOCK: note = SESSION.query(Notes).get((user_id, note_name)) if note: SESSION.delete(note) SESSION.commit() SELF_NOTES[user_id].pop(note_name) return True else: SESSION.close() return False
def set_whitelist(user_id, boolvalue): with INSERTION_LOCK: user = SESSION.query(PMTable).get(user_id) try: if not user: user = PMTable(user_id, boolvalue) else: user.boolvalue = str(boolvalue) SESSION.add(user) SESSION.commit() finally: SESSION.close() return user_id
def get_all_chats(): try: return SESSION.query(MyChats).all() finally: SESSION.close()
def get_num_notes(user_id): try: num_notes = SESSION.query(Notes).count() return num_notes finally: SESSION.close()