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 ensure_bot_in_db(): with INSERTION_LOCK: bot = Users(dispatcher.bot.id, dispatcher.bot.username) SESSION.merge(bot) SESSION.commit()