1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# -*- coding: utf-8 -*-
module ::Plugin::Command
class << self
def [](condition, *other)
if other.empty?
const_get(condition.to_sym)
else
const_get(condition.to_sym) & self[*other] end end
end
class Condition
def initialize
@cond = Proc.new
type_strict @cond => :call end
def &(follow)
type_strict follow => :call
Condition.new{ |opt| call(opt) && follow.call(opt) } end
def |(follow)
type_strict follow => :call
Condition.new{ |opt| call(opt) || follow.call(opt) } end
def call(opt)
@cond.call(opt) end
alias === call
alias [] call
end
# ==== timeline ロールの条件
# 一つでもMessageが選択されている
HasMessage = Condition.new{ |opt| not opt.messages.empty? }
# 一つだけMessageが選択されている
HasOneMessage = Condition.new{ |opt| opt.messages.size == 1 }
# 選択されているツイートが全てリプライ可能な時。
# ツイートが選択されていなければ偽
CanReplyAll = Condition.new{ |opt|
if not opt.messages.empty?
current_world, = Plugin.filtering(:world_current, nil)
current_world & opt.messages =~ :postable?
end
}
# 選択されているツイートのうち、一つでも現在のアカウントでリツイートできるものがあれば真を返す
CanReTweetAny = Condition.new { |opt|
current_world, = Plugin.filtering(:world_current, nil)
opt.messages.lazy.any?{|m|
Plugin[:command].retweet?(current_world, m) && !Plugin[:command].retweeted?(current_world, m)
}
}
# 選択されているツイートが全て、現在のアカウントでリツイート可能な時、真を返す。
# 既にリツイート済みのものはリツイート不可とみなす。
# ツイートが選択されていなければ偽
CanReTweetAll = Condition.new{ |opt|
current_world, = Plugin.filtering(:world_current, nil)
!opt.messages.empty? && opt.messages.lazy.all?{|m|
Plugin[:command].retweet?(current_world, m) && !Plugin[:command].retweeted?(current_world, m)
}
}
# 選択されているツイートを、現在のアカウントで全てリツイートしている場合。
# ツイートが選択されていなければ偽
IsReTweetedAll = Condition.new{ |opt|
current_world, = Plugin.filtering(:world_current, nil)
!opt.messages.empty? && opt.messages.lazy.all?{|m|
Plugin[:command].destroy_retweet?(current_world, m)
}
}
# 選択されているツイートのうち、一つでも現在のアカウントでふぁぼれるものがあれば真を返す
CanFavoriteAny = Condition.new { |opt|
current_world, = Plugin.filtering(:world_current, nil)
opt.messages.any?{|m|
Plugin[:command].favorite?(current_world, m) && !Plugin[:command].favorited?(current_world, m)
}
}
# 選択されているツイートが全て、現在のアカウントでお気に入りに追加可能な時、真を返す。
# 既にお気に入りに追加済みのものはお気に入りに追加不可とみなす。
# ツイートが選択されていなければ偽
CanFavoriteAll = Condition.new{ |opt|
current_world, = Plugin.filtering(:world_current, nil)
!opt.messages.empty? and opt.messages.all?{|m|
Plugin[:command].favorite?(current_world, m)
}
}
# 選択されているツイートを、現在のアカウントで全てお気に入りに追加している場合。
# ツイートが選択されていなければ偽
IsFavoritedAll = Condition.new{ |opt|
current_world, = Plugin.filtering(:world_current, nil)
!opt.messages.empty? and opt.messages.all?{|m|
Plugin[:command].unfavorite?(current_world, m)
}
}
# 選択しているのが全て自分のツイートの時
IsMyMessageAll = Condition.new{ |opt|
current_world, = Plugin.filtering(:world_current, nil)
not opt.messages.empty? and opt.messages.all?{|m| m | current_world =~ :from_me? }
}
# TL上のテキストが一文字でも選択されている
TimelineTextSelected = Condition.new{ |opt| opt.widget.selected_text(opt.messages.first) }
HasParmaLinkAll = Condition.new{ |opt|
not opt.messages.empty? and opt.messages.all? { |m| m.perma_link } }
# ==== postbox ロール
# 編集可能状態(入力中:グレーアウトしてない時)
Editable = Condition.new{ |opt| opt.widget.editable? }
end
|