Script: gntp_notify.rb

Growl notifications using ruby-gntp.
Author: tinifni — Version: 1.1 — License: GPL-3.0-or-later
For WeeChat ≥ 0.3.0, requires: ruby_gntp.
Tags: notify
Added: 2011-11-01 — Updated: 2012-02-08

Download GitHub Repository

 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
# Author: Justin Anderson
# Email: jandersonis@gmail.com
# Homepage: https://github.com/tinifni/gntp-notify
# Version: 1.1
# License: GPL3
# Depends on ruby_gntp (https://github.com/snaka/ruby_gntp)

require 'rubygems'
require 'ruby_gntp'

def weechat_init
  Weechat.register("gntp_notify",
                   "Justin Anderson",
                   "1.1",
                   "GPL3",
                   "GNTP Notify: Growl notifications using ruby_gntp.",
                   "",
                   "")

  hook_notifications

  @growl = GNTP.new("Weechat")
  @growl.register({
    :notifications => [{:name    => "Private",
                        :enabled => true},
                       {:name    => "Highlight",
                        :enabled => true}]
  })

  return Weechat::WEECHAT_RC_OK
end

def hook_notifications
  Weechat.hook_signal("weechat_pv", "show_private", "")
  Weechat.hook_signal("weechat_highlight", "show_highlight", "")
end

def unhook_notifications(data, signal, message)
  Weechat.unhook(show_private)
  Weechat.unhook(show_highlight)
end

def show_private(data, signal, message)
  message[0..1] == '--' ? sticky = false : sticky = true
  show_notification("Private", "Weechat Private Message",  message, sticky)
  return Weechat::WEECHAT_RC_OK
end

def show_highlight(data, signal, message)
  message[0..1] == '--' ? sticky = false : sticky = true
  show_notification("Highlight", "Weechat",  message, sticky)
  return Weechat::WEECHAT_RC_OK
end

def show_notification(name, title, message, sticky = true)
  @growl.notify({
    :name   => name,
    :title  => title,
    :text   => message,
    :icon   => "https://github.com/tinifni/gntp-notify/raw/master/weechat.png",
    :sticky => sticky
  })
end