Skip to content

Commit 76d8487

Browse files
authored
Add files via upload
1 parent 32cd2f5 commit 76d8487

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3624
-0
lines changed

Dockerfile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM python:3.9.6-slim-buster
2+
RUN apt-get update && apt-get upgrade -y
3+
RUN apt-get install git curl python3-pip ffmpeg -y
4+
RUN python3.9 -m pip install -U pip
5+
COPY . /app
6+
WORKDIR /app
7+
RUN python3.9 -m pip install -U -r requirements.txt
8+
CMD python3.9 -m VCPlayBot

Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
worker: python3 -m VCPlayBot

VCPlayBot/__main__.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import requests
2+
from pyrogram import Client as Bot
3+
4+
from VCPlayBot.config import API_HASH
5+
from VCPlayBot.config import API_ID
6+
from VCPlayBot.config import BG_IMAGE
7+
from VCPlayBot.config import BOT_TOKEN
8+
from VCPlayBot.services.callsmusic import run
9+
10+
response = requests.get(BG_IMAGE)
11+
file = open("./etc/foreground.png", "wb")
12+
file.write(response.content)
13+
file.close()
14+
15+
bot = Bot(
16+
":memory:",
17+
API_ID,
18+
API_HASH,
19+
bot_token=BOT_TOKEN,
20+
plugins=dict(root="VCPlayBot.modules"),
21+
)
22+
23+
bot.start()
24+
run()

VCPlayBot/config.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
from os import getenv
3+
4+
from dotenv import load_dotenv
5+
6+
if os.path.exists("local.env"):
7+
load_dotenv("local.env")
8+
9+
que = {}
10+
SESSION_NAME = getenv("SESSION_NAME", "session")
11+
BOT_TOKEN = getenv("BOT_TOKEN")
12+
BOT_NAME = getenv("BOT_NAME")
13+
UPDATES_CHANNEL = getenv("UPDATES_CHANNEL", "LaylaList")
14+
BG_IMAGE = getenv("BG_IMAGE", "https://telegra.ph/file/9b13ea3ce046a1a5c8098.png")
15+
admins = {}
16+
API_ID = int(getenv("API_ID"))
17+
API_HASH = getenv("API_HASH")
18+
BOT_USERNAME = getenv("BOT_USERNAME")
19+
ASSISTANT_NAME = getenv("ASSISTANT_NAME", "VCPlayAssistant")
20+
SUPPORT_GROUP = getenv("SUPPORT_GROUP", "AwesomeSupport")
21+
PROJECT_NAME = getenv("PROJECT_NAME", "VCPlayBot2.0")
22+
SOURCE_CODE = getenv("SOURCE_CODE", "github.com/QueenArzoo/VCPlayBot")
23+
DURATION_LIMIT = int(getenv("DURATION_LIMIT", "7"))
24+
ARQ_API_KEY = getenv("ARQ_API_KEY", None)
25+
PMPERMIT = getenv("PMPERMIT", None)
26+
LOG_GRP = getenv("LOG_GRP", None)
27+
COMMAND_PREFIXES = list(getenv("COMMAND_PREFIXES", "/ !").split())
28+
29+
SUDO_USERS = list(map(int, getenv("SUDO_USERS", "797768146").split()))

VCPlayBot/function/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from VCPlayBot.function.admins import admins
2+
from VCPlayBot.function.admins import get
3+
from VCPlayBot.function.admins import set
4+
5+
__all__ = ["set", "get", "admins"]

VCPlayBot/function/admins.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from typing import Dict
2+
from typing import List
3+
4+
5+
admins: Dict[int, List[int]] = {}
6+
7+
8+
def set(chat_id: int, admins_: List[int]):
9+
admins[chat_id] = admins_
10+
11+
12+
def get(chat_id: int) -> List[int]:
13+
if chat_id in admins:
14+
return admins[chat_id]
15+
return []

VCPlayBot/helpers/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

