Created
April 14, 2016 21:55
-
-
Save miek/1bd26e1319de7ca23bb012650d99e73f to your computer and use it in GitHub Desktop.
This file contains 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 | |
import re | |
SCRIPT_NAME = "slack-gw" | |
SCRIPT_AUTHOR = "Mike Walters <[email protected]>" | |
SCRIPT_VERSION = "1.0" | |
SCRIPT_LICENSE = "BSD" | |
SCRIPT_DESC = "Fix up messages coming from slack gateway" | |
settings = { | |
"targets" : "freenode.#gnuradio.slack-gw", | |
} | |
def privmsg_modifier_cb(userdata, modifier, servername, raw_irc_msg): | |
msg = weechat.info_get_hashtable( | |
"irc_message_parse", | |
{"message": raw_irc_msg} | |
) | |
target = "{}.{}.{}".format(servername, msg["channel"], msg["nick"]).lower() | |
targets = weechat.config_get_plugin("targets").lower().split(",") | |
if target in targets: | |
# Try to extract real nickname from message | |
m = re.match("<([^> ]+)> (.*)$", msg["arguments"].split(":", 1)[1]) | |
if m: | |
# Return modified PRIVMSG for matching slack-gw messages | |
return ":{}$!slack-gw@fake PRIVMSG {} :{}".format(m.group(1), msg["channel"], m.group(2)) | |
# Otherwise return unmodified | |
return raw_irc_msg | |
if __name__ == "__main__": | |
if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, | |
SCRIPT_DESC, "", ""): | |
# Set default settings | |
for option, default_value in settings.iteritems(): | |
if not weechat.config_is_set_plugin(option): | |
weechat.config_set_plugin(option, default_value) | |
weechat.hook_modifier("irc_in_privmsg", "privmsg_modifier_cb", "") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment