コード例 #1
0
def get_user_num_chats(user_id):
    try:
        return (
            SESSION.query(ChatMembers).filter(ChatMembers.user == int(user_id)).count()
        )
    finally:
        SESSION.close()
コード例 #2
0
def get_user_com_chats(user_id):
    try:
        chat_members = (SESSION.query(ChatMembers).filter(
            ChatMembers.user == int(user_id)).all())
        return [i.chat for i in chat_members]
    finally:
        SESSION.close()
コード例 #3
0
def get_buttons(chat_id, keyword):
    try:
        return (SESSION.query(Buttons).filter(
            Buttons.chat_id == str(chat_id),
            Buttons.keyword == keyword).order_by(Buttons.id).all())
    finally:
        SESSION.close()
コード例 #4
0
def __load_log_channels():
    global CHANNELS
    try:
        all_chats = SESSION.query(GroupLogs).all()
        CHANNELS = {chat.chat_id: chat.log_channel for chat in all_chats}
    finally:
        SESSION.close()
コード例 #5
0
def __load_flood_settings():
    global CHAT_FLOOD
    try:
        all_chats = SESSION.query(FloodControl).all()
        CHAT_FLOOD = {chat.chat_id: (None, DEF_COUNT, chat.limit) for chat in all_chats}
    finally:
        SESSION.close()
コード例 #6
0
ファイル: welcome_sql.py プロジェクト: kxrumi/MeguRobot
def get_welc_buttons(chat_id):
    try:
        return (SESSION.query(WelcomeButtons).filter(
            WelcomeButtons.chat_id == str(chat_id)).order_by(
                WelcomeButtons.id).all())
    finally:
        SESSION.close()
コード例 #7
0
def get_note(chat_id, note_name):
    try:
        return (SESSION.query(Notes).filter(
            func.lower(Notes.name) == note_name,
            Notes.chat_id == str(chat_id)).first())
    finally:
        SESSION.close()
コード例 #8
0
def get_buttons(chat_id, note_name):
    try:
        return (SESSION.query(Buttons).filter(
            Buttons.chat_id == str(chat_id),
            Buttons.note_name == note_name).order_by(Buttons.id).all())
    finally:
        SESSION.close()
コード例 #9
0
ファイル: welcome_sql.py プロジェクト: kxrumi/MeguRobot
def get_gdbye_buttons(chat_id):
    try:
        return (SESSION.query(GoodbyeButtons).filter(
            GoodbyeButtons.chat_id == str(chat_id)).order_by(
                GoodbyeButtons.id).all())
    finally:
        SESSION.close()
コード例 #10
0
def __migrate_filters():
    try:
        all_filters = SESSION.query(CustomFilters).distinct().all()
        for x in all_filters:
            if x.is_document:
                file_type = Types.DOCUMENT
            elif x.is_image:
                file_type = Types.PHOTO
            elif x.is_video:
                file_type = Types.VIDEO
            elif x.is_sticker:
                file_type = Types.STICKER
            elif x.is_audio:
                file_type = Types.AUDIO
            elif x.is_voice:
                file_type = Types.VOICE
            else:
                file_type = Types.TEXT

            print(str(x.chat_id), x.keyword, x.reply, file_type.value)
            if file_type == Types.TEXT:
                filt = CustomFilters(str(x.chat_id), x.keyword, x.reply,
                                     file_type.value, None)
            else:
                filt = CustomFilters(str(x.chat_id), x.keyword, None,
                                     file_type.value, x.reply)

            SESSION.add(filt)
            SESSION.commit()

    finally:
        SESSION.close()
コード例 #11
0
def user_should_report(user_id: int) -> bool:
    try:
        user_setting = SESSION.query(ReportingUserSettings).get(user_id)
        if user_setting:
            return user_setting.should_report
        return True
    finally:
        SESSION.close()
コード例 #12
0
def chat_should_report(chat_id: Union[str, int]) -> bool:
    try:
        chat_setting = SESSION.query(ReportingChatSettings).get(str(chat_id))
        if chat_setting:
            return chat_setting.should_report
        return True
    finally:
        SESSION.close()
