-
Notifications
You must be signed in to change notification settings - Fork 9
/
promote.js
69 lines (65 loc) · 1.97 KB
/
promote.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
import FormData from 'form-data'
import { getInfoForUser, transcript, initBot } from '../../utils'
import fetch from 'isomorphic-unfetch'
const approveUser = async user =>
new Promise((resolve, reject) => {
console.log("DISABLED-TEMP")
/*
const form = new FormData()
form.append('user', user)
form.append('token', process.env.SLACK_INVITE_TOKEN)
fetch(
'https://slack.com/api/users.admin.setRegular?slack_route=T0266FRGM',
{
method: 'POST',
body: form,
}
)
.then(res => {
console.log(res)
resolve(res)
})
.catch(err => reject(err))*/
})
const clippyApprove = async ({ promoterId, promotedId }) => {
return await fetch('https://clippy-bot-hackclub.herokuapp.com/promote', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
key: process.env.CLIPPY_KEY,
promotedId,
promoterId,
}),
})
}
const interactionSOMPromote = async (bot = initBot(), message) => {
const taggedUserID = (message.text.match(/<@([a-zA-Z0-9]*)|/) || [])[1]
console.log('promote user id', taggedUserID)
if (!taggedUserID) {
return // do something if we don't tag a user
}
const user = {}
user.tagged = await getInfoForUser(taggedUserID)
user.caller = await getInfoForUser(message.user)
if (user.caller.slackUser.is_restricted) {
console.log('caller is restricted, cancelling')
return
}
if (!user.caller.slackUser.is_admin) {
console.log('caller is not an admin, cancelling')
bot.replyPrivateDelayed(message, transcript('som.approve.notAdmin'))
return
}
if (!user.tagged.slackUser.is_restricted) {
console.log('tagged is not restricted, cancelling')
return
}
await Promise.all([
approveUser(taggedUserID),
clippyApprove({ promotedId: taggedUserID, promoterId: message.user }),
bot.replyPrivateDelayed(message, transcript('som.approve.success')),
])
}
export default interactionSOMPromote