-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
506 lines (436 loc) · 13 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
##################################################
## Biggest thanks to @theHamkerCat (on telegram)##
##################################################
from __future__ import unicode_literals
import youtube_dl
import asyncio
import aiohttp
import aiofiles
import time
import json
import os
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
from pyrogram import Client, filters
from pyrogram.types import Message, InlineKeyboardButton, InlineKeyboardMarkup
from youtube_search import YoutubeSearch
from config import owner_id, bot_token, radio_link, sudo_chat_id, neutron_id
app = Client(
":memory:",
bot_token=bot_token,
api_id=6,
api_hash="eb06d4abfb49dc3eeb1aeb98ae0f581e",
)
# Get User Input
def kwairi(message):
query = ""
for i in message.command[1:]:
query += f"{i} "
return query
def convert_seconds(seconds):
seconds = seconds % (24 * 3600)
seconds %= 3600
minutes = seconds // 60
seconds %= 60
return "%02d:%02d" % (minutes, seconds)
# For Blacklist filter
blacks = []
# Ping
@app.on_message(
filters.command(["ping"]) & filters.chat(sudo_chat_id) & ~filters.edited
)
async def ping(_, message):
global blacks
if message.from_user.id in blacks:
await message.reply_text("You're Blacklisted, So Stop Spamming. NOOB NIBBA")
return
start_time = int(round(time.time() * 1000))
m = await message.reply_text(".")
end_time = int(round(time.time() * 1000))
await m.edit(f"{end_time - start_time} ms")
# Start
@app.on_message(filters.command(["neutron"]) & ~filters.edited)
async def start(_, message: Message):
global blacks
if message.from_user.id in blacks:
await message.reply_text("You're Blacklisted, So Stop Spamming. NOOB NIBBA")
return
await message.reply_text(
"Hi!!! I am Neutron... I am ready to rock 😎🤘"
)
# Help
@app.on_message(
filters.command(["nhelp"]) & filters.chat(sudo_chat_id) & ~filters.edited
)
async def help(_, message: Message):
global blacks
if message.from_user.id in blacks:
await message.reply_text("You're Blacklisted, So Stop Spamming. NOOB NIBBA")
return
await message.reply_text(
"""Currently These Commands Are Supported.
〄⊏**Check Bot**⊐〄
/neutron To Start The bot.
/end To Stop Any Playing Music.
/help To Show This Message.
/ping To Ping All Datacenters Of Telegram.
〄⊏**Play Song**⊐〄
/play <song_name> To Play A Song From Jiosaavn.
/telegram To Play A Song Directly From Telegram File.
/radio To Play Radio Continuosly.
/pornhub Try it yourself...
〄⊏**Owner commands**⊐〄
/black To Blacklist A User.
/white To Whitelist A User.
/users To Get A List Of Blacklisted Users.
NOTE: **Do Not Write** as /ping@neutron_music_bot... Just write `/ping`"""
)
# Jiosaavn
# Global vars
s = None
m = None
@app.on_message(
filters.command(["play"])
& filters.chat(sudo_chat_id)
& ~filters.edited
)
async def JioSaavn(_, message: Message):
global blacks
if message.from_user.id in blacks:
await message.reply_text("You're Blacklisted, So Stop Spamming. NOOB NIBBA")
return
global s
global m
if len(message.command) < 2:
await message.reply_text("/play requires an argument")
return
try:
os.system("killall -9 mpv")
except:
pass
try:
await m.delete()
except:
pass
try:
await message.delete()
except:
pass
query = kwairi(message)
m = await message.reply_text(f"Searching for `{query}` on JioSaavn")
async with aiohttp.ClientSession() as session:
async with session.get(
f"https://jiosaavnapi.bhadoo.uk/result/?query={query}"
) as resp:
r = json.loads(await resp.text())
sname = r[0]["song"]
slink = r[0]["media_url"]
ssingers = r[0]["singers"]
sthumb = r[0]["image"]
sduration = r[0]["duration"]
sduration_converted = convert_seconds(int(sduration))
await m.edit("Processing Thumbnail.")
async with aiohttp.ClientSession() as session:
async with session.get(sthumb) as resp:
if resp.status == 200:
f = await aiofiles.open("background.png", mode="wb")
await f.write(await resp.read())
await f.close()
def changeImageSize(maxWidth, maxHeight, image):
widthRatio = maxWidth / image.size[0]
heightRatio = maxHeight / image.size[1]
newWidth = int(widthRatio * image.size[0])
newHeight = int(heightRatio * image.size[1])
newImage = image.resize((newWidth, newHeight))
return newImage
image1 = Image.open("./background.png")
image2 = Image.open("etc/foreground.png")
image3 = changeImageSize(1280, 720, image1)
image4 = changeImageSize(1280, 720, image2)
image5 = image3.convert("RGBA")
image6 = image4.convert("RGBA")
Image.alpha_composite(image5, image6).save("temp.png")
img = Image.open("temp.png")
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("etc/JetBrainsMonoNL-Regular.ttf", 32)
font2 = ImageFont.truetype("etc/abnes.ttf", 64)
draw.text(
(90, 350), f"NEUTRON BOT", (255, 255, 255), font=font2
)
draw.text(
(190, 550), f"Title: {sname}", (255, 255, 255), font=font
)
draw.text(
(190, 590), f"Artist: {ssingers}", (255, 255, 255), font=font
)
draw.text(
(190, 630),
f"Duration: {sduration_converted} Seconds",
(255, 255, 255),
font=font,
)
draw.text(
(190, 670),
f"Played By: {message.from_user.first_name}",
(255, 255, 255),
font=font,
)
img.save("final.png")
os.system("rm temp.png")
os.system("rm background.png")
await m.delete()
m = await message.reply_photo(
caption=f"Playing `{sname}` Via Jiosaavn #music #neutron",
photo="final.png",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
"STOP", callback_data="end"
)
]
]
),
parse_mode="markdown",
)
s = await asyncio.create_subprocess_shell(
f"mpv {slink} --no-video",
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
await s.wait()
await m.delete()
# Telegram Audio
@app.on_message(
filters.command(["telegram"]) & filters.chat(sudo_chat_id) & ~filters.edited
)
async def tgplay(_, message: Message):
global blacks
if message.from_user.id in blacks:
await message.reply_text("You're Blacklisted, So Stop Spamming. NOOB NIBBA")
return
global m
global s
if not message.reply_to_message:
await message.reply_text("Reply To A Telegram Audio To Play It.")
return
try:
await message.delete()
except:
pass
try:
await m.delete()
except:
pass
try:
os.system("killall -9 mpv")
except:
pass
try:
os.remove("audio.mp3")
except:
pass
try:
os.remove("downloads/audio.mp3")
except:
pass
m = await message.reply_text("Downloading")
await app.download_media(message.reply_to_message, file_name="audio.mp3")
await m.edit(f"Playing `{message.reply_to_message.link}` via Telegram.")
s = await asyncio.create_subprocess_shell(
"mpv downloads/audio.mp3 --no-video",
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
await s.wait()
await m.delete()
os.system("rm downloads/audio.mp3")
# Radio
@app.on_message(
filters.command(["radio"]) & filters.chat(sudo_chat_id) & ~filters.edited
)
async def radio(_, message: Message):
global blacks
if message.from_user.id in blacks:
await message.reply_text("You're Blacklisted, So Stop Spamming.")
return
global m
global s
try:
os.system("killall -9 mpv")
except:
pass
try:
await m.delete()
except:
pass
try:
await message.delete()
except:
pass
try:
os.remove("audio.mp3")
except:
pass
m = await message.reply_text(
f"Playing Radio\nRequested by - {message.from_user.mention}"
)
s = await asyncio.create_subprocess_shell(
f"mpv {radio_link} --no-video",
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
await s.wait()
await m.delete()
# End Music
async def getadmins(chat_id):
admins = []
async for i in app.iter_chat_members(chat_id, filter="administrators"):
admins.append(i.user.id)
return admins
@app.on_message(
filters.command(["end"]) & filters.chat(sudo_chat_id) & ~filters.edited
)
async def end(_, message: Message):
global blacks
global m
global s
if message.from_user.id in blacks:
await message.reply_text("You're Blacklisted, So Stop Spamming.")
return
list_of_admins = await getadmins(message.chat.id)
if message.from_user.id not in list_of_admins:
await message.reply_text("Dear... You are not an admin... SO GET THE FCK OUTTA HERE AND DONT STOP ME... Only admins and Rashh can stop me...")
return
try:
os.remove("audio.mp3")
except:
pass
try:
await message.delete()
except:
pass
try:
os.system("killall -9 mpv")
except:
pass
try:
s.terminate()
except:
pass
try:
await m.delete()
except:
pass
await message.reply_text(
f"{message.from_user.mention} Stopped The Music."
)
@app.on_callback_query(filters.regex("end"))
async def end_callback(_, CallbackQuery):
list_of_admins = await getadmins(CallbackQuery.message.chat.id)
if CallbackQuery.from_user.id not in list_of_admins:
await app.answer_callback_query(
CallbackQuery.id, "Well, you're not admin, SO YOU CAN'T STOP"
+ " ME, HAH!, how about i ban you?", show_alert=True)
return
global blacks
global m
global s
chat_id = int(CallbackQuery.message.chat.id)
if CallbackQuery.from_user.id in blacks:
return
try:
os.remove("audio.mp3")
except:
pass
try:
os.system("killall -9 mpv")
except:
pass
try:
s.terminate()
except:
pass
try:
await m.delete()
except:
pass
await app.send_message(
chat_id,
f"{CallbackQuery.from_user.mention} - {CallbackQuery.from_user.id} Stopped The Music.",
)
# Ban
@app.on_message(
filters.command(["black"]) & filters.chat(sudo_chat_id) & ~filters.edited
)
async def blacklist(_, message: Message):
global blacks
if message.from_user.id != owner_id:
await message.reply_text("Only owner can blacklist users.")
return
if not message.reply_to_message:
await message.reply_text(
"Reply to a message with /black to blacklist a user."
)
return
if message.reply_to_message.from_user.id in blacks:
await message.reply_text("This user is already blacklisted.")
return
blacks.append(message.reply_to_message.from_user.id)
await message.reply_text(
f"Blacklisted {message.reply_to_message.from_user.mention}"
)
# Unban
@app.on_message(
filters.command(["white"]) & filters.chat(sudo_chat_id) & ~filters.edited
)
async def whitelist(_, message: Message):
global blacks
if message.from_user.id != owner_id:
await message.reply_text("Only owner can whitelist users.")
return
if not message.reply_to_message:
await message.reply_text("Reply to a message to whitelist a user.")
return
if message.reply_to_message.from_user.id in blacks:
blacks.remove(message.reply_to_message.from_user.id)
await message.reply_text(
f"Whitelisted {message.reply_to_message.from_user.mention}"
)
else:
await message.reply_text("This user is already whitelisted.")
# Blacklisted users
@app.on_message(
filters.command(["users"]) & filters.chat(sudo_chat_id) & ~filters.edited
)
async def users(client, message: Message):
global blacks
if message.from_user.id in blacks:
await message.reply_text("You're Blacklisted, So Stop Spamming.")
return
output = "Blacklisted Users:\n"
n = 1
for i in blacks:
usern = (await client.get_users(i)).mention
output += f"{n}. {usern}\n"
n += 1
if len(blacks) == 0:
await message.reply_text("No Users Are Blacklisted")
return
await message.reply_text(output)
#PH
@app.on_message(
filters.command(["pornhub"]) & filters.chat(sudo_chat_id) & ~filters.edited
)
async def pornhub(_, message: Message):
global blacks
if message.from_user.id in blacks:
await message.reply_text("Abe bhencho.... Music bot hu... Tharki bsdk😡")
return
await message.reply_text(
"""Abe bhencho.... Music bot hu... Tharki bsdk😡"""
)
#DONE!!!!!!!!1
print("Neutron2 Bot Starting...")
app.run()