Skip to content

Instantly share code, notes, and snippets.

@swordfeng
Created February 16, 2017 07:54
Show Gist options
  • Save swordfeng/2aae09b0182b680c4ade05a38e2c9be2 to your computer and use it in GitHub Desktop.
Save swordfeng/2aae09b0182b680c4ade05a38e2c9be2 to your computer and use it in GitHub Desktop.

Revisions

  1. swordfeng created this gist Feb 16, 2017.
    70 changes: 70 additions & 0 deletions weechat-swutil.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,70 @@
    # Copyright (c) 2014 /cyb/
    #
    # Everyone is permitted to copy and distribute verbatim or modified
    # copies of this license document, and changing it is allowed as long
    # as the name is changed.
    #
    # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
    # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
    #
    # 0. You just DO WHAT THE FUCK YOU WANT TO.

    import weechat as w
    import re

    # Registstration variables.
    SCRIPT_NAME = "swutil"
    SCRIPT_AUTHOR = "swordfeng"
    SCRIPT_VERSION = "0.1"
    SCRIPT_LICENSE = "WTFPL"

    # Registration function.
    w.register(
    SCRIPT_NAME,
    SCRIPT_AUTHOR,
    SCRIPT_VERSION,
    SCRIPT_LICENSE,
    "","",""
    )

    w.hook_config("plugins.var.python." + SCRIPT_NAME + ".*", "config_cb", "")
    w.hook_modifier("weechat_print", "message_cb", "")

    # Script Variables.
    script_options = {
    }

    MOD_CHAR = "��~W"

    # Greentext callback function.
    def message_cb(data, modifier, modifier_data, string):
    try:
    nick, msg = string.split('\t')
    except ValueError, e:
    return string
    # Strip nick of colors, store in a separate var.
    nick = w.string_remove_color(nick,"")

    try:
    if nick == "toxsync":
    # This regex is matching the tox-irc nick convention "(nick) message"
    m = re.search('^\((.+?)\)\s*(.*)', msg)
    nick = w.string_remove_color(m.group(1),"")
    msg = m.group(2)
    except BaseException:
    return string
    try:
    if nick == "teleboto" or nick == "xmppbot":
    m = re.search('^.*?\[(.+?)\]\s*(.*)', msg)
    nick = w.string_remove_color(m.group(1),"")
    msg = m.group(2)
    return "%s%s%s\t%s" % (w.info_get('irc_nick_color', nick), nick, w.color('reset'), msg)
    except BaseException:
    return string

    def config_cb(data, option, value):
    return w.WEECHAT_RC_OK

    for option, default_value in script_options.items():
    if not w.config_is_set_plugin(option):
    w.config_set_plugin(option, default_value)