-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgithubGrant.js
139 lines (128 loc) · 3.85 KB
/
githubGrant.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import {
initBot,
getInfoForUser,
airFind,
airCreate,
transcript,
} from '../../utils'
import interactionMailMission from '../mailMission'
/*
to test
[ ] mailteam request vanilla grant
[ ] mailteam request recurring grant (valid)
[ ] mailteam request recurring grant (already had grant this semester)
[ ] hcb request vanilla grant
[ ] hcb request recurring grant (valid)
[ ] hcb request recurring grant (already had grant this semester)
[ ] request from non leader
*/
export const names = ['GitHub Grant', 'club grant']
export const details =
'Available to club leaders. Must have a meeting time set with `/meeting-time`'
export async function run(bot, message) {
const { user } = message
const { leader, club, history, personAddress } = await getInfoForUser(user)
if (!leader || !club) {
await bot.replyPrivateDelayed(
message,
transcript('promos.githubGrant.notAuthorized')
)
return
}
await bot.replyPrivateDelayed(
message,
transcript('promos.githubGrant.programClosed')
)
return // we're closing down grants this semester until we get more funding from GitHub
const lastGrant = await airFind(
'GitHub Grants',
`AND({Dummy} = 0, {Club} = '${club.fields['ID']}')`,
null,
{
selectBy: {
sort: [{ field: 'Initiated at', direction: 'desc' }],
},
}
)
if (!lastGrant) {
// this is their first grant
const grant = await airCreate('GitHub Grants', {
Club: [club.id],
Leader: [leader.id],
Type: 'First meeting ($100)',
'Grant amount': 100,
})
if (grant.fields['HCB Account']) {
// if they have an HCB account, we'll notify the bank team
await bot.replyPrivateDelayed(
message,
transcript('promos.githubGrant.hcbFulfillment', {
hcbLink: grant.fields['HCB Account'],
})
)
} else if (
personAddress.fields['Country'] === 'United States of America (US)'
) {
// if no HCB account, check if they're in the US. If so, setup a mail mission
await interactionMailMission(undefined, {
user,
text: 'new_club_grant',
})
await bot.replyPrivateDelayed(
message,
transcript('promos.githubGrant.usShipping')
)
} else {
// if no HCB account
await bot.replyPrivateDelayed(
message,
transcript('promos.githubGrant.otherSuccess')
)
}
return
} else {
// they've had a grant before
const lastGrantDate = new Date(lastGrant.fields['Initiated at'])
const today = new Date()
// our heuristic for keeping 1 grant per semester is to check if the last grant was both this semester & this year
// semesters are defined as:
// - first semester months are 6 through 11
// - second semester months are 0 through 5
const currentSemester = Math.floor(today.getMonth() / 5)
const lastGrantSemester = Math.floor(lastGrantDate.getMonth() / 5)
const hasSameYear = lastGrantDate.getYear() == today.getYear()
const hasSameSemester = lastGrantSemester == currentSemester
if (hasSameYear && hasSameSemester) {
const requester = (
await airFind(
'People',
`RECORD_ID() = '${lastGrant.fields['Leader'][0]}'`
)
).fields['Slack ID']
await bot.replyPrivateDelayed(
message,
transcript('promos.githubGrant.alreadyGranted', {
lastGrantDate,
requester,
})
)
return
}
if (!history.isActive) {
await bot.replyPrivateDelayed(
message,
transcript('promos.githubGrant.inactive')
)
}
const grant = await airCreate('GitHub Grants', {
Club: [club.id],
Leader: [leader.id],
Type: 'Semesterly ($50)',
'Grant amount': 50,
})
bot.replyPrivateDelayed(
message,
transcript('promos.githubGrant.requestForm', { id: grant.id })
)
}
}