Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class Config:
#heroku
API_KEY=os.environ.get("HEROKU_API_KEY", None)
APP_NAME=os.environ.get("HEROKU_APP_NAME", None)



#Optional Configuration
SHUFFLE=is_enabled(os.environ.get("SHUFFLE", 'True'))
ADMIN_ONLY=is_enabled(os.environ.get("ADMIN_ONLY", "False"))
Expand Down Expand Up @@ -92,6 +93,10 @@ class Config:

SCHEDULE_LIST=[]
playlist=[]
CONFIG_LIST = ["ADMINS", "IS_VIDEO", "IS_LOOP", "REPLY_PM", "ADMIN_ONLY", "SHUFFLE", "EDIT_TITLE", "CHAT",
"SUDO", "REPLY_MESSAGE", "STREAM_URL", "DELAY", "LOG_GROUP", "SCHEDULED_STREAM", "SCHEDULE_LIST",
"IS_VIDEO_RECORD", "IS_RECORDING", "WAS_RECORDING", "RECORDING_TITLE", "PORTRAIT", "RECORDING_DUMP", "HAS_SCHEDULE",
"CUSTOM_QUALITY"]

STARTUP_ERROR=None

Expand Down Expand Up @@ -133,7 +138,7 @@ class Config:
REPLY_PM=True
LOGGER.info("Reply Message Found, Enabled PM MSG")
else:
REPLY_MESSAGE=None
REPLY_MESSAGE=False
REPLY_PM=False

if E_BITRATE:
Expand Down
5 changes: 4 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
play,
start_stream,
startup_check,
sync_from_db
sync_from_db,
check_changes
)
from user import group_call, USER
from utils import LOGGER
Expand All @@ -25,6 +26,7 @@
from bot import bot
import asyncio
import os

if Config.DATABASE_URI:
from utils import db

Expand All @@ -43,6 +45,7 @@ async def main():
await db.del_config("RESTART")
except:
pass
await check_changes()
await sync_from_db()
except Exception as e:
LOGGER.error(f"Errors occured while setting up database for VCPlayerBot, check the value of DATABASE_URI. Full error - {str(e)}", exc_info=True)
Expand Down
26 changes: 21 additions & 5 deletions plugins/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,27 @@ async def set_heroku_var(client, message):
m = await message.reply("Checking config vars..")
if " " in message.text:
cmd, env = message.text.split(" ", 1)
if not "=" in env:
await m.edit("You should specify the value for env.\nExample: /env CHAT=-100213658211")
await delete_messages([message, m])
return
var, value = env.split("=", 1)
if "=" in env:
var, value = env.split("=", 1)
else:
if env == "STARTUP_STREAM":
env_ = "STREAM_URL"
elif env == "QUALITY":
env_ = "CUSTOM_QUALITY"
else:
env_ = env
ENV_VARS = ["ADMINS", "SUDO", "CHAT", "LOG_GROUP", "STREAM_URL", "SHUFFLE", "ADMIN_ONLY", "REPLY_MESSAGE",
"EDIT_TITLE", "RECORDING_DUMP", "RECORDING_TITLE", "IS_VIDEO", "IS_LOOP", "DELAY", "PORTRAIT",
"IS_VIDEO_RECORD", "PTN", "CUSTOM_QUALITY"]
if env_ in ENV_VARS:
await m.edit(f"Current Value for `{env}` is `{getattr(Config, env_)}`")
await delete_messages([message])
return
else:
await m.edit("This is an invalid env value. Read help on env to know about available env vars.")
await delete_messages([message, m])
return

else:
await m.edit("You haven't provided any value for env, you should follow the correct format.\nExample: <code>/env CHAT=-1020202020202</code> to change or set CHAT var.\n<code>/env REPLY_MESSAGE= <code>To delete REPLY_MESSAGE.")
await delete_messages([message, m])
Expand Down
4 changes: 2 additions & 2 deletions plugins/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ async def set_vol(_, m: Message):



