From The Compiler, 9 Years ago, written in Python.
Embed
  1. # vim: set fileencoding=utf-8 tabstop=8 expandtab shiftwidth=4 softtabstop=4 :
  2.  
  3. try:
  4.     import weechat
  5. except ImportError:
  6.     print("Error: this script is a plugin for weechat and needs to be run "
  7.           "inside weechat.")
  8.     raise
  9.  
  10. import shlex, subprocess, string
  11.  
  12. weechat.register("notify-command", "The Compiler", "0.1", "GPL3",
  13.                  "Call external commands on highlights/messages/dcc", "", "")
  14.  
  15. settings = {
  16.         "highlight_command": "/home/florian/write '%BUFFER% / %PREFIX% / %MESSAGE% / %DATE%' '/home/florian/weechat/h ilights'",
  17.         "privmsg_command": "/home/florian/write '%BUFFER% / %PREFIX% / %MESSAGE% / %DATE%' '/home/florian/weechat/privmsgs'",
  18. }
  19.  
  20. for option, default_value in settings.items():
  21.     if weechat.config_get_plugin(option) == "": # FIXME
  22.         weechat.config_set_plugin(option, default_value)
  23.  
  24. weechat.hook_print("",                # buffer
  25.                    "irc_privmsg",     # tags
  26.                    "",                # message
  27.                    1,                 # strip_colors
  28.                    "signal_callback", # callback
  29.                    "")                # callback_data
  30.  
  31. def call_command(msgtype, bufname, prefix, message, date):
  32.     if msgtype == 'privmsg':
  33.         cmdstr = weechat.config_get_plugin('privmsg_command')
  34.     elif msgtype == 'highlight':
  35.         cmdstr = weechat.config_get_plugin('highlight_command')
  36.  
  37.     cmdstr = cmdstr.replace('%BUFFER%', bufname)
  38.     cmdstr = cmdstr.replace('%PREFIX%', prefix)
  39.     cmdstr = cmdstr.replace('%MESSAGE%', message)
  40.     cmdstr = cmdstr.replace('%DATE%', date)
  41.     cmd = shlex.split(cmdstr)
  42.     subprocess.call(cmd, shell=False)
  43.  
  44. def signal_callback(data, bufferp, date, tags, displayed, highlight, prefix,
  45.                     message):
  46.     bufname = (weechat.buffer_get_string(bufferp, "short_name") or
  47.               weechat.buffer_get_string(bufferp, "name"))
  48.  
  49.     if weechat.buffer_get_string(bufferp, "localvar_type") == "private":
  50.         msgtype='privmsg'
  51.     elif highlight == "1":
  52.         msgtype='highlight'
  53.     else:
  54.         return(weechat.WEECHAT_RC_ERROR)
  55.  
  56.     call_command(msgtype, bufname, prefix, message, date)
  57.  
  58.     return(weechat.WEECHAT_RC_OK)