Skip to content

Commit

Permalink
v1.1 [ YukkiMusic ]
Browse files Browse the repository at this point in the history
  • Loading branch information
Vivekkumar-IN committed Oct 14, 2024
1 parent 851499d commit 1a7c51d
Show file tree
Hide file tree
Showing 74 changed files with 2,311 additions and 2,529 deletions.
16 changes: 12 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
FROM nikolaik/python-nodejs:python3.10-nodejs19
FROM python:3.12.7-slim

# Install necessary system dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends ffmpeg \
&& apt-get install -y --no-install-recommends \
curl ffmpeg git build-essential libssl-dev apt-utils \
zlib1g-dev libjpeg-dev libtiff5-dev libopenjp2-7 libtiff-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN curl -fsSL https://deb.nodesource.com/setup_19.x | bash - \
&& apt-get install -y nodejs \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

COPY . /app/
WORKDIR /app/
RUN python3 -m pip install --upgrade pip setuptools
RUN pip3 install --no-cache-dir --upgrade --requirement requirements.txt
RUN python3 -m pip install --upgrade pip setuptools \
&& pip3 install --no-cache-dir --upgrade --requirement requirements.txt

CMD python3 -m YukkiMusic
1 change: 1 addition & 0 deletions YukkiMusic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
YouTube = YouTubeAPI()
Carbon = CarbonAPI()
Spotify = SpotifyAPI()
Saavn = SaavnAPI()
Apple = AppleAPI()
Resso = RessoAPI()
SoundCloud = SoundAPI()
Expand Down
2 changes: 1 addition & 1 deletion YukkiMusic/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
# Please see < https://github.com/TheTeamVivek/YukkiMusic/blob/master/LICENSE >
#
# All rights reserved.
import sys
import asyncio
import importlib
import sys

from pyrogram import idle
from pytgcalls.exceptions import NoActiveGroupCall
Expand Down
65 changes: 48 additions & 17 deletions YukkiMusic/core/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from pyrogram import Client
from pyrogram.enums import ChatMemberStatus
from pyrogram.errors import FloodWait
from pyrogram.types import (
BotCommand,
BotCommandScopeAllChatAdministrators,
Expand All @@ -39,6 +40,37 @@ def __init__(self):
in_memory=True,
)

async def edit_message_text(self, *args, **kwargs):
try:
return await super().edit_message_text(*args, **kwargs)
except FloodWait as e:
time = int(e.value)
await asyncio.sleep(time)
if time < 25:
return await self.edit_message_text(self, *args, **kwargs)

async def send_message(self, *args, **kwargs):
if kwargs.get("send_direct", False):
kwargs.pop("send_direct", None)
return await super().send_message(*args, **kwargs)

try:
return await super().send_message(*args, **kwargs)
except FloodWait as e:
time = int(e.value)
await asyncio.sleep(time)
if time < 25:
return await self.send_message(self, *args, **kwargs)

async def send_photo(self, *args, **kwargs):
try:
return await super().send_photo(*args, **kwargs)
except FloodWait as e:
time = int(e.value)
await asyncio.sleep(time)
if time < 25:
return await self.send_photo(self, *args, **kwargs)

async def start(self):
await super().start()
get_me = await self.get_me()
Expand All @@ -50,45 +82,44 @@ async def start(self):
try:
await self.send_message(
config.LOG_GROUP_ID,
text=f"<u><b>{self.mention} ʙᴏᴛ sᴛᴀʀᴛᴇᴅ :</b><u>\n\nɪᴅ : <code>{self.id}</code>\nɴᴀᴍᴇ : {self.name}\nᴜsᴇʀɴᴀᴍᴇ : @{self.username}",
text=f"<u><b>{self.mention} Bot Started :</b><u>\n\nId : <code>{self.id}</code>\nName : {self.name}\nUsername : @{self.username}",
)
except:
LOGGER(__name__).error(
"Bot has failed to access the log Group. Make sure that you have added your bot to your log channel and promoted as admin!"
"Bot has failed to access the log group. Make sure that you have added your bot to your log channel and promoted as admin!"
)
# sys.exit()
if config.SET_CMDS == str(True):
try:

