def is_locked(chat_id, lock_type): curr_perm = SESSION.query(Permissions).get(str(chat_id)) SESSION.close() if not curr_perm: return False elif lock_type == "sticker": return curr_perm.sticker elif lock_type == "photo": return curr_perm.photo elif lock_type == "audio": return curr_perm.audio elif lock_type == "voice": return curr_perm.voice elif lock_type == "contact": return curr_perm.contact elif lock_type == "video": return curr_perm.video elif lock_type == "document": return curr_perm.document elif lock_type == "gif": return curr_perm.gif elif lock_type == "url": return curr_perm.url elif lock_type == "bots": return curr_perm.bots elif lock_type == "forward": return curr_perm.forward elif lock_type == "game": return curr_perm.game elif lock_type == "location": return curr_perm.location
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()
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()
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()
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()
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()
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()
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()
def get_fed_id(chat_id): curr = SESSION.query(ChatF).get(str(chat_id)) if curr: h = curr.fed_id else: h = False SESSION.close() return h
def get_all_feds_users_global(): r = SESSION.query(Federations).all() h = [] for I in r: h.append(I.fed_id) SESSION.close() return h
def get_all_fban_users_global(): r = SESSION.query(BansF).all() h = [] for I in r: h.append(I.user_id) SESSION.close() return h
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 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
def get_rules(chat_id): rules = SESSION.query(Rules).get(str(chat_id)) ret = "" if rules: ret = rules.rules SESSION.close() return ret
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
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
def get_del_pref(chat_id): welc = SESSION.query(Welcome).get(str(chat_id)) SESSION.close() if welc: return welc.del_joined return False
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
def get_chatname_by_chatid(chat_id): try: chat = SESSION.query(Chats).get(str(chat_id)) if chat: return chat.chat_name return None finally: SESSION.close()
def get_clean_pref(chat_id): welc = SESSION.query(Welcome).get(str(chat_id)) SESSION.close() if welc: return welc.clean_welcome return False
def get_restriction(chat_id): rest = SESSION.query(Chats).get(str(chat_id)) SESSION.close() if rest: return rest.restricted return False
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()
def __load_gmuted_userid_list(): global GMUTED_LIST try: GMUTED_LIST = { x.user_id for x in SESSION.query(GloballyMutedUsers).all() } finally: SESSION.close()
def command_reaction(chat_id: Union[str, int]) -> bool: try: chat_setting = SESSION.query(CommandReactionChatSettings).get( str(chat_id)) if chat_setting: return chat_setting.comm_reaction return False finally: SESSION.close()
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()
def get_all_fban_users(fed_id): r = SESSION.query(BansF).all() h = [] for I in r: if I.fed_id == fed_id: h.append(I.user_id) SESSION.close() return h
def __load_gmute_stat_list(): global GMUTESTAT_LIST try: GMUTESTAT_LIST = { x.chat_id for x in SESSION.query(GmuteSettings).all() if not x.setting } 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()
def get_warn_setting(chat_id): try: setting = SESSION.query(WarnSettings).get(str(chat_id)) if setting: return setting.warn_limit, setting.soft_warn else: return 3, False finally: SESSION.close()
def get_warns(user_id, chat_id): try: user = SESSION.query(Warns).get((user_id, str(chat_id))) if not user: return None reasons = user.reasons num = user.num_warns return num, reasons finally: SESSION.close()