commodore-github-bot
Version:
A hubot script to list and recurrently remind you about open pull requests and pull request assignments.
75 lines (59 loc) • 2.54 kB
text/coffeescript
_ = require "underscore"
class GenericAdapter
: "github-notifications-disabled"
: "github-dm-counts"
constructor: () ->
= null
= null
.brain.once "loaded", =>
= .brain.get(GenericAdapter.GITHUB_NOTIFICATIONS_DISABLED) or []
= .brain.get(GenericAdapter.GITHUB_DM_COUNTS) or {}
disableNotificationsFor: (user) ->
.logger.info "Disabling Github notifications for #{user.name}"
.push user.id
.brain.set GenericAdapter.GITHUB_NOTIFICATIONS_DISABLED, _().unique()
.brain.save()
enableNotificationsFor: (user) ->
.logger.info "Enabling Github notifications for #{user.name}"
= _().without user.id
.brain.set GenericAdapter.GITHUB_NOTIFICATIONS_DISABLED,
.brain.save()
incrementDMCountFor: (user) ->
return unless ?
return unless user?.id?
[user.id] ||= 0
[user.id]++
.brain.set GenericAdapter.GITHUB_DM_COUNTS,
.brain.save()
getDMCountFor: (user) ->
return 0 unless ?
return 0 unless user?.id?
[user.id] ||= 0
return [user.id]
send: (context, message) ->
if _(message).isString()
payload = message
else if message.text or message.attachments
payload = ""
if message.text
payload += "#{message.text}\n"
if message.attachments
for attachment in message.attachments
payload += "#{attachment.fallback}\n"
else
return .logger.error "Unable to find a message to send", message
.send room: context.message.room, payload
dm: (users, message) ->
users = [ users ] unless _(users).isArray()
for user in users when user
if _().contains user.id
.logger.debug "Github Notification surpressed for #{user.name}"
else
if message.author? and user.name is message.author.name
.logger.debug "Github Notification surpressed for #{user.name} because it would be a self-notification"
continue
message.text += "\n#{message.footer}" if message.text and message.footer and < 3
message: room: user.id, _(message).pick "attachments", "text"
user
getPermalink: (msg) -> ""
module.exports = GenericAdapter