video-stream/program/blockchat.py

86 lines
3.0 KiB
Python
Raw Normal View History

2022-02-22 23:17:00 +00:00
"""
Video + Music Stream Telegram Bot
Copyright (c) 2022-present levina=lab <https://github.com/levina-lab>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but without any warranty; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/licenses.html>
"""
2022-02-07 13:47:49 +00:00
from pyrogram.types import Message
from pyrogram import Client, filters
2022-02-21 08:52:21 +00:00
from config import BOT_USERNAME
2022-02-07 16:15:45 +00:00
from driver.core import bot
2022-02-21 08:52:21 +00:00
from driver.filters import command
2022-02-07 13:47:49 +00:00
from driver.decorators import sudo_users_only
from driver.database.dblockchat import (
blacklist_chat,
blacklisted_chats,
whitelist_chat,
)
2022-02-08 02:32:24 +00:00
@Client.on_message(command(["block", f"block@{BOT_USERNAME}", "blacklist"]) & ~filters.edited)
2022-02-07 13:47:49 +00:00
@sudo_users_only
async def blacklist_chat_func(_, message: Message):
if len(message.command) != 2:
return await message.reply_text(
"**usage:**\n\n» /block (`chat_id`)"
)
chat_id = int(message.text.strip().split()[1])
if chat_id in await blacklisted_chats():
return await message.reply_text("This chat already blacklisted.")
blacklisted = await blacklist_chat(chat_id)
if blacklisted:
return await message.reply_text(
"✅ This chat has blacklisted!"
)
await message.reply_text("❗️ something wrong happened, check logs!")
2022-02-08 02:32:24 +00:00
@Client.on_message(command(["unblock", f"unblock@{BOT_USERNAME}", "whitelist"]) & ~filters.edited)
2022-02-07 13:47:49 +00:00
@sudo_users_only
async def whitelist_chat_func(_, message: Message):
if len(message.command) != 2:
return await message.reply_text(
"**usage:**\n\n» /unblock (`chat_id`)"
)
chat_id = int(message.text.strip().split()[1])
if chat_id not in await blacklisted_chats():
return await message.reply_text("This chat already whitelisted.")
whitelisted = await whitelist_chat(chat_id)
if whitelisted:
return await message.reply_text(
"✅ This chat has whitelisted!"
)
await message.reply_text("❗️ something wrong happened, check logs!")
2022-02-08 02:32:24 +00:00
@Client.on_message(command(["blocklist", f"blocklist@{BOT_USERNAME}", "blacklisted"]) & ~filters.edited)
2022-02-07 13:47:49 +00:00
@sudo_users_only
async def blacklisted_chats_func(_, message: Message):
text = "📵 » Blocked Chat list:\n\n"
j = 0
for count, chat_id in enumerate(await blacklisted_chats(), 1):
try:
title = (await bot.get_chat(chat_id)).title
except Exception:
title = "Private"
j = 1
text += f"**{count}. {title}** [`{chat_id}`]\n"
if j == 0:
await message.reply_text("❌ no blacklisted chat.")
else:
await message.reply_text(text)