forked from m4l3vich/sBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uploader.js
76 lines (75 loc) · 2.18 KB
/
uploader.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
var rp = require('request-promise')
var api = require('./api')
module.exports = {
token: '',
mode: '',
photo: async function (buffer) {
var server = await api('photos.getMessagesUploadServer', {}, this.token)
var data = await rp({
method: 'POST',
uri: server.upload_url,
formData: {
photo: {
value: buffer,
options: {filename: 'photo.png', contentType: 'image/png'}
}
}
})
data = JSON.parse(data)
var result = await api('photos.saveMessagesPhoto', {
photo: data.photo,
server: data.server,
hash: data.hash
}, this.token)
return `photo${result[0].owner_id}_${result[0].id}`
},
// eslint-disable-next-line camelcase
audio_message: async function (buffer, peer_id) {
// eslint-disable-next-line camelcase
if (this.mode === 'group' && !peer_id) {
throw new Error('Unavailable in group mode')
} else {
var server = await api('docs.getMessagesUploadServer', {type: 'audio_message', peer_id}, this.token)
var data = await rp({
method: 'POST',
uri: server.upload_url,
formData: {
file: {
value: buffer,
options: {filename: 'audiomsg.ogg', contentType: 'audio/ogg'}
}
}
})
data = JSON.parse(data)
var result = await api('docs.save', {
file: data.file,
title: 'audiomsg'
}, this.token)
return `doc${result[0].owner_id}_${result[0].id}`
}
},
graffiti: async function (buffer) {
if (this.mode === 'group') {
throw new Error('Unavailable in group mode')
} else {
var server = await api('docs.getMessagesUploadServer', {type: 'graffiti'}, this.token)
console.log(server)
var data = await rp({
method: 'POST',
uri: server.upload_url,
formData: {
file: {
value: buffer,
options: {filename: 'graffiti.png', contentType: 'image/png'}
}
}
})
data = JSON.parse(data)
var result = await api('docs.save', {
file: data.file,
title: 'graffiti'
}, this.token)
return `doc${result[0].owner_id}_${result[0].id}`
}
}
}