def add_to_blacklist(chat_id, trigger): with BLACKLIST_FILTER_INSERTION_LOCK: blacklist_filt = BlackListFilters(str(chat_id), trigger) SESSION.merge(blacklist_filt) # merge to avoid duplicate key issues SESSION.commit() CHAT_BLACKLISTS.setdefault(str(chat_id), set()).add(trigger)
def migrate_chat(old_chat_id, new_chat_id): with BLACKLIST_FILTER_INSERTION_LOCK: chat_filters = SESSION.query(BlackListFilters).filter( BlackListFilters.chat_id == str(old_chat_id)).all() for filt in chat_filters: filt.chat_id = str(new_chat_id) 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()
def unblacklistChat(chat_id): with BANCHATLOCK: chat = SESSION.query(BannedChat).get(chat_id) if chat: SESSION.delete(chat) SESSION.commit() __load_blacklisted_chats_list()
def set_custom_gdbye(chat_id, custom_goodbye, goodbye_type, buttons=None): if buttons is None: buttons = [] with INSERTION_LOCK: welcome_settings = SESSION.query(Welcome).get(str(chat_id)) if not welcome_settings: welcome_settings = Welcome(str(chat_id), True) if custom_goodbye: welcome_settings.custom_leave = custom_goodbye welcome_settings.leave_type = goodbye_type.value else: welcome_settings.custom_leave = DEFAULT_GOODBYE welcome_settings.leave_type = Types.TEXT.value SESSION.add(welcome_settings) with LEAVE_BTN_LOCK: prev_buttons = SESSION.query(GoodbyeButtons).filter( GoodbyeButtons.chat_id == str(chat_id)).all() for btn in prev_buttons: SESSION.delete(btn) for b_name, url, same_line in buttons: button = GoodbyeButtons(chat_id, b_name, url, same_line) SESSION.add(button) SESSION.commit()
def set_welcome_mutes(chat_id, welcomemutes): with WM_LOCK: prev = SESSION.query(WelcomeMute).get((str(chat_id))) if prev: SESSION.delete(prev) welcome_m = WelcomeMute(str(chat_id), welcomemutes) SESSION.add(welcome_m) SESSION.commit()
def ungban_user(user_id): with GBANNED_USERS_LOCK: user = SESSION.query(GloballyBannedUsers).get(user_id) if user: SESSION.delete(user) SESSION.commit() __load_gbanned_userid_list()
def setKickTime(chat_id, value): with AUTOKICK_LOCK: prevObj = SESSION.query(AutoKickSafeMode).get(str(chat_id)) if prevObj: SESSION.delete(prevObj) newObj = AutoKickSafeMode(str(chat_id), int(value)) SESSION.add(newObj) SESSION.commit()
def blacklistChat(chat_id): with BANCHATLOCK: chat = SESSION.query(BannedChat).get(chat_id) if not chat: chat = BannedChat(chat_id) SESSION.merge(chat) SESSION.commit() __load_blacklisted_chats_list()
def ungmute_user(user_id): with GMUTED_USERS_LOCK: user = SESSION.query(GloballyMutedUsers).get(user_id) if user: SESSION.delete(user) SESSION.commit() __load_gmuted_userid_list()
def setDefenseStatus(chat_id, status): with DEFENSE_LOCK: prevObj = SESSION.query(DefenseMode).get(str(chat_id)) if prevObj: SESSION.delete(prevObj) newObj = DefenseMode(str(chat_id), status) SESSION.add(newObj) SESSION.commit()
def migrate_chat(old_chat_id, new_chat_id): with GMUTE_SETTING_LOCK: chat = SESSION.query(GmuteSettings).get(str(old_chat_id)) if chat: chat.chat_id = new_chat_id SESSION.add(chat) SESSION.commit()
def disable_gmutes(chat_id): with GMUTE_SETTING_LOCK: chat = SESSION.query(GmuteSettings).get(str(chat_id)) if not chat: chat = GmuteSettings(chat_id, False) chat.setting = False SESSION.add(chat) SESSION.commit() GMUTESTAT_LIST.add(str(chat_id))
def disable_gbans(chat_id): with GBAN_SETTING_LOCK: chat = SESSION.query(GbanSettings).get(str(chat_id)) if not chat: chat = GbanSettings(chat_id, False) chat.setting = False SESSION.add(chat) SESSION.commit() GBANSTAT_LIST.add(str(chat_id))
def set_clean_welcome(chat_id, clean_welcome): with INSERTION_LOCK: curr = SESSION.query(Welcome).get(str(chat_id)) if not curr: curr = Welcome(str(chat_id)) curr.clean_welcome = int(clean_welcome) SESSION.add(curr) SESSION.commit()
def set_cas_autoban(chat_id, autoban): with CAS_LOCK: status = True prevObj = SESSION.query(CombotCASStatus).get(str(chat_id)) if prevObj: status = prevObj.status SESSION.delete(prevObj) newObj = CombotCASStatus(str(chat_id), status, autoban) SESSION.add(newObj) SESSION.commit()
def set_cas_status(chat_id, status): with CAS_LOCK: ban = False prevObj = SESSION.query(CombotCASStatus).get(str(chat_id)) if prevObj: ban = prevObj.autoban SESSION.delete(prevObj) newObj = CombotCASStatus(str(chat_id), status, ban) SESSION.add(newObj) SESSION.commit()
def set_gdbye_preference(chat_id, should_goodbye): with INSERTION_LOCK: curr = SESSION.query(Welcome).get(str(chat_id)) if not curr: curr = Welcome(str(chat_id), should_goodbye=should_goodbye) else: curr.should_goodbye = should_goodbye SESSION.add(curr) SESSION.commit()
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 set_ses(chat_id, ses_id, expires): with INSERTION_LOCK: autochat = SESSION.query(ChatbotChats).get(str(chat_id)) if not autochat: autochat = ChatbotChats(str(chat_id), str(ses_id), str(expires)) else: autochat.ses_id = str(ses_id) autochat.expires = str(expires) SESSION.add(autochat) SESSION.commit()
def add_to_stickers(chat_id, trigger): with STICKERS_FILTER_INSERTION_LOCK: stickers_filt = StickersFilters(str(chat_id), trigger) SESSION.merge(stickers_filt) # merge to avoid duplicate key issues SESSION.commit() global CHAT_STICKERS if CHAT_STICKERS.get(str(chat_id), set()) == set(): CHAT_STICKERS[str(chat_id)] = {trigger} else: CHAT_STICKERS.get(str(chat_id), set()).add(trigger)
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 enable_gmutes(chat_id): with GMUTE_SETTING_LOCK: chat = SESSION.query(GmuteSettings).get(str(chat_id)) if not chat: chat = GmuteSettings(chat_id, True) chat.setting = True SESSION.add(chat) SESSION.commit() if str(chat_id) in GMUTESTAT_LIST: GMUTESTAT_LIST.remove(str(chat_id))
def update_gmute_reason(user_id, name, reason=None): with GMUTED_USERS_LOCK: user = SESSION.query(GloballyMutedUsers).get(user_id) if not user: return False user.name = name user.reason = reason SESSION.merge(user) SESSION.commit() return True
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 gmute_user(user_id, name, reason=None): with GMUTED_USERS_LOCK: user = SESSION.query(GloballyMutedUsers).get(user_id) if not user: user = GloballyMutedUsers(user_id, name, reason) else: user.name = name user.reason = reason SESSION.merge(user) SESSION.commit() __load_gmuted_userid_list()
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 rm_from_stickers(chat_id, trigger): with STICKERS_FILTER_INSERTION_LOCK: stickers_filt = SESSION.query(StickersFilters).get((str(chat_id), trigger)) if stickers_filt: if trigger in CHAT_STICKERS.get(str(chat_id), set()): # sanity check CHAT_STICKERS.get(str(chat_id), set()).remove(trigger) SESSION.delete(stickers_filt) SESSION.commit() return True SESSION.close() return False
def rm_afk(user_id): with INSERTION_LOCK: curr = SESSION.query(AFK).get(user_id) if curr: if user_id in AFK_USERS: # sanity check del AFK_USERS[user_id] SESSION.delete(curr) SESSION.commit() return True SESSION.close() return False
def set_afk(user_id, reason=""): with INSERTION_LOCK: curr = SESSION.query(AFK).get(user_id) if not curr: curr = AFK(user_id, reason, True) else: curr.is_afk = True curr.reason = reason AFK_USERS[user_id] = reason SESSION.add(curr) SESSION.commit()