File: conditions.rb

package info (click to toggle)
mikutter 5.0.4%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 9,700 kB
  • sloc: ruby: 21,307; sh: 181; makefile: 19
file content (161 lines) | stat: -rw-r--r-- 7,038 bytes parent folder | download | duplicates (3)
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# -*- coding: utf-8 -*-
module ::Plugin::Command
  class << self
    extend Gem::Deprecate

    # [in 3.9.0] このメソッドはDeprecateです。
    # [see] https://dev.mikutter.hachune.net/issues/1200
    def [](condition, *other)
      if other.empty?
        const_get(condition.to_sym)
      else
        const_get(condition.to_sym) & self[*other] end end
    deprecate :[], :none, 2020, 01
  end

  # [in 3.9.0] この定数はDeprecateです。
  # [see] https://dev.mikutter.hachune.net/issues/1200
  class Condition
    def initialize(&block)
      @cond = block
      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? }
  deprecate_constant :HasMessage

  # 一つだけMessageが選択されている
  # [in 3.9.0] この定数はDeprecateです。代わりに、condition:には以下のコードを使ってください。
  # ->opt{ opt.messages.size == 1 }
  HasOneMessage = Condition.new{ |opt| opt.messages.size == 1 }
  deprecate_constant :HasOneMessage

  # 選択されているツイートが全てリプライ可能な時。
  # ツイートが選択されていなければ偽
  # [in 3.9.0] この定数はDeprecateです。代わりに、condition:には以下のコードを使ってください。
  # ->opt{ !opt.messages.empty? && compose?(opt.world, to: opt.messages) }
  CanReplyAll = Condition.new{ |opt|
    if not opt.messages.empty?
      current_world, = Plugin.filtering(:world_current, nil)
      Plugin[:command].compose?(current_world, to: opt.messages)
    end
  }
  deprecate_constant :CanReplyAll

  # 選択されているツイートのうち、一つでも現在のアカウントでリツイートできるものがあれば真を返す
  # [in 3.9.0] この定数はDeprecateです。代わりに、condition:には以下のコードを使ってください。
  # ->opt{ opt.messages.any?{|m| share?(opt.world, m) && !shared?(opt.world, m) } }
  CanReTweetAny = Condition.new { |opt|
    current_world, = Plugin.filtering(:world_current, nil)
    opt.messages.lazy.any?{|m|
      Plugin[:command].share?(current_world, m) && !Plugin[:command].shared?(current_world, m)
    }
  }
  deprecate_constant :CanReTweetAny

  # 選択されているツイートが全て、現在のアカウントでリツイート可能な時、真を返す。
  # 既にリツイート済みのものはリツイート不可とみなす。
  # ツイートが選択されていなければ偽
  CanReTweetAll = Condition.new{ |opt|
    current_world, = Plugin.filtering(:world_current, nil)
    !opt.messages.empty? && opt.messages.lazy.all?{|m|
      Plugin[:command].share?(current_world, m) && !Plugin[:command].shared?(current_world, m)
    }
  }
  deprecate_constant :CanReTweetAll

  # 選択されているツイートを、現在のアカウントで全てリツイートしている場合。
  # ツイートが選択されていなければ偽
  # [in 3.9.0] この定数はDeprecateです。代わりに、condition:には以下のコードを使ってください。
  # ->opt{ !opt.messages.empty? && opt.messages.all?{|m| destroy_share?(opt.world, m) } }
  IsReTweetedAll = Condition.new{ |opt|
    current_world, = Plugin.filtering(:world_current, nil)
    !opt.messages.empty? && opt.messages.lazy.all?{|m|
      Plugin[:command].destroy_share?(current_world, m)
    }
  }
  deprecate_constant :IsReTweetedAll

  # 選択されているツイートのうち、一つでも現在のアカウントでふぁぼれるものがあれば真を返す
  # [in 3.9.0] この定数はDeprecateです。代わりに、condition:には以下のコードを使ってください。
  # ->opt{ opt.messages.any?{|m| favorite?(opt.world, m) && favorited?(opt.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)
    }
  }
  deprecate_constant :CanFavoriteAny

  # 選択されているツイートが全て、現在のアカウントでお気に入りに追加可能な時、真を返す。
  # 既にお気に入りに追加済みのものはお気に入りに追加不可とみなす。
  # ツイートが選択されていなければ偽
  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)
    }
  }
  deprecate_constant :CanFavoriteAll

  # 選択されているツイートを、現在のアカウントで全てお気に入りに追加している場合。
  # ツイートが選択されていなければ偽
  # [in 3.9.0] この定数はDeprecateです。代わりに、condition:には以下のコードを使ってください。
  # ->opt{ !opt.messages.empty? && opt.messages.all?{|m| Plugin[:command].unfavorite?(opt.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)
    }
  }
  deprecate_constant :IsFavoritedAll

  # 選択しているのが全て自分のツイートの時
  # [in 3.9.0] この定数はDeprecateです。代わりに、condition:には以下のコードを使ってください。
  # ->opt{ !opt.messages.empty? && opt.messages.all?{|m| m.from_me?(opt.world) } }
  IsMyMessageAll = Condition.new{ |opt|
    current_world, = Plugin.filtering(:world_current, nil)
    not opt.messages.empty? and opt.messages.all?{|m| m.from_me?(current_world) }
  }
  deprecate_constant :IsMyMessageAll

  # TL上のテキストが一文字でも選択されている
  # [in 3.9.0] この定数はDeprecateです。代わりに、condition:には以下のコードを使ってください。
  # ->opt{ opt.widget.selected_text(opt.messages.first) }
  TimelineTextSelected = Condition.new{ |opt| opt.widget.selected_text(opt.messages.first) }
  deprecate_constant :TimelineTextSelected

  HasParmaLinkAll = Condition.new{ |opt|
    not opt.messages.empty? and opt.messages.all? { |m| m.perma_link } }
  deprecate_constant :HasParmaLinkAll

  # ==== postbox ロール

  # 編集可能状態(入力中:グレーアウトしてない時)
  # [in 3.9.0] この定数はDeprecateです。代わりに、condition:には以下のコードを使ってください。
  # ->opt{ opt.widget.editable? }
  Editable = Condition.new{ |opt| opt.widget.editable? }
  deprecate_constant :Editable

  deprecate_constant :Condition
end