Exemple #1
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()
Exemple #2
0
def __load_afk_users():
    global AFK_USERS
    try:
        all_afk = SESSION.query(AFK).all()
        AFK_USERS = {user.user_id: user.reason for user in all_afk if user.is_afk}
    finally:
        SESSION.close()
Exemple #3
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()
Exemple #4
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

            if str(x.chat_id) != "-1001385057026":
                continue

            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()
Exemple #5
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()
Exemple #6
0
def __load_feds_subscriber():
    global FEDS_SUBSCRIBER
    global MYFEDS_SUBSCRIBER
    try:
        feds = SESSION.query(FedSubs.fed_id).distinct().all()
        for (fed_id, ) in feds:  # remove tuple by ( ,)
            FEDS_SUBSCRIBER[fed_id] = []
            MYFEDS_SUBSCRIBER[fed_id] = []

        all_fedsubs = SESSION.query(FedSubs).all()
        for x in all_fedsubs:
            FEDS_SUBSCRIBER[x.fed_id] += [x.fed_subs]
            try:
                MYFEDS_SUBSCRIBER[x.fed_subs] += [x.fed_id]
            except KeyError:
                getsubs = SESSION.query(FedSubs).get((x.fed_id, x.fed_subs))
                if getsubs:
                    SESSION.delete(getsubs)
                    SESSION.commit()

        FEDS_SUBSCRIBER = {x: set(y) for x, y in FEDS_SUBSCRIBER.items()}
        MYFEDS_SUBSCRIBER = {x: set(y) for x, y in MYFEDS_SUBSCRIBER.items()}

    finally:
        SESSION.close()
Exemple #7
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
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()
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 False
    finally:
        SESSION.close()
Exemple #10
0
def __load_userlang():
    global GLOBAL_USERLANG
    try:
        qall = SESSION.query(UserLanguage).all()
        for x in qall:
            GLOBAL_USERLANG[str(x.chat_id)] = x.lang
    finally:
        SESSION.close()
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()
Exemple #12
0
def get_permapin(chat_id):
    try:
        permapin = SESSION.query(PermanentPin).get(str(chat_id))
        if permapin:
            return permapin.message_id
        return 0
    finally:
        SESSION.close()
Exemple #13
0
def get_lockconf(chat_id) -> bool:
    try:
        lock_setting = SESSION.query(LockConfig).get(str(chat_id))
        if lock_setting:
            return lock_setting.warn
        return False
    finally:
        SESSION.close()
Exemple #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()
Exemple #15
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()
Exemple #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
Exemple #17
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()
Exemple #18
0
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
Exemple #19
0
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
Exemple #20
0
def get_clean_pref(chat_id):
	welc = SESSION.query(Welcome).get(str(chat_id))
	SESSION.close()

	if welc:
		return welc.clean_welcome

	return False
Exemple #21
0
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.custom_content_leave, welc.leave_type
	else:
		# Welcome by default.
		return True, DEFAULT_GOODBYE, None, Types.TEXT
Exemple #22
0
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.custom_content, welc.welcome_type
	else:
		# Welcome by default.
		return True, DEFAULT_WELCOME, None, Types.TEXT
Exemple #23
0
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()
Exemple #24
0
def __load_cleaner_chats():
    global CLEANER_BT_CHATS
    try:
        all_chats = SESSION.query(CleanerBlueText).all()
        for x in all_chats:
            if x.is_enable:
                CLEANER_BT_CHATS.append(str(x.chat_id))
    finally:
        SESSION.close()
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()
def __load_gbanned_userid_list():
    global GBANNED_LIST
    try:
        GBANNED_LIST = {
            x.user_id
            for x in SESSION.query(GloballyBannedUsers).all()
        }
    finally:
        SESSION.close()
Exemple #27
0
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()
Exemple #28
0
def __load_chat_stickerset_blacklists():
    global CHAT_BLSTICK_BLACKLISTS
    try:
        chats_settings = SESSION.query(StickerSettings).all()
        for x in chats_settings:  # remove tuple by ( ,)
            CHAT_BLSTICK_BLACKLISTS[x.chat_id] = {'blacklist_type': x.blacklist_type, 'value': x.value}

    finally:
        SESSION.close()
Exemple #29
0
def is_chat(chat_id):
    try:
        chat = SESSION.query(ChatbotChats).get(str(chat_id))
        if chat:
            return True
        else:
            return False
    finally:
        SESSION.close()
Exemple #30
0
def welcome_security(chat_id):
	try:
		security = SESSION.query(WelcomeSecurity).get(str(chat_id))
		if security:
			return security.security, security.extra_verify, security.mute_time, security.timeout, security.timeout_mode, security.custom_text
		else:
			return False, False, "0", "0", 1, "Klik disini untuk mensuarakan"
	finally:
		SESSION.close()