def add_note_button_to_db(chat_id, keyword, b_name, url, same_line): with BUTTON_LOCK: button = Buttons(chat_id, keyword, b_name, url, same_line) SESSION.add(button) SESSION.commit()
curr_perm.sticker = locked elif lock_type == "gif": curr_perm.gif = locked elif 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 == 'game': curr_perm.game = locked elif lock_type == 'location': curr_perm.location = locked SESSION.add(curr_perm) SESSION.commit() def update_restriction(chat_id, restr_type, locked): with RESTR_LOCK: curr_restr = SESSION.query(Restrictions).get(str(chat_id)) if not curr_restr: curr_restr = init_restrictions(chat_id) if restr_type == "messages": curr_restr.messages = locked elif restr_type == "media": curr_restr.media = locked elif restr_type == "other": curr_restr.other = locked elif restr_type == "previews":
def add_url(tg_chat_id, tg_feed_link, tg_old_entry_link): with INSERTION_LOCK: action = RSS(tg_chat_id, tg_feed_link, tg_old_entry_link) SESSION.add(action) SESSION.commit()
def toggle_report(self) -> bool: self.log_report = not self.log_report SESSION.commit() return self.log_report
def toggle_action(self) -> bool: self.log_action = not self.log_action SESSION.commit() return self.log_action
def migrate_chat(old_chat_id, new_chat_id): with INSERTION_LOCK: chat = SESSION.query(Rules).get(str(old_chat_id)) if chat: chat.chat_id = str(new_chat_id) SESSION.commit()
def del_thanks_count(ilikes_id): ilikes_data = SESSION.query(iLikes).get(str(ilikes_id)) ilikes_data.thanks = ilikes_data.thanks - 1 SESSION.commit()
def rem_chat(chat_id): with INSERTION_LOCK: chat = SESSION.query(Chats).get(str(chat_id)) if chat: SESSION.delete(chat) SESSION.commit()
def toggle_warn(self) -> bool: self.log_warn = not self.log_warn SESSION.commit() return self.log_warn
def disapprove(chat_id): rem = SESSION.query(forceSubscribe).get(chat_id) if rem: SESSION.delete(rem) SESSION.commit()
def add_warn_filter(chat_id, keyword, reply): with WARN_FILTER_INSERTION_LOCK: warn_filt = WarnFilters(str(chat_id), keyword, reply) SESSION.merge(warn_filt) # merge to avoid duplicate key issues SESSION.commit()
def add_iLike_Click(chat_id, msg_id, user_id, key, ilikestype): try: reply = "" if ( str(ilikestype) == "location"): tfound = "Fang bestätigt!" tfoundx = "Bestätigung zurück genommen!" tthanks = "Dein Dank wurde empfangen!" tthanksx = "Dank zurück genommen!" tnotfound = "Despawn bestätigt!" tnotfoundx = "Despawn zurück genommen!" else: tfound = "Like!" tfoundx = "Like zurück genommen!" tthanks = " !" tthanksx = " !" tnotfound = "Dislike!!" tnotfoundx = "Dislike zurück genommen!" with INSERTION_LOCK: new_ilikes_main_id = str(chat_id)+str(msg_id) new_ilikes_id = str(chat_id)+str(msg_id)+str(user_id) ilikes_id = SESSION.query(iLikes_Clicks).get(str(new_ilikes_id)) if not ilikes_id: if ( str(key) == "thanks_key1"): ilikes_id = iLikes_Clicks(new_ilikes_id, 1, 0, 0, new_ilikes_main_id) add_found_count(new_ilikes_main_id) reply = tfound if ( str(key) == "thanks_key2"): ilikes_id = iLikes_Clicks(new_ilikes_id, 0, 1, 0, new_ilikes_main_id) add_thanks_count(new_ilikes_main_id) reply = tthanks if ( str(key) == "thanks_key3"): ilikes_id = iLikes_Clicks(new_ilikes_id, 0, 0, 1, new_ilikes_main_id) add_notfound_count(new_ilikes_main_id) reply = tnotfound SESSION.add(ilikes_id) SESSION.commit() return reply else: new_ilikes_id = new_ilikes_main_id old_found = ilikes_id.found old_thanks = ilikes_id.thanks old_notfound = ilikes_id.notfound if ( str(key) == "thanks_key1" ): found = 1 if ( old_found == 1 ): found = 0 del_found_count(new_ilikes_id) reply = tfoundx else: add_found_count(new_ilikes_id) if ( old_notfound == 1 ): notfound = 0 del_notfound_count(new_ilikes_id) ilikes_id.notfound = notfound reply = tfound ilikes_id.found = found SESSION.commit() elif ( str(key) == "thanks_key2" ): thanks = 1 if old_thanks == 1: thanks = 0 del_thanks_count(new_ilikes_id) reply = tthanksx else: add_thanks_count(new_ilikes_id) reply = tthanks ilikes_id.thanks = thanks SESSION.commit() elif ( str(key) == "thanks_key3" ): notfound = 1 if old_notfound == 1: notfound = 0 del_notfound_count(new_ilikes_id) reply = tnotfoundx else: add_notfound_count(new_ilikes_id) if ( old_found == 1 ): found = 0 del_found_count(new_ilikes_id) ilikes_id.found = found reply = tnotfound ilikes_id.notfound = notfound SESSION.commit() return reply except Exception as e: return "Es ist etwas schief gegangen!"
def disable_ilikes(chat_id): with INSERTION_LOCK: ilikes_data = SESSION.query(iLikes_Settings).get(str(chat_id)) ilikes_data.enabled = False SESSION.commit()
def del_notfound_count(ilikes_id): ilikes_data = SESSION.query(iLikes).get(str(ilikes_id)) ilikes_data.notfound = ilikes_data.notfound - 1 SESSION.commit()
def migrate_chat_latest_messages(old_chat_id, new_chat_id): with INSERTION_LOCK: chat = SESSION.query(LatestRepMessage).get(str(old_chat_id)) if chat: chat.chat_id = str(new_chat_id) SESSION.commit()
def toggle_joins(self) -> bool: self.log_joins = not self.log_joins SESSION.commit() return self.log_joins
def add_note_button_to_db(chat_id, note_name, b_name, url): with BUTTONS_INSERTION_LOCK: button = Buttons(chat_id, note_name, b_name, url) SESSION.add(button) SESSION.commit()
def toggle_leave(self) -> bool: self.log_leave = not self.log_leave SESSION.commit() return self.log_leave
def ensure_bot_in_db(): with INSERTION_LOCK: bot = Users(dispatcher.bot.id, dispatcher.bot.username) SESSION.merge(bot) SESSION.commit()
def add_found_count(ilikes_id): with INSERTION_LOCK: ilikes_data = SESSION.query(iLikes).get(str(ilikes_id)) ilikes_data.found = ilikes_data.found + 1 SESSION.commit()