-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
91 lines (76 loc) · 2.57 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
const SlackBot = require('slackbots')
const config = require('./config')
const gpio = require('rpi-gpio')
const rpi_pin = 7
var PythonShell = require('python-shell')
const bot = new SlackBot({
token: config.token,
name: config.name
})
bot.on('start', function() {
console.log('bot connected to slack channel')
bot.on('message', function(event) {
if(event.type === 'message') {
return Promise.all([
bot.getUserById(event.user),
bot.getChannelById(event.channel)
])
.then(room => {
const chatter = {
channel: room[1].name,
username: room[0].profile.first_name,
message: event.text,
ts: event.ts
}
const up_messages = ['flag up', 'hoist the flag', 'moist the flag'];
const down_messages = ['flag down', 'dehoist the flag', 'demoist the flag'];
if(up_messages.includes(chatter.message.trim().toLowerCase())) {
console.log('executing flag command')
bot.postMessageToChannel(chatter.channel, chatter.username + ' executed flag up command :pogchamp:')
flagUp()
}
if(down_messages.includes(chatter.message.trim().toLowerCase())){
console.log('executing flag command')
bot.postMessageToChannel(chatter.channel, chatter.username + ' executed flag down command :pogchamp:')
flagDown()
}
})
.catch(err => {
console.log(err)
// bot.postMessageToChannel('general', 'Error :feelsbadman: ' + err)
})
}
})
})
bot.on('error', (err) => {
console.log(err)
})
function flagUp() {
PythonShell.run('flagup.py', {scriptPath: '/home/pi/flackbot'}, function(err) {
if(err) {
console.log(err)
} else {
console.log('finished script')
}
})
// gpio.setup(rpi_pin, gpio.DIR_OUT, write)
// write()
}
function flagDown() {
PythonShell.run('flagdown.py', {scriptPath: '/home/pi/flackbot'}, function(err) {
if(err) {
console.log(err)
} else {
console.log('finished script')
}
})
// gpio.setup(rpi_pin, gpio.DIR_OUT, write)
// write()
}
// function write() {
// console.log('writing')
// gpio.write(rpi_pin, true, (err) => {
// if(err) throw err
// console.log('written to pin')
// })
// }