-
Notifications
You must be signed in to change notification settings - Fork 3
/
trello.coffee
125 lines (107 loc) · 4.3 KB
/
trello.coffee
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
113
114
115
116
117
118
119
120
121
122
123
124
# Description:
# Add entries to trello directly from hubot
#
# Dependencies:
# "node-trello": "0.1.2"
#
# Configuration:
# HUBOT_TRELLO_KEY - your trello developer key
#
# Commands:
# hubot trello all the users - which users do we know about trello for
# hubot trello get token - provides instructions on acquiring a token
# hubot trello set token <token> - set the authentication token
# hubot trello forget me - deletes the authentication token
# hubot trello boards - list your trello boards
# hubot trello set my board to <board> - set your default board
# hubot trello lists - list your trello lists on the default board
# hubot trello set my list to <list> - set your default list
# hubot trello me <message> - add a new card to your default list
#
# Notes:
# Currently cards can only be added to your default list/board although
# this can be changed
#
# Author:
# beezly
module.exports = (robot) ->
Trello = require 'node-trello'
trello_key = process.env.HUBOT_TRELLO_KEY
robot.respond /trello all the users/i, (msg) ->
theReply = "Here is who I know:\n"
for own key, user of robot.brain.data.users
if(user.trellotoken)
theReply += user.name + "\n"
msg.send theReply
robot.respond /trello get token/, (msg) ->
msg.send "Get a token from https://trello.com/1/connect?key=#{trello_key}&name=cicsbot&response_type=token&scope=read,write&expiration=never"
msg.send "Then send it back to me as \"trello add token <token>\""
robot.respond /trello add token ([a-f0-9]+)/i, (msg) ->
trellotoken = msg.match[1]
msg.message.user.trellotoken = trellotoken
msg.send "Ok, your token is registered"
robot.respond /trello forget me/i, (msg) ->
user = msg.message.user
user.trellotoken = null
msg.reply("Ok, I have no idea who you are anymore.")
robot.respond /trello boards/i, (msg) ->
user = msg.message.user
trellotoken = msg.message.user.trellotoken
t = new Trello trello_key, trellotoken
t.get '/1/members/me/boards/', (err,data) ->
console.log board for board in data
msg.send board.name for board in data
robot.respond /trello set my board to (.*)/i, (msg) ->
board_name = msg.match[1]
user = msg.message.user
trellotoken = msg.message.user.trellotoken
t = new Trello trello_key, trellotoken
t.get '/1/members/me/boards/', (err, data) ->
for board in data
if board.name == board_name
user.trelloboard = board.id
msg.reply "Your trello board is set to #{board.name}"
robot.respond /trello lists/i, (msg) ->
user = msg.message.user
trellotoken = user.trellotoken
trelloboard = user.trelloboard
t = new Trello trello_key, trellotoken
if !trellotoken
msg.reply "You have no trellotoken"
else if !trelloboard
msg.reply "You have no trelloboard"
else
t.get "/1/boards/#{trelloboard}/lists", (err, data) ->
msg.send list.name for list in data
robot.respond /trello set my list to (.*)/i, (msg) ->
list_name = msg.match[1]
user = msg.message.user
trellotoken = user.trellotoken
trelloboard = user.trelloboard
t = new Trello trello_key, trellotoken
if !trellotoken
msg.reply "You have no trellotoken"
else if !trelloboard
msg.reply "You have no trelloboard"
else
t.get "/1/boards/#{trelloboard}/lists", (err, data) ->
for list in data
if list.name == list_name
user.trellolist = list.id
msg.reply "Your trello list is set to #{list.name}"
robot.respond /trello me (.*)/i, (msg) ->
content = msg.match[1]
user = msg.message.user
trelloboard = user.trelloboard
trellotoken = user.trellotoken
trellolist = user.trellolist
if !trellotoken
msg.reply "You don't seem to have a trello token registered. Use \"trello get token\"."
else if !trelloboard
msg.reply "You don't seem to have a default trello board configured. Use \"trello my board is\" to do that"
else if !trellolist
msg.reply "You don't seem to have a default trello list configured. Use \"trello my list is \" to do that"
else
t = new Trello trello_key, trellotoken
t.post "/1/lists/#{trellolist}/cards", { name: content }, (err, data) ->
msg.reply "Added to your list - #{data.url}"