Created
June 20, 2013 17:06
-
-
Save trobrock/5824587 to your computer and use it in GitHub Desktop.
weechat ruby notifications, thanks @joelteon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ruby_gntp' | |
Weechat.register "notify", "otters", "0.2", "GPL", "notify: A real time notification system for weechat", "", "" | |
Settings = { | |
:show_hilights => "on", | |
:show_priv_msg => "on" | |
} | |
def notify_show data, buffer, empty, tagsn, isdisp, ishilight, prefix, msg | |
doing_hilight = ishilight == "1" && | |
Weechat.config_get_plugin("show_hilights") == "on" | |
doing_pm = Weechat.buffer_get_string(buffer, "localvar_type") == "private" && | |
Weechat.config_get_plugin("show_priv_msg") == "on" | |
is_me = Weechat.info_get("irc_nick", Weechat.buffer_get_string(buffer, "localvar_server")) == prefix | |
msg = prefix == " *" ? "#{prefix} #{msg}" : "<#{prefix}> #{msg}" | |
bufname = Weechat.buffer_get_string(buffer, "short_name") || Weechat.buffer_get_string(buffer, "name") | |
this_buffer = Weechat.buffer_get_string(buffer, "name") == Weechat.buffer_get_string(Weechat.current_buffer, "name") | |
if (doing_pm || doing_hilight) && !is_me && !this_buffer | |
begin | |
title = doing_pm ? "private message" : bufname | |
$growl.notify :name => "highlight", :title => doing_pm ? "private message" : bufname, :text => msg | |
%x{ tmux set display-time 3000 } | |
%x{ tmux display-message "weechat: #{title} - #{msg}" } | |
rescue Errno::ECONNREFUSED, Errno::ECONNRESET | |
# screen detached | |
end | |
end | |
return Weechat::WEECHAT_RC_OK | |
end | |
def weechat_init | |
Settings.each do |k,v| | |
Weechat.config_set_plugin(k.to_s, v) if Weechat.config_get_plugin(k.to_s).empty? | |
end | |
$growl = GNTP.new "weechat" | |
$growl.register :notifications => [{ :name => "highlight", :enabled => true }] | |
Weechat.hook_print("", "irc_privmsg", "", 1, "notify_show", "") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment