Created
December 6, 2010 03:58
-
-
Save cbrunsdon/729825 to your computer and use it in GitHub Desktop.
ruby generic_notifier
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
#!/usr/bin/ruby | |
#based off jhawthorn's python generic_nofity.py | |
require 'net/http' | |
def send_notify(ticker, title, body) | |
if Weechat.config_get_plugin('account_name') == "" | |
return Weechat::WEECHAT_RC_OK | |
end | |
res = Net::HTTP.post_form(URI.parse('http://generic-notify.heroku.com/send'), { | |
'account_name'=>Weechat.config_get_plugin('account_name'), | |
'ticker'=>ticker, | |
'title'=>title, | |
'body'=>body, | |
}) | |
end | |
def get_notified_public(data, bufferp, uber_empty, tagsn, isdisplayed, ishilight, prefix, message) | |
name = (Weechat.buffer_get_string(bufferp, "short_name") || Weechat.buffer_get_string(bufferp, "name")) | |
if (ishilight == "1" and Weechat.config_get_plugin('show_highlight') == "on"): | |
if prefix != '@root' # shitty hack ignore bitlbee's root | |
send_notify("IRC message in #{name}", "#{prefix} in #{name} says", message) | |
end | |
end | |
return Weechat::WEECHAT_RC_OK | |
end | |
def get_notified_pm(a, type, data) | |
Weechat.print "", "yea got to pm" | |
data = data.split("\t") | |
user = data[0] | |
message = data[1] | |
send_notify("Private message from #{name}", "#{name} says", message) | |
return Weechat::WEECHAT_RC_OK | |
end | |
def weechat_init | |
Weechat.register("generic_notify", "cbrunsdon", "1.0", "GPL3", "generic_notify", "", "") | |
settings = { | |
"show_highlight" => "on", | |
"show_priv_msg" => "on", | |
"account_name" => "" | |
} | |
settings.each do |option, default_value| | |
if !Weechat.config_is_set_plugin(option) | |
Weechat.config_set_plugin(option, default_value) | |
end | |
end | |
Weechat.hook_print("", "irc_privmsg", "", 1, "get_notified_public", "") | |
Weechat.hook_signal("weechat_pv", "get_notified_pm", ""); | |
return Weechat::WEECHAT_RC_OK | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment