This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| 0: { | |
| "Introduction": "# intro/n/n ## hello there...." | |
| }, | |
| 1: { | |
| "Getting Started": | |
| { | |
| 0: { | |
| "Step One": "# stepone/n/n ## hello there..." | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [ | |
| { | |
| "Introduction": "# intro/n/n ## hello there...." | |
| }, | |
| { | |
| "Getting Started": | |
| [ | |
| { | |
| "Step One": "# stepone/n/n ## hello there..." | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const jwt = require('jsonwebtoken'); | |
| const models = require('../models'); | |
| const Strategy = require('passport-local'); | |
| function generateToken(req, res, next) { | |
| res.cookie('token', | |
| jwt.sign({ id: req.user.id }, process.env.SECRET), | |
| { | |
| maxAge: 86400000, | |
| httpOnly: true, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const jwt = require('jsonwebtoken'); | |
| const models = require('../models'); | |
| const Strategy = require('passport-local'); | |
| function generateToken(req, res, next) { | |
| res.cookie('token', | |
| jwt.sign({ id: req.user.id }, process.env.SECRET), | |
| { | |
| maxAge: 86400000, | |
| httpOnly: true, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (!process.env.token) { | |
| process.exit(1); | |
| } | |
| const Botkit = require('botkit'); | |
| const controller = Botkit.slackbot({ | |
| debug: true, | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| } else { | |
| const gameResults = playerIDs.map((id) => `<@${id}> played ${players[id].played}`); | |
| bot.reply(message, gameResults.join(' & ')); | |
| // reset the game data | |
| channels.save({ id: updateData.id }, (err) => { | |
| if (err) throw err; | |
| }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| channels.get(channel, (err, data) => { | |
| ... | |
| if (onlyOnePlayed) { | |
| channels.save(updateData, (err) => { | |
| if (err) throw err; | |
| bot.reply(message, `<@${user}> has played!`); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (convo.status === 'completed') { | |
| const prc = convo.extractResponse('rockPaperScissors'); | |
| channels.get(channel, (err, data) => { | |
| if (err) throw err; | |
| const updateData = data; | |
| updateData.players[user].played = prc; | |
| const { players } = updateData; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| convo.on('end', (convo) => { | |
| if (convo.status === 'completed') { | |
| // conversation completed correctly | |
| const prc = convo.extractResponse('rockPaperScissors'); | |
| } else { | |
| // this happens if the conversation ended prematurely for some reason | |
| bot.reply(message, 'OK, nevermind!'); | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function privateConvo(bot, message) { | |
| const { user, channel } = message; | |
| return (err, convo) => { | |
| if (err) throw err; | |
| convo.ask(...); | |
| // on end, update game data and broadcast info | |
| convo.on('end', callback); |