Created
April 10, 2014 20:13
-
-
Save antonva/10418633 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
#-*- coding: utf-8 -*- | |
# 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. | |
# ToxBot: | |
# ---------- | |
# | |
# Modifies Tox -> IRC relay bot output to avoid confusion. | |
# v 0.1 features: | |
# - Parses names from Bot message and outputs TOX nick as irc nick | |
# with a predefined glyph. | |
# TODO: | |
# - Make config changes via weechat work. (glyph/botname) | |
# - Explore nicklist options and possibly patch the TOX bot (https://github.com/aitjcize/tox-irc-sync/blob/master/tox-irc-sync.py) | |
import weechat as w | |
import re | |
# Registstration variables. | |
SCRIPT_NAME = "ToxBor" | |
SCRIPT_AUTHOR = "azk" | |
SCRIPT_VERSION = "0.1" | |
SCRIPT_LICENSE = "WTFPL" | |
SCRIPT_DESC = "Abstract Tox groupchat bot away from client." | |
# Registration function. | |
w.register( | |
SCRIPT_NAME, | |
SCRIPT_AUTHOR, | |
SCRIPT_VERSION, | |
SCRIPT_LICENSE, | |
SCRIPT_DESC, | |
"","" | |
) | |
w.hook_config("plugins.var.python." + SCRIPT_NAME + ".*", "config_cb", "") | |
w.hook_modifier("weechat_print", "toxbot_cb", "") | |
# Script Variables. | |
script_options = { | |
"bot_name" : "DemoBot", | |
"char" : "✗" | |
} | |
TOX_BOT = script_options["bot_name"] | |
TOX_CHAR = script_options["char"] | |
# Greentext callback function. | |
def toxbot_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. | |
strip_nick = w.string_remove_color(nick,"") | |
# Regex matches on most if not all IRC operator levels. | |
m = re.search('^([@+%~]|)(.*)', strip_nick) | |
strip_nick = m.group(2) | |
if strip_nick == TOX_BOT: | |
# This regex is matching the tox-irc nick convention "[nick]: message" | |
m = re.search('^\[([a-zA-Z0-9]+)(\]:\s*)(.*)', msg) | |
tox_nick = m.group(1) + TOX_CHAR | |
tox_msg = m.group(3) | |
return "%s\t%s" % (tox_nick, tox_msg) | |
else: | |
return string | |
# No idea how tehse two are supposed to work | |
def config_cb(data, option, value): | |
if option == "bot_name": | |
TOX_BOT = value | |
return w.WEECHAT_RC_OK | |
# Run through plugin options, set defaults. | |
for option, default_value in script_options.items(): | |
if not w.config_is_set_plugin(option): | |
if option == "bot_name": | |
TOX_BOT = default_value | |
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