Skip to content

Commit

Permalink
Continue @payou's work on #9.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephane Labruyere committed Mar 25, 2016
1 parent e5d0be9 commit 2321806
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
2 changes: 0 additions & 2 deletions scripts/hubot-sumologic-image-widget/widgetFinder.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ sumoToken = process.env.SUMOLOGIC_TOKEN || "ZnJvbnRlbmRAdGVhZHMudHY6RzhMZGNK
class WidgetFinder
constructor: (@name, @robot) ->
@config = _.get(mapping, @name)
if _.isUndefined(@config)
robot.logger.error "The widget '#{@name}' isn't mapped yet !"

exists: () ->
not _.isUndefined(@config)
Expand Down
49 changes: 44 additions & 5 deletions scripts/sumo-main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,50 @@ WidgetFinder = require './hubot-sumologic-image-widget/widgetFinder'
module.exports = (robot) ->

robot.respond /sumo (.*)/i, (result) ->
widget = new WidgetFinder(result.match[1], robot)
if widget.exists()
result.reply "Sure ! I process it and send you this one here !"
widget.getData(result.message)
argz = result.match[1].split(' ')
n = argz.length
# WARNING: Slack replaces "--" with "-" !
# FIXME: do this with a regex

verbose = false
if argz.indexOf('-v') > -1
verboseOptIndex = argz.indexOf('-v')
else
verboseOptIndex = argz.indexOf('-verbose')

if verboseOptIndex > -1
verbose = true
argz.splice(verboseOptIndex, 1) # remove it from argz
n = argz.length

if argz.indexOf('-a') > -1
addOptIndex = argz.indexOf('-a')
else
result.reply "I don't know this widget sorry... :disappointed:"
addOptIndex = argz.indexOf('—add')

if addOptIndex > -1
# add a widget to config
argz.splice(addOptIndex, 1) # remove it from argz
n = argz.length

# DIRTY!!!
# we should have --name "name" etc
if n >= 4
name = argz[0]
dashboardId = argz[1]
widgetId = argz[2]
type = argz[3]

result.reply "Ok, I'll remember the widget " + name + " (id " + widgetId + " - dashboardId " + dashboardId + " - type " + type + ")."
else
result.reply "To add a widget, I need 4 pieces of information!"

else
if n > -1
widgetName = argz[n-1]
widget = new WidgetFinder(widgetName, robot)
if widget.exists()
result.reply "I know this widget, let me grab it for you ;)"
widget.getData(result.message)
else
result.reply "I don't know this widget sorry... :disappointed:"
4 changes: 2 additions & 2 deletions scripts/welcome.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ getRandomItem = (items) => items[Math.floor(Math.random()*items.length)]

module.exports = (robot) ->

robot.messageRoom "general", "Hubot is back !!!!!! :banana:"
# robot.messageRoom "general", "Hubot is back !!!!!! :banana:"

responses = [
"uk:Hello!"
Expand Down Expand Up @@ -54,4 +54,4 @@ module.exports = (robot) ->
res.reply ":flag-" + randomResponse[0] + ": " + randomResponse[1]

robot.hear /(bichour)/i, (res) ->
res.reply "Bichour toi"
res.reply "Bichour toi"

0 comments on commit 2321806

Please sign in to comment.