Created
September 17, 2014 00:57
-
-
Save cr5315/09fcf183a0ec50e1cc7b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
__module_name__ = "Flashbang" | |
__module_version__ = "1.0" | |
__module_description__ = "Flash, aaahhhh" | |
__author__ = "cr5315" | |
import hexchat as hc | |
PENDING_COMMANDS = [] | |
class Command(object): | |
def __init__(self, command, channel): | |
self.command = command | |
self.channel = channel | |
def go(word, word_eol, userdata): | |
global PENDING_COMMANDS | |
channel = hc.get_info("channel") | |
nick = hc.get_info("nick") | |
command = "cs deop %s %s" % (channel, nick) | |
PENDING_COMMANDS.append(Command(command, channel)) | |
hc.command("cs op %s %s" % (channel, nick)) | |
return hc.EAT_ALL | |
hc.hook_command("go", go) | |
def op(word, word_eol, userdata): | |
print "\00310ChanServ\00301 gives channel operator status to \00312%s" % word[1] | |
if word[0] == "ChanServ" and word[1] == hc.get_info("nick"): | |
global PENDING_COMMANDS | |
channel = hc.get_info("channel") | |
popped_commands = [] | |
for i, command in enumerate(PENDING_COMMANDS): | |
if command.channel == channel: | |
hc.command(command.command) | |
popped_commands.append(command) | |
for i in popped_commands: | |
PENDING_COMMANDS.pop(PENDING_COMMANDS.index(i)) | |
return hc.EAT_ALL | |
hc.hook_print("Channel Operator", op) | |
def clear(word, word_eol, userdata): | |
global PENDING_COMMANDS | |
PENDING_COMMANDS = [] | |
return hc.EAT_ALL | |
hc.hook_command("gclear", clear) | |
def kick(word, word_eol, userdata): | |
if len(word) < 2: | |
print "Please provide a nick to kick." | |
return hc.EAT_ALL | |
global PENDING_COMMANDS | |
if len(word) > 2: | |
command = __get_kick_command(word[1], word[2:]) | |
else: | |
command = __get_kick_command(word[1]) | |
PENDING_COMMANDS.append(Command(command, hc.get_info("channel"))) | |
print "Added command: %s" % command | |
return hc.EAT_ALL | |
hc.hook_command("gkick", kick) | |
def account_ban(word, word_eol, userdata): | |
if len(word) < 2: | |
print "Please provide a nick to ban." | |
return hc.EAT_ALL | |
global PENDING_COMMANDS | |
users = hc.get_list("users") | |
try: | |
for user in users: | |
if user.nick.lower() == word[1].lower(): | |
if user.account == "": | |
print "User isn't logged in, banning IP instead." | |
ip_ban(word, word_eol, userdata) | |
return hc.EAT_ALL | |
else: | |
ban = "mode +b $a:%s" % user.account | |
PENDING_COMMANDS.append(Command(ban, hc.get_info("channel"))) | |
print "Added command: %s" % ban | |
if len(word) > 2: | |
kick_command = __get_kick_command(word[1], word[2:]) | |
else: | |
kick_command = __get_kick_command(word[1]) | |
PENDING_COMMANDS.append(Command(kick_command, hc.get_info("channel"))) | |
print "Added command: %s" % kick_command | |
return hc.EAT_ALL | |
except ValueError: | |
print "Unable to load user list." | |
return hc.EAT_ALL | |
hc.hook_command("ga", account_ban) | |
def host_ban(word, word_eol, userdata): | |
if len(word) < 2: | |
print "Please provide a nick to ban." | |
return hc.EAT_ALL | |
global PENDING_COMMANDS | |
users = hc.get_list("users") | |
try: | |
for user in users: | |
if user.nick.lower() == word[1].lower(): | |
ban = "mode +b %s" % user.host | |
PENDING_COMMANDS.append(Command(ban, hc.get_info("channel"))) | |
print "Added command: %s" % ban | |
if len(word) > 2: | |
kick_command = __get_kick_command(word[1], word[2:]) | |
else: | |
kick_command = __get_kick_command(word[1]) | |
PENDING_COMMANDS.append(Command(kick_command, hc.get_info("channel"))) | |
print "Added command: %s" % kick_command | |
return hc.EAT_ALL | |
except ValueError: | |
print "Unable to load user list." | |
return hc.EAT_ALL | |
hc.hook_command("gh", host_ban) | |
def ip_ban(word, word_eol, userdata): | |
if len(word) < 2: | |
print "Please provide a nick to ban." | |
return hc.EAT_ALL | |
global PENDING_COMMANDS | |
users = hc.get_list("users") | |
try: | |
for user in users: | |
if user.nick.lower() == word[1].lower(): | |
host = user.host | |
ip = host[host.index("@") + 1:] | |
ban = "mode +b *!*@%s" % ip | |
PENDING_COMMANDS.append(Command(ban, hc.get_info("channel"))) | |
print "Added command: %s" % ban | |
if len(word) > 2: | |
kick_command = __get_kick_command(word[1], word[2:]) | |
else: | |
kick_command = __get_kick_command(word[1]) | |
PENDING_COMMANDS.append(Command(kick_command, hc.get_info("channel"))) | |
print "Added command: %s" % kick_command | |
return hc.EAT_ALL | |
except ValueError: | |
print "Unable to load user list." | |
return hc.EAT_ALL | |
hc.hook_command("gip", ip_ban) | |
def __get_kick_command(nick, message=None): | |
if message is not None: | |
return "kick %s %s" % (nick, " ".join(message)) | |
else: | |
return "kick %s" % nick |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment