-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
77 lines (63 loc) · 2.19 KB
/
main.js
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
const { getBotInstance } = require('./src/config/Instances')
const { BotErrorResponse, BotSuccessResponse, TransmissionErrorResponse } = require('./src/models/Messages')
const { addTorrentToTransmission, getAllActiveTorrents, getFreeDiskSpace, renameTorrentById } = require('./src/services/TorrentServices')
const bot = getBotInstance()
bot.onText(/\/echo (.+)/, (msg, match) => {
console.info("User requested /echo")
const chatId = msg.chat.id
const response = match[1]
bot.sendMessage(chatId, response)
})
bot.onText(/\/help/, (msg) => {
console.info("User requested /help")
const chatId = msg.chat.id
const response = `
Commands:
*· Help*
*Use:* /help
*Description:* Shows this menu
*· Echo*
*Use:* /echo message
*Description:* Test the bot's response
*· List*
*Use:* /list
*Description:* Shows the current's downloads
*· Disk*
*Use:* /disk
*Description:* Shows the current free space in disk
*· Add*
*Use:* /add url
*Description:* Add the torrent to download queue
🚧 *· Rename* NOT WORKING 🚧
*Use:* /rename id fileName
*Description:* Add the torrent to download queue
`
bot.sendMessage(chatId, response, { parse_mode: "MarkdownV2" })
})
bot.onText(/\/list/, (msg) => {
console.info("User requested /list")
const chatId = msg.chat.id
getAllActiveTorrents(chatId, bot)
})
bot.onText(/\/add (.+)/, (msg, match) => {
console.info("User requested /add")
const URL_REGEX = /[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/ig
const chatId = msg.chat.id
const url = match[1]
if (URL_REGEX.test(url)) addTorrentToTransmission(chatId, bot, url)
else bot.sendMessage(chatId, BotErrorResponse.MALFORMED_URL)
})
/* 🚧 *· Rename* NOT WORKING 🚧 */
bot.onText(/\/rename (.+) (.+)/, (msg, match) => {
console.info("User requested /rename")
const chatId = msg.chat.id
const id = match[1]
const fileName = match[1]
if (id && fileName) renameTorrentById(chatId, bot, id, fileName)
else bot.sendMessage(chatId, "Error renombrando torrent")
})
bot.onText(/\/disk/, (msg, match) => {
console.info("User requested /disk")
const chatId = msg.chat.id
getFreeDiskSpace(chatId, bot)
})