await self.set_bot_commands(
commands=[
BotCommand("start", "sᴛᴀʀᴛ ᴛʜᴇ ʙᴏᴛ"),
BotCommand("help", "ɢᴇᴛ ᴛʜᴇ ʜᴇʟᴘ ᴍᴇɴᴜ"),
BotCommand("ping", "ᴄʜᴇᴄᴋ ʙᴏᴛ ɪs ᴀʟɪᴠᴇ ᴏʀ ᴅᴇᴀᴅ"),
BotCommand("start", "Start the bot"),
BotCommand("help", "Get the help menu"),
BotCommand("ping", "Check if the bot is alive or dead"),
],
scope=BotCommandScopeAllPrivateChats(),
)
await self.set_bot_commands(
commands=[
BotCommand("play", "sᴛᴀʀᴛ ᴘʟᴀʏɪɴɢ ʀᴇǫᴜᴇᴛᴇᴅ sᴏɴɢ"),
BotCommand("play", "Start playing requested song"),
],
scope=BotCommandScopeAllGroupChats(),
)
await self.set_bot_commands(
commands=[
BotCommand("play", "sᴛᴀʀᴛ ᴘʟᴀʏɪɴɢ ʀᴇǫᴜᴇᴛᴇᴅ sᴏɴɢ"),
BotCommand("skip", "ᴍᴏᴠᴇ ᴛᴏ ɴᴇxᴛ ᴛʀᴀᴄᴋ ɪɴ ǫᴜᴇᴜᴇ"),
BotCommand("pause", "ᴘʟᴀᴜsᴇ ᴛʜᴇ ᴄᴜʀʀᴇɴᴛ ᴘʟᴀʏɪɴɢ sᴏɴɢ"),
BotCommand("resume", "ʀᴇsᴜᴍᴇ ᴛʜᴇ ᴘᴀᴜsᴇᴅ sᴏɴɢ"),
BotCommand("end", "ᴄʟᴇᴀʀ ᴛʜᴇ ǫᴜᴇᴜᴇ ᴀᴍᴅ ʟᴇᴀᴠᴇ ᴠᴏɪᴄᴇᴄʜᴀᴛ"),
BotCommand("shuffle", "Rᴀɴᴅᴏᴍʟʏ sʜᴜғғʟᴇs ᴛʜᴇ ǫᴜᴇᴜᴇᴅ ᴘʟᴀʏʟɪsᴛ."),
BotCommand("play", "Start playing requested song"),
BotCommand("skip", "Move to next track in queue"),
BotCommand("pause", "Pause the current playing song"),
BotCommand("resume", "Resume the paused song"),
BotCommand("end", "Clear the queue and leave voicechat"),
BotCommand("shuffle", "Randomly shuffles the queued playlist."),
BotCommand(
"playmode",
"Aʟʟᴏᴡs ʏᴏᴜ ᴛᴏ ᴄʜᴀɴɢᴇ ᴛʜᴇ ᴅᴇғᴀᴜʟᴛ ᴘʟᴀʏᴍᴏᴅᴇ ғᴏʀ ʏᴏᴜʀ ᴄʜᴀᴛ",
"Allows you to change the default playmode for your chat",
),
BotCommand(
"settings",
"Oᴘᴇɴ ᴛʜᴇ sᴇᴛᴛɪɴɢs ᴏғ ᴛʜᴇ ᴍᴜsɪᴄ ʙᴏᴛ ғᴏʀ ʏᴏᴜʀ ᴄʜᴀᴛ.",
"Open the settings of the music bot for your chat.",
),
],
scope=BotCommandScopeAllChatAdministrators(),
Expand All @@ -100,15 +131,15 @@ async def start(self):
try:
a = await self.get_chat_member(config.LOG_GROUP_ID, self.id)
if a.status != ChatMemberStatus.ADMINISTRATOR:
LOGGER(__name__).error("Please promote Bot as Admin in Logger Group")
LOGGER(__name__).error("Please promote bot as admin in logger group")
sys.exit()
except Exception:
pass
if get_me.last_name:
self.name = get_me.first_name + " " + get_me.last_name
else:
self.name = get_me.first_name
LOGGER(__name__).info(f"MusicBot Started as {self.name}")
LOGGER(__name__).info(f"MusicBot started as {self.name}")

async def stop(self):
await super().stop()
57 changes: 36 additions & 21 deletions YukkiMusic/core/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from typing import Union

from ntgcalls import TelegramServerError
from pyrogram.errors import FloodWait
from pyrogram.types import InlineKeyboardMarkup
from pytgcalls import PyTgCalls, filters
from pytgcalls.exceptions import AlreadyJoinedError, NoActiveGroupCall
Expand All @@ -23,6 +22,7 @@
StreamVideoEnded,
Update,
)

