-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtorrent.js
More file actions
34 lines (25 loc) · 1.04 KB
/
torrent.js
File metadata and controls
34 lines (25 loc) · 1.04 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
const drive = require('./drive')
const update = require('./update')
async function torrent(ctx, url) {
try {
global.client.add(url, { path: './tempDownload' }, function (torrent) {
return new Promise((resolve, reject) => {
torrent.on('done', function () {
//We tell the user that the torrent is finished
console.log('Torrent ' + torrent.name + ' finished.')
ctx.reply('Torrent ' + torrent.name + ' finished.')
//Then we upload it to Drive
drive(ctx, torrent.name)
//Once the torrent has been downloaded, we remove it from the array of torrents
global.client.torrents.splice(global.client.torrents.indexOf(torrent),1)
resolve
})
torrent.on('error', reject)
})
})
} catch (error) {
console.log(error)
await ctx.reply('An error has ocurred during downloading the Torrent. See if the torrent is still up and it\'s correct.')
}
}
module.exports = torrent