VCPlayBot/helpers/admins.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
3+
from typing import List
4+
5+
from pyrogram.types import Chat
6+
7+
from VCPlayBot.function.admins import get as gett
8+
from VCPlayBot.function.admins import set
9+
10+
11+
async def get_administrators(chat: Chat) -> List[int]:
12+
get = gett(chat.id)
13+
14+
if get:
15+
return get
16+
else:
17+
administrators = await chat.get_members(filter="administrators")
18+
to_set = []
19+
20+
for administrator in administrators:
21+
if administrator.can_manage_voice_chats:
22+
to_set.append(administrator.user.id)
23+
24+
set(chat.id, to_set)
25+
return await get_administrators(chat)

VCPlayBot/helpers/channelmusic.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from pyrogram.types import Chat
2+
3+
4+
def get_chat_id(chat: Chat):
5+
if chat.title.startswith("Channel Music: ") and chat.title[16:].isnumeric():
6+
return int(chat.title[15:])
7+
return chat.id

VCPlayBot/helpers/decorators.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from typing import Callable
2+
3+
from pyrogram import Client
4+
from pyrogram.types import Message
5+
6+
from VCPlayBot.config import SUDO_USERS
7+
from VCPlayBot.helpers.admins import get_administrators
8+
9+
10+
def errors(func: Callable) -> Callable:
11+
async def decorator(client: Client, message: Message):
12+
try:
13+
return await func(client, message)
14+
except Exception as e:
15+
await message.reply(f"{type(e).__name__}: {e}")
16+
17+
return decorator
18+
19+
20+
def authorized_users_only(func: Callable) -> Callable:
21+
async def decorator(client: Client, message: Message):
22+
if message.from_user.id in SUDO_USERS:
23+
return await func(client, message)
24+
25+
administrators = await get_administrators(message.chat)
26+
27+
for administrator in administrators:
28+
if administrator == message.from_user.id:
29+
return await func(client, message)
30+
31+
return decorator

VCPlayBot/helpers/errors.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class DurationLimitError(Exception):
2+
pass
3+
4+
5+
class FFmpegReturnCodeError(Exception):
6+
pass

VCPlayBot/helpers/filters.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from typing import List
2+
from typing import Union
3+
4+
from pyrogram import filters
5+
6+
from VCPlayBot.config import COMMAND_PREFIXES
7+
8+
other_filters = filters.group & ~filters.edited & ~filters.via_bot & ~filters.forwarded
9+
other_filters2 = (
10+
filters.private & ~filters.edited & ~filters.via_bot & ~filters.forwarded
11+
)
12+
13+
14+
def command(commands: Union[str, List[str]]):
15+
return filters.command(commands, COMMAND_PREFIXES)

VCPlayBot/helpers/gets.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from typing import Union
2+
3+
from pyrogram.types import Audio
4+
from pyrogram.types import Message
5+
from pyrogram.types import Voice
6+
7+
8+
def get_url(message_1: Message) -> Union[str, None]:
9+
messages = [message_1]
10+
11+
if message_1.reply_to_message:
12+
messages.append(message_1.reply_to_message)
13+
14+
text = ""
15+
offset = None
16+
length = None
17+
18+
for message in messages:
19+
if offset:
20+
break
21+
22+
if message.entities:
23+
for entity in message.entities:
24+
if entity.type == "url":
25+
text = message.text or message.caption
26+
offset, length = entity.offset, entity.length
27+
break
28+
29+
if offset in (None,):
30+
return None
31+
32+
return text[offset : offset + length]
33+
34+
35+
def get_file_name(audio: Union[Audio, Voice]):
36+
return f'{audio.file_unique_id}.{audio.file_name.split(".")[-1] if not isinstance(audio, Voice) else "ogg"}'

VCPlayBot/modules/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

