def config(client, message): user = client.get_chat_member(message.chat.id, message.from_user.id) if user.status is "creator": chat_id = message.chat.id if len(message.command) > 1: input_str = message.command[1] input_str = input_str.replace("@", "") if input_str.lower() in ("off", "no", "disable"): sql.disapprove(chat_id) message.reply_text( "❌ **Force Subscribe is Disabled Successfully.**") elif input_str.lower() in ("clear"): sent_message = message.reply_text( "**Unmuting all members who are muted by me...**") try: for chat_member in client.get_chat_members( message.chat.id, filter="restricted"): if chat_member.restricted_by.id == ( client.get_me()).id: client.unban_chat_member(chat_id, chat_member.user.id) time.sleep(1) sent_message.edit( "✅ **UnMuted all members who are muted by me.**") except ChatAdminRequired: sent_message.edit( "❗ **I am not an admin in this chat.**\n__I can't unmute members because i am not an admin in this chat make me admin with ban user permission.__" ) else: try: client.get_chat_member(input_str, "me") sql.add_channel(chat_id, input_str) message.reply_text( f"✅ **Force Subscribe is Enabled**\n__Force Subscribe is enabled, all the group members have to subscribe this [channel](https://t.me/{input_str}) in order to send messages in this group.__", disable_web_page_preview=True, ) except UserNotParticipant: message.reply_text( f"❗ **Not an Admin in the Channel**\n__I am not an admin in the [channel](https://t.me/{input_str}). Add me as a admin in order to enable ForceSubscribe.__", disable_web_page_preview=True, ) except (UsernameNotOccupied, PeerIdInvalid): message.reply_text(f"❗ **Invalid Channel Username.**") except Exception as err: message.reply_text(f"❗ **ERROR:** ```{err}```") else: if sql.fs_settings(chat_id): message.reply_text( f"✅ **Force Subscribe is enabled in this chat.**\n__For this [Channel](https://t.me/{sql.fs_settings(chat_id).channel})__", disable_web_page_preview=True, ) else: message.reply_text( "❌ **Force Subscribe is disabled in this chat.**") else: message.reply_text( "❗ **Group Creator Required**\n__You have to be the group creator to do that.__" )
def _check_member(client, message): chat_id = message.chat.id chat_db = sql.fs_settings(chat_id) if chat_db: user_id = message.from_user.id if not client.get_chat_member(chat_id, user_id).status in ( "administrator", "creator", ): channel = chat_db.channel try: client.get_chat_member(channel, user_id) except UserNotParticipant: try: sent_message = message.reply_text( "{}, you are **not subscribed** to my [channel](https://t.me/{}) yet. Please [join](https://t.me/{}) and **press the Unmute Me button below** to unmute yourself.\n" .format(message.from_user.mention, channel, channel), disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup([ [ InlineKeyboardButton( "Join Channel", url="https://t.me/{}".format(channel), ) ], [ InlineKeyboardButton("Unmute Me", callback_data="LelJE") ], ]), ) client.restrict_chat_member( chat_id, user_id, ChatPermissions(can_send_messages=False)) except ChatAdminRequired: sent_message.edit( "❗ **Mizuki is not admin here..**\n__Give me ban permissions and retry, Ending FSub...__" ) except ChatAdminRequired: client.send_message( chat_id, text= f"❗ **I not an admin of @{channel} channel.**\n__Give me admin of that channel and retry. Ending FSub...__", )
def _onUnMuteRequest(client, cb): user_id = cb.from_user.id chat_id = cb.message.chat.id chat_db = sql.fs_settings(chat_id) if chat_db: channel = chat_db.channel chat_member = client.get_chat_member(chat_id, user_id) if chat_member.restricted_by: if chat_member.restricted_by.id == (client.get_me()).id: try: client.get_chat_member(channel, user_id) client.unban_chat_member(chat_id, user_id) cb.message.delete() # if cb.message.reply_to_message.from_user.id == user_id: # cb.message.delete() except UserNotParticipant: client.answer_callback_query( cb.id, text= f"❗ Join our @{channel} channel and press 'UnMute Me' button.", show_alert=True, ) else: client.answer_callback_query( cb.id, text= "❗ You have been muted by admins due to some other reason.", show_alert=True, ) else: if (not client.get_chat_member( chat_id, (client.get_me()).id).status == "administrator"): client.send_message( chat_id, f"❗ **{cb.from_user.mention} is trying to UnMute himself but i can't unmute him because i am not an admin in this chat add me as admin again.**\n__#Leaving this chat...__", ) else: client.answer_callback_query( cb.id, text="❗ Warning! Don't press the button when you cn talk.", show_alert=True, )