Skip to content

Commit

Permalink
Se simplifico la salida
Browse files Browse the repository at this point in the history
  • Loading branch information
lgaticaq committed Mar 20, 2016
1 parent c6b7e73 commit ae2c648
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions src/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
# Verifica si un email ha sido comprometido en alguna ruptura de seguridad
#
# Dependencies:
# "filesize": "^3.1.3",
# "moment": "^2.10.6"
# None
#
# Commands:
# hubot hesidohackeado <email> -> Retorna listado de sitios comprometidos con el email registrado
#
# Author:
# lgaticaq

filesize = require("filesize")
moment = require("moment")
numberFormat = require("underscore.string/numberFormat")

module.exports = (robot) ->
sendAttachment = (attachments, res) ->
data =
attachments: attachments
channel: res.message.room
robot.emit "slack.attachment", data

emailPattern = "([\\w.-]+@[\\w.-]+\\.[a-zA-Z.]{2,6})"
regex = new RegExp("hesidohackeado #{emailPattern}", "i")
robot.respond regex, (res) ->
Expand All @@ -35,21 +36,19 @@ module.exports = (robot) ->
else if data.status is "notfound"
res.send ":tada: ¡Felicidades! No hay registros para #{email} :tada:"
else if data.status is "found"
text = ""
if data.results is 1
text += ">Hay *1* registro para #{email}\n"
text = "Hay 1 registro para #{email}"
else
text += ">Hay *#{data.results}* registros para #{email}\n"
text = "Hay #{data.results} registros para #{email}"
format = "YYYY-MM-DD HH:mm:ss"
for d in data.data
text += ">*Fecha*: #{moment(d.date_leaked).format(format)}\n"
text += ">*Título*: #{d.title}\n"
text += ">*Autor*: #{d.author}\n"
text += ">*Sitio*: #{d.source_provider}\n"
text += ">*Red*: #{d.source_network}\n"
text += ">*Emails*: #{numberFormat(d.emails_count, 0, ",", ".")}\n"
text += ">*Tamaño*: #{filesize(d.source_size)}\n"
text += ">*Enlace*: #{d.details}\n\n"
res.send text
fields = data.data.map (x) ->
title: x.title
value: "Fecha: #{x.date_leaked.substr(0, 10)}"
short: true
attachments =
fallback: text
text: text
fields: fields
sendAttachment attachments, res
else
res.reply "La respuesta no es la esperada"

0 comments on commit ae2c648

Please sign in to comment.