Debian Codegraph @

plugin/command/conditions.rb

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 module ::Plugin::Command
3 class << self
4 extend Gem::Deprecate
5
6 # [in 3.9.0] このメソッドはDeprecateです。
7 # [see] https://dev.mikutter.hachune.net/issues/1200
8 def [](condition, *other)
9 if other.empty?
10 const_get(condition.to_sym)
11 else
12 const_get(condition.to_sym) & self[*other] end end
13 deprecate :[], :none, 2020, 01
14 end
15
16 # [in 3.9.0] この定数はDeprecateです。
17 # [see] https://dev.mikutter.hachune.net/issues/1200
18 class Condition
19 def initialize(&block)
20 @cond = block
21 type_strict @cond => :call
22 end
23
24 def &(follow)
25 type_strict follow => :call
26 Condition.new{ |opt| call(opt) && follow.call(opt) } end
27
28 def |(follow)
29 type_strict follow => :call
30 Condition.new{ |opt| call(opt) || follow.call(opt) } end
31
32 def call(opt)
33 @cond.call(opt) end
34 alias === call
35 alias [] call
36 end
37
38 # ==== timeline ロールの条件
39
40 # 一つでもMessageが選択されている
41 HasMessage = Condition.new{ |opt| not opt.messages.empty? }
42 deprecate_constant :HasMessage
43
44 # 一つだけMessageが選択されている
45 # [in 3.9.0] この定数はDeprecateです。代わりに、condition:には以下のコードを使ってください。
46 # ->opt{ opt.messages.size == 1 }
47 HasOneMessage = Condition.new{ |opt| opt.messages.size == 1 }
48 deprecate_constant :HasOneMessage
49
50 # 選択されているツイートが全てリプライ可能な時。
51 # ツイートが選択されていなければ偽
52 # [in 3.9.0] この定数はDeprecateです。代わりに、condition:には以下のコードを使ってください。
53 # ->opt{ !opt.messages.empty? && compose?(opt.world, to: opt.messages) }
54 CanReplyAll = Condition.new{ |opt|
55 if not opt.messages.empty?
56 current_world, = Plugin.filtering(:world_current, nil)
57 Plugin[:command].compose?(current_world, to: opt.messages)
58 end
59 }
60 deprecate_constant :CanReplyAll
61
62 # 選択されているツイートのうち、一つでも現在のアカウントでリツイートできるものがあれば真を返す
63 # [in 3.9.0] この定数はDeprecateです。代わりに、condition:には以下のコードを使ってください。
64 # ->opt{ opt.messages.any?{|m| share?(opt.world, m) && !shared?(opt.world, m) } }
65 CanReTweetAny = Condition.new { |opt|
66 current_world, = Plugin.filtering(:world_current, nil)
67 opt.messages.lazy.any?{|m|
68 Plugin[:command].share?(current_world, m) && !Plugin[:command].shared?(current_world, m)
69 }
70 }
71 deprecate_constant :CanReTweetAny
72
73 # 選択されているツイートが全て、現在のアカウントでリツイート可能な時、真を返す。
74 # 既にリツイート済みのものはリツイート不可とみなす。
75 # ツイートが選択されていなければ偽
76 CanReTweetAll = Condition.new{ |opt|
77 current_world, = Plugin.filtering(:world_current, nil)
78 !opt.messages.empty? && opt.messages.lazy.all?{|m|
79 Plugin[:command].share?(current_world, m) && !Plugin[:command].shared?(current_world, m)
80 }
81 }
82 deprecate_constant :CanReTweetAll
83
84 # 選択されているツイートを、現在のアカウントで全てリツイートしている場合。
85 # ツイートが選択されていなければ偽
86 # [in 3.9.0] この定数はDeprecateです。代わりに、condition:には以下のコードを使ってください。
87 # ->opt{ !opt.messages.empty? && opt.messages.all?{|m| destroy_share?(opt.world, m) } }
88 IsReTweetedAll = Condition.new{ |opt|
89 current_world, = Plugin.filtering(:world_current, nil)
90 !opt.messages.empty? && opt.messages.lazy.all?{|m|
91 Plugin[:command].destroy_share?(current_world, m)
92 }
93 }
94 deprecate_constant :IsReTweetedAll
95
96 # 選択されているツイートのうち、一つでも現在のアカウントでふぁぼれるものがあれば真を返す
97 # [in 3.9.0] この定数はDeprecateです。代わりに、condition:には以下のコードを使ってください。
98 # ->opt{ opt.messages.any?{|m| favorite?(opt.world, m) && favorited?(opt.world, m) } }
99 CanFavoriteAny = Condition.new { |opt|
100 current_world, = Plugin.filtering(:world_current, nil)
101 opt.messages.any?{|m|
102 Plugin[:command].favorite?(current_world, m) && !Plugin[:command].favorited?(current_world, m)
103 }
104 }
105 deprecate_constant :CanFavoriteAny
106
107 # 選択されているツイートが全て、現在のアカウントでお気に入りに追加可能な時、真を返す。
108 # 既にお気に入りに追加済みのものはお気に入りに追加不可とみなす。
109 # ツイートが選択されていなければ偽
110 CanFavoriteAll = Condition.new{ |opt|
111 current_world, = Plugin.filtering(:world_current, nil)
112 !opt.messages.empty? and opt.messages.all?{|m|
113 Plugin[:command].favorite?(current_world, m)
114 }
115 }
116 deprecate_constant :CanFavoriteAll
117
118 # 選択されているツイートを、現在のアカウントで全てお気に入りに追加している場合。
119 # ツイートが選択されていなければ偽
120 # [in 3.9.0] この定数はDeprecateです。代わりに、condition:には以下のコードを使ってください。
121 # ->opt{ !opt.messages.empty? && opt.messages.all?{|m| Plugin[:command].unfavorite?(opt.world, m) } }
122 IsFavoritedAll = Condition.new{ |opt|
123 current_world, = Plugin.filtering(:world_current, nil)
124 !opt.messages.empty? and opt.messages.all?{|m|
125 Plugin[:command].unfavorite?(current_world, m)
126 }
127 }
128 deprecate_constant :IsFavoritedAll
129
130 # 選択しているのが全て自分のツイートの時
131 # [in 3.9.0] この定数はDeprecateです。代わりに、condition:には以下のコードを使ってください。
132 # ->opt{ !opt.messages.empty? && opt.messages.all?{|m| m.from_me?(opt.world) } }
133 IsMyMessageAll = Condition.new{ |opt|
134 current_world, = Plugin.filtering(:world_current, nil)
135 not opt.messages.empty? and opt.messages.all?{|m| m.from_me?(current_world) }
136 }
137 deprecate_constant :IsMyMessageAll
138
139 # TL上のテキストが一文字でも選択されている
140 # [in 3.9.0] この定数はDeprecateです。代わりに、condition:には以下のコードを使ってください。
141 # ->opt{ opt.widget.selected_text(opt.messages.first) }
142 TimelineTextSelected = Condition.new{ |opt| opt.widget.selected_text(opt.messages.first) }
143 deprecate_constant :TimelineTextSelected
144
145 HasParmaLinkAll = Condition.new{ |opt|
146 not opt.messages.empty? and opt.messages.all? { |m| m.perma_link } }
147 deprecate_constant :HasParmaLinkAll
148
149 # ==== postbox ロール
150
151 # 編集可能状態(入力中:グレーアウトしてない時)
152 # [in 3.9.0] この定数はDeprecateです。代わりに、condition:には以下のコードを使ってください。
153 # ->opt{ opt.widget.editable? }
154 Editable = Condition.new{ |opt| opt.widget.editable? }
155 deprecate_constant :Editable
156
157 deprecate_constant :Condition
158 end
159
160
161