-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (47 loc) · 1.45 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
const { App } = require('@slack/bolt')
const { Avokudos } = require('./lib/avokudos')
const { LocalKeeper } = require('./lib/keepers/local')
const { RedisKeeper } = require('./lib/keepers/redis')
const redis = require('redis')
let keeper
if (process.env.REDIS_HOST !== undefined) {
console.log('REDIS_HOST is set. Using RedisKeeper')
const redisClient = redis.createClient({
socket: {
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT || 6379
},
password: process.env.REDIS_PASSWORD
})
redisClient.on('error', (err) => {
console.log('Redis Error: ' + err)
})
redisClient
.connect()
.then(() => {
console.log('Connected to redis instance')
})
.catch((err) => {
console.error('Failed to connect to redis: ' + err)
process.exit(1)
})
keeper = new RedisKeeper(redisClient)
} else {
console.log('Using LocalKeeper')
keeper = new LocalKeeper()
}
const avokudos = new Avokudos(keeper)
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
socketMode: true,
appToken: process.env.SLACK_APP_TOKEN
})
app.message(':avocado:', avokudos.hearMessage)
app.event('reaction_added', avokudos.hearReactionAdded)
app.event('reaction_removed', avokudos.hearReactionRemoved)
app.command('/leaderboard', avokudos.getLeaderboard);
(async () => {
await app.start(process.env.PORT || 3000)
console.log('🥑 Avokudos app is running!')
})()