async def check_incoming_messages(event): # TODO: exempt admins from locks peer_id = event.chat_id if is_locked(peer_id, "commands"): entities = event.message.entities is_command = False if entities: for entity in entities: if isinstance(entity, types.MessageEntityBotCommand): is_command = True if is_command: try: await event.delete() except Exception as e: await event.reply( "I don't seem to have ADMIN permission here. \n`{}`". format(str(e))) update_lock(peer_id, "commands", False) if is_locked(peer_id, "forward"): if event.fwd_from: try: await event.delete() except Exception as e: await event.reply( "I don't seem to have ADMIN permission here. \n`{}`". format(str(e))) update_lock(peer_id, "forward", False) if is_locked(peer_id, "email"): entities = event.message.entities is_email = False if entities: for entity in entities: if isinstance(entity, types.MessageEntityEmail): is_email = True if is_email: try: await event.delete() except Exception as e: await event.reply( "I don't seem to have ADMIN permission here. \n`{}`". format(str(e))) update_lock(peer_id, "email", False) if is_locked(peer_id, "url"): entities = event.message.entities is_url = False if entities: for entity in entities: if isinstance( entity, (types.MessageEntityTextUrl, types.MessageEntityUrl)): is_url = True if is_url: try: await event.delete() except Exception as e: await event.reply( "I don't seem to have ADMIN permission here. \n`{}`". format(str(e))) update_lock(peer_id, "url", False)
async def check_incoming_messages(event): # result = await borg(functions.channels.GetParticipantRequest( # channel=event.chat_id, # user_id=event.message.from_id # )) # if not event.is_private and isinstance(result.participant, (types.ChannelParticipantCreator, types.ChannelParticipantAdmin)): # # locks should not be affected for admins of the group # return False peer_id = event.chat_id if is_locked(peer_id, "forward"): if event.fwd_from: try: await event.delete() except Exception as e: await event.reply( "I don't seem to have ADMIN permission here. \n`{}`".format(str(e)) ) update_lock(peer_id, "forward", False) if is_locked(peer_id, "url"): entities = event.message.entities is_url = False if entities: for entity in entities: if isinstance(entity, (types.MessageEntityTextUrl, types.MessageEntityUrl)): is_url = True if is_url: try: await event.delete() except Exception as e: await event.reply( "I don't seem to have ADMIN permission here. \n`{}`".format(str(e)) ) update_lock(peer_id, "url", False) if is_locked(peer_id, "commands"): entities = event.message.entities is_command = False if entities: for entity in entities: if isinstance(entity, types.MessageEntityBotCommand): is_command = True if is_command: try: await event.delete() except Exception as e: await event.reply( "I don't seem to have ADMIN permission here. \n`{}`".format(str(e)) ) update_lock(peer_id, "commands", False)
async def _(event): # TODO: exempt admins from locks # check for "lock" "bots" if is_locked(event.chat_id, "bots"): # bots are limited Telegram accounts, # and cannot join by themselves if event.user_added: users_added_by = event.action_message.from_id is_ban_able = False rights = types.ChatBannedRights(until_date=None, view_messages=True) added_users = event.action_message.action.users for user_id in added_users: user_obj = await borg.get_entity(user_id) if user_obj.bot: is_ban_able = True try: await borg( functions.channels.EditBannedRequest( event.chat_id, user_obj, rights)) except Exception as e: await event.reply( "I don't seem to have ADMIN permission here. \n`{}`" .format(str(e))) update_lock(event.chat_id, "bots", False) break if Config.G_BAN_LOGGER_GROUP != -100123456789 and is_ban_able: ban_reason_msg = await event.reply( "!warn [user](tg://user?id={}) Please Do Not Add BOTs to this chat." .format(users_added_by))
async def _(event): try: from sql_helpers.locks_sql import is_locked, update_lock except Exception as e: logger.info("DB_URI is not configured.") logger.info(str(e)) return False # TODO: exempt admins from locks # check for "lock" "bots" if is_locked(event.chat_id, "bots"): # bots are limited Telegram accounts, # and cannot join by themselves if event.user_added: users_added_by = event.action_message.from_id is_ban_able = False rights = types.ChatBannedRights(until_date=None, view_messages=True) added_users = event.action_message.action.users for user_id in added_users: user_obj = await event.client.get_entity(user_id) if user_obj.bot: is_ban_able = True try: await event.client( functions.channels.EditBannedRequest( event.chat_id, user_obj, rights ) ) except Exception as e: await event.reply( "I don't seem to have ADMIN permission here. \n`{}`".format( str(e) ) ) update_lock(event.chat_id, "bots", False) break if Config.BOTLOG is not None and is_ban_able: ban_reason_msg = await event.reply( "!warn [user](tg://user?id={}) Please Do Not Add BOTs to this chat.".format( users_added_by ) )
async def _(event): # result = await borg(functions.channels.GetParticipantRequest( # channel=event.chat_id, # user_id=event.action_message.from_id # )) # if not event.is_private and not isinstance(result.participant, (types.ChannelParticipantCreator, types.ChannelParticipantAdmin)): # # locks should not be affected for admins of the group # return False # check for "lock" "bots" if is_locked(event.chat_id, "bots"): # bots are limited Telegram accounts, # and cannot join by themselves if event.user_added: users_added_by = event.action_message.from_id is_ban_able = False rights = types.ChatBannedRights( until_date=None, view_messages=True ) added_users = event.action_message.action.users for user_id in added_users: user_obj = await borg.get_entity(user_id) if user_obj.bot: is_ban_able = True try: await borg(functions.channels.EditBannedRequest( event.chat_id, user_obj, rights )) except Exception as e: await event.reply( "I don't seem to have ADMIN permission here. \n`{}`".format(str(e)) ) update_lock(event.chat_id, "bots", False) break if Config.G_BAN_LOGGER_GROUP != -100123456789 and is_ban_able: ban_reason_msg = await event.reply( "!warn [user](tg://user?id={}) Please Do Not Add BOTs to this chat.".format(users_added_by) )
async def check_incoming_messages(event): try: from sql_helpers.locks_sql import update_lock, is_locked except Exception as e: logger.info("DB_URI is not configured.") logger.info(str(e)) return False if await is_admin(event.client, event.chat_id, event.from_id): return peer_id = event.chat_id if is_locked(peer_id, "commands"): entities = event.message.entities is_command = False if entities: for entity in entities: if isinstance(entity, types.MessageEntityBotCommand): is_command = True if is_command: try: await event.delete() except Exception as e: await event.reply( "I don't seem to have ADMIN permission here. \n`{}`". format(str(e))) update_lock(peer_id, "commands", False) if is_locked(peer_id, "forward"): if event.fwd_from: try: await event.delete() except Exception as e: await event.reply( "I don't seem to have ADMIN permission here. \n`{}`". format(str(e))) update_lock(peer_id, "forward", False) if is_locked(peer_id, "email"): entities = event.message.entities is_email = False if entities: for entity in entities: if isinstance(entity, types.MessageEntityEmail): is_email = True if is_email: try: await event.delete() except Exception as e: await event.reply( "I don't seem to have ADMIN permission here. \n`{}`". format(str(e))) update_lock(peer_id, "email", False) if is_locked(peer_id, "url"): entities = event.message.entities is_url = False if entities: for entity in entities: if isinstance( entity, (types.MessageEntityTextUrl, types.MessageEntityUrl)): is_url = True if is_url: try: await event.delete() except Exception as e: await event.reply( "I don't seem to have ADMIN permission here. \n`{}`". format(str(e))) update_lock(peer_id, "url", False)