forked from AsmSafone/RadioPlayerV3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
186 lines (175 loc) · 5.62 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
"""
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 import functions, types
from user import USER
from pyrogram.types import Message
from pyrogram.errors import UserAlreadyParticipant
CHAT=Config.CHAT
ADMINS=Config.ADMINS
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:
return
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(
functions.bots.SetBotCommands(
commands=[
types.BotCommand(
command="start",
description="Start The Bot"
),
types.BotCommand(
command="help",
description="Show Help Message"
),
types.BotCommand(
command="play",
description="Play Music From YouTube"
),
types.BotCommand(
command="song",
description="Download Music As Audio"
),
types.BotCommand(
command="skip",
description="Skip The Current Music"
),
types.BotCommand(
command="pause",
description="Pause The Current Music"
),
types.BotCommand(
command="resume",
description="Resume The Paused Music"
),
types.BotCommand(
command="radio",
description="Start Radio/Live Stream"
),
types.BotCommand(
command="current",
description="Show Current Playing Song"
),
types.BotCommand(
command="playlist",
description="Show The Current Playlist"
),
types.BotCommand(
command="join",
description="Join To The Voice Chat"
),
types.BotCommand(
command="leave",
description="Leave From The Voice Chat"
),
types.BotCommand(
command="stop",
description="Stop Playing The Music"
),
types.BotCommand(
command="stopradio",
description="Stop Radio/Live Stream"
),
types.BotCommand(
command="replay",
description="Replay From The Begining"
),
types.BotCommand(
command="clean",
description="Clean Unused RAW PCM Files"
),
types.BotCommand(
command="mute",
description="Mute Userbot In Voice Chat"
),
types.BotCommand(
command="unmute",
description="Unmute Userbot In Voice Chat"
),
types.BotCommand(
command="volume",
description="Change The Voice Chat Volume"
),
types.BotCommand(
command="restart",
description="Update & Restart Bot (Owner Only)"
)
]
)
)
@bot.on_message(filters.command(["restart", f"restart@{USERNAME}"]) & filters.user(ADMINS) & (filters.chat(CHAT) | filters.private | filters.chat(LOG_GROUP)))
async def restart(_, message: Message):
k=await message.reply_text("🔄 **Checking Updates ...**")
await asyncio.sleep(3)
await k.edit("🔄 **Updating, Please Wait...**")
await asyncio.sleep(5)
await k.edit("🔄 **Successfully Updated!**")
await asyncio.sleep(3)
await k.edit("🔄 **Restarting, Please Wait...**")
await asyncio.sleep(5)
process = FFMPEG_PROCESSES.get(CHAT)
if process:
try:
process.send_signal(SIGINT)
except subprocess.TimeoutExpired:
process.kill()
except Exception as e:
print(e)
pass
FFMPEG_PROCESSES[CHAT] = ""
Thread(
target=stop_and_restart
).start()
try:
await k.edit("✅ **Restarted Successfully! \nJoin @AsmSafone For More!**")
await k.reply_to_message.delete()
except:
pass
idle()
bot.stop()
print("\n\nRadio Player Bot Stopped, Join @AsmSafone!")