mastodon_command 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +86 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/mastodon_command/convert.rb +19 -0
- data/lib/mastodon_command/convert_lang.rb +11 -0
- data/lib/mastodon_command/convert_random.rb +8 -0
- data/lib/mastodon_command/statuses_controller.rb +24 -0
- data/lib/mastodon_command/version.rb +3 -0
- data/lib/mastodon_command.rb +23 -0
- data/mastodon_command.gemspec +35 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6f2d03246916f0f0c9284b80fb3528006f3684db
|
4
|
+
data.tar.gz: c08b4a4cae3bbb351100ee55292e862a35678b19
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3fb8f98ea028114b70658d59b0676b60cd19e05c0c84b3ccfde2257fbbe7edace5dc925c36d3a82046b8cd1f5fa6be3ce913ae9070a0797077904dbe37d55851
|
7
|
+
data.tar.gz: 4ec386b988df20d77970c4bfd533a28f820e92af40bbca3a8fdc828169568da72c01cca12a56285544def25ef2f5da6893815f13dccfcdaeea857956c1cea934
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# MastodonCommand
|
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/mastodon_command`. 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 'mastodon_command'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install mastodon_command
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
- Make initializers file
|
26
|
+
config\initializers\mastodon_command.rb
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
MastodonCommand.setup do |status|
|
30
|
+
# おみくじ機能
|
31
|
+
fortune = MastodonCommand::Random.new('[ \n]?#(おみくじ|占い|運勢)[ \n]?', %w(大吉 中吉 小吉 吉 半吉 凶 大凶))
|
32
|
+
status = fortune.convert(status) if fortune.match(status)
|
33
|
+
|
34
|
+
# 大阪弁機能
|
35
|
+
osaka = MastodonCommand::Lang.new('[ \n]?#(大阪弁)[ \n]?', [
|
36
|
+
{
|
37
|
+
pattern: 'です',
|
38
|
+
replace: 'やで'
|
39
|
+
},
|
40
|
+
{
|
41
|
+
pattern: 'する',
|
42
|
+
replace: 'しよる'
|
43
|
+
},
|
44
|
+
{
|
45
|
+
pattern: 'だった',
|
46
|
+
replace: 'やった'
|
47
|
+
},
|
48
|
+
{
|
49
|
+
pattern: 'すごい',
|
50
|
+
replace: 'えらい'
|
51
|
+
},
|
52
|
+
{
|
53
|
+
pattern: '疲れた',
|
54
|
+
replace: 'しんどい'
|
55
|
+
},
|
56
|
+
{
|
57
|
+
pattern: 'ない',
|
58
|
+
replace: 'あれへん'
|
59
|
+
},
|
60
|
+
{
|
61
|
+
pattern: '(バカ|ばか)',
|
62
|
+
replace: 'アホ'
|
63
|
+
},
|
64
|
+
|
65
|
+
])
|
66
|
+
status = osaka.convert(status) if osaka.match(status)
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
- toot by mastodon
|
71
|
+
|
72
|
+
```text
|
73
|
+
すごい疲れた:joy:
|
74
|
+
#おみくじ
|
75
|
+
#大阪弁
|
76
|
+
```
|
77
|
+
|
78
|
+
## Development
|
79
|
+
|
80
|
+
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.
|
81
|
+
|
82
|
+
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).
|
83
|
+
|
84
|
+
## Contributing
|
85
|
+
|
86
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mastodon_command.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "mastodon_command"
|
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,19 @@
|
|
1
|
+
module MastodonCommand
|
2
|
+
class Convert
|
3
|
+
attr_accessor :pattern
|
4
|
+
attr_accessor :replaces
|
5
|
+
|
6
|
+
def initialize(pattern, replaces)
|
7
|
+
@pattern = pattern
|
8
|
+
@replaces = replaces
|
9
|
+
end
|
10
|
+
|
11
|
+
def match(input)
|
12
|
+
input.match(@pattern)
|
13
|
+
end
|
14
|
+
|
15
|
+
def convert(input)
|
16
|
+
input
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# モンキーパッチ
|
2
|
+
class Api::V1::StatusesController < Api::BaseController
|
3
|
+
|
4
|
+
def create
|
5
|
+
status = MastodonCommand.convert_toot(status_params[:status])
|
6
|
+
@status = PostStatusService.new.call(current_user.account,
|
7
|
+
status,
|
8
|
+
status_params[:in_reply_to_id].blank? ? nil : Status.find(status_params[:in_reply_to_id]),
|
9
|
+
media_ids: status_params[:media_ids],
|
10
|
+
sensitive: status_params[:sensitive],
|
11
|
+
spoiler_text: status_params[:spoiler_text],
|
12
|
+
visibility: status_params[:visibility],
|
13
|
+
application: doorkeeper_token.application,
|
14
|
+
idempotency: request.headers['Idempotency-Key'])
|
15
|
+
|
16
|
+
render :show
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
# 使用されているprivateメソッドも入れておかないとモンキーパッチが動かなかった
|
21
|
+
def status_params
|
22
|
+
params.permit(:status, :in_reply_to_id, :sensitive, :spoiler_text, :visibility, media_ids: [])
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "mastodon_command/version"
|
2
|
+
require "mastodon_command/convert"
|
3
|
+
require "mastodon_command/convert_random"
|
4
|
+
require "mastodon_command/convert_lang"
|
5
|
+
|
6
|
+
module MastodonCommand
|
7
|
+
def self.setup(&proc)
|
8
|
+
# create function for Monkey patch
|
9
|
+
extend self
|
10
|
+
(
|
11
|
+
class << self;
|
12
|
+
self
|
13
|
+
end).module_eval do
|
14
|
+
define_method 'convert_toot', &proc
|
15
|
+
# define_method 'b' do
|
16
|
+
# p 'b'
|
17
|
+
# end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Monkey patch
|
21
|
+
require "mastodon_command/statuses_controller"
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "mastodon_command/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mastodon_command"
|
8
|
+
spec.version = MastodonCommand::VERSION
|
9
|
+
spec.authors = ["kenchiki"]
|
10
|
+
spec.email = ["nagai-kj@nagai-galaxy.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Mastodon Toot Command.}
|
13
|
+
spec.description = %q{Mastodon Toot Command.}
|
14
|
+
spec.homepage = "http://nagai-galaxy.com/"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
"public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mastodon_command
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kenchiki
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-08 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: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
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
|
+
description: Mastodon Toot Command.
|
56
|
+
email:
|
57
|
+
- nagai-kj@nagai-galaxy.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- lib/mastodon_command.rb
|
71
|
+
- lib/mastodon_command/convert.rb
|
72
|
+
- lib/mastodon_command/convert_lang.rb
|
73
|
+
- lib/mastodon_command/convert_random.rb
|
74
|
+
- lib/mastodon_command/statuses_controller.rb
|
75
|
+
- lib/mastodon_command/version.rb
|
76
|
+
- mastodon_command.gemspec
|
77
|
+
homepage: http://nagai-galaxy.com/
|
78
|
+
licenses: []
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.6.11
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Mastodon Toot Command.
|
100
|
+
test_files: []
|