# Author: Ryan Feng # Version: 0.1 import gntp.notifier as notifier import weechat # Logging def log(msg): weechat.prnt("",msg) # Register plugin weechat.register("gntpnotify", "Ryan Feng", "0.1", "GPL3", "GNTP Notify: Grow notifications using python-gntp", "", "") # Create hooks weechat.hook_signal("*,irc_in2_PRIVMSG","private_msg","") weechat.hook_signal("weechat_highlight","hilight_msg","") # Create grow object growl = notifier.GrowlNotifier( applicationName = "Weechat", notifications = ["irc message"], defaultNotifications = ["irc message"], ) if not growl.register(): log("Cannot create notifier object") def show_notification(title, message): r = growl.notify( noteType = "irc message", title = title, description = message, sticky = False, priority = 1 ) if not r: log("Cannot send notification") def private_msg(data, signal, message): # message is a raw irc message sent from the server message = message[1:] # Get sender sender = message[:message.find('!')-1] # Get receiver receiver = message.split()[2] # Get message body msg = message[message.find(':')+1:] # Get the server which sent this message server = signal.partition(',')[0] # Ignore all PRIVMSGs send to a channel,the rest are messages send to 'me' if not receiver.startswith('#'): show_notification("%s @ #%s" % (sender,server),msg) return weechat.WEECHAT_RC_OK def hilight_msg(data, signal, message): # TODO: Get the sender of the message and the channel where the highlight displayed sender,_,tmp_msg = message.partition('\t') _,_,msg = tmp_msg.partition(' ') show_notification("%s" % sender, msg) return weechat.WEECHAT_RC_OK