VCPlayBot/modules/admins.py

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
2+
3+
from asyncio import QueueEmpty
4+
from pyrogram import Client
5+
from pyrogram import filters
6+
from pyrogram.types import Message
7+
8+
from VCPlayBot.config import que
9+
from VCPlayBot.function.admins import set
10+
from VCPlayBot.helpers.channelmusic import get_chat_id
11+
from VCPlayBot.helpers.decorators import authorized_users_only
12+
from VCPlayBot.helpers.decorators import errors
13+
from VCPlayBot.helpers.filters import command
14+
from VCPlayBot.helpers.filters import other_filters
15+
from VCPlayBot.services.callsmusic import callsmusic
16+
from VCPlayBot.services.queues import queues
17+
18+
19+
@Client.on_message(filters.command("adminreset"))
20+
async def update_admin(client, message: Message):
21+
chat_id = get_chat_id(message.chat)
22+
set(
23+
chat_id,
24+
[
25+
member.user
26+
for member in await message.chat.get_members(filter="administrators")
27+
],
28+
)
29+
await message.reply_text("❇️ Admin cache refreshed!")
30+
31+
32+
@Client.on_message(command("pause") & other_filters)
33+
@errors
34+
@authorized_users_only
35+
async def pause(_, message: Message):
36+
chat_id = get_chat_id(message.chat)
37+
if (chat_id not in callsmusic.active_chats) or (
38+
callsmusic.active_chats[chat_id] == "paused"
39+
):
40+
await message.reply_text("❗ Nothing is playing!")
41+
else:
42+
callsmusic.pause(chat_id)
43+
await message.reply_text("▶️ Paused!")
44+
45+
46+
@Client.on_message(command("resume") & other_filters)
47+
@errors
48+
@authorized_users_only
49+
async def resume(_, message: Message):
50+
chat_id = get_chat_id(message.chat)
51+
if (chat_id not in callsmusic.active_chats) or (
52+
callsmusic.active_chats[chat_id] == "playing"
53+
):
54+
await message.reply_text("❗ Nothing is paused!")
55+
else:
56+
callsmusic.resume(chat_id)
57+
await message.reply_text("⏸ Resumed!")
58+
59+
60+
@Client.on_message(command("end") & other_filters)
61+
@errors
62+
@authorized_users_only
63+
async def stop(_, message: Message):
64+
chat_id = get_chat_id(message.chat)
65+
if chat_id not in callsmusic.active_chats:
66+
await message.reply_text("❗ Nothing is streaming!")
67+
else:
68+
try:
69+
queues.clear(chat_id)
70+
except QueueEmpty:
71+
pass
72+
73+
await callsmusic.stop(chat_id)
74+
await message.reply_text("❌ Stopped streaming!")
75+
76+
77+
@Client.on_message(command("skip") & other_filters)
78+
@errors
79+
@authorized_users_only
80+
async def skip(_, message: Message):
81+
global que
82+
chat_id = get_chat_id(message.chat)
83+
if chat_id not in callsmusic.active_chats:
84+
await message.reply_text("❗ Nothing is playing to skip!")
85+
else:
86+
queues.task_done(chat_id)
87+
if queues.is_empty(chat_id):
88+
await callsmusic.stop(chat_id)
89+
else:
90+
await callsmusic.set_stream(
91+
chat_id,
92+
queues.get(chat_id)["file_path"]
93+
)
94+
95+
qeue = que.get(chat_id)
96+
if qeue:
97+
skip = qeue.pop(0)
98+
if not qeue:
99+
return
100+
await message.reply_text(f"- Skipped **{skip[0]}**\n- Now Playing **{qeue[0][0]}**")
101+
102+
103+
@Client.on_message(filters.command("admincache"))
104+
@errors
105+
async def admincache(client, message: Message):
106+
set(
107+
message.chat.id,
108+
[
109+
member.user
110+
for member in await message.chat.get_members(filter="administrators")
111+
],
112+
)
113+
await message.reply_text("❇️ Admin cache refreshed!")

0 commit comments

Comments
 (0)