-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
pm.js
43 lines (31 loc) · 1.02 KB
/
pm.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
const Snoowrap = require('snoowrap');
const { PMsDisabledError } = require('./errors');
async function sendPM(client, recipient, threadTitle, body) {
try {
let result = await client.composeMessage({
to: recipient,
subject: threadTitle,
text: body,
})
let lastSentPM = await client.getSentMessages({
amount: 1,
})[0]
// console.log(`lastSentPM:`, lastSentPM)
return lastSentPM.id
} catch (err) {
if (err.message.includes(`NOT_WHITELISTED_BY_USER_MESSAGE`)) {
throw new PMsDisabledError(`User has disabled PMs from strangers, not sending the PM!`)
} else {
throw err
}
}
}
module.exports.sendPM = sendPM
// async function replyToThread(client, threadId, body) {
// let firstMessage = await client.getMessage(threadId)
// console.log(`firstMessage:`, firstMessage)
// console.log(`Replying to thread...`)
// let result = await firstMessage.reply(body)
// console.log(`result:`, result)
// }
// module.exports.replyToThread = replyToThread