Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hubot script to accept the room name #214

Merged
merged 5 commits into from
Jul 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/rocketchat.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,13 @@ class RocketChatBotAdapter extends Adapter
@lastts = curts

user = @robot.brain.userForId newmsg.u._id, name: newmsg.u.username, alias: newmsg.alias
user.room = newmsg.rid

if newmsg.t is 'uj'
@robot.receive new EnterMessage user, null, newmsg._id
else
@chatdriver.getRoomName(newmsg.rid).then((roomName)=>
user.room = roomName
user.roomID = newmsg.rid
if newmsg.t is 'uj'
@robot.receive new EnterMessage user, null, newmsg._id
else
# check for the presence of attachments in the message
if newmsg.file? and newmsg.attachments.length
attachment = newmsg.attachments[0]
Expand All @@ -184,6 +186,10 @@ class RocketChatBotAdapter extends Adapter
message.text = "#{ @robot.name } #{ message.text }"
@robot.receive message
@robot.logger.info "Message sent to hubot brain."
).catch((roomErr) =>
@robot.logger.error "Unable to get room name: #{JSON.stringify(roomErr)} Reason: #{roomErr.reason}"
throw roomErr
)
)
.then(() =>
@emit 'connected'
Expand Down
12 changes: 8 additions & 4 deletions src/rocketchat_driver.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@ LRU = require('lru-cache')
# TODO: need to grab these values from process.env[]

_msgsubtopic = 'stream-room-messages' # 'messages'
_msgsublimit = 10 # this is not actually used right now
_msgsublimit = 10 # this is not actually used right now
_messageCollection = 'stream-room-messages'

# room id cache
_roomCacheSize = parseInt(process.env.ROOM_ID_CACHE_SIZE) || 10
_directMessageRoomCacheSize = parseInt(process.env.DM_ROOM_ID_CACHE_SIZE) || 100
_cacheMaxAge = parseInt(process.env.ROOM_ID_CACHE_MAX_AGE) || 300
_roomIdCache = LRU( max: _roomCacheSize, maxAge: 1000 * _cacheMaxAge )
_directMessageRoomIdCache = LRU( max: _directMessageRoomCacheSize, maxAge: 1000 * _cacheMaxAge )
_roomIdCache = LRU(max: _roomCacheSize, maxAge: 1000 * _cacheMaxAge)
_directMessageRoomIdCache = LRU(max: _directMessageRoomCacheSize, maxAge: 1000 * _cacheMaxAge)
_roomNameCache = LRU(max: _roomCacheSize, maxAge: 1000 * _cacheMaxAge)

# driver specific to Rocketchat hubot integration
# plugs into generic rocketchatbotadapter

class RocketChatDriver
constructor: (url, ssl, @logger, cb) ->
if ssl is 'true'
if ssl is 'true'
sslenable = true
else
sslenable = false
Expand All @@ -39,6 +40,9 @@ class RocketChatDriver
getRoomId: (room) =>
@tryCache _roomIdCache, 'getRoomIdByNameOrId', room, 'Room ID'

getRoomName: (room) =>
@tryCache _roomNameCache, 'getRoomNameById', room, 'Room Name'

getDirectMessageRoomId: (username) =>
@tryCache _directMessageRoomIdCache, 'createDirectMessage', username, 'DM Room ID'

Expand Down