lita-mattermost 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7a3ab02eb822839c0566b0b6bf6e477f070f1325dfe96d12f3c10c1711027ca0
4
+ data.tar.gz: 7d02f093717180c90ff7cfe4441cef4bac22df024273f253afe6fb7d3f785a7c
5
+ SHA512:
6
+ metadata.gz: 3ef9f5002fd966f53b2edbd2a2b99002d852fa59939c7c7a0d01d84b4cb8a46487dbf7c411849d90dde8381dead43cbbb3d31af3364dd212c19e2133bb10bfe1
7
+ data.tar.gz: e466dbcd9b1f9fe8251be976c95e77d799b222c02ba84f63670fbf75d281c9e559e7b32219e325ac673a8a01c8219532df85d1bf08eb049af242a8bf76b60119
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # lita-mattermost
2
+
3
+ Lita adapter to connect to Mattermost
4
+
5
+ ## Installation
6
+
7
+ Add lita-mattermost to your Lita instance's Gemfile:
8
+
9
+ ``` ruby
10
+ gem "lita-mattermost"
11
+ ```
12
+
13
+ ## Configuration
14
+
15
+ ```
16
+ config.robot.adapter = :mattermost
17
+ config.adapters.mattermost.server = <mattermost server url>
18
+ config.adapters.mattermost.token = <bot token>
19
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,7 @@
1
+ require "lita"
2
+
3
+ Lita.load_locales Dir[File.expand_path(
4
+ File.join("..", "..", "locales", "*.yml"), __FILE__
5
+ )]
6
+
7
+ require "lita/adapters/mattermost"
@@ -0,0 +1,80 @@
1
+ require('mattermost')
2
+
3
+ module Lita
4
+ module Adapters
5
+ class Mattermost < Adapter
6
+ config :server, type: String, required: true
7
+ config :token, type: String, required: true
8
+
9
+ def initialize(robot)
10
+ super
11
+ @client = ::Mattermost.new_client(config.server)
12
+ @client.use_access_token(config.token)
13
+
14
+ @ws_client = ::Mattermost::WebSocketClient.new("#{config.server}/api/v4/websocket", config.token)
15
+
16
+ me = @client.get_me().body
17
+ @me = Lita::User.create(me['id'], { name: me['username'] })
18
+ end
19
+
20
+ def run
21
+ # Make variables available in event handlers
22
+ saved_robot = robot
23
+ me = @me
24
+
25
+ @ws_client.on :open do
26
+ saved_robot.trigger(:connected)
27
+ end
28
+
29
+ @ws_client.on :message do |message|
30
+ # Receive message events
31
+ if message['event'] == 'posted'
32
+ data = message['data']
33
+ post = JSON.parse(data['post'])
34
+
35
+ user = Lita::User.create(post['user_id'], { name: data['sender_name'] })
36
+
37
+ # Ignore own messages
38
+ if user.id != me.id
39
+ private_message = data['channel_type'] == 'D'
40
+ source = Lita::Source.new(user: user, room: post['channel_id'], private_message: private_message)
41
+ message = Lita::Message.new(saved_robot, post['message'], source)
42
+ if private_message
43
+ message.command!
44
+ end
45
+ saved_robot.receive(message)
46
+ end
47
+ end
48
+ end
49
+
50
+ sleep
51
+ end
52
+
53
+ def send_messages(target, messages)
54
+ channel = target.room
55
+ if channel.nil?
56
+ user = target.user.id
57
+ channel = @client.create_direct_channel(@me.id, user).body['id']
58
+ end
59
+
60
+ messages.each do |message|
61
+ @client.create_post({ channel_id: channel, message: message })
62
+ end
63
+ end
64
+
65
+ def shut_down
66
+ @ws_client.close
67
+ end
68
+
69
+ def join(room_id)
70
+ @client.add_user_to_channel(room_id, @me.id)
71
+ end
72
+
73
+ def part(room_id)
74
+ @client.remove_user_from_channel(room_id, @me.id)
75
+ end
76
+
77
+ Lita.register_adapter(:mattermost, self)
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,25 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-mattermost"
3
+ spec.version = "0.2.0"
4
+ spec.authors = ["Maria Karamina"]
5
+ spec.email = ["maria.karamina@avlos.ai"]
6
+ spec.description = "Lita adapter for Mattermost"
7
+ spec.summary = "An adapter to use the Lita bot in Mattermost"
8
+ spec.homepage = "https://github.com/avlos/lita-mattermost/"
9
+ spec.license = "MIT"
10
+ spec.metadata = { "lita_plugin_type" => "adapter" }
11
+
12
+ spec.files = `git ls-files`.split($/)
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_runtime_dependency "lita", ">= 4.8"
18
+ spec.add_runtime_dependency "mattermost-api4-ruby", "~> 0.0.10"
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "pry-byebug"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rack-test"
24
+ spec.add_development_dependency "rspec", ">= 3.0.0"
25
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,4 @@
1
+ en:
2
+ lita:
3
+ adapters:
4
+ mattermost:
data/renovate.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
+ "extends": [
4
+ "config:base"
5
+ ]
6
+ }
@@ -0,0 +1,4 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Adapters::Mattermost, lita: true do
4
+ end
@@ -0,0 +1,6 @@
1
+ require "lita-mattermost"
2
+ require "lita/rspec"
3
+
4
+ # A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
5
+ # was generated with Lita 4, the compatibility mode should be left disabled.
6
+ Lita.version_3_compatibility_mode = false
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-mattermost
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Maria Karamina
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-05-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mattermost-api4-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.10
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.10
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack-test
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 3.0.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 3.0.0
111
+ description: Lita adapter for Mattermost
112
+ email:
113
+ - maria.karamina@avlos.ai
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - Gemfile
120
+ - README.md
121
+ - Rakefile
122
+ - lib/lita-mattermost.rb
123
+ - lib/lita/adapters/mattermost.rb
124
+ - lita-mattermost.gemspec
125
+ - locales/en.yml
126
+ - renovate.json
127
+ - spec/lita/adapters/mattermost_spec.rb
128
+ - spec/spec_helper.rb
129
+ homepage: https://github.com/avlos/lita-mattermost/
130
+ licenses:
131
+ - MIT
132
+ metadata:
133
+ lita_plugin_type: adapter
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubygems_version: 3.2.15
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: An adapter to use the Lita bot in Mattermost
153
+ test_files:
154
+ - spec/lita/adapters/mattermost_spec.rb
155
+ - spec/spec_helper.rb