Advertisement
Guest User

Untitled

a guest
May 6th, 2017
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. # Author: lavaramano <lavaramano AT gmail DOT com>
  2. # Improved by: BaSh - <bash.lnx AT gmail DOT com>
  3. # Ported to Weechat 0.3.0 by: Sharn - <sharntehnub AT gmail DOT com)
  4. # This Plugin Calls the libnotify bindings via python when somebody says your nickname, sends you a query, etc.
  5. # To make it work, you may need to download: python-notify (and libnotify - libgtk)
  6. # Requires Weechat 0.3.0
  7. # Released under GNU GPL v2
  8. #
  9. # 2010-02-20, Aron Griffis <agriffis@n01se.net>
  10. # version 0.0.5: Add nick_separator, don't call show_notification twice on
  11. # privmsg, fix spelling s/nofify/notify/, use nick as "summary" for privmsg
  12. # notification, fit in 80 columns, tweak vim modeline.
  13. # 2010-01-24, David Rubin <davidrub+weechat@gmail.com>
  14. # version 0.0.4.2 Fixed issue with self notifications when used with out "smart_notification"
  15. # 2010-01-19, Didier Roche <didrocks@ubuntu.com>
  16. # version 0.0.4.1: add private message sender name
  17. # 2010-01-19, Didier Roche <didrocks@ubuntu.com>
  18. # version 0.0.4: add smart notification:
  19. # be notified only if you're not in the current channel/pv window (off by default)
  20. # 2009-06-16, kba <unixprog@gmail.com.org>:
  21. # version 0.0.3: added config options for icon and urgency
  22. # 2009-05-02, FlashCode <flashcode@flashtux.org>:
  23. # version 0.0.2.1: sync with last API changes
  24.  
  25. import weechat, pynotify, string
  26.  
  27. weechat.register("notify", "lavaramano", "0.0.5", "GPL", "notify: A real time notification system for weechat", "", "")
  28.  
  29. # script options
  30. settings = {
  31. "show_hilights" : "on",
  32. "show_priv_msg" : "on",
  33. "nick_separator" : ": ",
  34. "icon" : "/usr/share/pixmaps/weechat.xpm",
  35. "urgency" : "normal",
  36. "smart_notification" : "off",
  37. }
  38.  
  39. urgencies = {
  40. "low" : pynotify.URGENCY_LOW,
  41. "critical" : pynotify.URGENCY_CRITICAL,
  42. "normal" : pynotify.URGENCY_NORMAL,
  43. }
  44.  
  45. # Init everything
  46. for option, default_value in settings.items():
  47. if weechat.config_get_plugin(option) == "":
  48. weechat.config_set_plugin(option, default_value)
  49.  
  50. # Hook privmsg/hilights
  51. weechat.hook_print("", "irc_privmsg", "", 1, "notify_show", "")
  52.  
  53. # Functions
  54. def notify_show(data, bufferp, uber_empty, tagsn, isdisplayed,
  55. ishilight, prefix, message):
  56. """Sends highlighted message to be printed on notification"""
  57.  
  58. if (weechat.config_get_plugin('smart_notification') == "on" and
  59. bufferp == weechat.current_buffer()):
  60. pass
  61.  
  62. elif (weechat.buffer_get_string(bufferp, "localvar_type") == "private" and
  63. weechat.config_get_plugin('show_priv_msg') == "on"):
  64. show_notification(prefix, message)
  65.  
  66. elif (ishilight == "1" and
  67. weechat.config_get_plugin('show_hilights') == "on"):
  68. buffer = (weechat.buffer_get_string(bufferp, "short_name") or
  69. weechat.buffer_get_string(bufferp, "name"))
  70. show_notification(buffer, prefix +
  71. weechat.config_get_plugin('nick_separator') + message)
  72.  
  73. return weechat.WEECHAT_RC_OK
  74.  
  75. def show_notification(chan,message):
  76. pynotify.init("wee-notifier")
  77. wn = pynotify.Notification(chan, message, weechat.config_get_plugin('icon'))
  78. wn.set_urgency(urgencies[weechat.config_get_plugin('urgency')] or
  79. pynotify.URGENCY_NORMAL)
  80. wn.show()
  81.  
  82. # vim: autoindent expandtab smarttab shiftwidth=4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement