From 7980bfdd3f4a51d7b28667b4b16df4a25efd818e Mon Sep 17 00:00:00 2001
From: yasirarism <55983182+yasirarism@users.noreply.github.com>
Date: Wed, 14 Jun 2023 14:11:53 +0000
Subject: [PATCH] Testing banned user & chat
---
misskaty/__init__.py | 2 +-
misskaty/plugins/ban_user_or_chat.py | 157 +++++++++++++++++++++++++++
misskaty/plugins/banned.py | 43 --------
misskaty/plugins/chatbot_ai.py | 2 +-
misskaty/plugins/dev.py | 4 +
misskaty/plugins/grup_tools.py | 97 +----------------
misskaty/plugins/sangmata.py | 2 +-
utils.py | 2 -
8 files changed, 166 insertions(+), 143 deletions(-)
create mode 100644 misskaty/plugins/ban_user_or_chat.py
delete mode 100644 misskaty/plugins/banned.py
diff --git a/misskaty/__init__.py b/misskaty/__init__.py
index 5663e088..1e8bea76 100644
--- a/misskaty/__init__.py
+++ b/misskaty/__init__.py
@@ -28,7 +28,7 @@ MOD_NOLOAD = ["subscene_dl"]
HELPABLE = {}
cleanmode = {}
botStartTime = time.time()
-misskaty_version = "v2.3 - Stable"
+misskaty_version = "v2.4 - Stable"
pymonclient = MongoClient(DATABASE_URI)
diff --git a/misskaty/plugins/ban_user_or_chat.py b/misskaty/plugins/ban_user_or_chat.py
new file mode 100644
index 00000000..5d6fa7ff
--- /dev/null
+++ b/misskaty/plugins/ban_user_or_chat.py
@@ -0,0 +1,157 @@
+from pyrogram import filters, Client
+from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message
+
+from database.users_chats_db import db
+from misskaty import app
+from misskaty.helper.localization import use_chat_lang
+from misskaty.vars import SUPPORT_CHAT
+
+
+@app.on_message(filters.private & filters.incoming, group=2)
+async def ban_reply(self: Client, ctx: Message):
+ ban = await db.get_ban_status(ctx.from_user.id)
+ if ban.get("is_banned"):
+ await ctx.reply_msg(f'I am sorry, You are banned to use Me. \nBan Reason: {ban["ban_reason"]}')
+
+
+@app.on_message(filters.group & filters.incoming, group=3)
+@use_chat_lang()
+async def grp_bd(self: Client, ctx: Message, strings):
+ chck = await db.get_chat(ctx.chat.id)
+ if chck:
+ buttons = [[InlineKeyboardButton("Support", url=f"https://t.me/{SUPPORT_CHAT}")]]
+ reply_markup = InlineKeyboardMarkup(buttons)
+ vazha = await db.get_chat(ctx.chat.id)
+ try:
+ k = await ctx.reply_msg(
+ f"CHAT NOT ALLOWED 🐞\n\nMy owner has restricted me from working here!\nReason : {vazha['reason']}.",
+ reply_markup=reply_markup,
+ )
+ await k.pin()
+ except:
+ pass
+ await self.leave_chat(ctx.chat.id)
+ else:
+ total = await bot.get_chat_members_count(ctx.chat.id)
+ r_j = ctx.from_user.mention if ctx.from_user else "Anonymous"
+ await self.send_message(
+ LOG_CHANNEL,
+ strings("log_bot_added").format(ttl=ctx.chat.title, cid=ctx.chat.id, tot=total, r_j=r_j),
+ )
+ await db.add_chat(ctx.chat.id, ctx.chat.title)
+
+
+@Client.on_message(filters.command('banuser') & filters.user(ADMINS))
+async def ban_a_user(bot, message):
+ if len(message.command) == 1:
+ return await message.reply('Give me a user id / username')
+ r = message.text.split(None)
+ if len(r) > 2:
+ reason = message.text.split(None, 2)[2]
+ chat = message.text.split(None, 2)[1]
+ else:
+ chat = message.command[1]
+ reason = "No reason Provided"
+ try:
+ chat = int(chat)
+ except:
+ pass
+ try:
+ k = await bot.get_users(chat)
+ except PeerIdInvalid:
+ return await message.reply("This is an invalid user, make sure i have met him before.")
+ except IndexError:
+ return await message.reply("This might be a channel, make sure its a user.")
+ except Exception as e:
+ return await message.reply(f'Error - {e}')
+ else:
+ jar = await db.get_ban_status(k.id)
+ if jar['is_banned']:
+ return await message.reply(f"{k.mention} is already banned\nReason: {jar['ban_reason']}")
+ await db.ban_user(k.id, reason)
+ await message.reply(f"Successfully banned this {k.mention}!! Reason: jar['ban_reason']")
+
+
+
+@Client.on_message(filters.command('unbanuser') & filters.user(ADMINS))
+async def unban_a_user(bot, message):
+ if len(message.command) == 1:
+ return await message.reply('Give me a user id / username')
+ r = message.text.split(None)
+ if len(r) > 2:
+ reason = message.text.split(None, 2)[2]
+ chat = message.text.split(None, 2)[1]
+ else:
+ chat = message.command[1]
+ reason = "No reason Provided"
+ try:
+ chat = int(chat)
+ except:
+ pass
+ try:
+ k = await bot.get_users(chat)
+ except PeerIdInvalid:
+ return await message.reply("This is an invalid user, make sure ia have met him before.")
+ except IndexError:
+ return await message.reply("This might be a channel, make sure its a user.")
+ except Exception as e:
+ return await message.reply(f'Error - {e}')
+ else:
+ jar = await db.get_ban_status(k.id)
+ if not jar['is_banned']:
+ return await message.reply(f"{k.mention} is not yet banned.")
+ await db.remove_ban(k.id)
+ await message.reply(f"Successfully unbanned ! Sudhrr ja babu {k.mention}")
+
+
+@app.on_message(filters.command("disablechat") & filters.user(SUDO))
+async def disable_chat(bot, message):
+ if len(message.command) == 1:
+ return await message.reply("Give me a chat id")
+ r = message.text.split(None)
+ if len(r) > 2:
+ reason = message.text.split(None, 2)[2]
+ chat = message.text.split(None, 2)[1]
+ else:
+ chat = message.command[1]
+ reason = "No reason Provided"
+ try:
+ chat_ = int(chat)
+ except:
+ return await message.reply("Give Me A Valid Chat ID")
+ cha_t = await db.get_chat(chat_)
+ if not cha_t:
+ return await message.reply("Chat Not Found In DB")
+ if cha_t["is_disabled"]:
+ return await message.reply(f"This chat is already disabled:\nReason- {cha_t['reason']} ")
+ await db.disable_chat(chat_, reason)
+ await message.reply("Chat Succesfully Disabled")
+ try:
+ buttons = [[InlineKeyboardButton("Support", url=f"https://t.me/{SUPPORT_CHAT}")]]
+ reply_markup = InlineKeyboardMarkup(buttons)
+ await bot.send_message(
+ chat_id=chat_,
+ text=f"Hello Friends, \nMy admin has told me to leave from group so i go! If you wanna add me again contact my support group. \nReason : {reason}",
+ reply_markup=reply_markup,
+ )
+ await bot.leave_chat(chat_)
+ except Exception as e:
+ await message.reply(f"Error - {e}")
+
+
+@app.on_message(filters.command("enablechat") & filters.user(SUDO))
+async def re_enable_chat(bot: Client, ctx: Message):
+ if len(ctx.command) == 1:
+ return await ctx.reply("Give me a chat id")
+ chat = ctx.command[1]
+ try:
+ chat_ = int(chat)
+ except:
+ return await ctx.reply("Give Me A Valid Chat ID")
+ sts = await db.get_chat(int(chat))
+ if not sts:
+ return await ctx.reply("Chat Not Found In DB !")
+ if not sts.get("is_disabled"):
+ return await ctx.reply("This chat is not yet disabled.")
+ await db.re_enable_chat(chat_)
+ await ctx.reply("Chat Succesfully re-enabled")
\ No newline at end of file
diff --git a/misskaty/plugins/banned.py b/misskaty/plugins/banned.py
deleted file mode 100644
index 7c7d4a51..00000000
--- a/misskaty/plugins/banned.py
+++ /dev/null
@@ -1,43 +0,0 @@
-from pyrogram import filters, Client
-from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message
-
-from database.users_chats_db import db
-from misskaty import app
-from misskaty.vars import SUPPORT_CHAT
-from utils import temp
-
-
-async def banned_users(_, client, message: Message):
- return message.from_user and message.from_user.id in temp.BANNED_USERS
-
-
-banned_user = filters.create(banned_users)
-
-
-async def disabled_chat(_, client, message: Message):
- return message.chat.id in temp.BANNED_CHATS
-
-
-disabled_group = filters.create(disabled_chat)
-
-
-@app.on_message(filters.private & banned_user & filters.incoming)
-async def ban_reply(self: Client, ctx: Message):
- ban = await db.get_ban_status(message.from_user.id)
- await ctx.reply_msg(f'Sorry Dude, You are Banned to use Me. \nBan Reason: {ban["ban_reason"]}')
-
-
-@app.on_message(filters.group & disabled_group & filters.incoming)
-async def grp_bd(self: Client, ctx: Message):
- buttons = [[InlineKeyboardButton("Support", url=f"https://t.me/{SUPPORT_CHAT}")]]
- reply_markup = InlineKeyboardMarkup(buttons)
- vazha = await db.get_chat(ctx.chat.id)
- k = await ctx.reply_msg(
- f"CHAT NOT ALLOWED 🐞\n\nMy admins has restricted me from working here ! If you want to know more about it contact support..\nReason : {vazha['reason']}.",
- reply_markup=reply_markup,
- )
- try:
- await k.pin()
- except:
- pass
- await self.leave_chat(message.chat.id)
diff --git a/misskaty/plugins/chatbot_ai.py b/misskaty/plugins/chatbot_ai.py
index e6df7408..f3b760ca 100644
--- a/misskaty/plugins/chatbot_ai.py
+++ b/misskaty/plugins/chatbot_ai.py
@@ -22,7 +22,7 @@ async def bard_chatbot(self: Client, ctx: Message, strings):
if len(ctx.command) == 1:
return await ctx.reply_msg(strings("no_question").format(cmd=ctx.command[0]), quote=True, del_in=5)
msg = await ctx.reply_msg(strings("find_answers_str"), quote=True)
- data = {'message': ctx.input, 'session_id':'XAjzKUFvf_nQtNg4bt0pG54rCLnaWeJFE1_FXuQnVjNyfmjDhkKZyoqXqW5cgBmmnf8Eqg.'}
+ data = {'message': ctx.input, 'session_id':'XQjzKRYITZ7fhplF-rXa_GTynUwdctKq4aGm-lqUCCJzF98xqDulL9UKopIadNpQn0lvnA.'}
try:
req = await http.post("https://bard-api-rho.vercel.app/ask", json=data)
await msg.edit_msg(req.json().get("content"))
diff --git a/misskaty/plugins/dev.py b/misskaty/plugins/dev.py
index f38a2205..1845e0ca 100644
--- a/misskaty/plugins/dev.py
+++ b/misskaty/plugins/dev.py
@@ -39,6 +39,10 @@ __HELP__ = """
/logs [int] - Check logs bot
/shell [args] - Run Exec/Terminal CMD
/download [link/reply_to_telegram_file] - Download file from Telegram
+/disablechat [chat id] - Remove blacklist group
+/enablechat [chat id] - Add Blacklist group
+/banuser [chat id] - Ban user and block user so cannot use bot
+/unbanuser [chat id] - Unban user and make their can use bot again
**For Public Use**
/stats - Check statistic bot
diff --git a/misskaty/plugins/grup_tools.py b/misskaty/plugins/grup_tools.py
index 354a0558..c1d87c75 100644
--- a/misskaty/plugins/grup_tools.py
+++ b/misskaty/plugins/grup_tools.py
@@ -135,47 +135,9 @@ async def member_has_joined(c: app, member: ChatMemberUpdated, strings):
pass
-@app.on_message(filters.new_chat_members & filters.group)
+@app.on_message(filters.new_chat_members & filters.group, group=4)
@use_chat_lang()
-async def save_group(bot, message, strings):
- r_j_check = [u.id for u in message.new_chat_members]
- if temp.ME in r_j_check:
- if not await db.get_chat(message.chat.id):
- total = await bot.get_chat_members_count(message.chat.id)
- r_j = message.from_user.mention if message.from_user else "Anonymous"
- await bot.send_message(
- LOG_CHANNEL,
- strings("log_bot_added").format(ttl=message.chat.title, cid=message.chat.id, tot=total, r_j=r_j),
- )
-
- await db.add_chat(message.chat.id, message.chat.title)
- if message.chat.id in temp.BANNED_CHATS:
- # Inspired from a boat of a banana tree
- buttons = [[InlineKeyboardButton(strings("support_btn"), url=f"https://t.me/{SUPPORT_CHAT}")]]
- reply_markup = InlineKeyboardMarkup(buttons)
- k = await message.reply(
- text=strings("chat_not_allowed"),
- reply_markup=reply_markup,
- )
-
- try:
- await k.pin()
- except:
- pass
- await bot.leave_chat(message.chat.id)
- return
- buttons = [
- [
- InlineKeyboardButton(strings("help_btn"), url=f"https://t.me/{temp.U_NAME}?start=help"),
- InlineKeyboardButton(strings("update_btn"), url="https://t.me/YasirPediaChannel"),
- ]
- ]
- reply_markup = InlineKeyboardMarkup(buttons)
- await message.reply_text(
- text=strings("welcome_thanks").format(ttl=message.chat.title),
- reply_markup=reply_markup,
- )
- else:
+async def greet_group(bot, message, strings):
for u in message.new_chat_members:
try:
pic = await app.download_media(u.photo.big_file_id, file_name=f"pp{u.id}.png")
@@ -245,61 +207,6 @@ async def leave_a_chat(bot, message):
await bot.leave_chat(chat)
-@app.on_message(filters.command("disable") & filters.user(SUDO))
-async def disable_chat(bot, message):
- if len(message.command) == 1:
- return await message.reply("Give me a chat id")
- r = message.text.split(None)
- if len(r) > 2:
- reason = message.text.split(None, 2)[2]
- chat = message.text.split(None, 2)[1]
- else:
- chat = message.command[1]
- reason = "No reason Provided"
- try:
- chat_ = int(chat)
- except:
- return await message.reply("Give Me A Valid Chat ID")
- cha_t = await db.get_chat(chat_)
- if not cha_t:
- return await message.reply("Chat Not Found In DB")
- if cha_t["is_disabled"]:
- return await message.reply(f"This chat is already disabled:\nReason- {cha_t['reason']} ")
- await db.disable_chat(chat_, reason)
- temp.BANNED_CHATS.append(chat_)
- await message.reply("Chat Succesfully Disabled")
- try:
- buttons = [[InlineKeyboardButton("Support", url=f"https://t.me/{SUPPORT_CHAT}")]]
- reply_markup = InlineKeyboardMarkup(buttons)
- await bot.send_message(
- chat_id=chat_,
- text=f"Hello Friends, \nMy admin has told me to leave from group so i go! If you wanna add me again contact my support group. \nReason : {reason}",
- reply_markup=reply_markup,
- )
- await bot.leave_chat(chat_)
- except Exception as e:
- await message.reply(f"Error - {e}")
-
-
-@app.on_message(filters.command("enable") & filters.user(SUDO))
-async def re_enable_chat(bot, message):
- if len(message.command) == 1:
- return await message.reply("Give me a chat id")
- chat = message.command[1]
- try:
- chat_ = int(chat)
- except:
- return await message.reply("Give Me A Valid Chat ID")
- sts = await db.get_chat(int(chat))
- if not sts:
- return await message.reply("Chat Not Found In DB !")
- if not sts.get("is_disabled"):
- return await message.reply("This chat is not yet disabled.")
- await db.re_enable_chat(chat_)
- temp.BANNED_CHATS.remove(chat_)
- await message.reply("Chat Succesfully re-enabled")
-
-
# Not to be used
# @app.on_message(filters.command('invite') & filters.user(SUDO))
async def gen_invite(bot, message):
diff --git a/misskaty/plugins/sangmata.py b/misskaty/plugins/sangmata.py
index 0445d597..cf665730 100644
--- a/misskaty/plugins/sangmata.py
+++ b/misskaty/plugins/sangmata.py
@@ -18,7 +18,7 @@ This feature inspired from SangMata Bot. I'm created simple detection to check u
# Check user that change first_name, last_name and usernaname
@app.on_message(
filters.group & ~filters.bot & ~filters.via_bot,
- group=3,
+ group=5,
)
@use_chat_lang()
async def cek_mataa(self: Client, ctx: Message, strings):
diff --git a/utils.py b/utils.py
index adde04ce..bfd81f0f 100644
--- a/utils.py
+++ b/utils.py
@@ -55,8 +55,6 @@ async def auto_clean():
# temp db for banned
class temp(object):
- BANNED_USERS = []
- BANNED_CHATS = []
ME = None
CURRENT = int(os.environ.get("SKIP", 2))
CANCEL = False