def __import_data__(chat_id, data): # set chat locks locks = data.get("locks", {}) for itemlock in locks: if itemlock in LOCK_TYPES: sql.update_lock(chat_id, itemlock, locked=True) elif itemlock in LOCK_CHAT_RESTRICTION: sql.update_restriction(chat_id, itemlock, locked=True)
def lock(update: Update, context: CallbackContext) -> str: bot, args = context.bot, context.args chat = update.effective_chat user = update.effective_user message = update.effective_message if can_delete(chat, bot.id): if len(args) >= 1: if args[0] in LOCK_TYPES: sql.update_lock(chat.id, args[0], locked=True) message.reply_text( "Locked {} messages for all non-admins!".format(args[0])) return ( f"<b>{html.escape(chat.title)}:</b>\n" f"#LOCK\n" f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n" f"Locked <code>{args[0]}</code>.") elif args[0] in RESTRICTION_TYPES: sql.update_restriction(chat.id, args[0], locked=True) """ if args[0] == "messages": chat.set_permissions(can_send_messages=False) elif args[0] == "media": chat.set_permissions(can_send_media_messages=False) elif args[0] == "other": chat.set_permissions(can_send_other_messages=False) elif args[0] == "previews": chat.set_permissions(can_add_web_page_previews=False) elif args[0] == "all": chat.set_permissions(can_send_messages=False) """ message.reply_text("Locked {} for all non-admins!".format( args[0])) return ( f"<b>{html.escape(chat.title)}:</b>\n" f"#LOCK\n" f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n" f"Locked <code>{args[0]}</code>.") else: message.reply_text( "What are you trying to lock...? Try /locktypes for the list of lockables" ) else: message.reply_text( "I'm not an administrator, or haven't got delete rights.") return ""
def unlock(update: Update, context: CallbackContext) -> str: bot, args = context.bot, context.args chat = update.effective_chat user = update.effective_user message = update.effective_message if is_user_admin(chat, message.from_user.id): if len(args) >= 1: if args[0] in LOCK_TYPES: sql.update_lock(chat.id, args[0], locked=False) message.reply_text(f"Unlocked {args[0]} for everyone!") return ( f"<b>{html.escape(chat.title)}:</b>\n" f"#UNLOCK\n" f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n" f"Unlocked <code>{args[0]}</code>.") elif args[0] in RESTRICTION_TYPES: sql.update_restriction(chat.id, args[0], locked=False) """ #members = users_sql.get_chat_members(chat.id) if args[0] == "messages": chat.set_permissions(can_send_messages=True) elif args[0] == "media": chat.set_permissions(can_send_media_messages=True) elif args[0] == "other": chat.set_permissions(can_send_other_messages=True) elif args[0] == "previews": chat.set_permissions(can_add_web_page_previews=True) elif args[0] == "all": chat.set_permissions(can_send_messages=True, can_send_media_messages=True, can_send_other_messages=True, can_add_web_page_previews=True, can_send_polls=True) """ message.reply_text("Unlocked {} for everyone!".format(args[0])) return ( f"<b>{html.escape(chat.title)}:</b>\n" f"#UNLOCK\n" f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n" f"Unlocked <code>{args[0]}</code>.") else: message.reply_text( "What are you trying to unlock...? Try /locktypes for the list of lockables" ) else: bot.sendMessage(chat.id, "What are you trying to unlock...?") return ""
def unlock(update, context) -> str: args = context.args chat = update.effective_chat user = update.effective_user message = update.effective_message if is_user_admin(chat, message.from_user.id): if len(args) >= 1: ltype = args[0].lower() if ltype in LOCK_TYPES: # Connection check conn = connected(context.bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = chat.title text = "Unlocked {} for everyone in {}!".format( ltype, chat_name) else: if update.effective_message.chat.type == "private": send_message( update.effective_message, "This command is meant to use in group not in PM", ) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title text = "Unlocked {} for everyone!".format(ltype) sql.update_lock(chat.id, ltype, locked=False) send_message(update.effective_message, text, parse_mode="markdown") return ("<b>{}:</b>" "\n#UNLOCK" "\n<b>Admin:</b> {}" "\nUnlocked <code>{}</code>.".format( html.escape(chat.title), mention_html(user.id, user.first_name), ltype, )) elif ltype in UNLOCK_CHAT_RESTRICTION: # Connection check conn = connected(context.bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = chat.title text = "Unlocked {} for everyone in {}!".format( ltype, chat_name) else: if update.effective_message.chat.type == "private": send_message( update.effective_message, "This command is meant to use in group not in PM", ) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title text = "Unlocked {} for everyone!".format(ltype) current_permission = context.bot.getChat(chat_id).permissions context.bot.set_chat_permissions( chat_id=chat_id, permissions=get_permission_list( eval(str(current_permission)), UNLOCK_CHAT_RESTRICTION[ltype.lower()], ), ) send_message(update.effective_message, text, parse_mode="markdown") return ("<b>{}:</b>" "\n#UNLOCK" "\n<b>Admin:</b> {}" "\nUnlocked <code>{}</code>.".format( html.escape(chat.title), mention_html(user.id, user.first_name), ltype, )) else: send_message( update.effective_message, "What are you trying to unlock...? Try /locktypes for the list of lockables.", ) else: send_message(update.effective_message, "What are you trying to unlock...?") return ""
def lock(update, context) -> str: args = context.args chat = update.effective_chat user = update.effective_user if (can_delete(chat, context.bot.id) or update.effective_message.chat.type == "private"): if len(args) >= 1: ltype = args[0].lower() if ltype in LOCK_TYPES: # Connection check conn = connected(context.bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = chat.title text = "Locked {} for non-admins in {}!".format( ltype, chat_name) else: if update.effective_message.chat.type == "private": send_message( update.effective_message, "This command is meant to use in group not in PM", ) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title text = "Locked {} for non-admins!".format(ltype) sql.update_lock(chat.id, ltype, locked=True) send_message(update.effective_message, text, parse_mode="markdown") return ("<b>{}:</b>" "\n#LOCK" "\n<b>Admin:</b> {}" "\nLocked <code>{}</code>.".format( html.escape(chat.title), mention_html(user.id, user.first_name), ltype, )) elif ltype in LOCK_CHAT_RESTRICTION: # Connection check conn = connected(context.bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = chat.title text = "Locked {} for all non-admins in {}!".format( ltype, chat_name) else: if update.effective_message.chat.type == "private": send_message( update.effective_message, "This command is meant to use in group not in PM", ) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title text = "Locked {} for all non-admins!".format(ltype) current_permission = context.bot.getChat(chat_id).permissions context.bot.set_chat_permissions( chat_id=chat_id, permissions=get_permission_list( eval(str(current_permission)), LOCK_CHAT_RESTRICTION[ltype.lower()], ), ) send_message(update.effective_message, text, parse_mode="markdown") return ("<b>{}:</b>" "\n#Permission_LOCK" "\n<b>Admin:</b> {}" "\nLocked <code>{}</code>.".format( html.escape(chat.title), mention_html(user.id, user.first_name), ltype, )) else: send_message( update.effective_message, "What are you trying to lock...? Try /locktypes for the list of lockables", ) else: send_message(update.effective_message, "What are you trying to lock...?") else: send_message( update.effective_message, "I am not administrator or haven't got enough rights.", ) return ""
def unlock(update, context) -> str: args = context.args chat = update.effective_chat user = update.effective_user message = update.effective_message if is_user_admin(chat, message.from_user.id): if len(args) >= 1: ltype = args[0].lower() if ltype in LOCK_TYPES: # Connection check conn = connected(context.bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = chat.title text = "{} qrupunda {} kilidi açıldı!".format( chat_name, ltype) else: if update.effective_message.chat.type == "private": send_message( update.effective_message, "Bu əmri qrupda işlədin", ) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title text = "{} kilidi açıldı!".format(ltype) sql.update_lock(chat.id, ltype, locked=False) send_message(update.effective_message, text, parse_mode="markdown") return ("<b>{}:</b>" "\n#UNLOCK" "\n<b>Admin:</b> {}" "\nUnlocked <code>{}</code>.".format( html.escape(chat.title), mention_html(user.id, user.first_name), ltype, )) elif ltype in UNLOCK_CHAT_RESTRICTION: # Connection check conn = connected(context.bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = chat.title text = "{} qrupunda {} kilidi açıldı!".format( chat_name, ltype) else: if update.effective_message.chat.type == "private": send_message( update.effective_message, "Bu əmri qrupda işlədin", ) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title text = "{} kilidi açıldı!".format(ltype) current_permission = context.bot.getChat(chat_id).permissions context.bot.set_chat_permissions( chat_id=chat_id, permissions=get_permission_list( eval(str(current_permission)), UNLOCK_CHAT_RESTRICTION[ltype.lower()], ), ) send_message(update.effective_message, text, parse_mode="markdown") return ("<b>{}:</b>" "\n#UNLOCK" "\n<b>Admin:</b> {}" "\nUnlocked <code>{}</code>.".format( html.escape(chat.title), mention_html(user.id, user.first_name), ltype, )) else: send_message( update.effective_message, "Nəyin kilidini açmaq istəyirsənki...? /locktypes yazaraq mövcud kilidlərə baxa bilərsən.", ) else: send_message(update.effective_message, "Nəyin kilidini açmaq istəyirsənki...?") return ""