File: conditions.rb

package info (click to toggle)
mikutter 3.5.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 10,256 kB
  • ctags: 2,165
  • sloc: ruby: 19,079; sh: 205; makefile: 20
file content (95 lines) | stat: -rw-r--r-- 3,857 bytes parent folder | download | duplicates (2)
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
# -*- 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|
    not opt.messages.empty? and opt.messages.all?(&:repliable?) }

  # 選択されているツイートのうち、一つでも現在のアカウントでリツイートできるものがあれば真を返す
  CanReTweetAny = Condition.new { |opt|
    opt.messages.any? { |message| message.retweetable? and not message.retweeted_by_me? Service.primary } }

  # 選択されているツイートが全て、現在のアカウントでリツイート可能な時、真を返す。
  # 既にリツイート済みのものはリツイート不可とみなす。
  # ツイートが選択されていなければ偽
  CanReTweetAll = Condition.new{ |opt|
    not opt.messages.empty? and opt.messages.all? { |m|
      m.retweetable? and not m.retweeted_by_me?(Service.primary) } }

  # 選択されているツイートを、現在のアカウントで全てリツイートしている場合。
  # ツイートが選択されていなければ偽
  IsReTweetedAll = Condition.new{ |opt|
    not opt.messages.empty? and opt.messages.all? { |m|
      m.retweetable? and m.retweeted_by_me?(Service.primary) } }

  # 選択されているツイートのうち、一つでも現在のアカウントでふぁぼれるものがあれば真を返す
  CanFavoriteAny = Condition.new { |opt|
    opt.messages.any? { |message| message.favoritable? and not message.favorited_by_me? Service.primary } }

  # 選択されているツイートが全て、現在のアカウントでお気に入りに追加可能な時、真を返す。
  # 既にお気に入りに追加済みのものはお気に入りに追加不可とみなす。
  # ツイートが選択されていなければ偽
  CanFavoriteAll = Condition.new{ |opt|
    not opt.messages.empty? and opt.messages.all? { |m|
      m.favoritable? and not m.favorited_by_me?(Service.primary) } }

  # 選択されているツイートを、現在のアカウントで全てお気に入りに追加している場合。
  # ツイートが選択されていなければ偽
  IsFavoritedAll = Condition.new{ |opt|
    not opt.messages.empty? and opt.messages.all? { |m|
      m.favoritable? and m.favorited_by_me?(Service.primary) } }

  # 選択しているのが全て自分のツイートの時
  IsMyMessageAll = Condition.new{ |opt|
    not opt.messages.empty? and opt.messages.all?(&: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