import config
from strings import get_string
from YukkiMusic import LOGGER, YouTube, app, userbot
Expand All @@ -45,14 +45,15 @@
from YukkiMusic.utils.stream.autoclear import auto_clean
from YukkiMusic.utils.thumbnails import gen_thumb


async def _clear_(chat_id):
popped = db.pop(chat_id, None)
if popped:
await auto_clean(popped)
db[chat_id] = []
await remove_active_video_chat(chat_id)
await remove_active_chat(chat_id)
await set_loop(chat_id, 0)


class Call:
def __init__(self):
self.calls = []
Expand Down Expand Up @@ -200,16 +201,16 @@ async def join_call(
)
except NoActiveGroupCall:
raise AssistantErr(
"**ɴᴏ ᴀᴄᴛɪᴠᴇ ᴠɪᴅᴇᴏ ᴄʜᴀᴛ ғᴏᴜɴᴅ**\n\nᴩʟᴇᴀsᴇ ᴍᴀᴋᴇ sᴜʀᴇ ʏᴏᴜ sᴛᴀʀᴛᴇᴅ ᴛʜᴇ ᴠɪᴅᴇᴏᴄʜᴀᴛ."
"**No active video chat found **\n\nPlease make sure you started the voicechat."
)

except AlreadyJoinedError:
raise AssistantErr(
"**ᴀssɪsᴛᴀɴᴛ ᴀʟʀᴇᴀᴅʏ ɪɴ ᴠɪᴅᴇᴏᴄʜᴀᴛ**\n\nᴍᴜsɪᴄ ʙᴏᴛ sʏsᴛᴇᴍs ᴅᴇᴛᴇᴄᴛᴇᴅ ᴛʜᴀᴛ ᴀssɪᴛᴀɴᴛ ɪs ᴀʟʀᴇᴀᴅʏ ɪɴ ᴛʜᴇ ᴠɪᴅᴇᴏᴄʜᴀᴛ, ɪғ ᴛʜɪs ᴩʀᴏʙʟᴇᴍ ᴄᴏɴᴛɪɴᴜᴇs ʀᴇsᴛᴀʀᴛ ᴛʜᴇ ᴠɪᴅᴇᴏᴄʜᴀᴛ ᴀɴᴅ ᴛʀʏ ᴀɢᴀɪɴ."
"**ASSISTANT IS ALREADY IN VOICECHAT **\n\nMusic bot system detected that assistant is already in the voicechat, if the problem continues restart the videochat and try again."
)
except TelegramServerError:
raise AssistantErr(
"**ᴛᴇʟᴇɢʀᴀᴍ sᴇʀᴠᴇʀ ᴇʀʀᴏʀ**\n\nᴩʟᴇᴀsᴇ ᴛᴜʀɴ ᴏғғ ᴀɴᴅ ʀᴇsᴛᴀʀᴛ ᴛʜᴇ ᴠɪᴅᴇᴏᴄʜᴀᴛ ᴀɢᴀɪɴ."
"**TELEGRAM SERVER ERROR**\n\nPlease restart Your voicechat."
)
await add_active_chat(chat_id)
await music_on(chat_id)
Expand All @@ -228,6 +229,11 @@ async def change_stream(self, client, chat_id):
await set_loop(chat_id, loop)
if popped:
await auto_clean(popped)
if popped.get("mystic"):
try:
await popped.get("mystic").delete()
except Exception:
pass
if not check:
await _clear_(chat_id)
return await client.leave_call(chat_id)
Expand Down Expand Up @@ -453,23 +459,32 @@ async def change_stream(self, client, chat_id):
)
db[chat_id][0]["mystic"] = run
db[chat_id][0]["markup"] = "tg"
elif "saavn" in videoid:
button = telegram_markup(_, chat_id)
run = await app.send_photo(
original_chat_id,
photo=check[0]["thumb"],
caption=_["stream_1"].format(
title, config.SUPPORT_GROUP, check[0]["dur"], user
),
reply_markup=InlineKeyboardMarkup(button),
)
db[chat_id][0]["mystic"] = run
db[chat_id][0]["markup"] = "tg"
else:
img = await gen_thumb(videoid)
button = stream_markup(_, videoid, chat_id)
try:
run = await app.send_photo(
original_chat_id,
photo=img,
caption=_["stream_1"].format(
title[:27],
f"https://t.me/{app.username}?start=info_{videoid}",
check[0]["dur"],
user,
),
reply_markup=InlineKeyboardMarkup(button),
)
except FloodWait as e:
await asyncio.sleep(e.value)
run = await app.send_photo(
original_chat_id,
photo=img,
caption=_["stream_1"].format(
title[:27],
f"https://t.me/{app.username}?start=info_{videoid}",
check[0]["dur"],
user,
),
reply_markup=InlineKeyboardMarkup(button),
)
db[chat_id][0]["mystic"] = run
db[chat_id][0]["markup"] = "stream"

