-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
157 lines (139 loc) · 5.02 KB
/
index.js
File metadata and controls
157 lines (139 loc) · 5.02 KB
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
const tg = require("node-telegram-bot-api");
const fs = require("fs");
const express = require("express");
require("dotenv").config();
const music = require("./src/m2");
const fb = require("./src/fbmusic");
const c = require("./utils/console");
const feedback = require("./src/feedback");
const token = process.env.TOKEN;
const url = process.env.URL || ""; // "https://tg-music-bot-svnp.onrender.com";
const start = async () => {
// const cache = JSON.parse(fs.readFileSync("x.json", "utf-8"));
if (!token) {
return console.error(`TOKEN [ERR]: Token not found`);
}
c(
"Starter",
`
╭―――――――――――――――――――――――――――――――――――――――――╮
│ │
│ Welcome to Telegram Music Bot │
│ Developed by Ryann Kim Sesgundo │
│ │
╰―――――――――――――――――――――――――――――――――――――――――╯`,
);
const directory = `${__dirname}/temp`;
try {
let api = null;
if (url.length > 1) {
api = new tg(token, {
polling: false,
});
const app = express();
app.use(express.json());
app.get("/", (req, res) => {
res.send("Currently working now");
});
api.setWebHook(`${url}/bot${token}`);
app.post(`/bot${token}`, (req, res) => {
api.processUpdate(req.body);
res.sendStatus(200);
});
app.listen(process.env.PORT || 3000, () => {
c("Server Initiator", "Server started.");
c("Server Initiator", "Developed under MPOP Reverse II");
});
} else {
api = new tg(token, {
polling: true,
});
}
if (fs.existsSync(directory)) {
fs.rm(directory, { recursive: true }, (e) => {});
}
setTimeout(() => {
fs.mkdirSync(directory);
}, 1000);
// setTimeout(() => {
// if (Object.keys(cache).length > 0) {
// c("Log", "Trying hard");
// for (let i in Object.keys(cache)) {
// music(api, cache[i], i);
// }
// }
// }, 1500);
c("Server Engine", "Server is now restarted...");
api.onText(/([\w\W]+)/gi, (msg, match) => {
if (match[0].startsWith("/start")) {
api.deleteMessage(msg.chat.id, msg.message_id);
api
.sendMessage(
msg.chat.id,
"Greetings, I am ඞ, your telegram bot music (based on youtube music). If you want to get started, kindly message back your music you want to look for its either title or link. If you want to grab a music easily from Youtube, you may click on share from youtube, look for telegram or telegram x and look for my profile.\n\nThis message will automatically deleted after 2 minutes.\n\n- Developed by MPOP Reverse II",
)
.then((r) => {
setTimeout(() => {
api.deleteMessage(r.chat.id, r.message_id);
}, 120000);
})
.catch((e) => {});
} else if (match[0].startsWith("/delete")) {
if (msg.reply_to_message) {
api.deleteMessage(
msg.reply_to_message.chat.id,
msg.reply_to_message.message_id,
);
api.deleteMessage(msg.chat.id, msg.message_id);
}
} else if (match[0].startsWith("/fbmusic ")) {
const s = match[1];
fb(api, msg, s.substring("/fbmusic ".length));
} else if (match[0].startsWith("/clear")) {
if (fs.existsSync(`${directory}/${msg.chat.id}`)) {
fs.rm(`${directory}/${msg.chat.id}`, { recursive: true }, (e) => {});
}
api
.sendMessage(msg.chat.id, "Done")
.then((r) => {
setTimeout(() => {
api.deleteMessage(r.chat.id, r.message_id);
api.deleteMessage(msg.chat.id, msg.message_id);
}, 1500);
})
.catch((e) => {});
} else if (match[0].startsWith("/feedback ")) {
feedback(api, msg, match[0].substring("/feedback ".length));
setTimeout(() => {
api.deleteMessage(msg.chat.id, msg.message_id);
}, 1000);
} else {
if (msg.chat.type === "private" || match[0].startsWith("/music")) {
if (match[0].startsWith("/")) {
const spl = match[0].split(" ");
spl.shift();
match[0] = spl.join(" ");
}
if (match[1]) {
music(api, msg, match[0]);
setTimeout(() => {
api.deleteMessage(msg.chat.id, msg.message_id);
}, 1000);
} else {
api
.sendMessage(msg.chat.id, "Invalid message, please try again")
.then((r) => {
setTimeout(() => {
api.deleteMessage(r.chat.id, r.message_id);
});
})
.catch((e) => {});
}
}
}
});
} catch (error) {
c("Fallback", `ERR: ${error}`, "error");
}
};
start();