Skip to content

Commit

Permalink
3.5.0に対応
Browse files Browse the repository at this point in the history
  • Loading branch information
kenchiki committed Jul 12, 2023
1 parent bee56b7 commit 79dab78
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 46 deletions.
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"
end

0 comments on commit 79dab78

Please sign in to comment.