def save_note(user_id, note_name, note_data, msgtype, file_id=None, file_ref=None): global SELF_NOTES with INSERTION_LOCK: prev = SESSION.query(Notes).get((user_id, note_name)) if prev: SESSION.delete(prev) note = Notes( user_id, note_name, note_data, msgtype=int(msgtype), file_id=file_id, file_ref=file_ref, ) SESSION.add(note) SESSION.commit() if not SELF_NOTES.get(user_id): SELF_NOTES[user_id] = {} SELF_NOTES[user_id][note_name] = { "value": note_data, "type": msgtype, "file_id": file_id, "file_ref": file_ref, }
def set_afk(afk, reason): global MY_AFK afk_db = SESSION.query(AFK).get(str(OWNER_ID)) if afk_db: SESSION.delete(afk_db) afk_db = AFK(OWNER_ID, afk, reason) SESSION.add(afk_db) SESSION.commit() MY_AFK[OWNER_ID] = {"afk": afk, "reason": reason}
def ungmute(sender): global GMUTE_USERS with INSERTION_LOCK: rem = SESSION.query(GMute).get(sender) if rem: GMUTE_USERS.remove(sender) SESSION.delete(rem) SESSION.commit() return
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 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 update_chat(chat): global MY_ALL_CHATS if (chat.id in list(MY_ALL_CHATS) and MY_ALL_CHATS.get(chat.id) and MY_ALL_CHATS[chat.id].get("name") == chat.title and MY_ALL_CHATS[chat.id].get("username") == chat.username): return chat_db = SESSION.query(MyChats).get(str(chat.id)) if chat_db: SESSION.delete(chat_db) chat_db = MyChats(str(chat.id), chat.title, chat.username) SESSION.add(chat_db) SESSION.commit() MY_ALL_CHATS[chat.id] = {"name": chat.title, "username": chat.username}
def clear_credential(chat_id): with INSERTION_LOCK: saved_cred = SESSION.query(gDriveCreds).get(chat_id) if saved_cred: SESSION.delete(saved_cred) SESSION.commit()