Skip to content

Commit f0276ce

Browse files
committed
initial batch of doc
1 parent 66dec0c commit f0276ce

14 files changed

+249
-13
lines changed

api/channel-is-forbidden.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* check if the slack channel is forbidden
3+
* @function
4+
* @param {string} channelID - The ID of the slack channel
5+
* @returns {boolean}
6+
*/
17
export default (channelID) => {
28
const forbiddenChannels = [
39
'C74HZS5A5', // #lobby

api/close-stale-calls.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import Prisma from "./prisma.js"
22
import closeZoomCall from "./close-zoom-call.js"
33

4+
/**
5+
* @param {Object}
6+
*/
47
export default async ({creatorSlackID} = {}) => {
58
const startTS = Date.now()
69
console.log(`Starting to close stale calls at ${startTS}`)
710

811
const cutoff = 60 * 2 * 1000 // 2 minutes
912

13+
// get meetings started more than two minutes ago
14+
// that haven't ended
1015
const where = {
1116
endedAt: {
1217
equals: null,
@@ -26,7 +31,6 @@ export default async ({creatorSlackID} = {}) => {
2631

2732
if (closedCall) {
2833
closedCalls.push(closedCall)
29-
3034
}
3135
}))
3236

api/find-or-create-meeting.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
import Bottleneck from 'bottleneck'
2-
32
import Prisma from './prisma.js'
43
import openZoomMeeting from "./open-zoom-meeting.js"
54
import sendHostKey from "./send-host-key.js";
65

6+
/**
7+
* finds an existing meeting or create a new one with the query id
8+
* @function
9+
* @params {string} queryID - The schedule link id
10+
*/
711
const findOrCreateMeeting = async (queryID) => {
812
// Find the scheduling link record with the ID we've been given
913
let link = await Prisma.find('schedulingLink', {
1014
where: {name: queryID}
1115
})
16+
1217
if (!link) {
1318
const err = Error('Scheduling meeting not found!')
1419
err.statusCode = 404
1520
throw err
1621
}
1722

23+
// find open meetings using the schedule link id
1824
let openMeetingsCount = await Prisma.count('meeting', { where: { endedAt: {
1925
equals: null,
2026
}, schedulingLinkId: link.id } })

api/get-public-meetings.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ import Prisma from "./prisma.js"
22
import transcript from "./transcript.js"
33
import fetch from 'node-fetch'
44

5+
/**
6+
* Get the number of participants in a slack call
7+
* @function
8+
* @param {string} slackCallID - The ID of the slack call
9+
* @returns {Promise<number>}
10+
*/
511
async function getParticipantCount(slackCallID) {
612
const callInfo = await fetch('https://slack.com/api/calls.info', {
713
method: 'post',
@@ -19,6 +25,11 @@ async function getParticipantCount(slackCallID) {
1925
return callInfo.call.users.length
2026
}
2127

28+
/**
29+
* Get a list of meetings having one or more participants
30+
* @function
31+
* @returns {Promise<Object[]>}
32+
*/
2233
export default async function() {
2334
const meetings = await Prisma.get('meeting', {where: {NOT: {startedAt: {equals: null}}, endedAt: {equals: null}, public: true}})
2435
const meetingsWithParticipants = await Promise.all(

api/get-scheduled-meetings.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import prisma from "./prisma.js"
22

3+
/**
4+
* Get scheduled meetings
5+
* @function
6+
* @param {string} user - The slack ID of the user
7+
* @returns {Promise<Object[]>}
8+
*/
39
export default async function(user) {
410
const linksWhere = {
511
creatorSlackID: user,

api/hack-night.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import fetch from "node-fetch";
22
import { currentTimeHash } from "./time-hash.js";
33

4+
/**
5+
* Get the title of a bookmarked slack channel
6+
* @function
7+
* @returns {Promise<string>}
8+
*/
49
export async function fetchBookmarkTitle () {
510
const response = await fetch('https://slack.com/api/bookmarks.list?channel_id=C0JDWKJVA', {
611
headers: {
@@ -12,6 +17,12 @@ export async function fetchBookmarkTitle () {
1217
return title;
1318
}
1419

20+
/**
21+
* Set the bookmark title of a slack channel
22+
* @function
23+
* @param {string} title - The new title of the bookmark
24+
* @returns {Promise<Object>}
25+
*/
1526
export async function setBookmarkTitle (title) {
1627
const response = await fetch('https://slack.com/api/bookmarks.edit', {
1728
method: 'POST',
@@ -31,16 +42,35 @@ export async function setBookmarkTitle (title) {
3142
return json;
3243
}
3344

45+
/**
46+
* Return the number of participants in a hack night call
47+
* @function
48+
* @returns {Promise<number>}
49+
*/
3450
export async function fetchParticipantNumber () {
3551
const title = await fetchBookmarkTitle();
3652
const number = +(title.split('').filter(char => !isNaN(char)).join('') || '0');
3753
return number;
3854
}
3955

56+
/**
57+
* Set the participant number in a hack night call
58+
* @function
59+
* @param {number} - number
60+
* @returns {Promise<string>}
61+
*/
4062
export async function setParticipantNumber (number) {
4163
return await setBookmarkTitle('Join Hack Night! 👤 ' + number);
4264
}
4365

66+
/**
67+
* Return the stats of a hack night call
68+
* @function
69+
* @param {string} event - The event name e.g "meeting.ended"
70+
* @param {any} meeting
71+
* @param {Object} payload
72+
* @returns {Promise<void>}
73+
*/
4474
export default async function hackNightStats (event, meeting, payload) {
4575
switch (event) {
4676
case 'meeting.ended':

api/is-public-slack-channel.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import airbridge from "./airbridge.js"
22
import fetch from 'node-fetch'
33

4+
/**
5+
* Returns true if the channelID is a public slack channel
6+
* @function
7+
* @param {string} channelID - The ID of the slack channel
8+
* @returns {Promise<boolean>}
9+
*/
410
export default async function(channelID) {
511
if (channelID[0].toLowerCase() != 'c') {
612
// slack channels start with 'c'

api/open-zoom-meeting.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ const hackNightSettings = {
88
participants_share_simultaneously: 'multiple'
99
}
1010

11+
/**
12+
* Pick a random host not used in a call
13+
* @function
14+
* @returns {Promise<Object>}
15+
*/
1116
async function availableHost() {
1217
const hosts = await Prisma.get("host", {
1318
where: {
@@ -26,6 +31,14 @@ async function availableHost() {
2631
return hosts[Math.floor(Math.random() * hosts.length)];
2732
}
2833

34+
/**
35+
* Opens a new zoom meeting
36+
* @function
37+
* @param {Object} prop
38+
* @param {string} prop.creatorSlackID - The ID of the slack creator
39+
* @param {boolean} prop.isHackNight - Should the zoom meeting be a hack night
40+
* @returns {Object}
41+
*/
2942
export default async ({ creatorSlackID, isHackNight } = {}) => {
3043
// find an open host w/ less then 2 open meetings. why 2? Zoom lets us host up to 2 concurrent meetings
3144
// https://support.zoom.us/hc/en-us/articles/206122046-Can-I-Host-Concurrent-Meetings-

api/prisma.js

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import pkg from "@prisma/client"
22
import metrics from "../metrics.js"
33
const { PrismaClient } = pkg
4-
let prisma = new PrismaClient()
5-
64
import Bottleneck from 'bottleneck'
75

86
const VERBOSE_PRISMA_LOGGING = process.env.VERBOSE_PRISMA_LOGGING ? false : process.env.VERBOSE_PRISMA_LOGGING=='true'
@@ -11,9 +9,18 @@ const limiter = new Bottleneck({
119
maxConcurrent: 4,
1210
})
1311

12+
let prisma = new PrismaClient()
1413
// prismaGet('Meeting')
1514
// prismaGet('Meeting', '01234567')
1615
// prismaGet('Meeting', { where: {id: '01234567'} })
16+
17+
/**
18+
* Get all records matching clauses in options
19+
* @function
20+
* @param {string} table - The name of the database table
21+
* @param {Object} options - options
22+
* @returns {Promise<Object[]>}
23+
*/
1724
const get = async (table, options) => {
1825
const ts = Date.now()
1926
if (VERBOSE_PRISMA_LOGGING)
@@ -42,6 +49,14 @@ const get = async (table, options) => {
4249
// prismaFind('User')
4350
// prismaFind('User', '01234567')
4451
// prismaFind('User', )
52+
53+
/**
54+
* Returns a single record matching the clauses in options
55+
* @function
56+
* @param {string} table - The database table name
57+
* @param {Object} options - The query options
58+
* @returns {Promise<Object>}
59+
*/
4560
const find = async (table, options) => {
4661
const ts = Date.now()
4762
if (VERBOSE_PRISMA_LOGGING)
@@ -66,6 +81,13 @@ const find = async (table, options) => {
6681
}
6782
}
6883

84+
/**
85+
* Returns the number of records in table
86+
* @function
87+
* @param {string} table - The database table name
88+
* @param {Object} - The query options
89+
* @returns {Promise<number>}
90+
*/
6991
const count = async (table, options) => {
7092
let where, orderBy, include
7193
if (VERBOSE_PRISMA_LOGGING)
@@ -87,6 +109,14 @@ const count = async (table, options) => {
87109
}
88110
}
89111

112+
/**
113+
* Update fields on record with {recordID} in table
114+
* @function
115+
* @param {string} table - The table name in the database
116+
* @param {string} recordID - The ID of the record in table
117+
* @param {Object} fields - The fields to update on the record
118+
* @returns {Promise<Object>}
119+
*/
90120
const patch = async (table, recordID, fields) => {
91121
const ts = Date.now()
92122
try {
@@ -108,6 +138,13 @@ const patch = async (table, recordID, fields) => {
108138
}
109139
}
110140

141+
/**
142+
* Create a new record with {fields} in {table}
143+
* @function
144+
* @param {string} table - The database table name
145+
* @param {Object} fields - The new record's values
146+
* @returns {Promise<Object>}
147+
*/
111148
const create = async (table, fields) => {
112149
const ts = Date.now()
113150
try {
@@ -124,6 +161,13 @@ const create = async (table, fields) => {
124161
}
125162
}
126163

164+
/**
165+
* Delete the record with id {id} from {table}
166+
* @function
167+
* @param {string} table - The database table name
168+
* @param {string} id - The id of the record to delete in {table}
169+
* @returns {Promise<Object>}
170+
*/
127171
const destroy = async (table, id) => {
128172
const ts = Date.now()
129173
try {

api/transcript.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ import { readFileSync } from 'fs'
33
import path from 'path'
44
import os from "os"
55

6+
/**
7+
* Returns the plural of {word}
8+
* @function
9+
* @param {string} word
10+
* @param {number} count
11+
* @returns {string}
12+
*/
613
const pluralize = (word, count) => {
714
// want to use this method? make sure to add your word to transcript.yml under 'plurals'
815
if (count == 1) {
@@ -18,6 +25,11 @@ const sample = (arr) => {
1825
return arr[Math.floor(Math.random() * arr.length)]
1926
}
2027

28+
/**
29+
* Loads the transcipt.yml file
30+
* @function
31+
* @returns {string}
32+
*/
2133
const loadTranscript = () => {
2234
const moduleURL = new URL(import.meta.url);
2335
let __dirname = decodeURIComponent(path.dirname(moduleURL.pathname));
@@ -32,6 +44,7 @@ const loadTranscript = () => {
3244
console.error(e)
3345
}
3446
}
47+
3548
const recurseTranscript = (searchArr, transcriptObj, fallback) => {
3649
const searchCursor = searchArr.shift()
3750
const targetObj = transcriptObj[searchCursor]
@@ -66,6 +79,14 @@ const replaceErrors = (key, value) => {
6679
return value
6780
}
6881

82+
/**
83+
* Returns the
84+
* @function
85+
* @param {string} search - the word to transcribe
86+
* @param {Object} vars
87+
* @param {Object} fallback
88+
* @returns {string}
89+
*/
6990
const transcript = (search, vars, fallback) => {
7091
if (vars) {
7192
console.log(
@@ -82,6 +103,7 @@ const transcript = (search, vars, fallback) => {
82103
const dehydratedTarget = recurseTranscript(searchArr, transcriptObj, fallback)
83104
return hydrateObj(dehydratedTarget, vars)
84105
}
106+
85107
const hydrateObj = (obj, vars = {}) => {
86108
if (obj == null) {
87109
return null

api/user-is-restricted.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import fetch from 'node-fetch'
22

3+
/**
4+
* Determine if a channel is restricted or not
5+
* @function
6+
* @param {string} userID - The slack user ID
7+
* @returns {Promise<boolean>}
8+
*/
39
export default async (userID) => {
410
const userInfo = await fetch(`https://slack.com/api/users.info?user=${userID}`, {
511
headers: {

0 commit comments

Comments
 (0)