Merge pull request #3 from uhoreg/master

miscellaneous improvements
This commit is contained in:
David A Roberts 2016-10-03 20:39:24 +10:00 committed by GitHub
commit 2878880fd5
2 changed files with 26 additions and 7 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "hubot-matrix", "name": "hubot-matrix",
"version": "1.1.0", "version": "1.1.1",
"description": "Matrix adapter for hubot", "description": "Matrix adapter for hubot",
"main": "src/matrix.coffee", "main": "src/matrix.coffee",
"scripts": { "scripts": {
@ -10,7 +10,7 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"parent-require": "^1.0.0", "parent-require": "^1.0.0",
"matrix-js-sdk": ">=0.3.0" "matrix-js-sdk": "^0.6.0"
}, },
"peerDependencies": { "peerDependencies": {
"hubot": ">=2.0" "hubot": ">=2.0"

View File

@ -18,12 +18,28 @@ class Matrix extends Adapter
if /^(f|ht)tps?:\/\//i.test(str) if /^(f|ht)tps?:\/\//i.test(str)
@sendImage envelope, str @sendImage envelope, str
else else
@client.sendTextMessage envelope.room, str @client.sendMessage envelope.room, {
msgtype: "m.notice",
body: str
}
emote: (envelope, strings...) ->
for str in strings
@client.sendMessage envelope.room, {
msgtype: "m.emote",
body: str
}
reply: (envelope, strings...) -> reply: (envelope, strings...) ->
for str in strings for str in strings
@send envelope, "#{envelope.user.name}: #{str}" @send envelope, "#{envelope.user.name}: #{str}"
topic: (envelope, strings...) ->
for str in strings
@client.sendEvent envelope.room, "m.room.topic", {
topic: str
}
sendImage: (envelope, url) -> sendImage: (envelope, url) ->
@client.uploadContent(stream: request url, name: url).done (murl) => @client.uploadContent(stream: request url, name: url).done (murl) =>
@client.sendMessage envelope.room, { @client.sendMessage envelope.room, {
@ -49,11 +65,14 @@ class Matrix extends Adapter
baseUrl: process.env.HUBOT_MATRIX_HOST_SERVER || 'https://matrix.org' baseUrl: process.env.HUBOT_MATRIX_HOST_SERVER || 'https://matrix.org'
accessToken: @access_token accessToken: @access_token
userId: @user_id userId: @user_id
@client.on 'syncComplete', => @client.on 'sync', (state, prevState, data) =>
@robot.logger.info "Synced #{@client.getRooms().length} rooms" switch state
@emit 'connected' when "PREPARED"
@robot.logger.info "Synced #{@client.getRooms().length} rooms"
@emit 'connected'
@client.on 'Room.timeline', (event, room, toStartOfTimeline) => @client.on 'Room.timeline', (event, room, toStartOfTimeline) =>
if event.getType() == 'm.room.message' and toStartOfTimeline == false @client.sendReadReceipt(event)
if event.getType() == 'm.room.message' and event.getContent().msgtype != "m.notice" and toStartOfTimeline == false
message = event.getContent().body message = event.getContent().body
name = event.getSender() name = event.getSender()
user = @robot.brain.userForId name user = @robot.brain.userForId name