コード例 #1
0
ファイル: welcome_sql.py プロジェクト: BotHub-1/Aira
def welcome_mutes(chat_id):
    try:
        welcomemutes = SESSION.query(WelcomeMute).get(str(chat_id))
        if welcomemutes:
            return welcomemutes.welcomemutes
        return False
    finally:
        SESSION.close()
コード例 #2
0
ファイル: welcome_sql.py プロジェクト: BotHub-1/Aira
def get_welc_pref(chat_id):
    welc = SESSION.query(Welcome).get(str(chat_id))
    SESSION.close()
    if welc:
        return welc.should_welcome, welc.custom_welcome, welc.welcome_type
    else:
        # Welcome by default.
        return True, DEFAULT_WELCOME, Types.TEXT
コード例 #3
0
ファイル: welcome_sql.py プロジェクト: BotHub-1/Aira
def get_cas_status(chat_id):
    try:
        resultObj = SESSION.query(CombotCASStatus).get(str(chat_id))
        if resultObj:
            return resultObj.status
        return True
    finally:
        SESSION.close()
コード例 #4
0
ファイル: welcome_sql.py プロジェクト: BotHub-1/Aira
def set_welcome_mutes(chat_id, welcomemutes):
    with WM_LOCK:
        prev = SESSION.query(WelcomeMute).get((str(chat_id)))
        if prev:
            SESSION.delete(prev)
        welcome_m = WelcomeMute(str(chat_id), welcomemutes)
        SESSION.add(welcome_m)
        SESSION.commit()
コード例 #5
0
ファイル: welcome_sql.py プロジェクト: BotHub-1/Aira
def get_custom_welcome(chat_id):
    welcome_settings = SESSION.query(Welcome).get(str(chat_id))
    ret = DEFAULT_WELCOME
    if welcome_settings and welcome_settings.custom_welcome:
        ret = welcome_settings.custom_welcome

    SESSION.close()
    return ret
コード例 #6
0
ファイル: welcome_sql.py プロジェクト: BotHub-1/Aira
def get_clean_pref(chat_id):
    welc = SESSION.query(Welcome).get(str(chat_id))
    SESSION.close()

    if welc:
        return welc.clean_welcome

    return False
コード例 #7
0
ファイル: welcome_sql.py プロジェクト: BotHub-1/Aira
def get_del_pref(chat_id):
    welc = SESSION.query(Welcome).get(str(chat_id))
    SESSION.close()

    if welc:
        return welc.del_joined

    return False
コード例 #8
0
ファイル: notes_sql.py プロジェクト: mry0000/MissSerabot
def rm_note(chat_id, note_name):
    with NOTES_INSERTION_LOCK:
        note = SESSION.query(Notes).get((str(chat_id), note_name))
        if note:
            with BUTTONS_INSERTION_LOCK:
                buttons = SESSION.query(Buttons).filter(Buttons.chat_id == str(chat_id),
                                                        Buttons.note_name == note_name).all()
                for btn in buttons:
                    SESSION.delete(btn)

            SESSION.delete(note)
            SESSION.commit()
            return True

        else:
            SESSION.close()
            return False
コード例 #9
0
ファイル: welcome_sql.py プロジェクト: BotHub-1/Aira
def get_gdbye_pref(chat_id):
    welc = SESSION.query(Welcome).get(str(chat_id))
    SESSION.close()
    if welc:
        return welc.should_goodbye, welc.custom_leave, welc.leave_type
    else:
        # Welcome by default.
        return True, DEFAULT_GOODBYE, Types.TEXT
コード例 #10
0
def get_rules(chat_id):
    rules = SESSION.query(Rules).get(str(chat_id))
    ret = ""
    if rules:
        ret = rules.rules

    SESSION.close()
    return ret
コード例 #11
0
def __load_all_feds_settings():
    global FEDERATION_NOTIFICATION
    try:
        getuser = SESSION.query(FedsUserSettings).all()
        for x in getuser:
            FEDERATION_NOTIFICATION[str(x.user_id)] = x.should_report
    finally:
        SESSION.close()
