forked from shaykalyan/slack-ascii
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
112 lines (100 loc) · 3.79 KB
/
index.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
var express = require('express');
var Slack = require('node-slack');
var request = require('request');
var dotenv = require('dotenv');
dotenv.load();
var app = express();
var slack = new Slack(process.env.SLACK_HOOK_URL);
var asciiEmoticons = {
"bear": "ʕ •ᴥ•ʔ",
"diretide": "༼ つ ◕_◕ ༽つ GIVE DIRETIDE",
"do it": "(☞゚ヮ゚)☞",
"eyes": "ಠ_ಠ",
"flip": "(╯°□°)╯︵ ┻━┻",
"lenny": "( ͡° ͜ʖ ͡°)",
"shades": "(⌐■_■)",
"shrug": "¯\\_(ツ)_/¯",
"unflip": "┬──┬◡ノ(° -°ノ)",
"y u no": "ლ(ಠ益ಠლ)",
"epic flip": "(˚Õ˚)ر ~~~~╚╩╩╝",
"flip all dem tables": "┻━┻( \\(°□°)/ ( ┻━┻",
"unflip all dem tables": "┏━┓┏━┓┏━┓ ︵ /(^.^/)",
"punch": "O=(‘-‘Q)",
"pistols": " ̿’ ̿’\̵͇̿̿\з=(◕_◕)=ε/̵͇̿̿/’̿’̿ ̿",
"dont mess": "ᕙ(⇀‸↼‶)ᕗ",
"peace": "(‾⌣‾)♉",
"gimme": "༼ つ ◕_◕ ༽つ",
"serious": "(ಠ_ಠ)",
"angry": "(⋟﹏⋞)",
"sorry": "(ノ´д`)",
"meh": "ヽ(。_°)ノ",
"zombie": "[¬º-°]¬",
"confused": "( •᷄ὤ•᷅)?",
"crazy": "(⊙_◎)",
"party time": "┏(-_-)┛┗(-_- )┓┗(-_-)┛┏(-_-)┓",
"sunglasses": "( •_•) ( •_•)>⌐■-■ (⌐■_■)",
"help": "٩(͡๏̯͡๏)۶",
"zap": "( ●_●)-((⌼===<((() ≍≍≍≍≍ ♒ ✺ ♒ ZAP!",
"rage": "t(ಠ益ಠt)",
"sad": "(╥﹏╥)",
"sleeping": "(-.-)Zzz…",
"love eyes": "(♥_♥)",
"omg wat": "◕_◕",
"man tears": "ಥ_ಥ",
"hide": "|_・) |・ω・`)",
"yay": "\\(ˆ˚ˆ)/",
"woot": "\\(^O^)/",
"sword": "o()xxxx[{::::::::::::::::::::::::::::::::::>",
"band aid": "( ̲̅:̲̅:̲̅:̲̅[̲̅ ̲̅]̲̅:̲̅:̲̅:̲̅ )",
"koala": "@( * O * )@",
"ping pong": "( •_•)O*¯`·.¸.·´¯`°Q(•_• )",
"chillin": "<(^.^)>",
"hugs": "(っ◕‿◕)っ",
"whatevs": "ヾ(o・ω・)ノ"
};
var helpResponseMessage = '';
for (emoticon in asciiEmoticons) {
helpResponseMessage += '*' + emoticon + '*: ' + asciiEmoticons[emoticon] + '\n';
}
app.use('/', function(req, res, next) {
if (req.query.token !== process.env.SLACK_SLASH_COMMAND_TOKEN) {
return res.status(500).send('Cross-site request detected!');
}
next();
});
app.get('/', function(req, res) {
if (req.query.text == "help") {
return res.send(helpResponseMessage);
}
var userRequestUrl =
'https://slack.com/api/users.info?' +
'token=' + process.env.SLACK_TEAM_API_TOKEN +
'&user=' + req.query.user_id;
request(userRequestUrl, function (userErr, userRes, userBody) {
if (!userErr && userRes.statusCode == 200) {
userInfo = JSON.parse(userBody);
if (userInfo.ok) {
var emoticon = asciiEmoticons[req.query.text];
if (emoticon) {
var payload = {
text: emoticon,
channel: req.query.channel_id,
username: userInfo.user.real_name,
icon_url: userInfo.user.profile.image_48
};
slack.send(payload);
res.send();
} else {
res.status(404).send(' `' + req.query.text + '` not found. ' +
'Enter `' + req.query.command + ' help` for a list of available ASCII emoticons.');
}
} else {
res.status(500).send('Error: `' + userInfo.error +'`.');
}
} else {
res.status(500).send('Error: User `' + req.query.user_name +'` not found.');
}
});
});
app.set('port', (process.env.PORT || 5000));
app.listen(app.get('port'));