Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import xchat
- import re
- import random
- __module_name__ = "Bot script"
- __module_version__ = "1.0"
- __module_description__ = "has bot commands"
- # Timer
- def command_timer(userdata):
- if type(userdata) is str:
- xchat.command(userdata)
- else:
- if (len(userdata) > 2):
- thechannel = xchat.find_context(server=userdata[1],channel=userdata[2])
- if thechannel:
- thechannel.command(userdata[0])
- else:
- thechannel = xchat.find_context(channel=userdata[1])
- if thechannel:
- thechannel.command(userdata[0])
- #very bad rate limiter
- wait_timer = 100
- def timer_reset(userdata):
- global wait_timer
- wait_timer -= 2000
- if wait_timer < 100:
- wait_timer = 100
- def send(msg):
- global wait_timer
- timer = wait_timer
- wait_timer += 2000
- xchat.hook_timer(2000, timer_reset)
- if wait_timer > 16000:
- return
- if timer < 5000:
- timer = 100
- xchat.hook_timer(timer, command_timer, msg)
- # All the command functions
- command_list = [ ]
- def command_add(command):
- command_list.append(command)
- echo_botlist = [ "stewiegriffin", "stewiegriffinsub", "t156", "crsbot", "oytaku", "pytaku", "nucbot", "mitch|hater"]
- def command_echo(text, user, server, channel):
- echotext = ""
- stripped = False
- for i in text[1:]:
- if not stripped and user.host != "~wolfy1339@unaffiliated/wolfy1339":
- i = i.lstrip(";+!$@^#%'&.~") #remove bot prefixes and color codes
- for j in echo_botlist: #remove bot names, so !echo can't do commands this way either
- if j in i.lower():
- i = ""
- txt = color_strip(i.lower())
- if len(i) > 0:
- echotext = echotext + i + " "
- stripped = True
- if len(echotext) > 0:
- send(["msg " + channel + " " + echotext, server, channel])
- def command_potato(text, user, server, channel):
- send(["action is a moldy potato", server, channel])
- def command_list2(text, user, server, channel):
- listtext = ""
- for i in command_list:
- if i[3] == "*":
- Enabled = True
- for j in i[4:]:
- if j == channel:
- Enabled = False
- if Enabled:
- if len(listtext):
- listtext += ", "
- listtext += i[0]
- else:
- for j in i[3:]:
- if j == channel:
- if len(listtext):
- listtext += ", "
- listtext += i[0]
- send(["msg " + channel + " " + user.nick + ": " + listtext, server, channel])
- def command_help(text, user, server, channel):
- if len(text) < 2:
- text.append("help")
- for i in command_list:
- if text[1] == i[0].lstrip("*") or text[1] == i[0]:
- send(["msg " + channel + " " + user.nick + ": " + i[2], server, channel])
- return
- def command_enable(text, user, server, channel):
- if len(text) < 2:
- return
- command = text[1]
- if len(text) > 2:
- channel = text[2]
- for i in command_list:
- if command == i[0].lstrip("*") and len(i) > 3:
- if i[3] == "*":
- for j in i[4:]:
- if j == channel:
- i.remove(channel)
- print "enabled " + command
- else:
- for j in i[3:]:
- if j == channel:
- return
- i.append(channel)
- print "enabled " + command
- return
- def command_disable(text, user, server, channel):
- if len(text) < 2:
- return
- command = text[1]
- if len(text) > 2:
- channel = text[2]
- for i in command_list:
- if command == i[0].lstrip("*") and len(i) > 3:
- if i[3] == "*":
- for j in i[4:]:
- if j == channel:
- return
- i.append(channel)
- print "disabled " + command
- else:
- for j in i[3:]:
- if j == channel:
- i.remove(channel)
- print "disabled " + command
- ignore_list = [ "OphalBot", "StewieGriffin", "StewieGriffinSub", "t156", "CrsBot", "MitchBot", "Tribot200", "Bott", "Crackbot", "/bot/", "xsBot", "SexiestBrownie"]
- def command_ignore(text, user, server, channel):
- if len(text) < 2 or "jac" in text[1] or "wolfy" in text[1]:
- return
- if "unignore" in text[0]:
- for i in ignore_list:
- if i == text[1]:
- ignore_list.remove(text[1])
- print "unignored " + text[1]
- return
- else:
- for i in ignore_list:
- if i == text[1]:
- return
- ignore_list.append(text[1])
- print "ignored " + text[1]
- def command_ping(text, user, server, channel):
- send(["msg " + channel + " PONG", server, channel])
- def color_strip(text):
- regex = re.compile("\x03(?:\d{1,2}(?:,\d{1,2})?)?|\x01|\x02|\x09|\x0f|\x13|\x15|\x16|\x1f", re.UNICODE)
- return regex.sub("", text)
- class tempuser:
- nick = ""
- host = ""
- prefix = ""
- def get_user(username, server, channel):
- try:
- if channel is not None:
- thechannel = xchat.find_context(server, channel)
- else:
- thechannel = xchat.get_context()
- except:
- thechannel = channel
- if thechannel:
- thechannel.command("")
- users = thechannel.get_list("users")
- for i in range(len(users)):
- if users[i].nick == username:
- return users[i]
- # Main Main Main Main
- # Main Main Main Main
- # Main Main Main Main
- # Main Main Main Main
- def main(word, word_eol, userdata):
- if len(word) < 2:
- return
- server = xchat.get_info("server")
- channel = xchat.get_info("channel")
- text = word[1].split()
- if len(text) < 1:
- return
- tmpuser = color_strip(word[0])
- user = get_user(tmpuser, server, channel)
- if not user and "#" in channel:
- return
- elif not user:
- user = tempuser()
- user.nick = tmpuser
- user.host = "unknown"
- user.prefix = ""
- for i in ignore_list: #ignore both nicks and hosts
- if user.nick == i or i in user.host:
- return
- command = text[0].lower()
- for i in command_list:
- if command == i[0] and len(i) > 3:
- if i[3] == "*":
- Enabled = True
- for j in i[3:]:
- if channel == j and not "wolfy" in user.nick and not "1" in user.nick:
- Enabled = False
- if Enabled:
- i[1](text, user, server, channel)
- else:
- commandEnabled = False
- for j in i[3:]:
- if channel == j or j == "*" or "wolfy" in user.nick or "1" in user.nick:
- commandEnabled = True
- if commandEnabled:
- i[1](text, user, server, channel)
- command_add(["*echo", command_echo, "Repeats text", "##powder-bots"])
- command_add(["*potato", command_potato, "I'm a moldy potato", "##powder-bots"])
- command_add(["*list", command_list2, "Lists all commands available in the channel", "*"])
- command_add(["*help", command_help, "(!help <command>) Shows help for a command", "*"])
- command_add(["*enable", command_enable, "Enables a command", ""])
- command_add(["*disable", command_disable, "Disables a command", ""])
- command_add(["*ignore", command_ignore, "Ignores a user", ""])
- command_add(["*unignore", command_ignore, "Unignores a user", ""])
- command_add(["*ping", command_ping, "PONG", "*"])
- # Hooks
- def hook_unload(text, user, server, channel):
- xchat.unhook(hooks[0])
- xchat.unhook(hooks[1])
- xchat.unhook(hooks[2])
- xchat.unhook(hooks[3])
- xchat.unhook(hooks[4])
- xchat.unhook(hooks[5])
- xchat.unhook(hooks[6])
- print("*** Unloaded script")
- def hook_unload2(userdata):
- hook_unload("", "", "", "")
- command_add(["*panic", hook_unload, "panic and disable all hooks", ""])
- hooks = [ ]
- hooks.append(xchat.hook_print("Channel Message", main))
- hooks.append(xchat.hook_print("Channel Msg Hilight", main))
- hooks.append(xchat.hook_print("Channel Action", main))
- hooks.append(xchat.hook_print("Channel Action Hilight", main))
- hooks.append(xchat.hook_print("Your Message", main))
- hooks.append(xchat.hook_print("Your Action", main))
- hooks.append(xchat.hook_unload(hook_unload2))
- random.seed()
- print ("*** Loaded script")
Advertisement
Add Comment
Please, Sign In to add comment