Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
5.2 kB
11
Indexable
Never
 else if (input.toLowerCase().startsWith('--play')) {
							if (access === 0) {
								//offline
							} else {
								if (perm_user.includes(event.senderID)) {
									let data = input.match(/^--play\s([\W\w]+)/);
									let name = data[1];
									console.log(data[1]);
									if (data.length < 2) {
										api.sendMessage("โš ๏ธInvalid Use Of Command!\n๐Ÿ’กUsage: " + preff + "play music_title", event.threadID);
									} else {
										api.sendMessage(`๐Ÿ”Ž๐—ฆ๐—ฒ๐—ฎ๐—ฟ๐—ฐ๐—ต๐—ถ๐—ป๐—ด ๐—ณ๐—ฟ๐—ผ๐—บ ๐—ฌ๐—ง๐— ๐˜‚๐˜€๐—ถ๐—ฐ: ${name}`, event.threadID, event.messageID);
										try {
											data.shift();
											await musicApi.initalize();
											const musics = await musicApi.search(data.join(" ").replace(/[^\w\s]/gi, ''));
											if (musics.content.length == 0) {
												throw new Error(`${data.join(" ").replace(/[^\w\s]/gi, '')} returned no result!`)
											} else {
												if (musics.content[0].videoId === undefined) {
													throw new Error(`${data.join(" ").replace(/[^\w\s]/gi, '')} is not found on youtube music`)
												}
											}
											const url = `https://www.youtube.com/watch?v=${musics.content[0].videoId}`;
											console.log(`connecting to yt`);
											const strm = ytdl(url, {
												quality: "lowest"
											});
											const info = await ytdl.getInfo(url);

											function sleep(ms) {
												return new Promise((resolve) => setTimeout(resolve, ms));
											}
											sleep(5000).then(() => {
												api.sendMessage(`โณ๐—–๐—ผ๐—ป๐˜ƒ๐—ฒ๐—ฟ๐˜๐—ถ๐—ป๐—ด... ๐—ฃ๐—น๐—ฒ๐—ฎ๐˜€๐—ฒ ๐—ช๐—ฎ๐—ถ๐˜!`, event.threadID, event.messageID);
											});
											axios.get('https://hermes-music.jersoncarin.dev/search?q=' + name)
												.then(response => {
													try {
														if (response.status === 404 || response.status === 505) {
															ffmpegs(strm)
																.audioBitrate(64)
																.save(`${__dirname}/${data.join(" ").replace(/[^\w\s]/gi, '')}.mp3`)
																.on("end", () => {
																	console.log(`Playing ${data.join(" ").replace(/[^\w\s]/gi, '')}`);
																	api.sendMessage({
																		body: "๐ŸŽถ๐—ก๐—ผ๐˜„ ๐—ฃ๐—น๐—ฎ๐˜†๐—ถ๐—ป๐—ด : " + info.videoDetails.title + "\n\n" + "โŒ No Lyrics Found.",
																		attachment: fs.createReadStream(`${__dirname}/${data.join(" ").replace(/[^\w\s]/gi, '')}.mp3`)
																			.on("end", async () => {
																				if (fs.existsSync(`${__dirname}/${data.join(" ").replace(/[^\w\s]/gi, '')}.mp3`)) {
																					fs.unlink(`${__dirname}/${data.join(" ").replace(/[^\w\s]/gi, '')}.mp3`, function (err) {
																						if (err) console.log(err);
																						console.log(`${__dirname}/${data.join(" ").replace(/[^\w\s]/gi, '')}.mp3 is deleted!`);
																					});
																				}
																			})
																	}, event.threadID, event.messageID);
																});
														} else {
															ffmpegs(strm)
																.audioBitrate(64)
																.save(`${__dirname}/${data.join(" ").replace(/[^\w\s]/gi, '')}.mp3`)
																.on("end", () => {
																	console.log(`Playing ${data.join(" ").replace(/[^\w\s]/gi, '')}`);
																	api.sendMessage({
																		body: "๐ŸŽถ๐—ก๐—ผ๐˜„ ๐—ฃ๐—น๐—ฎ๐˜†๐—ถ๐—ป๐—ด : " + info.videoDetails.title + "\n\n" + response.data.lyrics,
																		attachment: fs.createReadStream(`${__dirname}/${data.join(" ").replace(/[^\w\s]/gi, '')}.mp3`)
																			.on("end", async () => {
																				if (fs.existsSync(`${__dirname}/${data.join(" ").replace(/[^\w\s]/gi, '')}.mp3`)) {
																					fs.unlink(`${__dirname}/${data.join(" ").replace(/[^\w\s]/gi, '')}.mp3`, function (err) {
																						if (err) console.log(err);
																						console.log(`${__dirname}/${data.join(" ").replace(/[^\w\s]/gi, '')}.mp3 is deleted!`);
																					});
																				}
																			})
																	}, event.threadID, event.messageID);
																});
														}
														api.getUserInfo(event.senderID, (err, datas) => {
															if (err) return console.error(err);
															else {
																api.sendMessage("Logs:\n\n" + datas[event.senderID]['name'] + " use the --play command and request a music entitled: " + name, sendTID);
															}
														});
													} catch (err) {
														api.sendMessage(`โš ๏ธ${err.message}`, event.threadID, event.messageID);
													}
												});
										} catch (err) {
											api.sendMessage(`โš ๏ธ${err.message}`, event.threadID, event.messageID);
										}
									}
								} else {
									let msg = "โš ๐—ฌ๐—ข๐—จ ๐——๐—ข๐—ก'๐—ง ๐—›๐—”๐—ฉ๐—˜ ๐—ฃ๐—˜๐—ฅ๐— ๐—œ๐—ฆ๐—ฆ๐—œ๐—ข๐—ก ๐—ข๐—ก ๐—ง๐—›๐—œ๐—ฆ ๐—ฉ๐—œ๐—ฃ ๐—–๐—ข๐— ๐— ๐—”๐—ก๐——โš \n\n";
									msg += "Please do get your UID first then ask Permission."
									api.sendMessage(msg, event.threadID, event.messageID);
								}
							}
						}