コード例 #13
0
def group_is_bl(chat_id: Union[str, int]) -> bool:
    try:
        chat = SESSION.query(BlacklistGroups).get(str(chat_id))
        if chat:
            return chat.blacklist
        return False
    finally:
        SESSION.close()
コード例 #14
0
def get_chat_filters(chat_id):
    try:
        return (SESSION.query(CustomFilters).filter(
            CustomFilters.chat_id == str(chat_id)).order_by(
                func.length(CustomFilters.keyword).desc()).order_by(
                    CustomFilters.keyword.asc()).all())
    finally:
        SESSION.close()
コード例 #15
0
def __load_gban_stat_list():
    global GBANSTAT_LIST
    try:
        GBANSTAT_LIST = {
            x.chat_id for x in SESSION.query(GbanSettings).all() if not x.setting
        }
    finally:
        SESSION.close()
コード例 #16
0
def get_rules(chat_id):
    rules = SESSION.query(Rules).get(str(chat_id))
    ret = ""
    if rules:
        ret = rules.rules

    SESSION.close()
    return ret
コード例 #17
0
def rem_chat(chat_id):
    with INSERTION_LOCK:
        chat = SESSION.query(Chats).get(str(chat_id))
        if chat:
            SESSION.delete(chat)
            SESSION.commit()
        else:
            SESSION.close()
コード例 #18
0
def get_user(user_id):
    user = SESSION.query(LastFMUsers).get(str(user_id))
    rep = ""
    if user:
        rep = str(user.username)

    SESSION.close()
    return rep
コード例 #19
0
def get_reason(user_id):
    user = SESSION.query(BlacklistUsers).get(str(user_id))
    rep = ""
    if user:
        rep = user.reason

    SESSION.close()
    return rep
コード例 #20
0
ファイル: welcome_sql.py プロジェクト: kxrumi/MeguRobot
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
コード例 #21
0
ファイル: welcome_sql.py プロジェクト: kxrumi/MeguRobot
def clean_service(chat_id: Union[str, int]) -> bool:
    try:
        chat_setting = SESSION.query(CleanServiceSetting).get(str(chat_id))
        if chat_setting:
            return chat_setting.clean_service
        return False
    finally:
        SESSION.close()
コード例 #22
0
ファイル: welcome_sql.py プロジェクト: kxrumi/MeguRobot
def get_clean_pref(chat_id):
    welc = SESSION.query(Welcome).get(str(chat_id))
    SESSION.close()

    if welc:
        return welc.clean_welcome

    return False
コード例 #23
0
ファイル: welcome_sql.py プロジェクト: kxrumi/MeguRobot
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
コード例 #24
0
ファイル: welcome_sql.py プロジェクト: kxrumi/MeguRobot
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
コード例 #25
0
ファイル: welcome_sql.py プロジェクト: kxrumi/MeguRobot
def get_welc_mutes_pref(chat_id):
    welcomemutes = SESSION.query(WelcomeMute).get(str(chat_id))
    SESSION.close()

    if welcomemutes:
        return welcomemutes.welcomemutes

    return False
コード例 #26
0
ファイル: welcome_sql.py プロジェクト: kxrumi/MeguRobot
def welcome_mutes(chat_id):
    try:
        welcomemutes = SESSION.query(WelcomeMute).get(str(chat_id))
        if welcomemutes:
            return welcomemutes.welcomemutes
        return False
    finally:
        SESSION.close()
コード例 #27
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()
コード例 #28
0
def is_nsfw(chat_id):
    try:
        chat = SESSION.query(NSFWChats).get(str(chat_id))
        if chat:
            return True
        else:
            return False
    finally:
        SESSION.close()
コード例 #29
0
def get_userid_by_name(username):
    try:
        return (
            SESSION.query(Users)
            .filter(func.lower(Users.username) == username.lower())
            .all()
        )
    finally:
        SESSION.close()
コード例 #30
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()