@Client.on_message(filters.command(['mute', f"mute@{Config.BOT_USERNAME}"]) & admin_filter & chat_filter)
@Client.on_message(filters.command(['vcmute', f"vcmute@{Config.BOT_USERNAME}"]) & admin_filter & chat_filter)
async def set_mute(_, m: Message):
if not Config.CALL_STATUS:
await m.reply_text(
Expand All @@ -197,7 +197,7 @@ async def set_mute(_, m: Message):
k = await m.reply_text("Already muted.")
await delete_messages([m, k])

@Client.on_message(filters.command(['unmute', f"unmute@{Config.BOT_USERNAME}"]) & admin_filter & chat_filter)
@Client.on_message(filters.command(['vcunmute', f"vcunmute@{Config.BOT_USERNAME}"]) & admin_filter & chat_filter)
async def set_unmute(_, m: Message):
if not Config.CALL_STATUS:
await m.reply_text(
Expand Down
17 changes: 13 additions & 4 deletions plugins/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,17 @@ async def add_to_playlist(_, message: Message):
nyav = now.strftime("%d-%m-%Y-%H:%M:%S")
if type in ["video", "audio"]:
if type == "audio":
if m_video.title is None:
if m_video.file_name is None:
title_ = "Music"
else:
title_ = m_video.file_name
else:
title_ = m_video.title
if m_video.performer is not None:
title = f"{m_video.performer} - {m_video.title}"
title = f"{m_video.performer} - {title_}"
else:
title=m_video.title
title=title_
unique = f"{nyav}_{m_video.file_size}_audio"
else:
title=m_video.file_name
Expand All @@ -167,6 +174,8 @@ async def add_to_playlist(_, message: Message):
if title_:
title = title_
file_id=m_video.file_id
if title is None:
title = 'Music'
data={1:title, 2:file_id, 3:"telegram", 4:user, 5:unique}
if message.command[0] == "fplay":
pla = [data] + Config.playlist
Expand Down Expand Up @@ -462,11 +471,11 @@ async def stream(client, m: Message):



admincmds=["yplay", "leave", "pause", "resume", "skip", "restart", "volume", "shuffle", "clearplaylist", "export", "import", "update", 'replay', 'logs', 'stream', 'fplay', 'schedule', 'record', 'slist', 'cancel', 'cancelall', 'vcpromote', 'vcdemote', 'refresh', 'rtitle', 'seek', 'mute', 'unmute',
admincmds=["yplay", "leave", "pause", "resume", "skip", "restart", "volume", "shuffle", "clearplaylist", "export", "import", "update", 'replay', 'logs', 'stream', 'fplay', 'schedule', 'record', 'slist', 'cancel', 'cancelall', 'vcpromote', 'vcdemote', 'refresh', 'rtitle', 'seek', 'vcmute', 'unmute',
f'stream@{Config.BOT_USERNAME}', f'logs@{Config.BOT_USERNAME}', f"replay@{Config.BOT_USERNAME}", f"yplay@{Config.BOT_USERNAME}", f"leave@{Config.BOT_USERNAME}", f"pause@{Config.BOT_USERNAME}", f"resume@{Config.BOT_USERNAME}", f"skip@{Config.BOT_USERNAME}",
f"restart@{Config.BOT_USERNAME}", f"volume@{Config.BOT_USERNAME}", f"shuffle@{Config.BOT_USERNAME}", f"clearplaylist@{Config.BOT_USERNAME}", f"export@{Config.BOT_USERNAME}", f"import@{Config.BOT_USERNAME}", f"update@{Config.BOT_USERNAME}",
f'play@{Config.BOT_USERNAME}', f'schedule@{Config.BOT_USERNAME}', f'record@{Config.BOT_USERNAME}', f'slist@{Config.BOT_USERNAME}', f'cancel@{Config.BOT_USERNAME}', f'cancelall@{Config.BOT_USERNAME}', f'vcpromote@{Config.BOT_USERNAME}',
f'vcdemote@{Config.BOT_USERNAME}', f'refresh@{Config.BOT_USERNAME}', f'rtitle@{Config.BOT_USERNAME}', f'seek@{Config.BOT_USERNAME}', f'mute@{Config.BOT_USERNAME}', f'unmute@{Config.BOT_USERNAME}'
f'vcdemote@{Config.BOT_USERNAME}', f'refresh@{Config.BOT_USERNAME}', f'rtitle@{Config.BOT_USERNAME}', f'seek@{Config.BOT_USERNAME}', f'mute@{Config.BOT_USERNAME}', f'vcunmute@{Config.BOT_USERNAME}'
]

allcmd = ["play", "player", f"play@{Config.BOT_USERNAME}", f"player@{Config.BOT_USERNAME}"] + admincmds
Expand Down
13 changes: 11 additions & 2 deletions plugins/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,17 @@ async def schedule_vc(bot, message):
nyav = now.strftime("%d-%m-%Y-%H:%M:%S")
if type in ["video", "audio"]:
if type == "audio":
if m_video.title is None:
if m_video.file_name is None:
title_ = "Music"
else:
title_ = m_video.file_name
else:
title_ = m_video.title
if m_video.performer is not None:
title = f"{m_video.performer} - {m_video.title}"
title = f"{m_video.performer} - {title_}"
else:
title=m_video.title
title=title_
unique = f"{nyav}_{m_video.file_size}_audio"
else:
title=m_video.file_name
Expand All @@ -133,6 +140,8 @@ async def schedule_vc(bot, message):
title_ = ny.get("title")
if title_:
title = title_
if title is None:
title = 'Music'
data={'1':title, '2':m_video.file_id, '3':"telegram", '4':user, '5':unique}
sid=f"{message.chat.id}_{msg.message_id}"
Config.SCHEDULED_STREAM[sid] = data
Expand Down
14 changes: 11 additions & 3 deletions utils/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ def __init__(self):
self.db = self._client[Config.DATABASE_NAME]
self.col = self.db.config
self.playlist = self.db.playlist
def new_config(self, name, value):
def new_config(self, name, value, dvalue):
return dict(
name = name,
dvalue = dvalue,
value = value,
)
def add_config(self, name, value):
config = self.new_config(name, value)
def add_config(self, name, value, dvalue=None):
config = self.new_config(name, value, dvalue)
self.col.insert_one(config)

def new_song(self, id_, song):
Expand All @@ -48,6 +49,13 @@ async def is_saved(self, name):

async def edit_config(self, name, value):
await self.col.update_one({'name': name}, {'$set': {'value': value}})

async def edit_default(self, name, dvalue):
await self.col.update_one({'name': name}, {'$set': {'dvalue': dvalue}})

async def get_default(self, name):
config = await self.col.find_one({'name':name})
return config.get('dvalue')

async def get_config(self, name):
config = await self.col.find_one({'name':name})
Expand Down
Loading