This repository has been archived by the owner on Jul 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
202 lines (182 loc) · 6.45 KB
/
bot.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
193
194
195
196
197
198
199
200
201
202
# Examined dashezup's vcbot repo for make this working only for contacts and userbot!
# SDBOTs Inifinity <https://t.me/SDBOTs_inifinity>
import os
from pytgcalls import GroupCall
import ffmpeg
from config import Config
from datetime import datetime
from pyrogram import filters, Client, idle
import requests
import wget
import aiohttp
from random import randint
import aiofiles
VOICE_CHATS = {}
DEFAULT_DOWNLOAD_DIR = 'downloads/vcbot/'
# deezer download web of william butcher bot
ARQ = "https://thearq.tech/"
api_id=Config.API_ID
api_hash=Config.API_HASH
session_name=Config.STRING_SESSION
app = Client(session_name, api_id, api_hash)
# userbot and contacts filter by dashezup's tgvc-userbot
self_or_contact_filter = filters.create(
lambda
_,
__,
message:
(message.from_user and message.from_user.is_contact) or message.outgoing
)
# fetch url for deezer download
async def fetch(url):
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
try:
data = await resp.json()
except:
data = await resp.text()
return data
# get args for saavn download
def get_arg(message):
msg = message.text
msg = msg.replace(" ", "", 1) if msg[1] == " " else msg
split = msg[1:].replace("\n", " \n").split(" ")
if " ".join(split[1:]).strip() == "":
return ""
return " ".join(split[1:])
# start message
@app.on_message(filters.command('start'))
async def start(client, message):
await message.reply("Heya, I'm SDVC Player 🎵\n\nRepo > https://github.com/sadew451/vcplayerbot",
disable_web_page_preview=True)
# ping checker
@app.on_message(filters.command('ping') & self_or_contact_filter)
async def ping(client, message):
start = datetime.now()
tauk = await message.reply('Pong!')
end = datetime.now()
m_s = (end - start).microseconds / 1000
await tauk.edit(f'**Pong!**\n> `{m_s} ms`')
# jiosaavn song download
@app.on_message(filters.command('saavn') & self_or_contact_filter)
async def song(client, message):
message.chat.id
message.from_user["id"]
args = get_arg(message) + " " + "song"
if args.startswith(" "):
await message.reply("What's the song you want 🧐")
return ""
pak = await message.reply('Downloading...')
try:
# @Darkridersslk <SDBOTs Inifinity>
r = requests.get(f"https://jevcplayerbot-saavndl.herokuapp.com/result/?query={args}")
except Exception as e:
await pak.edit(str(e))
return
sname = r.json()[0]["song"]
slink = r.json()[0]["media_url"]
ssingers = r.json()[0]["singers"]
file = wget.download(slink)
ffile = file.replace("mp4", "m4a")
os.rename(file, ffile)
await pak.edit('Uploading...')
await message.reply_audio(audio=ffile, title=sname, performer=ssingers)
os.remove(ffile)
await pak.delete()
async def download_song(url):
song_name = f"{randint(6969, 6999)}.mp3"
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
if resp.status == 200:
f = await aiofiles.open(song_name, mode="wb")
await f.write(await resp.read())
await f.close()
return song_name
# deezer download by william butcher bot
@app.on_message(filters.command("deezer") & self_or_contact_filter)
async def deezer(_, message):
if len(message.command) < 2:
await message.reply_text("What's the song you want 🧐")
return
text = message.text.split(None, 1)[1]
query = text.replace(" ", "%20")
hike = await message.reply_text("Searching...")
try:
r = await fetch(f"{ARQ}deezer?query={query}&count=1")
title = r[0]["title"]
url = r[0]["url"]
artist = r[0]["artist"]
except Exception as e:
await hike.edit(str(e))
return
await hike.edit("Downloading...")
song = await download_song(url)
await hike.edit("Uploading...")
await message.reply_audio(audio=song, title=title, performer=artist)
os.remove(song)
await hike.delete()
@app.on_message(filters.command('play') & self_or_contact_filter)
async def play_track(client, message):
if not message.reply_to_message or not message.reply_to_message.audio:
return
input_filename = os.path.join(
client.workdir, DEFAULT_DOWNLOAD_DIR,
'input.raw',
)
audio = message.reply_to_message.audio
audio_original = await message.reply_to_message.download()
a = await message.reply('Downloading...')
ffmpeg.input(audio_original).output(
input_filename,
format='s16le',
acodec='pcm_s16le',
ac=2, ar='48k',
).overwrite_output().run()
os.remove(audio_original)
if VOICE_CHATS and message.chat.id in VOICE_CHATS:
text = f'▶️ Playing **{audio.title}** here by SDVC BOT...'
else:
try:
group_call = GroupCall(client, input_filename)
await group_call.start(message.chat.id)
except RuntimeError:
await message.reply('Group Call doesnt exist')
return
VOICE_CHATS[message.chat.id] = group_call
await a.edit(f'▶️ Playing **{audio.title}** here by SDVC BOT...')
@app.on_message(filters.command('stopvc') & self_or_contact_filter)
async def stop_playing(_, message):
group_call = VOICE_CHATS[message.chat.id]
group_call.stop_playout()
os.remove('downloads/vcbot/input.raw')
await message.reply('Stopped Playing ❌')
@app.on_message(filters.command('joinvc') & self_or_contact_filter)
async def join_voice_chat(client, message):
input_filename = os.path.join(
client.workdir, DEFAULT_DOWNLOAD_DIR,
'input.raw',
)
if message.chat.id in VOICE_CHATS:
await message.reply('Already joined to Voice Chat 🛠')
return
chat_id = message.chat.id
try:
group_call = GroupCall(client, input_filename)
await group_call.start(chat_id)
except RuntimeError:
await message.reply('lel error!')
return
VOICE_CHATS[chat_id] = group_call
await message.reply('Joined the Voice Chat ✅')
@app.on_message(filters.command('leavevc') & self_or_contact_filter)
async def leave_voice_chat(client, message):
chat_id = message.chat.id
group_call = VOICE_CHATS[chat_id]
await group_call.stop()
VOICE_CHATS.pop(chat_id, None)
await message.reply('Left Voice Chat ✅')
app.start()
print('>>> SDVC USERBOT STARTED')
idle()
app.stop()
print('\n>>> SDVC USERBOT STOPPED')