Debian Codegraph @

plugin/notify/notify.rb

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 Plugin.create(:notify) do
4
5 DEFAULT_SOUND_DIRECTORY = File.join(Skin.default_dir, 'sounds')
6
7 settings(_("通知")) do
8 def self.defnotify(label, kind)
9 settings(label) do
10 boolean _('ポップアップ'), "notify_#{kind}".to_sym, switch: true
11 fileselect(_('サウンド'), "notify_sound_#{kind}".to_sym,
12 dir: DEFAULT_SOUND_DIRECTORY,
13 shortcuts: [DEFAULT_SOUND_DIRECTORY],
14 filters: {_('非圧縮音声ファイル (*.wav, *.aiff)') => ['wav', 'WAV', 'aiff', 'AIFF'],
15 _('FLAC (*.flac, *.fla)') => ['flac', 'FLAC', 'fla', 'FLA'],
16 _('MPEG-1/2 Audio Layer-3 (*.mp3)') => ['mp3', 'MP3'],
17 _('Ogg (*.ogg)') => ['ogg', 'OGG'],
18 _('全てのファイル') => ['*']
19 }) end end
20
21 defnotify _("フレンドタイムライン"), :friend_timeline
22 defnotify _("リプライ"), :mention
23 defnotify _('フォローされたとき'), :followed
24 defnotify _('フォロー解除されたとき'), :removed
25 defnotify _('リツイートされたとき'), :retweeted
26 defnotify _('ふぁぼられたとき'), :favorited
27 defnotify _('ダイレクトメッセージ受信'), :direct_message
28 adjustment(_('通知を表示し続ける秒数'), :notify_expire_time, 1, 60)
29 end
30
31 onupdate do |post, raw_messages|
32 messages = Plugin.filtering(:show_filter, raw_messages.select{ |m| !(m.from_me? || m.to_me?) && m.created > defined_time }).first
33 unless messages.empty?
34 if UserConfig[:notify_friend_timeline]
35 messages.reject(&:from_me?).each do |message|
36 notify(message.user, message)
37 end
38 end
39 notify_sound(UserConfig[:notify_sound_friend_timeline])
40 end
41 end
42
43 onmention do |post, raw_messages|
44 messages = Plugin.filtering(:show_filter, raw_messages.select{ |m| !(m.from_me? || m.retweet?) && m.created > defined_time }).first
45 unless messages.empty?
46 if !UserConfig[:notify_friend_timeline] && UserConfig[:notify_mention]
47 messages.each do |message|
48 notify(message.user, message)
49 end
50 end
51 notify_sound(UserConfig[:notify_sound_mention])
52 end
53 end
54
55 on_followers_created do |world, users|
56 unless users.empty?
57 if UserConfig[:notify_followed]
58 notify(users.first, _('%{users} にフォローされました。') % { users: users.map{|u| "@#{u[:idname]}" }.join(' ') })
59 end
60 notify_sound(UserConfig[:notify_sound_followed])
61 end
62 end
63
64 on_followers_destroy do |world, users|
65 unless users.empty?
66 if UserConfig[:notify_removed]
67 notify(users.first, _('%{users} にリムーブされました。') % { users: users.map{|u| "@#{u.idname}" }.join(' ') })
68 end
69 notify_sound(UserConfig[:notify_sound_removed])
70 end
71 end
72
73 on_favorite do |_, by, to|
74 if to.from_me?
75 if UserConfig[:notify_favorited]
76 notify(by, _("fav by %{from_user} \"%{text}\"") % { from_user: by.idname, text: to.to_s })
77 end
78 notify_sound(UserConfig[:notify_sound_favorited])
79 end
80 end
81
82 onmention do |_, raw_messages|
83 messages = Plugin.filtering(:show_filter, raw_messages.select{ |m| m.created > defined_time && m.retweet? && !m.from_me? }).first.to_a
84 unless messages.empty?
85 if UserConfig[:notify_retweeted]
86 messages.each do |message|
87 notify(message.user, _('Share by %{from_user}: %{text}') % { from_user: message.user.idname, text: message.retweet_source.to_s })
88 end
89 end
90 notify_sound(UserConfig[:notify_sound_retweeted])
91 end
92 end
93
94 on_direct_messages do |post, dms|
95 newer_dms = dms.select{ |dm| Time.parse(dm[:created_at]) > defined_time }
96 if not(newer_dms.empty?)
97 if(UserConfig[:notify_direct_message])
98 newer_dms.each{ |dm|
99 notify(User.generate(dm[:sender]), dm[:text]) } end
100 if(UserConfig[:notify_sound_direct_message])
101 notify_sound(UserConfig[:notify_sound_direct_message]) end end end
102
103 def notify(user, text)
104 Plugin.call(:popup_notify, user, text)
105 end
106
107 def notify_sound(sndfile)
108 if sndfile&.respond_to?(:to_s) && FileTest.exist?(sndfile.to_s)
109 Plugin.call(:play_sound, sndfile)
110 end
111 end
112
113 end