This file contains 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 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 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 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 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 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 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 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); |
This file contains 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
return (err, convo) => { | |
convo.ask('Do you want to play `paper`, `rock`, or `scissors`?', [ | |
{ | |
pattern: 'paper|rock|scissors', | |
callback(response, convo) { | |
// since no further messages are queued after this, | |
// the conversation will end naturally with status === ‘completed’ | |
convo.next(); | |
}, | |
}, { |
This file contains 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) { | |
return (err, convo) => {}; | |
} | |
... | |
bot.startPrivateConversation(message, privateConvo(bot, message)); |