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 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 update_link(website, link): adder = SESSION.query(database).get(website) if adder: adder.link = link else: adder = database(website, link) SESSION.add(adder) 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_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_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()): # sanity check CHAT_BLACKLISTS.get(str(chat_id), set()).remove(trigger) SESSION.delete(blacklist_filt) SESSION.commit() return True SESSION.close() return False
def add_welcome_setting( chat_id, custom_welcome_message, should_clean_welcome, previous_welcome, media_file_id, ): # 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 add_snip(keyword, reply, f_mesg_id): to_check = get_snips(keyword) if not to_check: adder = Note(keyword, reply, f_mesg_id) SESSION.add(adder) SESSION.commit() return True rem = SESSION.query(Note).get(keyword) SESSION.delete(rem) SESSION.commit() adder = Note(keyword, reply, f_mesg_id) SESSION.add(adder) SESSION.commit() return False
def approve(chat_id, reason): adder = PMPermit(str(chat_id), str(reason)) SESSION.add(adder) SESSION.commit()
def disapprove(chat_id): rem = SESSION.query(PMPermit).get(str(chat_id)) if rem: SESSION.delete(rem) 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 addecho(user_id, chat_id): adder = ECHOSQL(str(user_id), str(chat_id)) SESSION.add(adder) SESSION.commit()
def rm_welcome_setting(chat_id): rem = SESSION.query(Welcome).get(str(chat_id)) if rem: SESSION.delete(rem) SESSION.commit()
def ungmute(sender): rem = SESSION.query(GMute).get((str(sender))) if rem: SESSION.delete(rem) SESSION.commit()
def mute(sender, chat_id): adder = Mute(str(sender), str(chat_id)) SESSION.add(adder) SESSION.commit()
def remove_filter(chat_id, keyword): saved_filter = SESSION.query(Filters).get((str(chat_id), keyword)) if saved_filter: SESSION.delete(saved_filter) SESSION.commit()
def remove_echo(user_id, chat_id): note = SESSION.query(ECHOSQL).get((str(user_id), str(chat_id))) if note: SESSION.delete(note) SESSION.commit()
def remove_all_filters(chat_id): saved_filter = SESSION.query(Filters).filter( Filters.chat_id == str(chat_id)) if saved_filter: saved_filter.delete() SESSION.commit()
def remove_snip(keyword): note = SESSION.query(Snips).filter(Snips.snip == keyword) if note: note.delete() SESSION.commit()
def unmute(sender, chat_id): rem = SESSION.query(Mute).get((str(sender), str(chat_id))) if rem: SESSION.delete(rem) SESSION.commit()
def gmute(sender): adder = GMute(str(sender)) SESSION.add(adder) SESSION.commit()