Skip to content

Commit

Permalink
Merge pull request #3593 from pooza/4_30_4
Browse files Browse the repository at this point in the history
4.30.4
  • Loading branch information
pooza committed Dec 1, 2023
2 parents 6912c8c + afd8544 commit 35281ec
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 46 deletions.
8 changes: 4 additions & 4 deletions Gemfile.lock
Expand Up @@ -192,7 +192,7 @@ GEM
multi_xml (>= 0.5.2)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
json (2.6.3)
json (2.7.0)
json-schema (4.1.1)
addressable (>= 2.8)
jwt (2.7.1)
Expand Down Expand Up @@ -220,7 +220,7 @@ GEM
mustermann (3.0.0)
ruby2_keywords (~> 0.0.1)
mutex_m (0.2.0)
net-imap (0.4.6)
net-imap (0.4.7)
date
net-protocol
net-pop (0.1.2)
Expand All @@ -230,7 +230,7 @@ GEM
net-smtp (0.4.0)
net-protocol
netrc (0.11.0)
nio4r (2.6.1)
nio4r (2.7.0)
nokogiri (1.15.5)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
Expand Down Expand Up @@ -421,4 +421,4 @@ RUBY VERSION
ruby 3.2.2p53

BUNDLED WITH
2.4.20
2.4.22
15 changes: 15 additions & 0 deletions app/lib/mulukhiya/handler/mfmize_handler.rb
@@ -0,0 +1,15 @@
module Mulukhiya
class MfmizeHandler < Handler
def disable?
return true unless Environment.note?
return super
end

def handle_pre_toot(payload, params = {})
self.payload = payload
parser.text = payload[text_field] = parser.mfmize
rescue => e
errors.push(class: e.class.to_s, message: e.message, status: @status)
end
end
end
4 changes: 0 additions & 4 deletions app/lib/mulukhiya/nowplaying_handler.rb
Expand Up @@ -86,10 +86,6 @@ def artist_prefix
end

def push(line)
if Environment.note?
uri = Ginseng::URI.parse(line) rescue nil
line = "[#{uri.host}](#{uri})" if uri&.absolute? && uri.scheme.start_with?('http')
end
line.chomp!
key = rand.to_s if line.empty?
key ||= [line, @recent_keyword].join("\n").sha256
Expand Down
15 changes: 15 additions & 0 deletions app/lib/mulukhiya/parser/note_parser.rb
Expand Up @@ -33,5 +33,20 @@ def default_max_length
e.log(text:)
return service.max_post_text_length
end

def mfmize
temp = text.dup
matches = text.scan(/\[.*?\]\(.*?\)/)
matches.each_with_index do |match, i|
temp.gsub!(match, "____#{i}____")
end
uris.select {|v| v.to_s.start_with?('http')}.each do |uri|
temp.gsub!(uri.to_s, "[#{uri.host}](#{uri})")
end
matches.each_with_index do |match, i|
temp.gsub!("____#{i}____", match)
end
return temp
end
end
end
13 changes: 7 additions & 6 deletions app/lib/mulukhiya/service/annict_service.rb
Expand Up @@ -167,13 +167,14 @@ def oauth_uri

def self.create_viewer_info(viewer)
viewer = viewer.clone.deep_symbolize_keys
return viewer.compact.merge(
id: viewer[:annictId],
avatar_uri: Ginseng::URI.parse(viewer[:avatarUrl]),
works: viewer.dig(:works, :nodes)
viewer[:id] = viewer[:annictId]
viewer[:avatar_uri] = Ginseng::URI.parse(viewer[:avatarUrl]) if viewer[:avatar_uri]
if nodes = viewer.dig(:works, :nodes)
viewer[:works] = nodes
.select {|node| node[:viewerStatusState] == 'WATCHING'}
.map {|node| create_work_info(node)},
)
.map {|node| create_work_info(node)}
end
return viewer
end

