Last active
March 27, 2021 04:37
-
-
Save rekyuu/045aa75700c8357a3a9f to your computer and use it in GitHub Desktop.
weechat ifttt script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import weechat, requests | |
weechat.register("ifttt", "rekyuu", "1.0", "MIT", "IFTTT: Send push notifications to IFTTT.", "", "") | |
settings = { | |
"trigger": "", | |
"token": "" | |
} | |
for option, default_value in settings.items(): | |
if weechat.config_get_plugin(option) == "": | |
weechat.prnt("", weechat.prefix("error") + "IFTTT: Please set option: %s" % option) | |
weechat.prnt("", "IFTTT: /set plugins.var.python.ifttt.%s STRING" % option) | |
weechat.hook_print("", "irc_privmsg", "", 1, "notify_show", "") | |
def notify_show(data, bufferp, uber_empty, tagsn, isdisplayed, ishilight, prefix, message): | |
# get local nick for buffer | |
mynick = weechat.buffer_get_string(bufferp, "localvar_nick") | |
# only notify if the message was not sent by myself | |
if (weechat.buffer_get_string(bufferp, "localvar_type") == "private") and (prefix!=mynick): | |
show_notification("PM", prefix, message) | |
elif ishilight == 1: | |
buffer = (weechat.buffer_get_string(bufferp, "short_name") or weechat.buffer_get_string(bufferp, "name")) | |
show_notification(buffer, prefix, message) | |
return weechat.WEECHAT_RC_OK | |
def show_notification(chan, nick, message): | |
IFTTT_TRIGGER = weechat.config_get_plugin("trigger") | |
IFTTT_API_SECRET = weechat.config_get_plugin("token") | |
if IFTTT_TRIGGER != "" and IFTTT_API_SECRET != "": | |
url = "https://maker.ifttt.com/trigger/{}/with/key/{}".format(IFTTT_TRIGGER, IFTTT_API_SECRET) | |
postdata = { | |
'value1': chan, | |
'value2': nick, | |
'value3': message | |
} | |
r = requests.post(url, data=postdata) | |
weechat.prnt("", "IFTTT: Sent notification - {} {}".format(r.status_code, r.reason)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment