diff options
author | Noah Loomans <noahloomans@gmail.com> | 2017-09-27 12:14:52 +0200 |
---|---|---|
committer | Noah Loomans <noahloomans@gmail.com> | 2017-09-27 12:14:52 +0200 |
commit | 512c9689b5124656f37086619087a277262c3e03 (patch) | |
tree | f78c112b465accce2f289aa766f17af65cee1c0c /src/server/routes | |
parent | dfe3d68edaddd71b020f39ae676ac7e1ec3d7c04 (diff) |
Support all types of users
Diffstat (limited to 'src/server/routes')
-rw-r--r-- | src/server/routes/slack.js | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/src/server/routes/slack.js b/src/server/routes/slack.js index 5dc7047..abd0154 100644 --- a/src/server/routes/slack.js +++ b/src/server/routes/slack.js @@ -1,24 +1,34 @@ const express = require('express') const router = express.Router() +const getUserIndex = require('../lib/getUserIndex') + router.all('/', function (req, res, next) { - if (!/^[0-9]+$/.test(req.body.text)) { + getUserIndex().then(users => { + const query = req.query.text + const user = + users.filter(user => user.value === query)[0] + + if (!user) { + res.json({ + "response_type": "ephemeral", + "mrkdwn": true, + "text": `Sorry, I tried my best, but I couldn't find _${query}_` + }) + return + } + res.json({ - "response_type": "ephemeral", - "text": "Only student id's are currently supported, more comming soon!" + "response_type": "in_channel", + "text": `Here is the schedule of _${query}_`, + "mrkdwn": true, + "attachments": [ + { + "fallback": `https://beta.rooster.hetmml.nl/${user.type}/${user.value}`, + "image_url": `https://beta.rooster.hetmml.nl/get/${user.type}/${user.value}.png` + } + ] }) - return - } - res.json({ - "response_type": "in_channel", - "text": `Here is the schedule of _${req.body.text}_`, - "mrkdwn": true, - "attachments": [ - { - "fallback": `https://beta.rooster.hetmml.nl/s/${req.body.text}`, - "image_url": `https://beta.rooster.hetmml.nl/get/s/${req.body.text}.png` - } - ] }) }) |