Initial commit

This commit is contained in:
Tony Blyler 2016-06-09 22:09:35 -04:00
parent 7df8c4c67e
commit 2e17cc22c9
No known key found for this signature in database
GPG key ID: 25C9D3A655D1A65C
2 changed files with 38 additions and 1 deletions

View file

@ -1,2 +1,7 @@
# pyshnotify # pyshnotify
Weechat shell executions from notifications [Weechat](https://weechat.org) shell executions from notifications
## Installation and Usage
1. `curl https://raw.githubusercontent.com/tblyler/pyshnotify/master/pyshnotify.py > "${HOME}/.weechat/python/autoload/pyshnotify.py`
2. If Weechat is running you can load the plugin with `/python reload`
3. Set the command to run with `/set plugins.var.python.pyshnotify.command "curl example.com/{{buffer_name}}/{{msg}}"`

32
pyshnotify.py Normal file
View file

@ -0,0 +1,32 @@
import weechat as w
import shlex, subprocess
SCRIPT_NAME = "pyshnotify"
SCRIPT_AUTHOR = "Tony Blyler <tony@blyler.cc>"
SCRIPT_VERSION = "1.0"
SCRIPT_LICENSE = "GPL3"
SCRIPT_DESC = "Execute command from highlights and private messages"
def on_msg(data, buffer, timestamp, tags, displayed, highlight, sender, message):
if data == "private" or int(highlight) or w.buffer_get_string(buffer, "localvar_type") == "private":
buffer_name = w.buffer_get_string(buffer, "name")
cmd = w.config_get_plugin("command")
if not cmd:
return w.WEECHAT_RC_OK
cmd = cmd.replace("{{buffer_name}}", buffer_name).replace("{{msg}}", message)
proc = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
if proc.returncode != 0:
w.prnt("", weechat.prefix("error") + " Unable to run command: '" + cmd + "' stdout: '" + stdout + "' stderr: '" + stderr + "'")
return w.WEECHAT_RC_ERROR
return w.WEECHAT_RC_OK
if __name__ == "__main__" and w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
w.config_set_desc_plugin("command", "Shell command to execute {{buffer_name}} and {{msg}} will be replaced per message")
if not w.config_get_plugin("command"):
w.config_set_plugin("command", "")
w.hook_print("", "irc_privmsg", "", 1, "on_msg", "")