forked from aykhan026/MusicUserBot
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvocal.py
166 lines (140 loc) · 5.66 KB
/
vocal.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
# Ballasresmi - MusicUserBot
# Burdan hər hansı modulu kodu faylı reponu
# Kopyalayan peysərdi..!!!!
# Sahib - @BOT_RAMO
import os
import ffmpeg
import asyncio
from datetime import datetime
from pyrogram import emoji
from pyrogram.methods.messages.download_media import DEFAULT_DOWNLOAD_DIR as fmedaddyy
from pyrogram.types import Message
from pytgcalls import GroupCall
from ɴᴏᴛᴇʙᴏᴏᴋ.design_i import *
from ᴍɪꜱᴀ_ᴀᴍᴀɴᴇ.life_death import *
"""
\____/ / \ \____/ / \ \____/ / \ \____/ / \ \____/ / \ \____/ /
/ __ \ \__/ / __ \ \__/ / __ \ \__/ / __ \ \__/ / __ \ \__/ / __ \ \_
"""
"+|==========================================🍁----------[-_-]----------🍁==============================================|+"
class DeathCharm(object):
def __init__(self):
self.voice_chatting = GroupCall(None, path_to_log_file='')
self.chat_id = None
self.start_time = None
self.playlist = []
self.msg = {}
async def update_start_time(self, reset=False):
self.start_time = (
None if reset
else datetime.utcnow().replace(microsecond=0)
)
async def send_playlist(self):
playlist = self.playlist
if not playlist:
pl = f"{emoji.NO_ENTRY}**Playlist yoxdur**"
else:
if len(playlist) == 1:
pl = f"""🎧**Səslənir**🎧:\n
"""
else:
pl = f"""🎧**Səslənir**🎧:\n
"""
pl += "\n".join([
f"**{i}**. **[{x.audio.title}]({x.link})**"
for i, x in enumerate(playlist)
])
if self.msg.get('playlist') is not None:
await self.msg['playlist'].delete()
self.msg['playlist'] = await self.send_text(pl)
async def skip_current_playing(self):
voice_chatting = self.voice_chatting
playlist = self.playlist
if not playlist:
return
if len(playlist) == 1:
await self.update_start_time()
return
client = voice_chatting.client
raw_hug = os.path.join(client.workdir, fmedaddyy)
voice_chatting.input_filename = os.path.join(
raw_hug,
f"{playlist[1].audio.file_unique_id}.raw"
)
await self.update_start_time()
# remove old track from playlist
old_track = playlist.pop(0)
print(f"- Oxumağa başladım: {playlist[0].audio.title}")
await self.send_playlist()
os.remove(os.path.join(
raw_hug,
f"{old_track.audio.file_unique_id}.raw")
)
if len(playlist) == 1:
return
await self.download_audio(playlist[1])
async def send_text(self, text):
voice_chatting = self.voice_chatting
client = voice_chatting.client
chat_id = self.chat_id
message = await client.send_message(
chat_id,
text,
disable_web_page_preview=True,
disable_notification=True
)
return message
async def download_audio(self, ryui: Message):
voice_chatting = self.voice_chatting
client = voice_chatting.client
raw_file = os.path.join(client.workdir, fmedaddyy,
f"{ryui.audio.file_unique_id}.raw")
if not os.path.isfile(raw_file):
original_file = await ryui.download()
ffmpeg.input(original_file).output(
raw_file,
format='s16le',
acodec='pcm_s16le',
ac=2,
ar='48k',
loglevel='error'
).overwrite_output().run()
os.remove(original_file)
ded = DeathCharm()
"+|==========================================🍁----------[-_-]----------🍁==============================================|+"
@ded.voice_chatting.on_network_status_changed
async def network_status_changed_handler(ip: GroupCall, is_connected: bool):
if is_connected:
ded.chat_id = int("-100" + str(ip.full_chat.id))
hawk = await ded.send_text(
f"✅ **Səsli söhbətə qoşuldum**\n"
)
await delete_switch_on((hawk,), SWITCH_ON_TIME)
else:
hawk = await ded.send_text(
f"❌ **Səsli söhbətdən ayrıldım**\n"
)
await delete_switch_off((hawk,), SWITCH_OFF_TIME)
ded.chat_id = None
"+|==========================================🍁----------[-_-]----------🍁==============================================|+"
async def delete_switch_on(messages: tuple, delay: int):
await asyncio.sleep(delay)
for msg in messages:
await msg.delete()
async def delete_switch_off(messages: tuple, delay: int):
await asyncio.sleep(delay)
for msg in messages:
await msg.delete()
"+|==========================================🍁----------[-_-]----------🍁==============================================|+"
@ded.voice_chatting.on_playout_ended
async def playout_ended_handler(_, __):
await ded.skip_current_playing()
"""
\ / \ / \ / \ / \ / \
\__/ \__/ \__/ \__/ \__/ \__/
/ \ / \ / \ / \ / \ / \
BOT_RAMO
__/ \__/ \__/ \__/ \__/ \__/
\ / \ / \ / \ / \ / \
\__/ \__/ \__/ \__/ \__/ \__/
"""