-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
813b660
commit 7e03a89
Showing
1 changed file
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import asyncio | ||
from sys import version as pyver | ||
|
||
import pyrogram | ||
from shizuchat import shizuchat | ||
from pyrogram import __version__ as pyrover | ||
from pyrogram import filters, idle | ||
from config import OWNER_ID | ||
from pyrogram.errors import FloodWait | ||
from pyrogram.types import Message | ||
|
||
import config | ||
from shizuchat.modules.helpers import mongo | ||
from shizuchat.modules.helpers.mongo import db | ||
|
||
@shizuchat.on_cmd( | ||
filters.command("block") & filters.user(OWNER_ID) | ||
) | ||
async def block_func(_, message: Message): | ||
if db is None: | ||
return await message.reply_text( | ||
"MONGO_DB_URI var not defined. Please define it first" | ||
) | ||
if message.reply_to_message: | ||
if not message.reply_to_message.forward_sender_name: | ||
return await message.reply_text( | ||
"Please reply to forwarded messages only." | ||
) | ||
replied_id = message.reply_to_message_id | ||
try: | ||
replied_user_id = save[replied_id] | ||
except Exception as e: | ||
print(e) | ||
return await message.reply_text( | ||
"Failed to fetch user. You might've restarted bot or some error happened. Please check logs" | ||
) | ||
if await mongo.is_banned_user(replied_user_id): | ||
return await message.reply_text("Already Blocked") | ||
else: | ||
await mongo.add_banned_user(replied_user_id) | ||
await message.reply_text("Banned User from The Bot") | ||
try: | ||
await app.send_message( | ||
replied_user_id, | ||
"You're now banned from using the Bot by admins.", | ||
) | ||
except: | ||
pass | ||
else: | ||
return await message.reply_text( | ||
"Reply to a user's forwarded message to block him from using the bot" | ||
) | ||
|
||
@shizuchat.on_cmd( | ||
filters.command("unblock") & filters.user(OWNER_ID) | ||
) | ||
async def unblock_func(_, message: Message): | ||
if db is None: | ||
return await message.reply_text( | ||
"MONGO_DB_URI var not defined. Please define it first" | ||
) | ||
if message.reply_to_message: | ||
if not message.reply_to_message.forward_sender_name: | ||
return await message.reply_text( | ||
"Please reply to forwarded messages only." | ||
) | ||
replied_id = message.reply_to_message_id | ||
try: | ||
replied_user_id = save[replied_id] | ||
except Exception as e: | ||
print(e) | ||
return await message.reply_text( | ||
"Failed to fetch user. You might've restarted bot or some error happened. Please check logs" | ||
) | ||
if not await mongo.is_banned_user(replied_user_id): | ||
return await message.reply_text("Already UnBlocked") | ||
else: | ||
await mongo.remove_banned_user(replied_user_id) | ||
await message.reply_text( | ||
"Unblocked User from The Bot" | ||
) | ||
try: | ||
await app.send_message( | ||
replied_user_id, | ||
"You're now unbanned from the Bot by admins.", | ||
) | ||
except: | ||
pass | ||
else: | ||
return await message.reply_text( | ||
"Reply to a user's forwarded message to unblock him from the bot" | ||
) |