Expand Down Expand Up @@ -501,4 +516,4 @@ async def stream_end_handler(client, update: Update):
await self.change_stream(client, update.chat_id)


Yukki = Call()
Yukki = Call()
8 changes: 0 additions & 8 deletions YukkiMusic/core/dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#
import logging
import os
import sys
from os import listdir, mkdir

from config import TEMP_DB_FOLDER
Expand All @@ -29,16 +28,9 @@


def dirr():
assets_folder = "assets"
downloads_folder = "downloads"
cache_folder = "cache"

if assets_folder not in listdir():
logging.warning(
f"{assets_folder} Folder not Found. Please clone or fork repository again."
)
sys.exit()

for file in os.listdir():
if any(file.endswith(ext) for ext in files):
os.remove(file)
Expand Down
3 changes: 3 additions & 0 deletions YukkiMusic/core/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
import asyncio
import shlex
from typing import Tuple

from git import Repo
from git.exc import GitCommandError, InvalidGitRepositoryError

import config

from ..logging import LOGGER

loop = asyncio.get_event_loop_policy().get_event_loop()
Expand Down
17 changes: 5 additions & 12 deletions YukkiMusic/core/userbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
#
import asyncio
import sys

from pyrogram import Client
from ..logging import LOGGER

import config

from ..logging import LOGGER

assistants = []
assistantids = []

Expand All @@ -37,15 +40,7 @@ async def _start(self, client, index):
LOGGER(__name__).info("Starting Assistant Clients")
try:
await client.start()
try:
await client.join_chat("TheYukki")
await client.join_chat("YukkiSupport")
await client.join_chat("TheTeamVivek")
except:
pass

assistants.append(index) # Mark the assistant as active

assistants.append(index)
await client.send_message(config.LOG_GROUP_ID, "Assistant Started")

get_me = await client.get_me()
Expand All @@ -70,7 +65,5 @@ async def start(self):

async def stop(self):
"""Gracefully stop all clients."""
LOGGER(__name__).info("Stopping all assistant clients...")
tasks = [client.stop() for client in self.clients]
await asyncio.gather(*tasks)
LOGGER(__name__).info("All assistant clients stopped.")
1 change: 0 additions & 1 deletion YukkiMusic/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

from config import LOG_FILE_NAME


logging.basicConfig(
level=logging.INFO,
format="[%(asctime)s - %(levelname)s] - %(name)s - %(message)s",
Expand Down
Loading

0 comments on commit 1a7c51d

Please sign in to comment.