Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
Sample envv
Browse files Browse the repository at this point in the history
  • Loading branch information
TheHamkerCat committed Jul 18, 2021
1 parent 79b2f9b commit 6a7ef69
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 25 deletions.
Binary file added etc/sample_input.raw
Binary file not shown.
31 changes: 24 additions & 7 deletions functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
from sample_config import SESSION_STRING

app = Client(
SESSION_STRING if HEROKU else "tgvc", api_id=API_ID, api_hash=API_HASH
SESSION_STRING if HEROKU else "tgvc",
api_id=API_ID,
api_hash=API_HASH,
)
session = ClientSession()
arq = ARQ(ARQ_API, ARQ_API_KEY, session)
Expand Down Expand Up @@ -136,7 +138,8 @@ def convert_seconds(seconds: int):
def time_to_seconds(time):
stringt = str(time)
return sum(
int(x) * 60 ** i for i, x in enumerate(reversed(stringt.split(":")))
int(x) * 60 ** i
for i, x in enumerate(reversed(stringt.split(":")))
)


Expand All @@ -157,7 +160,9 @@ async def send(*args, **kwargs):
# Generate cover for youtube


async def generate_cover(requested_by, title, artist, duration, thumbnail):
async def generate_cover(
requested_by, title, artist, duration, thumbnail
):
async with session.get(thumbnail) as resp:
if resp.status == 200:
f = await aiofiles.open("background.png", mode="wb")
Expand All @@ -176,24 +181,36 @@ async def generate_cover(requested_by, title, artist, duration, thumbnail):
img = Image.open(temp)
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("etc/font.otf", 32)
draw.text((190, 550), f"Title: {title}", (255, 255, 255), font=font)
draw.text((190, 590), f"Duration: {duration}", (255, 255, 255), font=font)
draw.text(
(190, 550), f"Title: {title}", (255, 255, 255), font=font
)
draw.text(
(190, 590),
f"Duration: {duration}",
(255, 255, 255),
font=font,
)
draw.text(
(190, 630),
f"Artist: {artist}",
(255, 255, 255),
font=font,
)
draw.text(
(190, 670), f"Requested By: {requested_by}", (255, 255, 255), font=font
(190, 670),
f"Requested By: {requested_by}",
(255, 255, 255),
font=font,
)
img.save(final)
os.remove(temp)
os.remove(background)
try:
await change_vc_title(title)
except Exception:
await send(text="[ERROR]: FAILED TO EDIT VC TITLE, MAKE ME ADMIN.")
await send(
text="[ERROR]: FAILED TO EDIT VC TITLE, MAKE ME ADMIN."
)
pass
return final

Expand Down
59 changes: 43 additions & 16 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import traceback

from pyrogram import filters, idle
from pyrogram.errors.exceptions.bad_request_400 import ChatAdminRequired
from pyrogram.errors.exceptions.bad_request_400 import \
ChatAdminRequired
from pyrogram.raw.functions.phone import CreateGroupCall
from pyrogram.raw.types import InputPeerChannel
from pyrogram.types import Message
Expand All @@ -17,8 +18,8 @@
db.init()

from db import db
from functions import (CHAT_ID, app, get_default_service, play_song, session,
telegram)
from functions import (CHAT_ID, app, get_default_service, play_song,
session, telegram)
from misc import HELP_TEXT, REPO_TEXT

running = False # Tells if the queue is running or not
Expand All @@ -35,11 +36,15 @@ async def repo(_, message):


@app.on_message(
filters.command("joinvc") & ~filters.private & filters.chat(CHAT_ID)
filters.command("joinvc")
& ~filters.private
& filters.chat(CHAT_ID)
)
async def joinvc(_, message, manual=False):
if "call" in db:
return await message.reply_text("__**Bot Is Already In The VC**__")
return await message.reply_text(
"__**Bot Is Already In The VC**__"
)
os.popen("cp etc/sample_input.raw input.raw")
vc = GroupCall(app, "input.raw")
db["call"] = vc
Expand Down Expand Up @@ -69,7 +74,9 @@ async def joinvc(_, message, manual=False):


@app.on_message(
filters.command("leavevc") & ~filters.private & filters.chat(CHAT_ID)
filters.command("leavevc")
& ~filters.private
& filters.chat(CHAT_ID)
)
async def leavevc(_, message):
if "call" in db:
Expand All @@ -80,7 +87,9 @@ async def leavevc(_, message):


