Exemplo n.º 1
0
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()
Exemplo n.º 2
0
def disconnect(user_id):
    with CONNECTION_INSERTION_LOCK:
        disconnect = SESSION.query(Connection).get((int(user_id)))
        if disconnect:
            SESSION.delete(disconnect)
            SESSION.commit()
            return True
        SESSION.close()
        return False
Exemplo n.º 3
0
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
Exemplo n.º 4
0
def disable_antichannel(chat_id: int):
    with ANTICHANNEL_SETTING_LOCK:
        chat = SESSION.query(AntiChannelSettings).get(str(chat_id))
        if not chat:
            chat = AntiChannelSettings(chat_id, False)

        chat.setting = False
        SESSION.add(chat)
        SESSION.commit()
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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()
Exemplo n.º 7
0
def user_demote_fed(fed_id, user_id):
    with FEDS_LOCK:
        global FEDERATION_BYOWNER, FEDERATION_BYFEDID, FEDERATION_BYNAME
        # Variables
        getfed = FEDERATION_BYFEDID.get(str(fed_id))
        owner_id = getfed["owner"]
        fed_name = getfed["fname"]
        fed_rules = getfed["frules"]
        fed_log = getfed["flog"]
        # Temp set
        try:
            members = eval(eval(getfed["fusers"])["members"])
        except ValueError:
            return False
        members.remove(user_id)
        # Set user
        FEDERATION_BYOWNER[str(owner_id)]["fusers"] = str({
            "owner":
            str(owner_id),
            "members":
            str(members)
        })
        FEDERATION_BYFEDID[str(fed_id)]["fusers"] = str({
            "owner": str(owner_id),
            "members": str(members)
        })
        FEDERATION_BYNAME[fed_name]["fusers"] = str({
            "owner": str(owner_id),
            "members": str(members)
        })
        # Set on database
        fed = Federations(
            str(owner_id),
            fed_name,
            str(fed_id),
            fed_rules,
            fed_log,
            str({
                "owner": str(owner_id),
                "members": str(members)
            }),
        )
        SESSION.merge(fed)
        SESSION.commit()
        return True

        curr = SESSION.query(UserF).all()
        result = False
        for r in curr:
            if int(r.user_id) == int(user_id):
                if r.fed_id == fed_id:
                    SESSION.delete(r)
                    SESSION.commit()
                    result = True

        SESSION.close()
        return result
Exemplo n.º 8
0
def migrate_chat(old_chat_id, new_chat_id):
    with INSERTION_FLOOD_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()
Exemplo n.º 9
0
def disapprove(chat_id, user_id):
    with APPROVE_INSERTION_LOCK:
        disapprove_user = SESSION.query(Approvals).get((str(chat_id), user_id))
        if disapprove_user:
            SESSION.delete(disapprove_user)
            SESSION.commit()
            return True
        SESSION.close()
        return False
Exemplo n.º 10
0
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()
Exemplo n.º 11
0
def update_url(row_id, new_entry_links):
    with INSERTION_LOCK:
        row = SESSION.query(RSS).get(row_id)

        # set the new old_entry_link with the latest update from the RSS Feed
        row.old_entry_link = new_entry_links[0]

        # commit the changes to the DB
        SESSION.commit()
Exemplo n.º 12
0
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 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()
Exemplo n.º 14
0
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()
Exemplo n.º 15
0
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
Exemplo n.º 16
0
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
Exemplo n.º 17
0
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()
Exemplo n.º 18
0
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))
Exemplo n.º 19
0
def set_cleanbt(chat_id, is_enable):
    with CLEANER_CHAT_SETTINGS:
        curr = SESSION.query(CleanerBlueTextChatSettings).get(str(chat_id))
        if curr:
            SESSION.delete(curr)

        newcurr = CleanerBlueTextChatSettings(str(chat_id), is_enable)

        SESSION.add(newcurr)
        SESSION.commit()
Exemplo n.º 20
0
def disable_nlp(chat_id):
    with NLP_SETTING_LOCK:
        chat = SESSION.query(NLPSettings).get(str(chat_id))
        if not chat:
            chat = NLPSettings(chat_id, False)

        chat.setting = False
        SESSION.add(chat)
        SESSION.commit()
        NLPSTAT_LIST.add(str(chat_id))
Exemplo n.º 21
0
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()
Exemplo n.º 22
0
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()
Exemplo n.º 23
0
def migrate_chat(old_chat_id, new_chat_id):
    with LOGS_INSERTION_LOCK:
        chat = SESSION.query(GroupLogs).get(str(old_chat_id))
        if chat:
            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()
Exemplo n.º 24
0
def set_privnotes_setting(chat_id, setting):
    with PRIVATE_NOTES_LOCK:
        res = SESSION.query(PrivateNotes).get(str(chat_id))
        if not res:
            res = PrivateNotes(str(chat_id), setting)
            SESSION.add(res)
            SESSION.flush()
        else:
            res.setting = setting
        SESSION.commit()
Exemplo n.º 25
0
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()
Exemplo n.º 26
0
def set_warn_limit(chat_id, warn_limit):
    with WARN_SETTINGS_LOCK:
        curr_setting = SESSION.query(WarnSettings).get(str(chat_id))
        if not curr_setting:
            curr_setting = WarnSettings(chat_id, warn_limit=warn_limit)

        curr_setting.warn_limit = warn_limit

        SESSION.add(curr_setting)
        SESSION.commit()
Exemplo n.º 27
0
def reset_warns(user_id, chat_id):
    with WARN_INSERTION_LOCK:
        warned_user = SESSION.query(Warns).get((user_id, str(chat_id)))
        if warned_user:
            warned_user.num_warns = 0
            warned_user.reasons = []

            SESSION.add(warned_user)
            SESSION.commit()
        SESSION.close()
Exemplo n.º 28
0
def disapprove(chat_id, user_id):
    with APPROVE_INSERTION_LOCK:
        note = SESSION.query(Approvals).get((str(chat_id), user_id))
        if note:
            SESSION.delete(note)
            SESSION.commit()
            return True
        else:
            SESSION.close()
            return False
Exemplo n.º 29
0
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()
Exemplo n.º 30
0
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))