def add_repo_to_db(chat_id, name, value, backoffset): with GIT_LOCK: prev = SESSION.query(GitHub).get((str(chat_id), name)) if prev: SESSION.delete(prev) repo = GitHub(str(chat_id), name, value, backoffset) SESSION.add(repo) SESSION.commit()
def migrate_chat(old_chat_id, new_chat_id): with ASPAM_SETTING_LOCK: gban = SESSION.query(AntispamSettings).get(str(old_chat_id)) if gban: gban.chat_id = new_chat_id SESSION.add(gban) SESSION.commit()
def switch_to_locale(chat_id, locale_name): with LOCALES_INSERTION_LOCK: prev = SESSION.query(Locales).get((str(chat_id))) if prev: SESSION.delete(prev) switch_locale = Locales(str(chat_id), locale_name) SESSION.add(switch_locale) SESSION.commit()
def init_permissions(chat_id, reset=False): curr_perm = SESSION.query(Permissions).get(str(chat_id)) if reset: SESSION.delete(curr_perm) SESSION.flush() perm = Permissions(str(chat_id)) SESSION.add(perm) SESSION.commit() return perm
def set_lockconf(chat_id, should_warn): with CONF_LOCK: lock_setting = SESSION.query(LockConfig).get(str(chat_id)) if not lock_setting: lock_setting = LockConfig(str(chat_id)) lock_setting.warn = should_warn SESSION.add(lock_setting) SESSION.commit()
def init_restrictions(chat_id, reset=False): curr_restr = SESSION.query(Restrictions).get(str(chat_id)) if reset: SESSION.delete(curr_restr) SESSION.flush() restr = Restrictions(str(chat_id)) SESSION.add(restr) SESSION.commit() return restr
def set_rules(chat_id, rules_text): with INSERTION_LOCK: rules = SESSION.query(Rules).get(str(chat_id)) if not rules: rules = Rules(str(chat_id)) rules.rules = rules_text SESSION.add(rules) SESSION.commit()
def set_allow_connect_to_chat(chat_id: Union[int, str], setting: bool): with CHAT_ACCESS_LOCK: chat_setting = SESSION.query(ChatAccessConnectionSettings).get(str(chat_id)) if not chat_setting: chat_setting = ChatAccessConnectionSettings(chat_id, setting) chat_setting.allow_connect_to_chat = setting SESSION.add(chat_setting) SESSION.commit()
def migrate_chat(old_chat_id, new_chat_id): with LOGS_INSERTION_LOCK: if chat := SESSION.query(GroupLogs).get(str(old_chat_id)): chat.chat_id = str(new_chat_id) SESSION.add(chat) if str(old_chat_id) in CHANNELS: CHANNELS[str(new_chat_id)] = CHANNELS.get(str(old_chat_id)) SESSION.commit()
def new_fed(owner_id, fed_name, fed_id): with FEDS_LOCK: global FEDERATION_BYOWNER, FEDERATION_BYFEDID, FEDERATION_BYNAME fed = Federations(str(owner_id), fed_name, str(fed_id), 'Rules is not set in this federation.', None, str({ 'owner': str(owner_id), 'members': '[]' })) SESSION.add(fed) SESSION.commit() FEDERATION_BYOWNER[str(owner_id)] = ({ 'fid': str(fed_id), 'fname': fed_name, 'frules': 'Rules is not set in this federation.', 'flog': None, 'fusers': str({ 'owner': str(owner_id), 'members': '[]' }) }) FEDERATION_BYFEDID[str(fed_id)] = ({ 'owner': str(owner_id), 'fname': fed_name, 'frules': 'Rules is not set in this federation.', 'flog': None, 'fusers': str({ 'owner': str(owner_id), 'members': '[]' }) }) FEDERATION_BYNAME[fed_name] = ({ 'fid': str(fed_id), 'owner': str(owner_id), 'frules': 'Rules is not set in this federation.', 'flog': None, 'fusers': str({ 'owner': str(owner_id), 'members': '[]' }) }) return fed
def set_user_setting(user_id: int, setting: bool): with USER_LOCK: user_setting = SESSION.query(ReportingUserSettings).get(user_id) if not user_setting: user_setting = ReportingUserSettings(user_id) user_setting.should_report = setting SESSION.add(user_setting) SESSION.commit()
def reset_warns(user_id, chat_id): with WARN_INSERTION_LOCK: if warned_user := SESSION.query(Warns).get((user_id, str(chat_id))): warned_user.num_warns = 0 warned_user.reasons = [] SESSION.add(warned_user) SESSION.commit() SESSION.close()
def set_clean_service(chat_id: Union[int, str], setting: bool): with CS_LOCK: chat_setting = SESSION.query(CleanServiceSetting).get(str(chat_id)) if not chat_setting: chat_setting = CleanServiceSetting(chat_id) chat_setting.clean_service = setting SESSION.add(chat_setting) SESSION.commit()
def connect(user_id, chat_id): with CONNECTION_INSERTION_LOCK: prev = SESSION.query(Connection).get((int(user_id))) if prev: SESSION.delete(prev) connect_to_chat = Connection(int(user_id), chat_id) SESSION.add(connect_to_chat) SESSION.commit() return True
def add_history(user_id, chat_id1, chat_id2, chat_id3, updated): with HISTORY_LOCK: prev = SESSION.query(ConnectionHistory).get((int(user_id))) if prev: SESSION.delete(prev) history = ConnectionHistory(user_id, chat_id1, chat_id2, chat_id3, updated) SESSION.add(history) SESSION.commit()
def set_chat_setting(chat_id: Union[int, str], setting: bool): with CHAT_LOCK: chat_setting = SESSION.query(AntiArabicChatSettings).get(str(chat_id)) if not chat_setting: chat_setting = AntiArabicChatSettings(chat_id) chat_setting.antiarabic = setting SESSION.add(chat_setting) SESSION.commit()
def set_permapin(chat_id, message_id): with PERMPIN_LOCK: permpin = SESSION.query(PermanentPin).get(str(chat_id)) if not permpin: permpin = PermanentPin(chat_id) permpin.message_id = int(message_id) SESSION.add(permpin) SESSION.commit()
def set_chat_setting(chat_id: Union[int, str], setting: bool): with CHAT_LOCK: chat_setting = SESSION.query(ReportingChatSettings).get(str(chat_id)) if not chat_setting: chat_setting = ReportingChatSettings(chat_id) chat_setting.should_report = setting SESSION.add(chat_setting) SESSION.commit()
def set_user_me_info(user_id, info): with INSERTION_LOCK: userinfo = SESSION.query(UserInfo).get(user_id) if userinfo: userinfo.info = info else: userinfo = UserInfo(user_id, info) SESSION.add(userinfo) 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 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_user_bio(user_id, bio): with INSERTION_LOCK: userbio = SESSION.query(UserBio).get(user_id) if userbio: userbio.bio = bio else: userbio = UserBio(user_id, bio) SESSION.add(userbio) SESSION.commit()
def set_warn_strength(chat_id, soft_warn): with WARN_SETTINGS_LOCK: curr_setting = SESSION.query(WarnSettings).get(str(chat_id)) if not curr_setting: curr_setting = WarnSettings(chat_id, soft_warn=soft_warn) curr_setting.soft_warn = soft_warn SESSION.add(curr_setting) SESSION.commit()
def set_command_reaction(chat_id: Union[int, str], setting: bool): with CHAT_LOCK: chat_setting = SESSION.query(CommandReactionChatSettings).get( str(chat_id)) if not chat_setting: chat_setting = CommandReactionChatSettings(chat_id) chat_setting.comm_reaction = setting SESSION.add(chat_setting) SESSION.commit()
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_user(user_id, username): with INSERTION_LOCK: user = SESSION.query(LastFMUsers).get(str(user_id)) if not user: user = LastFMUsers(str(user_id), str(username)) else: user.username = str(username) SESSION.add(user) 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_warn_mode(chat_id, warn_mode): with WARN_SETTINGS_LOCK: curr_setting = SESSION.query(WarnSettings).get(str(chat_id)) if not curr_setting: curr_setting = WarnSettings(chat_id, warn_mode=warn_mode) curr_setting.warn_mode = warn_mode SESSION.add(curr_setting) SESSION.commit()
def private_note(chat_id, is_private, is_delete): with PMNOTE_INSERTION_LOCK: curr = SESSION.query(PrivateNote).get(str(chat_id)) if curr: SESSION.delete(curr) curr = PrivateNote(str(chat_id), is_private, is_delete) SESSION.add(curr) SESSION.commit()
def disable_antispam(chat_id): with ASPAM_SETTING_LOCK: chat = SESSION.query(AntispamSettings).get(str(chat_id)) if not chat: chat = AntispamSettings(chat_id, False) chat.setting = False SESSION.add(chat) SESSION.commit() GBANSTAT_LIST.add(str(chat_id))