Skip to content

Commit

Permalink
Merge pull request #1 from kenchiki/development
Browse files Browse the repository at this point in the history
3.5.0に対応
  • Loading branch information
kenchiki authored Jul 12, 2023
2 parents bee56b7 + 06c1016 commit c72aeaf
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 50 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# MastodonCommand
- おみくじ機能や大阪弁機能などをつけることができます。
- ローカルでマストドンのバージョン3.4.6にて動作を確認済み
- ローカルでマストドンのバージョン3.5.0にて動作を確認済み
(このプログラムを使って問題が起こっても保証はできないので予めご了承ください🙇‍♂️)

## Installation

```ruby
gem 'mastodon_command', '0.1.9'
gem 'mastodon_command', '0.1.10'
```

## Usage
Expand All @@ -21,11 +21,11 @@ Rails.application.configure do
config.after_initialize do
MastodonCommand.setup do |status|
# おみくじ機能
fortune = MastodonCommand::Random.new('[  \n]?#(おみくじ|占い|運勢)[  \n]?', %w(大吉 中吉 小吉 吉 半吉 凶 大凶))
fortune = MastodonCommand::RandomConverter.new('[  \n]?#(おみくじ|占い|運勢)[  \n]?', %w(大吉 中吉 小吉 吉 半吉 凶 大凶))
status = fortune.convert(status) if fortune.match(status)

# 大阪弁機能
osaka = MastodonCommand::Lang.new('[  \n]?#(大阪弁)[  \n]?', [
osaka = MastodonCommand::LangConverter.new('[  \n]?#(大阪弁)[  \n]?', [
{
pattern: 'です',
replace: 'やで'
Expand Down
23 changes: 6 additions & 17 deletions lib/mastodon_command.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
require "mastodon_command/version"
require "mastodon_command/convert"
require "mastodon_command/convert_random"
require "mastodon_command/convert_lang"
require "mastodon_command/statuses_controller_patch"
require 'mastodon_command/version'
require 'mastodon_command/converter'
require 'mastodon_command/random_converter'
require 'mastodon_command/lang_converter'
require 'mastodon_command/statuses_controller_patch'

module MastodonCommand
def self.setup(&proc)
# create function for Monkey patch
extend self
(
class << self;
self
end).module_eval do
define_method 'convert_toot', &proc
# define_method 'b' do
# p 'b'
# end
end
define_singleton_method(:convert_toot, &proc)

# Monkey patch
Api::V1::StatusesController.prepend(MastodonCommand::StatusesControllerPatch)
end
end

8 changes: 0 additions & 8 deletions lib/mastodon_command/convert_random.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module MastodonCommand
class Convert
attr_accessor :pattern
attr_accessor :replaces
class Converter
attr_accessor :pattern, :replaces

def initialize(pattern, replaces)
@pattern = pattern
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
module MastodonCommand
class Lang < MastodonCommand::Convert

class LangConverter < MastodonCommand::Converter
def convert(input)
@replaces.each {|replace|
@replaces.each do |replace|
input = input.gsub(/#{replace[:pattern]}/, replace[:replace])
}
end
input
end
end
Expand Down
7 changes: 7 additions & 0 deletions lib/mastodon_command/random_converter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module MastodonCommand
class RandomConverter < MastodonCommand::Converter
def convert(input)
"#{input}\nあなたの運勢は「#{@replaces.sample}」です"
end
end
end
29 changes: 16 additions & 13 deletions lib/mastodon_command/statuses_controller_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ module MastodonCommand
module StatusesControllerPatch
def create
status = MastodonCommand.convert_toot(status_params[:status])
@status = PostStatusService.new.call(current_user.account,
text: status,
thread: @thread,
media_ids: status_params[:media_ids],
sensitive: status_params[:sensitive],
spoiler_text: status_params[:spoiler_text],
visibility: status_params[:visibility],
scheduled_at: status_params[:scheduled_at],
application: doorkeeper_token.application,
poll: status_params[:poll],
idempotency: request.headers['Idempotency-Key'],
with_rate_limit: true)

@status = PostStatusService.new.call(
current_user.account,
text: status,
thread: @thread,
media_ids: status_params[:media_ids],
sensitive: status_params[:sensitive],
spoiler_text: status_params[:spoiler_text],
visibility: status_params[:visibility],
language: status_params[:language],
scheduled_at: status_params[:scheduled_at],
application: doorkeeper_token.application,
poll: status_params[:poll],
idempotency: request.headers['Idempotency-Key'],
with_rate_limit: true
)

render json: @status, serializer: @status.is_a?(ScheduledStatus) ? REST::ScheduledStatusSerializer : REST::StatusSerializer
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mastodon_command/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module MastodonCommand
VERSION = "0.1.9"
VERSION = '0.1.10'.freeze
end

0 comments on commit c72aeaf

Please sign in to comment.