def migrate_chat(old_chat_id, new_chat_id): with INSERTION_LOCK: flood = SESSION.query(FloodControl).get(str(old_chat_id)) if flood: CHAT_FLOOD[str(new_chat_id)] = CHAT_FLOOD.get( str(old_chat_id), DEF_OBJ) flood.chat_id = str(new_chat_id) SESSION.commit() SESSION.close()
def enable_gbans(chat_id): with GBAN_SETTING_LOCK: chat = SESSION.query(GbanSettings).get(str(chat_id)) if not chat: chat = GbanSettings(chat_id, True) chat.setting = True SESSION.add(chat) SESSION.commit() if str(chat_id) in GBANSTAT_LIST: GBANSTAT_LIST.remove(str(chat_id))
def add_channel(chat_id, channel): adder = SESSION.query(forceSubscribe).get(chat_id) if adder: adder.channel = channel else: adder = forceSubscribe( chat_id, channel ) SESSION.add(adder) SESSION.commit()
def gban_user(user_id, name, reason=None): with GBANNED_USERS_LOCK: user = SESSION.query(GloballyBannedUsers).get(user_id) if not user: user = GloballyBannedUsers(user_id, name, reason) else: user.name = name user.reason = reason SESSION.merge(user) SESSION.commit() __load_gbanned_userid_list()
def add_welcome_setting(chat_id, should_clean_welcome, previous_welcome, f_mesg_id): adder = SESSION.query(Welcome).get(chat_id) if adder: adder.should_clean_welcome = should_clean_welcome adder.previous_welcome = previous_welcome adder.f_mesg_id = f_mesg_id else: adder = Welcome(chat_id, should_clean_welcome, previous_welcome, f_mesg_id) SESSION.add(adder) SESSION.commit()
def update_gban_reason(user_id, name, reason=None): with GBANNED_USERS_LOCK: user = SESSION.query(GloballyBannedUsers).get(user_id) if not user: return None old_reason = user.reason user.name = name user.reason = reason SESSION.merge(user) SESSION.commit() return old_reason
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()): CHAT_BLACKLISTS.get(str(chat_id), set()).remove(trigger) SESSION.delete(blacklist_filt) SESSION.commit() return True SESSION.close() return False
def remove_url(tg_chat_id, tg_feed_link): with INSERTION_LOCK: # this loops to delete any possible duplicates for the same TG User ID, TG Chat ID and link for row in check_url_availability(tg_chat_id, tg_feed_link): # add the action to the DB query SESSION.delete(row) SESSION.commit()
def add_snip(keyword, reply, snip_type, media_id, media_access_hash, media_file_reference): adder = SESSION.query(Snips).get(keyword) if adder: adder.reply = reply adder.snip_type = snip_type adder.media_id = media_id adder.media_access_hash = media_access_hash adder.media_file_reference = media_file_reference else: adder = Snips(keyword, reply, snip_type, media_id, media_access_hash, media_file_reference) SESSION.add(adder) SESSION.commit()
def set_flood(chat_id, amount): with INSERTION_LOCK: flood = SESSION.query(FloodControl).get(str(chat_id)) if not flood: flood = FloodControl(str(chat_id)) flood.user_id = None flood.limit = amount CHAT_FLOOD[str(chat_id)] = (None, DEF_COUNT, amount) SESSION.add(flood) SESSION.commit()
def update_url(row_id, new_entry_links): with INSERTION_LOCK: row = SESSION.query(RSS).get(row_id) # set the new old_entry_link with the latest update from the RSS Feed row.old_entry_link = new_entry_links[0] # commit the changes to the DB SESSION.commit()
def remove_warn(user_id, chat_id): with WARN_INSERTION_LOCK: removed = False warned_user = SESSION.query(Warns).get((user_id, str(chat_id))) if warned_user and warned_user.num_warns > 0: warned_user.num_warns -= 1 SESSION.add(warned_user) SESSION.commit() removed = True SESSION.close() return removed
def update_lock(chat_id, lock_type, locked): curr_perm = SESSION.query(Locks).get(str(chat_id)) if not curr_perm: curr_perm = init_locks(chat_id) if lock_type == "url": curr_perm.url = locked elif lock_type == "bots": curr_perm.bots = locked elif lock_type == "forward": curr_perm.forward = locked elif lock_type == "commands": curr_perm.commands = locked SESSION.add(curr_perm) SESSION.commit()
def add_filter(chat_id, keyword, reply, snip_type, media_id, media_access_hash, media_file_reference): adder = SESSION.query(Filters).get((str(chat_id), keyword)) if adder: adder.reply = reply adder.snip_type = snip_type adder.media_id = media_id adder.media_access_hash = media_access_hash adder.media_file_reference = media_file_reference else: adder = Filters(chat_id, keyword, reply, snip_type, media_id, media_access_hash, media_file_reference) SESSION.add(adder) SESSION.commit()
def add_welcome_setting(chat_id, custom_welcome_message, should_clean_welcome, previous_welcome, message_type=0, media_id=None, media_access_hash=None, media_file_reference=None): # adder = SESSION.query(Welcome).get(chat_id) adder = Welcome(chat_id, custom_welcome_message, should_clean_welcome, previous_welcome, message_type, media_id, media_access_hash, media_file_reference) SESSION.add(adder) SESSION.commit()
def add_welcome_setting( chat_id, custom_welcome_message, should_clean_welcome, previous_welcome, media_file_id=None ): # adder = SESSION.query(Welcome).get(chat_id) adder = Welcome( chat_id, custom_welcome_message, should_clean_welcome, previous_welcome, media_file_id ) SESSION.add(adder) SESSION.commit()
def warn_user(user_id, chat_id, reason=None): with WARN_INSERTION_LOCK: warned_user = SESSION.query(Warns).get((user_id, str(chat_id))) if not warned_user: warned_user = Warns(user_id, str(chat_id)) warned_user.num_warns += 1 if reason: warned_user.reasons = warned_user.reasons + "\r\n\r\n" + reason # TODO:: double check this wizardry reasons = warned_user.reasons num = warned_user.num_warns SESSION.add(warned_user) SESSION.commit() return num, reasons
def add_s( user_id, chat_id, session_id, session_expires ): adder = SESSION.query(LydiaAI).get((user_id, chat_id)) if adder: adder.session_id = session_id adder.session_expires = session_expires else: adder = LydiaAI( user_id, chat_id, session_id, session_expires ) SESSION.add(adder) SESSION.commit()
def remove_filter(chat_id, keyword): saved_filter = SESSION.query(Filters).get((chat_id, keyword)) if saved_filter: SESSION.delete(saved_filter) SESSION.commit()
def remove_chat_fban(chat_id): rem = SESSION.query(FBan).get(str(chat_id)) if rem: SESSION.delete(rem) SESSION.commit()
def add_chat_fban(chat_id): adder = FBan(str(chat_id)) SESSION.add(adder) SESSION.commit()
def delgvar(variable): rem = SESSION.query(Globals).filter(Globals.variable == str(variable))\ .delete(synchronize_session="fetch") if rem: SESSION.commit()
def rm_welcome_setting(chat_id): rem = SESSION.query(Welcome).get(chat_id) if rem: SESSION.delete(rem) SESSION.commit()
def disapprove(chat_id): rem = SESSION.query(forceSubscribe).get(chat_id) if rem: SESSION.delete(rem) SESSION.commit()
def disapprove(chat_id): rem = SESSION.query(NOLogPMs).get(chat_id) if rem: SESSION.delete(rem) SESSION.commit()
def approve(chat_id): adder = NOLogPMs(chat_id) SESSION.add(adder) SESSION.commit()
def remove_all_filters(chat_id): saved_filter = SESSION.query(Filters).filter(Filters.chat_id == chat_id) if saved_filter: saved_filter.delete() SESSION.commit()
def update_previous_welcome(chat_id, previous_welcome): row = SESSION.query(Welcome).get(chat_id) row.previous_welcome = previous_welcome # commit the changes to the DB SESSION.commit()
def remove_s(user_id, chat_id): note = SESSION.query(LydiaAI).get((user_id, chat_id)) if note: SESSION.delete(note) SESSION.commit()
def rm_all_notes(chat_id): notes = SESSION.query(Notes).filter(Notes.chat_id == str(chat_id)) if notes: notes.delete() SESSION.commit()