###################################
# RejoinOnRemove v1.0             #
# COPYRIGHTED BY THE MIT LICENSE. #
###################################

import hexchat

__module_name__ = "rejoin"
__module_version__ = "1.0"
__module_description__ = "Rejoins channels you are removed from"

def youpart_cb(word, word_eol, userdata):
    if "requested" in word[3]:
        print '\x031You were removed from \x0322{}\x031, by \x0318{}\x031 (for \x0319{}\x031), rejoining.'.format(word[2],word[3][1:-1].split(" ")[2], word[3][1:-1].split(" ")[3][1:-1])
        hexchat.command("cycle {}".format(word[2]))
    return hexchat.EAT_ALL

hexchat.hook_print("You Part with Reason", youpart_cb)