ruboty-mastodon 0.1.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: 9237a602f5cd97d2f80244b4c7b248ffd28ebc10c52f5fb610437fbb4b690a51
4
+ data.tar.gz: 22d3cc27fc34626812994a947eab75c234442406bf97aeccd691f79b63d64515
5
+ SHA512:
6
+ metadata.gz: 310da1b6555189654dd4163050b61a5a4e8c10164f959553946e339d6cf6ba984a5d09471b436981d301a7fbe9d4a76a06ed111081cbaafbc922715b9e80dd6a
7
+ data.tar.gz: c8c521d92a27cfa067b886890f80e1630c9f4aa19423c0ce791a2036b623fb993dff13d39bd8f92683859ca8096495c1381d3375a889fbae0721e4b9e5e817f2
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .envrc
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.1
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-mastodon.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,84 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ruboty-mastodon (0.1.0)
5
+ lru_redux
6
+ mastodon-api
7
+ ruboty
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (5.2.3)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 0.7, < 2)
15
+ minitest (~> 5.1)
16
+ tzinfo (~> 1.1)
17
+ addressable (2.6.0)
18
+ public_suffix (>= 2.0.2, < 4.0)
19
+ buftok (0.2.0)
20
+ concurrent-ruby (1.1.5)
21
+ diff-lcs (1.3)
22
+ domain_name (0.5.20180417)
23
+ unf (>= 0.0.5, < 1.0.0)
24
+ dotenv (2.7.2)
25
+ http (3.3.0)
26
+ addressable (~> 2.3)
27
+ http-cookie (~> 1.0)
28
+ http-form_data (~> 2.0)
29
+ http_parser.rb (~> 0.6.0)
30
+ http-cookie (1.0.3)
31
+ domain_name (~> 0.5)
32
+ http-form_data (2.1.1)
33
+ http_parser.rb (0.6.0)
34
+ i18n (1.6.0)
35
+ concurrent-ruby (~> 1.0)
36
+ lru_redux (1.1.0)
37
+ mastodon-api (2.0.0)
38
+ addressable (~> 2.6)
39
+ buftok (~> 0)
40
+ http (~> 3.3)
41
+ oj (~> 3.7)
42
+ mem (0.1.5)
43
+ minitest (5.11.3)
44
+ oj (3.7.12)
45
+ public_suffix (3.0.3)
46
+ rake (10.5.0)
47
+ rspec (3.8.0)
48
+ rspec-core (~> 3.8.0)
49
+ rspec-expectations (~> 3.8.0)
50
+ rspec-mocks (~> 3.8.0)
51
+ rspec-core (3.8.0)
52
+ rspec-support (~> 3.8.0)
53
+ rspec-expectations (3.8.3)
54
+ diff-lcs (>= 1.2.0, < 2.0)
55
+ rspec-support (~> 3.8.0)
56
+ rspec-mocks (3.8.0)
57
+ diff-lcs (>= 1.2.0, < 2.0)
58
+ rspec-support (~> 3.8.0)
59
+ rspec-support (3.8.0)
60
+ ruboty (1.3.0)
61
+ activesupport
62
+ bundler
63
+ dotenv
64
+ mem
65
+ slop
66
+ slop (4.6.2)
67
+ thread_safe (0.3.6)
68
+ tzinfo (1.2.5)
69
+ thread_safe (~> 0.1)
70
+ unf (0.1.4)
71
+ unf_ext
72
+ unf_ext (0.0.7.6)
73
+
74
+ PLATFORMS
75
+ ruby
76
+
77
+ DEPENDENCIES
78
+ bundler (~> 2.0)
79
+ rake (~> 10.0)
80
+ rspec (~> 3.0)
81
+ ruboty-mastodon!
82
+
83
+ BUNDLED WITH
84
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Sho Kusano
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Ruboty::Mastodon
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ruboty/mastodon`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ruboty-mastodon'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ruboty-mastodon
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rosylilly/ruboty-mastodon.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'ruboty/mastodon'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,102 @@
1
+ require 'lru_redux'
2
+ require 'mastodon'
3
+ require 'json'
4
+
5
+ module Ruboty
6
+ module Adapters
7
+ class Mastodon < Base
8
+ env :MASTODON_BASE_URL, 'Base URL of your mastodon server'
9
+ env :MASTODON_BEARER_TOKEN, 'API token of your mastodon account'
10
+ env :MASTODON_IGNORE_BOT_MESSAGE, 'Ignroe bot user message', optional: true
11
+
12
+ def run
13
+ init
14
+ connect
15
+ end
16
+
17
+ def say(message)
18
+ rest_client.create_status(message[:body])
19
+ end
20
+
21
+ protected
22
+
23
+ def init
24
+ cache.clear
25
+ account = rest_client.verify_credentials
26
+
27
+ ENV['RUBOTY_NAME'] ||= account.username
28
+ end
29
+
30
+ def connect
31
+ Thread.new do
32
+ loop do
33
+ begin
34
+ streaming_client.stream('public/local') do |data|
35
+ receive(data)
36
+ end
37
+ rescue => e
38
+ Ruboty.logger.error(e)
39
+ end
40
+ sleep 10
41
+ end
42
+ end
43
+
44
+ loop do
45
+ begin
46
+ streaming_client.user do |data|
47
+ receive(data)
48
+ end
49
+ rescue => e
50
+ Ruboty.logger.error(e)
51
+ end
52
+ sleep 10
53
+ end
54
+ end
55
+
56
+ def receive(data)
57
+ case data
58
+ when ::Mastodon::Notification
59
+ on_status(data.status) if data.type == 'mention'
60
+ when ::Mastodon::Status
61
+ on_status(data)
62
+ end
63
+ end
64
+
65
+ def on_status(status)
66
+ return if cache[status.id]
67
+
68
+ cache[status.id] = 1
69
+
70
+ return if status.account.bot? && ENV['MASTODON_IGNORE_BOT_MESSAGE']
71
+
72
+ message = {
73
+ body: status.content.gsub(/<.+?>/, ''),
74
+ from: status.account.acct,
75
+ status: status,
76
+ account: status.account
77
+ }
78
+ Ruboty.logger.debug(status)
79
+
80
+ robot.receive(message)
81
+ end
82
+
83
+ def rest_client
84
+ @rest_client ||= ::Mastodon::REST::Client.new(
85
+ base_url: ENV['MASTODON_BASE_URL'],
86
+ bearer_token: ENV['MASTODON_BEARER_TOKEN']
87
+ )
88
+ end
89
+
90
+ def streaming_client
91
+ @streaming_client ||= ::Mastodon::Streaming::Client.new(
92
+ base_url: ENV['MASTODON_BASE_URL'],
93
+ bearer_token: ENV['MASTODON_BEARER_TOKEN']
94
+ )
95
+ end
96
+
97
+ def cache
98
+ @cache ||= LruRedux::Cache.new(20)
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module Mastodon
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require 'ruboty/mastodon/version'
2
+ require 'ruboty/adapters/mastodon'
@@ -0,0 +1,30 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'ruboty/mastodon/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'ruboty-mastodon'
7
+ spec.version = Ruboty::Mastodon::VERSION
8
+ spec.authors = ['Sho Kusano']
9
+ spec.email = ['rosylilly@aduca.org']
10
+
11
+ spec.summary = 'Mastodon adapter for ruboty'
12
+ spec.description = spec.summary
13
+ spec.homepage = 'https://github.com/rosylilly/ruboty-mastodon'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
18
+ end
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'bundler', '~> 2.0'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.0'
26
+
27
+ spec.add_dependency 'lru_redux'
28
+ spec.add_dependency 'mastodon-api'
29
+ spec.add_dependency 'ruboty'
30
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-mastodon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sho Kusano
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: lru_redux
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
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: mastodon-api
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
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: ruboty
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Mastodon adapter for ruboty
98
+ email:
99
+ - rosylilly@aduca.org
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/ruboty/adapters/mastodon.rb
115
+ - lib/ruboty/mastodon.rb
116
+ - lib/ruboty/mastodon/version.rb
117
+ - ruboty-mastodon.gemspec
118
+ homepage: https://github.com/rosylilly/ruboty-mastodon
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubygems_version: 3.0.2
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Mastodon adapter for ruboty
141
+ test_files: []