Last active
February 23, 2016 04:15
-
-
Save wolfy1339/67be707cd07cd2f15158 to your computer and use it in GitHub Desktop.
WIP takeover script for hexchat
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
from __future__ import print_function | |
import hexchat | |
__module_name__ = 'Takeover plugin' | |
__module_version__ = "1.0" | |
__module_description__ = 'Python plugin to takeover channels' | |
def chunks(l, n): | |
"""Yield successive n-sized chunks from l.""" | |
for i in range(0, len(l), n): | |
yield l[i:i+n] | |
def getContext(channel=None): | |
return hexchat.find_context(channel=channel) | |
def getData(channel=None): | |
if channel: | |
data = getContext(channel).get_list('users') | |
else: | |
data = hexchat.get_list('users') | |
hosts = [i.host for i in data] | |
users = {} | |
users['hostmasks'] = [] | |
for i in data: | |
if i.nick == mine: | |
pass | |
else: | |
nicks = [i.nick for i in data] | |
users['nicks'] = list(chunks(nicks, 4)) | |
hostmasks = [] | |
for i in list(range(len(hosts))): | |
if hosts[i].find("wolfy1339") != -1: | |
pass | |
else: | |
hostmasks.append("*!*@" + hosts[i].split("@")[1]) | |
users['hostmasks'] = list(chunks(hostmasks, 4)) | |
return users | |
mine = hexchat.get_info('nick') | |
whitelist = ['##takeover'] | |
def ban(channel, users): | |
hexchat.command("MODE {0} +e $a:wolfy1339".format(channel)) | |
for i in list(range(len(users['hostmasks']))): | |
u = " ".join(users['hostmasks'][i]) | |
hexchat.command("MODE {0} +bbbb {1}".format(channel, u)) | |
def deOp(channel, users): | |
# Left here for good ol' sake | |
# for i in list(range(len(users['nicks']))): | |
# u = " ".join(users['nicks'][i]) | |
# hexchat.command("MODE {0} -oooo {1} {2} {3} {4}".format(channel, u)) | |
hexchat.command("DOAT {0} MDEOP".format(channel)) | |
def kick(channel, users): | |
# for i in list(range(len(users['nicks']))): | |
# hexchat.command("DOAT {0} KICK {1}".format(channel, i)) | |
hexchat.command("DOAT {0} MKICK".format(channel)) | |
def main(word, word_eol, userdata): | |
channel = hexchat.get_info('channel') | |
if channel in whitelist and word[1] == "^takeover": | |
data = getData(channel) | |
deOp(channel, data) | |
ban(channel, data) | |
kick(channel, data) | |
return hexchat.EAT_NONE | |
hexchat.hook_print("Channel Message", main) | |
#hexchat.hook_command("TAKEOVER", main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment