def backup_indentity(first_name, last_name, bio): cloner_db = SESSION.query(Cloner).get(str(Owner)) if cloner_db: SESSION.delete(cloner_db) cloner_db = Cloner(Owner, first_name, last_name, bio) SESSION.add(cloner_db) SESSION.commit()
def rem_chat(chat_id): with INSERTION_LOCK: autochat = SESSION.query(ChatbotChats).get(str(chat_id)) if autochat: SESSION.delete(autochat) SESSION.commit()
async def set_name_theme_set(my_id, name_theme): name_theme_db = SESSION.query(ThemeSet).get(my_id) if name_theme_db: SESSION.delete(name_theme_db) name_theme_db = ThemeSet(my_id, name_theme) SESSION.add(name_theme_db) SESSION.commit()
def save_selfnote(user_id, note_name, note_data, msgtype, file=None, file_ref=None, message_id=0): global SELF_NOTES with INSERTION_LOCK: prev = SESSION.query(SelfNotes).get((user_id, note_name)) if prev: SESSION.delete(prev) note = SelfNotes(user_id, note_name, note_data, msgtype=int(msgtype), file=file, file_ref=file_ref, message_id=message_id) 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': file, 'file_ref': file_ref, 'message_id': message_id }
def set_sticker_set(my_id, sticker): sticker_db = SESSION.query(StickerSet).get(my_id) if sticker_db: SESSION.delete(sticker_db) sticker_db = StickerSet(my_id, sticker) SESSION.add(sticker_db) SESSION.commit()
def switch_to_locale(chat_id, locale_name): with LOCALES_INSERTION_LOCK: prev = SESSION.query(Locales).get((str(chat_id))) if prev: SESSION.delete(prev) switch_locale = Locales(str(chat_id), locale_name) SESSION.add(switch_locale) SESSION.commit()
def set_afk(afk, reason): global MY_AFK afk_db = SESSION.query(AFK).get(str(Owner)) if afk_db: SESSION.delete(afk_db) afk_db = AFK(Owner, afk, reason) SESSION.add(afk_db) SESSION.commit() MY_AFK[Owner] = {"afk": afk, "reason": reason}
def del_whitelist(user_id): with INSERTION_LOCK: user = SESSION.query(WhitelistUsers).get(str(user_id)) if user: SESSION.delete(user) SESSION.commit() else: SESSION.close() return False
def update_chat(chat): global MY_ALL_CHATS if str(chat.id) in list(MY_ALL_CHATS): if MY_ALL_CHATS.get(str(chat.id)) and MY_ALL_CHATS[str(chat.id)].get('name') == chat.title and MY_ALL_CHATS[str(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[str(chat.id)] = {"name": chat.title, "username": chat.username}
def rm_selfnote(user_id, note_name): global SELF_NOTES with INSERTION_LOCK: note = SESSION.query(SelfNotes).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 delete_my_chat_admin(chat, status): global MY_ALL_ADMINS, MY_CHATS_CREATOR, MY_CHATS_ADMINS if str(chat.id) in list(MY_ALL_ADMINS): chat_db = SESSION.query(MyChatsAdmin).get(str(chat.id)) if chat_db: SESSION.delete(chat_db) SESSION.commit() MY_ALL_ADMINS.pop(str(chat.id)) print("Deleted " + chat.title) if status == "creator": MY_CHATS_CREATOR.pop(str(chat.id)) if status == "administrator": MY_CHATS_ADMINS.pop(str(chat.id))
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 update_chat_admin(chat, status): global MY_ALL_ADMINS, MY_CHATS_CREATOR, MY_CHATS_ADMINS if str(chat.id) in list(MY_ALL_ADMINS): if MY_ALL_ADMINS.get(str(chat.id)) and MY_ALL_ADMINS[str(chat.id)].get('name') == chat.title and MY_ALL_ADMINS[str(chat.id)].get('username') == chat.username: return chat_db = SESSION.query(MyChatsAdmin).get(str(chat.id)) if chat_db: SESSION.delete(chat_db) chat_db = MyChatsAdmin(str(chat.id), chat.title, chat.username, status) SESSION.add(chat_db) SESSION.commit() MY_ALL_ADMINS[str(chat.id)] = {"name": chat.title, "username": chat.username} if status == "creator": MY_CHATS_CREATOR[str(chat.id)] = {"name": chat.title, "username": chat.username} if status == "administrator": MY_CHATS_ADMINS[str(chat.id)] = {"name": chat.title, "username": chat.username}
def save_selfnote(user_id, note_name, note_data, msgtype, file=None): global SELF_NOTES with INSERTION_LOCK: prev = SESSION.query(SelfNotes).get((user_id, note_name)) if prev: SESSION.delete(prev) note = SelfNotes(user_id, note_name, note_data, msgtype=int(msgtype), file=file) 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": file, }
def del_flist(chat_id): rem = SESSION.query(Fban).get(str(chat_id)) if rem: SESSION.delete(rem) SESSION.commit()