Skip to content

Instantly share code, notes, and snippets.

@swordfeng
Created February 16, 2017 07:54
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 swordfeng/2aae09b0182b680c4ade05a38e2c9be2 to your computer and use it in GitHub Desktop.
Save swordfeng/2aae09b0182b680c4ade05a38e2c9be2 to your computer and use it in GitHub Desktop.
swordfeng's script for weechat
# 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment