Skip to content

Instantly share code, notes, and snippets.

@SupaHam
Last active July 15, 2016 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SupaHam/62edf7aaafede3b66140f0978406cb1c to your computer and use it in GitHub Desktop.
Save SupaHam/62edf7aaafede3b66140f0978406cb1c to your computer and use it in GitHub Desktop.
Weechat script for PushBullet
# Gib me all ur credits kthx
# - ur pal al
import weechat
import re
from pushbullet.pushbullet import PushBullet
SCRIPT_NAME = "weepush"
SCRIPT_AUTHOR = "SupaHam <me@supa.me>"
SCRIPT_VERSION = "1"
SCRIPT_LICENSE = "None"
SCRIPT_DESC = "Dem notifications tho"
NICK_REGEX = "(^|,)nick_([^,]*)(,|$)"
CONFIG_FILE_NAME = "weepush"
wp_config_file = ""
wp_config_option = {}
def wp_config_init():
global wp_config_file, wp_config_option
wp_config_file = weechat.config_new(CONFIG_FILE_NAME, "weepush_config_reload_cb", "")
if wp_config_file == "":
return
section_general = weechat.config_new_section(wp_config_file, "general", 0, 0, "", "", "", "", "", "", "", "", "", "")
if section_general == "":
weechat.config_free(wp_config_file)
return # TODO END?
wp_config_option["api_key"] = weechat.config_new_option(wp_config_file, section_general, "api_key", "string",
"PushBullet API key", "", 0, 0, "", "", 0, "", "", "", "", "", "")
def wp_config_read():
global wp_config_file
return weechat.config_read(wp_config_file)
def pb_push(data, buffer, date, tags, displayed, highlight, prefix, message):
global pb
if not displayed:
return weechat.WEECHAT_RC_OK
nick_search = re.search(NICK_REGEX, tags)
if not nick_search:
return weechat.WEECHAT_RC_OK
# Check if the sender is us
sender_nick = nick_search.group(2)
if (sender_nick == weechat.buffer_get_string(buffer, "localvar_nick") or
sender_nick == "*highlight"):
# We (or *highlight) are the sender, no push.
return weechat.WEECHAT_RC_OK
if (not sender_nick.startswith("*") and
(highlight or "notify_private" in tags)):
channel_name = weechat.buffer_get_string(buffer, "localvar_channel")
title_header = sender_nick + " in " + channel_name
# Private message
if sender_nick == channel_name:
title_header = "PM: " + sender_nick
devices = pb.getDevices()
pb.pushNote(devices[0]["iden"], title_header, message)
return weechat.WEECHAT_RC_OK
if __name__ == "__main__":
if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
global pb
wp_config_init()
wp_config_read()
pb = PushBullet(weechat.config_string(wp_config_option['api_key']))
weechat.hook_print("", "", "", 1, "pb_push", "")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment