video-stream/program/essentials.py

201 lines
6.4 KiB
Python
Raw Normal View History

2022-02-22 23:30:19 +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-01-31 12:41:47 +00:00
2022-02-11 16:14:14 +00:00
2022-01-31 12:41:47 +00:00
import asyncio
2022-02-13 06:27:09 +00:00
import traceback
2022-02-05 05:36:39 +00:00
2022-01-31 12:41:47 +00:00
from pyrogram.types import Message
2022-02-05 05:36:39 +00:00
from pyrogram import Client, filters, __version__ as pyrover
from pytgcalls import (__version__ as pytgver)
2022-02-15 04:44:58 +00:00
2022-02-05 05:36:39 +00:00
from program import __version__ as ver
from program.start import __python_version__ as pyver
2022-02-22 23:30:19 +00:00
from driver.core import me_bot
2022-01-31 12:41:47 +00:00
from driver.filters import command
2022-02-08 21:59:05 +00:00
from driver.decorators import bot_creator, sudo_users_only
2022-01-31 12:41:47 +00:00
from driver.database.dbchat import get_served_chats
2022-02-05 05:36:39 +00:00
from driver.database.dbusers import get_served_users
from driver.database.dbpunish import get_gbans_count
from driver.database.dbqueue import get_active_chats
2022-01-31 12:41:47 +00:00
2022-02-11 16:14:14 +00:00
from config import BOT_USERNAME as uname
2022-01-31 12:41:47 +00:00
2022-02-05 05:36:39 +00:00
@Client.on_message(command(["broadcast", f"broadcast@{uname}"]) & ~filters.edited)
2022-02-08 21:59:05 +00:00
@bot_creator
2022-02-08 02:37:26 +00:00
async def broadcast_message_nopin(c: Client, message: Message):
2022-01-31 12:41:47 +00:00
if not message.reply_to_message:
pass
else:
x = message.reply_to_message.message_id
y = message.chat.id
sent = 0
chats = []
schats = await get_served_chats()
for chat in schats:
chats.append(int(chat["chat_id"]))
for i in chats:
try:
m = await c.forward_messages(i, y, x)
await asyncio.sleep(0.3)
sent += 1
except Exception:
pass
await message.reply_text(f"✅ Broadcast complete in {sent} Group.")
return
if len(message.command) < 2:
await message.reply_text(
"**usage**:\n\n/broadcast (`message`) or (`reply to message`)"
)
return
text = message.text.split(None, 1)[1]
sent = 0
chats = []
schats = await get_served_chats()
for chat in schats:
chats.append(int(chat["chat_id"]))
for i in chats:
try:
m = await c.send_message(i, text=text)
await asyncio.sleep(0.3)
sent += 1
except Exception:
pass
await message.reply_text(f"✅ Broadcast complete in {sent} Group.")
2022-02-05 05:36:39 +00:00
@Client.on_message(command(["broadcast_pin", f"broadcast_pin@{uname}"]) & ~filters.edited)
2022-02-08 21:59:05 +00:00
@bot_creator
2022-02-08 02:37:26 +00:00
async def broadcast_message_pin(c: Client, message: Message):
2022-01-31 12:41:47 +00:00
if not message.reply_to_message:
pass
else:
x = message.reply_to_message.message_id
y = message.chat.id
sent = 0
pin = 0
chats = []
schats = await get_served_chats()
for chat in schats:
chats.append(int(chat["chat_id"]))
for i in chats:
try:
m = await c.forward_messages(i, y, x)
try:
await m.pin(disable_notification=True)
pin += 1
except Exception:
pass
await asyncio.sleep(0.3)
sent += 1
except Exception:
pass
await message.reply_text(
2022-02-11 01:24:34 +00:00
f"✅ Broadcast complete in {sent} Group.\n📌 Sent with {pin} chat pins."
2022-01-31 12:41:47 +00:00
)
return
if len(message.command) < 2:
await message.reply_text(
2022-02-08 02:37:26 +00:00
"**usage**:\n\n/broadcast_pin (`message`) or (`reply to message`)"
2022-01-31 12:41:47 +00:00
)
return
text = message.text.split(None, 1)[1]
sent = 0
pin = 0
chats = []
schats = await get_served_chats()
for chat in schats:
chats.append(int(chat["chat_id"]))
for i in chats:
try:
m = await c.send_message(i, text=text)
try:
await m.pin(disable_notification=True)
pin += 1
except Exception:
pass
await asyncio.sleep(0.3)
sent += 1
except Exception:
pass
await message.reply_text(
2022-02-11 01:24:34 +00:00
f"✅ Broadcast complete in {sent} Group.\n📌 Sent with {pin} chat pins."
2022-01-31 12:41:47 +00:00
)
2022-02-05 05:36:39 +00:00
@Client.on_message(command(["stats", f"stats@{uname}"]) & ~filters.edited)
@sudo_users_only
async def bot_statistic(c: Client, message: Message):
2022-02-15 04:44:58 +00:00
name = me_bot.first_name
2022-02-05 05:36:39 +00:00
chat_id = message.chat.id
msg = await c.send_message(
2022-02-11 01:24:34 +00:00
chat_id, "❖ Collecting Stats..."
2022-02-05 05:36:39 +00:00
)
served_chats = len(await get_served_chats())
served_users = len(await get_served_users())
gbans_usertl = await get_gbans_count()
tgm = f"""
2022-02-05 06:26:15 +00:00
📊 Current Statistic of [{name}](https://t.me/{uname})`:`
2022-02-05 05:36:39 +00:00
**Groups Chat** : `{served_chats}`
**Users Dialog** : `{served_users}`
**Gbanned Users** : `{gbans_usertl}`
**Python Version** : `{pyver}`
2022-02-05 06:50:24 +00:00
**PyTgCalls Version** : `{pytgver.__version__}`
2022-02-05 05:36:39 +00:00
**Pyrogram Version** : `{pyrover}`
🤖 bot version: `{ver}`"""
await msg.edit(tgm, disable_web_page_preview=True)
@Client.on_message(command(["calls", f"calls@{uname}"]) & ~filters.edited)
@sudo_users_only
2022-02-24 06:32:46 +00:00
async def active_group_calls(c: Client, message: Message):
served_chats = []
try:
chats = await get_active_chats()
for chat in chats:
served_chats.append(int(chat["chat_id"]))
except Exception as e:
2022-03-02 13:01:45 +00:00
await message.reply_text(f"🚫 错误: `{e}`")
text = ""
j = 0
for x in served_chats:
try:
title = (await c.get_chat(x)).title
2022-02-24 06:32:46 +00:00
except BaseException:
2022-03-02 13:01:45 +00:00
title = "私人群组"
if (await c.get_chat(x)).username:
2022-02-24 06:32:46 +00:00
data = (await c.get_chat(x)).username
text += (
2022-02-24 06:32:46 +00:00
f"**{j + 1}.** [{title}](https://t.me/{data}) [`{x}`]\n"
)
else:
text += f"**{j + 1}.** {title} [`{x}`]\n"
j += 1
if not text:
2022-03-02 13:01:45 +00:00
await message.reply_text("❌ 没有正在播放的语音聊天")
else:
await message.reply_text(
2022-03-02 13:01:45 +00:00
f"✏️ **正在播放的语音聊天:**\n\n{text}",
disable_web_page_preview=True,
)