@app.on_message(
filters.command("volume") & ~filters.private & filters.chat(CHAT_ID)
filters.command("volume")
& ~filters.private
& filters.chat(CHAT_ID)
)
async def volume_bot(_, message):
usage = "**Usage:**\n/volume [1-200]"
Expand All @@ -100,7 +109,9 @@ async def volume_bot(_, message):


@app.on_message(
filters.command("pause") & ~filters.private & filters.chat(CHAT_ID)
filters.command("pause")
& ~filters.private
& filters.chat(CHAT_ID)
)
async def pause_song_func(_, message):
if "call" not in db:
Expand All @@ -110,11 +121,15 @@ async def pause_song_func(_, message):
return await message.reply_text("**Already paused**")
db["paused"] = True
db["call"].pause_playout()
await message.reply_text("**Paused The Music, Send `/resume` To Resume.**")
await message.reply_text(
"**Paused The Music, Send `/resume` To Resume.**"
)


@app.on_message(
filters.command("resume") & ~filters.private & filters.chat(CHAT_ID)
filters.command("resume")
& ~filters.private
& filters.chat(CHAT_ID)
)
async def resume_song(_, message):
if "call" not in db:
Expand All @@ -124,7 +139,9 @@ async def resume_song(_, message):
return await message.reply_text("**Already playing**")
db["paused"] = False
db["call"].resume_playout()
await message.reply_text("**Resumed, Send `/pause` To Pause The Music.**")
await message.reply_text(
"**Resumed, Send `/pause` To Pause The Music.**"
)


@app.on_message(
Expand Down Expand Up @@ -155,7 +172,8 @@ async def queuer(_, message):
__**/play Reply_On_Audio**__"""

if len(message.command) < 2 and (
not message.reply_to_message or not message.reply_to_message.audio
not message.reply_to_message
or not message.reply_to_message.audio
):
return await message.reply_text(usage)
if "call" not in db:
Expand Down Expand Up @@ -202,7 +220,9 @@ async def queuer(_, message):


@app.on_message(
filters.command("queue") & ~filters.private & filters.chat(CHAT_ID)
filters.command("queue")
& ~filters.private
& filters.chat(CHAT_ID)
)
async def queue_list(_, message):
if "queue" not in db:
Expand Down Expand Up @@ -257,12 +277,17 @@ async def start_queue(message=None):
await telegram(data["message"])
else:
await play_song(
data["requested_by"], data["query"], data["message"], service
data["requested_by"],
data["query"],
data["message"],
service,
)


@app.on_message(
filters.command("delqueue") & ~filters.private & filters.chat(CHAT_ID)
filters.command("delqueue")
& ~filters.private
& filters.chat(CHAT_ID)
)
async def clear_queue(_, message):
global db
Expand All @@ -278,7 +303,9 @@ async def clear_queue(_, message):


@app.on_message(
filters.command("playlist") & ~filters.private & filters.chat(CHAT_ID)
filters.command("playlist")
& ~filters.private
& filters.chat(CHAT_ID)
)
async def playlist(_, message: Message, redirected=False):
if message.reply_to_message:
Expand Down
2 changes: 2 additions & 0 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ API_HASH=e46b6c854d2bf58a0

SESSION_STRING=your_session # Run generate_string_session.py to get session

CHAT_ID=-10036546354

DEFAULT_SERVICE=youtube # Must be one of youtube/deezer/saavn

ARQ_API_KEY=Get_it_from @ARQRobot
Expand Down
8 changes: 6 additions & 2 deletions sample_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
load_dotenv() # take environment variables from .env.
API_ID = int(environ["API_ID"])
API_HASH = environ["API_HASH"]
SESSION_STRING = environ["SESSION_STRING"] # Check Readme for session
SESSION_STRING = environ[
"SESSION_STRING"
] # Check Readme for session
ARQ_API_KEY = environ["ARQ_API_KEY"]
CHAT_ID = int(environ["CHAT_ID"])
DEFAULT_SERVICE = environ.get("DEFAULT_SERVICE") or "youtube"
Expand All @@ -20,7 +22,9 @@
API_HASH = "e46b6c854d2bf58a0"
ARQ_API_KEY = "Get this from @ARQRobot"
CHAT_ID = -100546355432
DEFAULT_SERVICE = "youtube" # Must be one of "youtube"/"deezer"/"saavn"
DEFAULT_SERVICE = (
"youtube" # Must be one of "youtube"/"deezer"/"saavn"
)

# don't make changes below this line
ARQ_API = "https://thearq.tech"

0 comments on commit 6a7ef69

Please sign in to comment.