├── README.md └── pushover-weechat.rb /README.md: -------------------------------------------------------------------------------- 1 | Pushover for Weechat 2 | ==================== 3 | 4 | Send private messages and highlights to your Android device via 5 | the Pushover service (https://pushover.net/home) 6 | 7 | Install 8 | ------- 9 | 10 | Load the pushover-weechat.rb plugin into Weechat. Place it in the 11 | ~/.weechat/ruby directory: 12 | 13 | /ruby load pushover-weechat.rb 14 | 15 | It also requires a Pushover account and Ruby, the Ruby OpenSSL libraries, and RubyGems installed on your host. 16 | 17 | Setup 18 | ----- 19 | 20 | Set your Pushover user key. 21 | 22 | /set plugins.var.ruby.pushover-weechat.userkey 123456789abcdefgh 23 | 24 | Options 25 | ------- 26 | 27 | * plugins.var.ruby.pushover-weechat.userkey 28 | 29 | The user key for your Pushover service. Defaults to an empty string and must be set for pushover-weechat to work. 30 | 31 | * plugins.var.ruby.pushover-weechat.interval 32 | 33 | The interval between notifications. Doesn't notify if the last 34 | notification was within x seconds. 35 | 36 | Default: 60 seconds 37 | 38 | * plugins.var.ruby.pushover-weechat.sound 39 | 40 | Set your notification sound options (Current listing located at https://pushover.net/apisounds) 41 | 42 | - pushover - Pushover (default) 43 | - bike - Bike 44 | - bugle - Bugle 45 | - cashregister - Cash Register 46 | - classical - Classical 47 | - cosmic - Cosmic 48 | - falling - Falling 49 | - gamelan - Gamelan 50 | - incoming - Incoming 51 | - intermission - Intermission 52 | - magic - Magic 53 | - mechanical - Mechanical 54 | - pianobar - Piano Bar 55 | - siren - Siren 56 | - spacealarm - Space Alarm 57 | - tugboat - Tug Boat 58 | - alien - Alien Alarm (long) 59 | - climb - Climb (long) 60 | - persistent - Persistent (long) 61 | - echo - Pushover Echo (long) 62 | - updown - Up Down (long) 63 | - none - None (silent) 64 | 65 | Default: blank (Sound will be device default tone set in Pushover) 66 | 67 | Author 68 | ------ 69 | 70 | James Turnbull () 71 | 72 | Contributions from [Zach Leslie](https://twitter.com/xaque208), [Ben Hughes](https://twitter.com/benjammingh), and [Erica Baker](https://twitter.com/EricaJoy). 73 | 74 | License 75 | ------- 76 | 77 | Apache 2.0 78 | 79 | -------------------------------------------------------------------------------- /pushover-weechat.rb: -------------------------------------------------------------------------------- 1 | # James Turnbull 2 | # https://github.com/jamtur01/pushover-weechat 3 | # http://www.kartar.net 4 | # (See below for LICENSE.) 5 | # 6 | # pushover for Weechat 7 | # --------------- 8 | # 9 | # Send private messages and highlights to your Android device via 10 | # the Pushover service (https://pushover.net/home) 11 | # 12 | # Install 13 | # ------- 14 | # 15 | # Load the pushover-weechat.rb plugin into Weechat. Place it in the 16 | # ~/.weechat/ruby directory: 17 | # 18 | # /ruby load pushover-weechat.rb 19 | # 20 | # It also requires a Pushover account. 21 | # 22 | # Setup 23 | # ----- 24 | # 25 | # Set your Pushover user key. 26 | # 27 | # /set plugins.var.ruby.pushover-weechat.userkey 123456789abcdefgh 28 | # 29 | # Options 30 | # ------- 31 | # 32 | # plugins.var.ruby.pushover-weechat.userkey 33 | # 34 | # The user key for your Pushover service. 35 | # Default: Empty string 36 | # 37 | # plugins.var.ruby.pushover-weechat.interval 38 | # 39 | # The interval between notifications. Doesn't notify if the last 40 | # notification was within x seconds. 41 | # Default: 60 seconds 42 | # 43 | # plugins.var.ruby.pushover-weechat.away 44 | # 45 | # Check whether the client is to /away for the current buffer and 46 | # notifies if they're away. Set to on for this to happen. 47 | # Default: off 48 | # 49 | # plugins.var.ruby.pushover-weechat.sound 50 | # 51 | # Set your notification sound 52 | # options (Current listing located at https://pushover.net/api#sounds) 53 | # pushover - Pushover (default) 54 | # bike - Bike 55 | # bugle - Bugle 56 | # cashregister - Cash Register 57 | # classical - Classical 58 | # cosmic - Cosmic 59 | # falling - Falling 60 | # gamelan - Gamelan 61 | # incoming - Incoming 62 | # intermission - Intermission 63 | # magic - Magic 64 | # mechanical - Mechanical 65 | # pianobar - Piano Bar 66 | # siren - Siren 67 | # spacealarm - Space Alarm 68 | # tugboat - Tug Boat 69 | # alien - Alien Alarm (long) 70 | # climb - Climb (long) 71 | # persistent - Persistent (long) 72 | # echo - Pushover Echo (long) 73 | # updown - Up Down (long) 74 | # none - None (silent) 75 | # Default: blank (Sound will be device default tone set in Pushover) 76 | # 77 | # plugins.var.ruby.pushover-weechat.ignore_re 78 | # 79 | # Regular expression to skip certain kinds of highlights 80 | # 81 | 82 | # fix for weechat UTF_7 encoding issue 83 | require 'enc/encdb.so' 84 | 85 | require 'rubygems' 86 | require 'net/https' 87 | require 'json' 88 | 89 | SCRIPT_NAME = 'pushover-weechat' 90 | SCRIPT_AUTHOR = 'James Turnbull ' 91 | SCRIPT_DESC = 'Send highlights and private messages in channels to your Android or IOS device via Pushover' 92 | SCRIPT_VERSION = '0.1' 93 | SCRIPT_LICENSE = 'APL' 94 | 95 | DEFAULTS = { 96 | 'apikey' => "eWEPQ0QQrM2A4WBfx8zZoEpYWBAuBa", 97 | 'userkey' => "", 98 | 'interval' => "60", 99 | 'sound' => "", 100 | 'away' => 'off' 101 | } 102 | 103 | def weechat_init 104 | Weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", "") 105 | DEFAULTS.each_pair do |option, def_value| 106 | cur_value = Weechat.config_get_plugin(option) 107 | Weechat.config_set_plugin(option, def_value) if cur_value.nil? || cur_value.empty? 108 | end 109 | 110 | @last = Time.now - Weechat.config_get_plugin('interval').to_i 111 | 112 | Weechat.print("", "pushover-weechat: Please set your API key with: /set plugins.var.ruby.pushover-weechat.userkey") 113 | 114 | Weechat.hook_signal("weechat_highlight", "notify", "") 115 | Weechat.hook_signal("weechat_pv", "notify", "") 116 | 117 | return Weechat::WEECHAT_RC_OK 118 | end 119 | 120 | def notify(data, signal, signal_data) 121 | 122 | @last = Time.now unless @last 123 | 124 | # Only check if we're away if the plugin says to, only notify if we are 125 | # away. 126 | if Weechat.config_get_plugin('away') == 'on' 127 | buffer = Weechat.current_buffer 128 | isaway = Weechat.buffer_get_string(buffer, "localvar_away") != "" 129 | 130 | return Weechat::WEECHAT_RC_OK unless isaway 131 | end 132 | 133 | if signal == "weechat_pv" 134 | event = "Weechat Private message from #{signal_data.split.first}" 135 | elsif signal == "weechat_highlight" 136 | event = "Weechat Highlight from #{signal_data.split.first}" 137 | end 138 | 139 | if (Time.now - @last) > Weechat.config_get_plugin('interval').to_i 140 | message = signal_data[/^\S+\t(.*)/, 1] 141 | url = URI.parse("https://api.pushover.net/1/messages.json") 142 | req = Net::HTTP::Post.new(url.path, 'Content-Type' => 'application/json') 143 | req.body = JSON.generate({ 144 | :token => Weechat.config_get_plugin('apikey'), 145 | :user => Weechat.config_get_plugin('userkey'), 146 | :sound => Weechat.config_get_plugin('sound'), 147 | :title => event, 148 | :message => message 149 | }) 150 | res = Net::HTTP.new(url.host, url.port) 151 | res.use_ssl = true 152 | res.verify_mode = OpenSSL::SSL::VERIFY_NONE 153 | res.start { |http| http.request(req) } 154 | @last = Time.now 155 | else 156 | Weechat.print("", "pushover-weechat: Skipping notification, too soon since last notification") 157 | end 158 | 159 | return Weechat::WEECHAT_RC_OK 160 | end 161 | 162 | __END__ 163 | __LICENSE__ 164 | 165 | Copyright 2011 James Turnbull 166 | 167 | Licensed under the Apache License, Version 2.0 (the "License"); 168 | you may not use this file except in compliance with the License. 169 | You may obtain a copy of the License at 170 | 171 | http://www.apache.org/licenses/LICENSE-2.0 172 | 173 | Unless required by applicable law or agreed to in writing, software 174 | distributed under the License is distributed on an "AS IS" BASIS, 175 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 176 | See the License for the specific language governing permissions and 177 | limitations under the License. 178 | --------------------------------------------------------------------------------