forked from AsmSafone/RadioPlayerV3
-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.py
192 lines (181 loc) · 5.8 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
"""
RadioPlayerV3, Telegram Voice Chat Bot
Copyright (c) 2021 Asm Safone <https://github.com/AsmSafone>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>
"""
import os
import sys
import asyncio
import subprocess
from time import sleep
from threading import Thread
from signal import SIGINT
from pyrogram import Client, filters, idle
from config import Config
from utils import mp, USERNAME, FFMPEG_PROCESSES
from pyrogram.raw.functions.bots import SetBotCommands
from pyrogram.raw.types import BotCommand, BotCommandScopeDefault
from user import USER
from pyrogram.types import Message
from pyrogram.errors import UserAlreadyParticipant
ADMINS=Config.ADMINS
CHAT_ID=Config.CHAT_ID
LOG_GROUP=Config.LOG_GROUP
bot = Client(
"RadioPlayer",
Config.API_ID,
Config.API_HASH,
bot_token=Config.BOT_TOKEN,
plugins=dict(root="plugins.bot")
)
if not os.path.isdir("./downloads"):
os.makedirs("./downloads")
async def main():
async with bot:
await mp.start_radio()
try:
await USER.join_chat("AsmSafone")
except UserAlreadyParticipant:
pass
except Exception as e:
print(e)
pass
def stop_and_restart():
bot.stop()
os.system("git pull")
sleep(10)
os.execl(sys.executable, sys.executable, *sys.argv)
bot.run(main())
bot.start()
print("\n\nRadio Player Bot Started, Join @AsmSafone!")
bot.send(
SetBotCommands(
scope=BotCommandScopeDefault(),
lang_code="en",
commands=[
BotCommand(
command="start",
description="Start The Bot"
),
BotCommand(
command="help",
description="Show Help Message"
),
BotCommand(
command="play",
description="Play Music From YouTube"
),
BotCommand(
command="song",
description="Download Music As Audio"
),
BotCommand(
command="skip",
description="Skip The Current Music"
),
BotCommand(
command="pause",
description="Pause The Current Music"
),
BotCommand(
command="resume",
description="Resume The Paused Music"
),
BotCommand(
command="radio",
description="Start Radio / Live Stream"
),
BotCommand(
command="current",
description="Show Current Playing Song"
),
BotCommand(
command="playlist",
description="Show The Current Playlist"
),
BotCommand(
command="join",
description="Join To The Voice Chat"
),
BotCommand(
command="leave",
description="Leave From The Voice Chat"
),
BotCommand(
command="stop",
description="Stop Playing The Music"
),
BotCommand(
command="stopradio",
description="Stop Radio / Live Stream"
),
BotCommand(
command="replay",
description="Replay From The Begining"
),
BotCommand(
command="clean",
description="Clean Unused RAW PCM Files"
),
BotCommand(
command="mute",
description="Mute Userbot In Voice Chat"
),
BotCommand(
command="unmute",
description="Unmute Userbot In Voice Chat"
),
BotCommand(
command="volume",
description="Change The Voice Chat Volume"
),
BotCommand(
command="restart",
description="Update & Restart Bot (Owner Only)"
),
BotCommand(
command="setvar",
description="Set / Change Configs Var (For Heroku)"
)
]
)
)
@bot.on_message(filters.command(["restart", f"restart@{USERNAME}"]) & filters.user(ADMINS) & (filters.chat(CHAT_ID) | filters.private | filters.chat(LOG_GROUP)))
async def restart(_, message: Message):
k=await message.reply_text("🔄 **Checking ...**")
await asyncio.sleep(3)
if Config.HEROKU_APP:
await k.edit("🔄 **Heroku Detected, \nRestarting Your App...**")
Config.HEROKU_APP.restart()
else:
await k.edit("🔄 **Restarting, Please Wait...**")
process = FFMPEG_PROCESSES.get(CHAT_ID)
if process:
try:
process.send_signal(SIGINT)
except subprocess.TimeoutExpired:
process.kill()
except Exception as e:
print(e)
pass
FFMPEG_PROCESSES[CHAT_ID] = ""
Thread(
target=stop_and_restart()
).start()
try:
await k.edit("✅ **Restarted Successfully! \nJoin @AsmSafone For Update!**")
await k.reply_to_message.delete()
except:
pass
idle()
print("\n\nRadio Player Bot Stopped, Join @AsmSafone!")
bot.stop()