コード例 #12
0
ファイル: welcome_sql.py プロジェクト: BotHub-1/Aira
def get_custom_gdbye(chat_id):
    welcome_settings = SESSION.query(Welcome).get(str(chat_id))
    ret = DEFAULT_GOODBYE
    if welcome_settings and welcome_settings.custom_leave:
        ret = welcome_settings.custom_leave

    SESSION.close()
    return ret
コード例 #13
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
コード例 #14
0
def __load_blacklist_userid_list():
    global BLACKLIST_USERS
    try:
        BLACKLIST_USERS = {
            int(x.user_id)
            for x in SESSION.query(BlacklistUsers).all()
        }
    finally:
        SESSION.close()
コード例 #15
0
ファイル: locks_sql.py プロジェクト: mry0000/MissSerabot
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
コード例 #16
0
ファイル: rss_sql.py プロジェクト: mry0000/MissSerabot
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()
コード例 #17
0
def __load_gkick_userid_list():
    global GKICK_LIST
    try:
        GKICK_LIST = {
            x.user_id
            for x in SESSION.query(GloballyKickedUsers).all()
        }
    finally:
        SESSION.close()
コード例 #18
0
def gkick_setvalue(user_id, name, value):
    user = SESSION.query(GloballyKickedUsers).get(user_id)
    if user:
        user.times = value
    if not user:
        user = GloballyKickedUsers(user_id, name, value)
    SESSION.merge(user)
    SESSION.commit()
    __load_gkick_userid_list()
コード例 #19
0
ファイル: userinfo_sql.py プロジェクト: mry0000/MissSerabot
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()
コード例 #20
0
ファイル: warns_sql.py プロジェクト: mry0000/MissSerabot
def __load_chat_warn_filters():
    global WARN_FILTERS
    try:
        chats = SESSION.query(WarnFilters.chat_id).distinct().all()
        for (chat_id, ) in chats:  # remove tuple by ( ,)
            WARN_FILTERS[chat_id] = []

        all_filters = SESSION.query(WarnFilters).all()
        for x in all_filters:
            WARN_FILTERS[x.chat_id] += [x.keyword]

        WARN_FILTERS = {
            x: sorted(set(y), key=lambda i: (-len(i), i))
            for x, y in WARN_FILTERS.items()
        }

    finally:
        SESSION.close()
コード例 #21
0
ファイル: locks_sql.py プロジェクト: mry0000/MissSerabot
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
コード例 #22
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()
コード例 #23
0
ファイル: antiflood_sql.py プロジェクト: mry0000/MissSerabot
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()
コード例 #24
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()
コード例 #25
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()
コード例 #26
0
def allow_connect_to_chat(chat_id: Union[str, int]) -> bool:
    try:
        chat_setting = SESSION.query(ChatAccessConnectionSettings).get(
            str(chat_id))
        if chat_setting:
            return chat_setting.allow_connect_to_chat
        return False
    finally:
        SESSION.close()
コード例 #27
0
ファイル: disable_sql.py プロジェクト: Vivektp/Filter-BOT
def __load_disabled_commands():
    global DISABLED
    try:
        all_chats = SESSION.query(Disable).all()
        for chat in all_chats:
            DISABLED.setdefault(chat.chat_id, set()).add(chat.command)

    finally:
        SESSION.close()
コード例 #28
0
ファイル: lydia_sql.py プロジェクト: mry0000/MissSerabot
def is_chat(chat_id):
    try:
        chat = SESSION.query(ChatbotChats).get(str(chat_id))
        if chat:
            return True
        else:
            return False
    finally:
        SESSION.close()
コード例 #29
0
ファイル: lydia_sql.py プロジェクト: mry0000/MissSerabot
def get_ses(chat_id):
    autochat = SESSION.query(ChatbotChats).get(str(chat_id))
    sesh = ""
    exp = ""
    if autochat:
        sesh = str(autochat.ses_id)
        exp = str(autochat.expires)
        
    SESSION.close()
    return sesh, exp
コード例 #30
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