def self.create_work_info(work)
Expand Down
9 changes: 0 additions & 9 deletions app/query/annict/account.graphql.erb
Expand Up @@ -4,14 +4,5 @@
name
username
avatarUrl
works {
nodes {
annictId
title
seasonYear
officialSiteUrl
viewerStatusState
}
}
}
}
9 changes: 0 additions & 9 deletions app/query/annict/activity.graphql.erb
Expand Up @@ -4,15 +4,6 @@
name
username
avatarUrl
works {
nodes {
annictId
title
seasonYear
officialSiteUrl
viewerStatusState
}
}
activities(orderBy: { field: CREATED_AT, direction: DESC }, first: 50) {
edges {
node {
Expand Down
20 changes: 9 additions & 11 deletions config/application.yaml
Expand Up @@ -154,6 +154,9 @@ handler:
audio: audio
image: image
video: video
mfmize:
disable: true
experimental: true
peer_tube_url_nowplaying:
tagging: false
timeout: 10
Expand Down Expand Up @@ -484,8 +487,7 @@ meisskey:
- shortened_url
- url_normalize
- canonical_url
- itunes_url
- amazon_url
- mfmize
- itunes_url_nowplaying
- spotify_url_nowplaying
- you_tube_url_nowplaying
Expand All @@ -506,8 +508,7 @@ meisskey:
- shortened_url
- url_normalize
- canonical_url
- itunes_url
- amazon_url
- mfmize
- itunes_url_nowplaying
- spotify_url_nowplaying
- you_tube_url_nowplaying
Expand Down Expand Up @@ -537,8 +538,7 @@ meisskey:
- shortened_url
- url_normalize
- canonical_url
- itunes_url
- amazon_url
- mfmize
- itunes_url_nowplaying
- spotify_url_nowplaying
- you_tube_url_nowplaying
Expand Down Expand Up @@ -656,8 +656,7 @@ misskey:
- shortened_url
- url_normalize
- canonical_url
- itunes_url
- amazon_url
- mfmize
- itunes_url_nowplaying
- spotify_url_nowplaying
- you_tube_url_nowplaying
Expand Down Expand Up @@ -687,8 +686,7 @@ misskey:
- shortened_url
- url_normalize
- canonical_url
- itunes_url
- amazon_url
- mfmize
- itunes_url_nowplaying
- spotify_url_nowplaying
- you_tube_url_nowplaying
Expand Down Expand Up @@ -814,7 +812,7 @@ package:
- tkoishi@b-shock.co.jp
license: MIT
url: https://github.com/pooza/mulukhiya-toot-proxy
version: 4.30.3
version: 4.30.4
parser:
note:
fields:
Expand Down
2 changes: 1 addition & 1 deletion test/annict_service.rb
Expand Up @@ -21,7 +21,7 @@ def test_account
assert_predicate(@service.account[:id], :positive?)
assert_predicate(@service.account[:name], :present?)
assert_predicate(@service.account[:username], :present?)
assert_kind_of(Ginseng::URI, @service.account[:avatar_uri])
assert_kind_of(Ginseng::URI, @service.account[:avatar_uri]) if @service.account[:avatar_uri]
end

def test_works
Expand Down
11 changes: 9 additions & 2 deletions test/note_parser.rb
Expand Up @@ -6,11 +6,18 @@ def disable?
end

def setup
@parser = NoteParser.new('さぁデリシャススマイル・フルパワーで')
end

def test_default_max_length
assert_kind_of(Integer, @parser.default_max_length)
parser = NoteParser.new('さぁデリシャススマイル・フルパワーで')

assert_kind_of(Integer, parser.default_max_length)
end

def test_mfmize
parser = NoteParser.new('[YouTube](https://www.youtube.com) and [Google](https://google.com) https://www.amazon.co.jp')

assert_equal('[YouTube](https://www.youtube.com) and [Google](https://google.com) [www.amazon.co.jp](https://www.amazon.co.jp)', parser.mfmize)
end
end
end
1 change: 1 addition & 0 deletions views/reaction.md.erb
@@ -1,4 +1,5 @@
<%= params[:receipt].acct %>
リアクション <%= params.dig(:payload, :reaction) %> を送りました。

powered by
[<%= package_class.name %>](<%= package_class.url %>) <%= package_class.version %>

0 comments on commit 35281ec

Please sign in to comment.