jacob614

hexchat python plugin

Feb 4th, 2013
1,560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 31.97 KB | None | 0 0
  1. import xchat
  2. import re
  3. import random
  4. import unicodedata
  5. import httplib
  6.  
  7. __module_name__ = "Jacob1's plugin"
  8. __module_version__ = "1.0"
  9. __module_description__ = "All my commands"
  10.  
  11. #do not directly copy everything in this script, but you can use any part of it if you really want .....
  12.  
  13. # Timer
  14. def command_timer(userdata):
  15.     mynick = xchat.get_info("nick")
  16.     byte_limit = 469-len(mynick) #463
  17.     myhost = get_user(mynick, xchat.get_info("server"), "#powder")
  18.     if not myhost:       #this is written badly I know ... I know a better way to fix it but it doesn't really matter ...
  19.         myhost = get_user(mynick, xchat.get_info("server"), "##powder-bots")
  20.     if not myhost:
  21.         myhost = get_user(mynick, xchat.get_info("server"), "##jacob1")
  22.     if myhost and myhost.host:
  23.         byte_limit = 499-len(mynick) - len(myhost.host)
  24.     if type(userdata) is str:
  25.         send = userdata[0:byte_limit]
  26.         if re.match(".*moo+ $", color_strip(send)):
  27.             send = send + "." #moo
  28.         xchat.command(send)
  29.     else:
  30.         send = userdata[0][0:byte_limit]
  31.         if re.match(".*moo+$", color_strip(send)):
  32.             send = send + "."
  33.         if (len(userdata) > 2):
  34.             thechannel = xchat.find_context(server=userdata[1],channel=userdata[2])
  35.             if thechannel:
  36.                 thechannel.command(send)
  37.         else:
  38.             thechannel = xchat.find_context(channel=userdata[1])
  39.             if thechannel:
  40.                 thechannel.command(send)
  41.  
  42. #this is the only way I can make this work
  43. wait_timer = [ ]
  44. wait_timer.append(100)
  45.  
  46. def timer_reset(userdata):
  47.     wait_timer[0] -= 2000
  48.     if wait_timer[0] < 100:
  49.         wait_timer[0] = 100
  50.  
  51. def send(msg):
  52.     timer = wait_timer[0]
  53.     wait_timer[0] += 2000
  54.     xchat.hook_timer(2000, timer_reset)
  55.     if wait_timer[0] > 16000:
  56.         return
  57.     if timer < 5000:
  58.         timer = 100
  59.     xchat.hook_timer(timer, command_timer, msg)
  60.  
  61. def isowner(user):
  62.     if user and (user.host == "~jacob1@Powder/Developer/jacob1" or user.host == "[email protected]"):#or user.host == "[email protected]"):
  63.         #print("owner")
  64.         return True
  65.     #print("not owner")
  66.     return False
  67.  
  68. trusted_hostmasks = ["~jacob1@Powder/Developer/jacob1", "~meow@Powder/Developer/cracker64", "jacksonmj@2a01:7e00::f03c:91ff:fedf:890f", "~Triclops2@Powder/Developer/Triclops200", "~Ximon@Powder/Developer/Simon", "antb@Powder/Staff/Xenocide"]
  69. def istrusted(user):
  70.     if not user:
  71.         return False
  72.     for i in trusted_hostmasks:
  73.         if user.host == i:
  74.             return True
  75.     return False
  76.  
  77. # All the command functions
  78. command_list = [ ]
  79.  
  80. def command_add(command):
  81.     command_list.append(command)
  82.  
  83. badwords_list = [ ]
  84. #badwords_list = [ "^\.$", "Stop saying that" ]
  85. #badwords_list = [ "yolo", "#YOLO", "nigger", "Don't be racist", "nigga", "Don't be racist", "dong", "you know why."]
  86. badwords_timers = []
  87. def command_badwordsearch(text, user, server, channel):
  88.     if istrusted(user):
  89.         return
  90.     for i in text:
  91.         word = color_strip(i.lower())
  92.         for j in range(len(badwords_list)):
  93.             if not j%2 and len(badwords_list[j]) > 2:
  94.                 if badwords_list[j] in word or re.match(badwords_list[j], word):
  95.                     #send([ "action kicks " + user.nick, server, channel ])
  96.                     timer = 20
  97.                     for k in badwords_timers:
  98.                         if user.host == k:
  99.                             timer += 20
  100.                         elif user.nick == k:
  101.                             timer += 20
  102.  
  103.                     toban = user.nick
  104.                     if user.host:
  105.                         badwords_timers.append(user.host)
  106.                         toban = user.host
  107.                     else:
  108.                         badwords_timers.append(user.nick)
  109.  
  110.  
  111.                     user_kick(user.nick, server, channel, "Badwords auto ban: " + badwords_list[j+1])
  112.                     if do_ban("+b", 0, toban, server, channel) == 1:
  113.                         do_ban("-b", timer*1000, toban, server, channel)
  114.                     return
  115.  
  116. def command_badwords(text, user, server, channel):
  117.     if not istrusted(user):
  118.         send("notice " + user.nick + " Error: you cannot use this command")
  119.         return
  120.     if channel == "##powder-bots" and text[0] == "$badwords":
  121.         return
  122.     if len(text) < 2:
  123.         text.append("badwords")
  124.         command_help(text, user, server, channel)
  125.         return
  126.     if text[1] == "list":
  127.         for i in range(len(badwords_list)):
  128.             if not i%2:
  129.                 message = badwords_list[i]
  130.                 length = len(badwords_list[i])
  131.                 if length < 20:
  132.                     for j in range(20-length):
  133.                         message = message + " "
  134.                 send(["notice " + user.nick + " " + message + " Reason: " + badwords_list[i+1], server, channel])
  135.     elif text[1] == "remove" and len(text) > 2:
  136.         for i in range(len(badwords_list)):
  137.             if not i%2:
  138.                 if badwords_list[i] == text[2]:
  139.                     badwords_list.pop(i+1)
  140.                     badwords_list.pop(i)
  141.                     send(["notice " + user.nick + " " + text[2] + " was removed from the list", server, channel])
  142.                     return
  143.     elif text[1] == "add" and len(text) > 2:
  144.         for i in range(len(badwords_list)):
  145.             if not i%2:
  146.                 if badwords_list[i] == text[2]:
  147.                     send(["notice " + user.nick + " " + text[2] + " is already in the list", server, channel])
  148.                     return
  149.         badwords_list.append(text[2])
  150.         if len(text) > 3:
  151.             reason = ""
  152.             for i in text[3:]:
  153.                 reason = reason + i + " "
  154.             badwords_list.append(reason)
  155.         else:
  156.             badwords_list.append("Don't say " + text[2])
  157.         send(["notice " + user.nick + " " + text[2] + " was added to the list", server, channel])
  158.     elif text[1] == "clear":
  159.         while badwords_list:
  160.             badwords_list.pop()
  161.     else:
  162.         text[1] = "badwords"
  163.         command_help(text, user, server, channel)
  164.  
  165. echo_banned = ["prequels" , "yolo" , "hugelistofotherbadwordsi'mnotposting"]
  166. echo_regex_banned = [ "^f+a+g", "ni+g+[a|e+r]", "p[0|o]rn", "pr[0|o]n", "p[e|ae|3]+n+[i|1]+s", "^ass$", "^asshole$", "^homo$", ".*\+\+$", ".*\-\-$"]
  167. echo_botlist = [ "stewiegriffin", "stewiegriffinsub", "t156", "crsbot", "oytaku", "pytaku", "nucbot", "mitch|hater", "thebotmaker"]
  168. def command_echo(text, user, server, channel):
  169.     echotext = ""
  170.     stripped = False
  171.     for i in text[1:]:
  172.         if not stripped:# and not isowner(user):
  173.             nocolor = color_strip(color_strip(i))
  174.             nobot = nocolor.lstrip(";+!$@^#%'&./~?\\")
  175.             if i != nocolor and nobot != nocolor:
  176.                 i = " " + i
  177.             else:
  178.                 i = i.lstrip(";+!$@^#%'&./~?\\\x01") #remove bot prefixes and color codes
  179.            
  180.             for j in echo_botlist: #remove bot names, so !echo can't do commands this way either
  181.                 if j in i.lower():
  182.                     i = ""
  183.         txt = color_strip(i.lower())
  184.         if txt == "alot":
  185.             i = "a lot"
  186.         banned = False
  187.         for j in echo_banned:
  188.             if j in txt:
  189.                 banned = True
  190.         if not banned:
  191.             for j in echo_regex_banned:
  192.                 if re.match(j, txt):
  193.                     banned = True
  194.         #if isowner(user):
  195.         #    banned = False
  196.         if not banned and len(i) > 0:
  197.             echotext = echotext + i + " "
  198.             stripped = True
  199.     #if re.match(".*mo+ $", echotext):
  200.     #    echotext = echotext.rstrip() + "."
  201.     if len(echotext) > 0 and not "is no longer away" in echotext and not "is away:" in echotext and not "!py" in echotext and not " ‮" in echotext and not "⃧" in echotext:
  202.         send(["msg " + channel + " " + echotext.rstrip(), server, channel])
  203.  
  204. def command_mod(text, user, server, channel):
  205.     send(["msg " + channel + " " + user.nick + ": http://tpt.io/:11117", server, channel])
  206.  
  207. def command_ban(text, user, server, channel):
  208.     if istrusted(user):
  209.         try:
  210.             timer = int(text[2])
  211.         except:
  212.             timer = 0
  213.         do_ban("+b", 0, text[1], server, channel)
  214.         if timer > 0:
  215.             send(["notice " + user.nick + " " + text[1] + " has been banned for " + str(timer) + " seconds", server, channel])
  216.             do_ban("-b", 400+timer*1000, text[1], server, channel)
  217.  
  218. def command_unban(text, user, server, channel):
  219.     if istrusted(user):
  220.         do_ban("-b", 0, text[1], server, channel)
  221.  
  222. def command_stab(text, user, server, channel):
  223.     if istrusted(user):
  224.         timer = 0
  225.         try:
  226.             timer = int(text[2])
  227.         except:
  228.             timer = random.randint(60, 600)
  229.         do_ban("+q", 0, text[1], server, channel)
  230.         if timer > 0:
  231.             send(["notice " + user.nick + " " + text[1] + " has been quieted for " + str(timer) + " seconds", server, channel])
  232.             do_ban("-q", 400+timer*1000, text[1], server, channel)
  233.  
  234. def command_unstab(text, user, server, channel):
  235.     if istrusted(user):
  236.         do_ban("-q", 0, text[1], server, channel)
  237.  
  238. def command_potato(text, user, server, channel):
  239.     if user.nick == "DrNublet":
  240.         send(["action slaps DrNublet with a sack of potatoes", server, channel])
  241.     else:
  242.         send(["action is a potato", server, channel])
  243.  
  244. def command_list2(text, user, server, channel):
  245.     listtext = ""
  246.     for i in command_list:
  247.         if i[3] == "*":
  248.             Enabled = True
  249.             for j in i[4:]:
  250.                 if j == channel:
  251.                     Enabled = False
  252.             if Enabled:
  253.                 if len(listtext):
  254.                     listtext += ", "
  255.                 listtext += i[0]
  256.         else:
  257.             for j in i[3:]:
  258.                 if j == channel:
  259.                     if len(listtext):
  260.                         listtext += ", "
  261.                     listtext += i[0]
  262.     send(["msg " + channel + " " + user.nick + ": " + listtext, server, channel])
  263.  
  264. def command_help(text, user, server, channel):
  265.     if len(text) < 2:
  266.         text.append("help")
  267.     for i in command_list:
  268.         if text[1] == i[0].lstrip("!"):
  269.             send(["msg " + channel + " " + user.nick + ": " + i[2], server, channel])
  270.     if (text[1].lower() == "me"):
  271.         send(["msg " + channel + " " + user.nick + ": Help is on the way. It will arrive in approximately 2-3 hours", server, channel])
  272.     return
  273.  
  274. def command_enable(text, user, server, channel):
  275.     if len(text) < 2:
  276.         return
  277.     command = text[1]
  278.     if len(text) > 2:
  279.         channel = text[2]
  280.     for i in command_list:
  281.         if command == i[0].lstrip("!") and len(i) > 3:
  282.             if i[3] == "*":
  283.                 for j in i[4:]:
  284.                     if j == channel:
  285.                         i.remove(channel)
  286.             else:
  287.                 for j in i[3:]:
  288.                     if j == channel:
  289.                         return
  290.                 i.append(channel)
  291.             return
  292.  
  293. def command_disable(text, user, server, channel):
  294.     if len(text) < 2:
  295.         return
  296.     command = text[1]
  297.     if len(text) > 2:
  298.         channel = text[2]
  299.     for i in command_list:
  300.         if command == i[0].lstrip("!") and len(i) > 3:
  301.             if i[3] == "*":
  302.                 for j in i[4:]:
  303.                     if j == channel:
  304.                         return
  305.                 i.append(channel)
  306.             else:
  307.                 for j in i[3:]:
  308.                     if j == channel:
  309.                         i.remove(channel)
  310.  
  311. ignore_list = [ "OphalBot", "StewieGriffin", "StewieGriffinSub", "t156", "CrsBot",
  312.                 "MitchBot", "Tribot200", "Bott", "Crackbot", "/bot/",
  313.                 "SexiestBrownie", "Mitch|hater", "TheBotMaker", "boxnode", "guffaw", "ErEnUa",
  314.                 "MitchSupy", "HaliteBot", "KELVINBOT", "boxmini", "iamscript", "boxnode"]
  315. def command_ignore(text, user, server, channel):
  316.     if len(text) < 2 or "jacob1" in text[1]:
  317.         return
  318.     if "unignore" in text[0]:
  319.         for i in ignore_list:
  320.             if i == text[1]:
  321.                 ignore_list.remove(text[1])
  322.                 return
  323.     else:
  324.         for i in ignore_list:
  325.             if i == text[1]:
  326.                 return
  327.         ignore_list.append(text[1])
  328.  
  329. def command_ping(text, user, server, channel):
  330.     send(["msg " + channel + " PONG", server, channel])
  331.  
  332. def command_test(text, user, server, channel):
  333.     try:
  334.         con = httplib.HTTPConnection( "mniip.com",80)
  335.         con.request("GET", "/bot.lua?msg=" + text[1])
  336.         con.close()
  337.     except Exception as e:
  338.         xchat.command("say Error while connecting to xsBot.")
  339.         print e
  340.  
  341. def command_vote(text, user, server, channel):
  342.     if len(text) < 2:
  343.         text.append("vote")
  344.         command_help(text, user, server, channel)
  345.         return
  346.     if text[1] == "init":
  347.         if istrusted(user):
  348.             global votes
  349.             votes = []
  350.     if text[1] == "start":
  351.         try:
  352.             if not istrusted(user):
  353.                 send(["notice " + user.nick + " You cannot start votes", server, channel])
  354.                 return
  355.             elif len(votes):
  356.                 send(["notice " + user.nick + " There is already a vote going on", server, channel])
  357.                 return
  358.             elif len(text) < 3:
  359.                 command_help(text, user, channel)
  360.                 return
  361.         except:
  362.             send(["notice " + user.nick + " Error: the script is broken, do !vote init", server, channel])
  363.             return
  364.         votereason = ""
  365.         for i in text[2:]:
  366.             votereason = votereason + i + " "
  367.         votes = []
  368.         votes.append(votereason)
  369.         votes.append(0)
  370.         votes.append(0)
  371.         send(["msg " + channel + " Current vote: " + votes[0], server, channel])
  372.     elif text[1] == "end":
  373.         if len(votes):
  374.             if istrusted(user):
  375.                 send(["msg " + channel + " Vote ended. Votes yes: " + str(votes[1]) + " Votes no: " + str(votes[2]), server, channel])
  376.                 votes = []
  377.             else:
  378.                 send(["notice " + user.nick + " You cannot end votes", server, channel])
  379.         else:
  380.             send(["msg " + channel + " There is no vote going on right now", server, channel])
  381.     elif text[1] == "yes":
  382.         if len(votes):
  383.             for i in votes[3:]:
  384.                 if i == user.nick or i == user.host:
  385.                     send(["notice " + user.nick + " You have already voted", server, channel])
  386.                     return
  387.             votes[1] = votes[1] + 1
  388.             votes.append(user.nick)
  389.             votes.append(user.host)
  390.             send(["notice " + user.nick + " You voted yes", server, channel])
  391.         else:
  392.             send(["msg " + channel + " There is no vote going on right now", server, channel])
  393.     elif text[1] == "no":
  394.         if len(votes):
  395.             for i in votes[3:]:
  396.                 if i == user.nick or i == user.host:
  397.                     send(["notice " + user.nick + " You have already voted", server, channel])
  398.                     return
  399.             votes[2] = votes[2] + 1
  400.             votes.append(user.nick)
  401.             votes.append(user.host)
  402.             send(["notice " + user.nick + " You voted no", server, channel])
  403.         else:
  404.             send(["msg " + channel + " There is no vote going on right now", server, channel])
  405.     elif text[1] == "moo":
  406.         if len(votes):
  407.             send(["msg " + channel + " mooooo", server, channel])
  408.     elif text[1] == "info":
  409.         if len(votes):
  410.             send(["msg " + channel + " Current vote: " + votes[0], server, channel])
  411.         else:
  412.             send(["msg " + channel + " There is no vote going on right now", server, channel])
  413.     else:
  414.         text[1] = "vote"
  415.         command_help(text, user, server, channel)
  416.     return
  417.  
  418. sgs_info = [False, 0, "jacob1", "hobana.freenode.net", "##jacob1", "Error: this shouldn't be printed here"]
  419. def command_sgs(text, user, server, channel):
  420.     if len(text) < 2:
  421.         text.append("sgs")
  422.         command_help(text, user, server, channel)
  423.         return
  424.     if sgs_info[0] == True:
  425.         send(["notice " + user.nick + " Error: only one !sgs can be done at a time", server, channel])
  426.         return
  427.     whitelist = ["apropos", "at", "balls", "banmask", "base", "binary","browse",
  428.                  "calc", "coin", "comic", "convert", "ctime", "ctof", "define",
  429.                  "dice", "dict", "eightball", "elapsed", "fight", "ftoc",
  430.                  "geoip", "git", "google", "help", "hostmask", "insult", "isup",
  431.                  "justme", "karma", "kicked", "lucky", "monologue", "network",
  432.                  "ping", "pirate", "profile", "rand", "random", "randomsave",
  433.                  "rpn", "save", "seconds", "server", "time", "until", "wolf",
  434.                  "yarn" ]
  435.     whitelistspam = ["aol", "bold", "capitalize", "cmd", "color", "colorize",
  436.                      "commands",  "concat", "cpu", "cut", "field", "flip",
  437.                      "format", "gnu", "hebrew", "hexlify", "jeffk", "last",
  438.                      "leet", "list", "lithp", "lower", "ls", "moo", "moomoo",
  439.                      "more", "morse", "net", "rainbow", "repr",
  440.                      "reverse", "rot13", "scramble", "seen", "shrink", "source",
  441.                      "spellit", "squish", "stats", "status", "stripcolor",
  442.                      "suppa1337", "threads", "title", "underline", "undup",
  443.                      "unhexlify", "units", "unuid", "unmorse", "upper", "uptime",
  444.                      "version" ]
  445.     command = ""
  446.     text[1] = text[1].lstrip("$")
  447.     if text[1] == "balls":
  448.         text[1] = "karma"
  449.     elif text[1] == "ctof":
  450.         text[1] = "calc"
  451.         text.append("* 1.8 + 32")
  452.     elif text[1] == "flip":
  453.         text[1] = "unuid"
  454.     elif text[1] == "ftoc":
  455.         text[1] = "rpn"
  456.         text.append("32 - 1.8 /")
  457.     elif text[1] == "isup":
  458.         text[1] = "justme"
  459.     elif text[1] == "ls":
  460.         text[1] = "list"
  461.     elif text[1] == "moo":
  462.         text = ["!sgs", "rainbow moomoomoomoomoomoomoo"]
  463.     elif text[1] == "moomoo":
  464.         text = ["!sgs", "reverse oom oom"]
  465.     elif text[1] == "pirateinsult":
  466.         text[1] = "pirate {insult "
  467.         text.append("}")
  468.     elif text[1] == "randominsult":
  469.         text = ["!sgs", "stripcolor you are nothing but a {random 2} little {random}, go {random} in a {random}"]
  470.     elif text[1] == "save":
  471.         text[1] = "browse"
  472.     elif text[1] == "geoip" and len(text) > 2:
  473.         tempuser = get_user(text[2], server, channel)
  474.         if tempuser:
  475.             text[2] = tempuser.host
  476.     elif text[1] == "commands" or text[1] == "more":
  477.         if channel != "#powder":
  478.             sortedlist = sorted(whitelist + whitelistspam)
  479.             output = ""
  480.             if text[1] == "commands":
  481.                 for i in range(len(sortedlist)/2):
  482.                     output = output + sortedlist[i] + ", "
  483.                 output = output.rstrip(", ") + " (1 more message)"
  484.             else:
  485.                 for i in range(len(sortedlist)):
  486.                     if i >= len(sortedlist)/2:
  487.                         output = output + sortedlist[i] + ", "
  488.                 output = output.rstrip(", ")
  489.             send(["msg " + channel + " " + user.nick + ": " + output, server, channel])
  490.             return
  491.     else:
  492.         allowed = False
  493.         for i in whitelist:
  494.             if text[1] == i:
  495.                 allowed = True
  496.                 break
  497.         if not allowed and channel != "#powder":
  498.             for i in whitelistspam:
  499.                 if text[1] == i:
  500.                     allowed = True
  501.                     break
  502.         if not allowed and not isowner(user):
  503.             send(["msg " + channel + " Error: This command is not in the whitelist", server, channel])
  504.             return
  505.     for i in text[1:]:
  506.         if ("{" in i or "}" in i) and not isowner(user):
  507.             send(["msg " + channel + " Error: You cannot use '{' or '}' yet", server, channel])
  508.             return
  509.         command = command + i + " "
  510.     sgs_info[0] = True
  511.     sgs_info[1] = sgs_info[1] + 1
  512.     sgs_info[2] = user.nick
  513.     sgs_info[3] = server
  514.     sgs_info[4] = channel
  515.     sgs_info[5] = "Error: no response"
  516.     for channel in xchat.get_list('channels'):
  517.         if "freenode" in channel.server and channel.channel == "##powder-bots" and get_user("StewieGriffinSub", channel.server, channel.channel):
  518.             send(["msg StewieGriffinSub " + command, channel.server, channel.channel])
  519.             break
  520.     xchat.hook_timer(10000, sgs_timeout, sgs_info[1])
  521.  
  522. def notice_hook(word, word_eol, userdata):
  523.     if sgs_info[0] == True and word[0] == "StewieGriffinSub":
  524.         sgs_info[0] = False
  525.         text = word[1].split()
  526.         if len(text) < 1:
  527.             return
  528.         output = ""
  529.         output2 = ""
  530.         output3 = ""
  531.         for i in text:
  532.             banned = False
  533.             for j in echo_banned:
  534.                 if j in i.lower():
  535.                     banned = True
  536.             if not banned:
  537.                 for j in echo_regex_banned[:-2]:
  538.                     if re.match(j, i.lower()):
  539.                         banned = True
  540.             if sgs_info[4] == "###xsbot":
  541.                 if "http" in i:
  542.                     i = i[1:len(i)-2]
  543.             if not banned:
  544.                 if sgs_info[4] != "###xsbot" or len(output) + len(i) < 92:
  545.                     output = output + i + " "
  546.                 elif sgs_info[4] != "###xsbot" or len(output2) + len(i) < 100:
  547.                     output2 = output2 + i + " "
  548.                 else:
  549.                     output3 = output3 + i + " "
  550.         if sgs_info[4] == "###xsbot":
  551.             output = "result: " + output
  552.         elif sgs_info[2] != "jacob1":
  553.             output = sgs_info[2] + ": " + output
  554.         if len(output):
  555.             send(["msg " + sgs_info[4] + " " + output.rstrip(), sgs_info[3], sgs_info[4]])
  556.         if len(output2):
  557.             send(["msg " + sgs_info[4] + " ... " + output2.rstrip(), sgs_info[3], sgs_info[4]])
  558.         if len(output3):
  559.             send(["msg " + sgs_info[4] + " ... " + output3.rstrip(), sgs_info[3], sgs_info[4]])
  560.         return xchat.EAT_XCHAT
  561.  
  562. def sgs_timeout(userdata):
  563.     if sgs_info[0] == True and userdata == sgs_info[1]:
  564.         sgs_info[0] = False
  565.         send(["msg " + sgs_info[4] + " " + sgs_info[2] + ": Error: no response", sgs_info[3], sgs_info[4]])
  566.  
  567. def command_hostmask(text, user, server, channel):
  568.     if len(text) < 2:
  569.         send(["msg " + channel+ " " + user.nick + ": " + user.host, server, channel])
  570.     else:
  571.         tempuser = get_user(text[1], server, channel)
  572.         if tempuser:
  573.             send(["msg " + channel+ " " + user.nick + ": " + tempuser.host, server, channel])
  574.         else:
  575.             send(["msg " + channel+ " " + user.nick + ": user not found", server, channel])
  576.  
  577. # Random useful functions
  578. def get_bot(server, channel):
  579.     #xchat.find_context(server, channel)
  580.     bot = get_user("StewieGriffin", server, channel)
  581.     if bot == None or bot.prefix == None or bot.prefix == "+":
  582.         bot = get_user("StewieGriffinSub", server, channel)
  583.     if bot == None or bot.prefix == None or bot.prefix == "+":
  584.         bot = get_user("Otaku", server, channel)
  585.     if bot == None or bot.prefix == None or bot.prefix == "+":
  586.         return None
  587.     return bot
  588.  
  589. def do_ban(mode, timer, user, server, channel):
  590.     banuser = get_user(user, server, channel)
  591.     jacob1 = get_user("jacob1", server, channel)
  592.     bot = get_bot(server, channel)
  593.     if banuser:
  594.         if "+" in mode and (istrusted(banuser) or banuser.host is "~Stewie@Powder/Bot/StewieGriffin"):
  595.             print("Error: will not ban " + user)
  596.             return 0
  597.         toban = banuser.nick
  598.         if banuser.host:
  599.             toban = banuser.host
  600.     else:
  601.         toban = user
  602.     if "+" in mode and "jacob1" in toban:
  603.         print("Error: will not ban jacob1")
  604.         return 0
  605.     if jacob1 and jacob1.prefix and jacob1.prefix != "+":
  606.         xchat.hook_timer(timer, command_timer, ["mode " + channel + " " + mode + " " + toban, server, channel])
  607.         return 1
  608.     elif bot and bot.prefix and bot.prefix != "+":
  609.         xchat.hook_timer(timer, command_timer, ["msg " + bot.nick + " mode " + channel + " " + mode + " " + toban, server, channel])
  610.         return 1
  611.     print("Error: cannot ban " + user)
  612.     return 0
  613.  
  614. def user_kick(user, server, channel, message):
  615.     tokick = get_user(user, server, channel)
  616.     jacob1 = get_user("jacob1", server, channel)
  617.     bot = get_bot(server, channel)
  618.    
  619.     if tokick and not istrusted(tokick) and not "jacob1" in tokick.nick:
  620.         xchat.command("gui flash")
  621.         xchat.command("gui color 3")
  622.         if jacob1 and jacob1.prefix and jacob1.prefix != "+":
  623.             send(["kick " + tokick.nick + " " + message, server, channel])
  624.             return 1
  625.         elif bot and bot.prefix and bot.prefix != "+":
  626.             send(["msg " + bot.nick + " kick " + channel + " " + tokick.nick + " " + message, server, channel])
  627.             return 1
  628.     print("Error: cannot kick " + user)
  629.     return 0
  630.            
  631. def color_strip(text):
  632.     regex = re.compile("\x03(?:\d{1,2}(?:,\d{1,2})?)?|\x01|\x02|\x09|\x0f|\x13|\x15|\x16|\x1d|\x1f", re.UNICODE)
  633.     return regex.sub("", text)
  634.  
  635. class tempuser:
  636.     nick = ""
  637.     host = ""
  638.     prefix = ""
  639.  
  640. def get_user(username, server, channel):
  641.     try:
  642.         if channel is not None:
  643.             thechannel = xchat.find_context(server, channel)
  644.         else:
  645.             thechannel = xchat.get_context()
  646.     except:
  647.         thechannel = channel
  648.     if thechannel:
  649.         thechannel.command("")
  650.         users = thechannel.get_list("users")
  651.         for i in range(len(users)):
  652.             if users[i].nick == username:
  653.                 return users[i]
  654.  
  655. # Main Main Main Main
  656. # Main Main Main Main
  657. # Main Main Main Main
  658. # Main Main Main Main
  659. def main(word, word_eol, userdata):
  660.     if len(word) < 2:
  661.         return
  662.     #if xchat.get_info("network") != "wolfznc" and xchat.get_info("network") != "iota": # a fix for it doing commands twice when commected twice
  663.     #    return
  664.     server = xchat.get_info("server")
  665.     channel = xchat.get_info("channel")
  666.     text = word[1].split()
  667.     if channel == "###xsbot" and "<" in text[0] and ">" in text[0]:
  668.         text.pop(0)
  669.     if len(text) < 1:
  670.         return
  671.     jacob1 = get_user(xchat.get_info("nick"), server, channel)
  672.     if (channel == "#powder" or channel == "##powder-bots" or channel == "##jacob1") and not jacob1.prefix:
  673.         return
  674.    
  675.     tmpuser = color_strip(word[0])
  676.     user = get_user(tmpuser, server, channel)
  677.     if not user and "#" in channel:
  678.         return
  679.     elif not user:
  680.         user = tempuser()
  681.         user.nick = tmpuser
  682.         if tmpuser == xchat.get_info("nick"):
  683.             user.host = "~jacob1@Powder/Developer/jacob1"
  684.         else:
  685.             user.host = "unknown"
  686.         user.prefix = ""
  687.     for i in ignore_list: #ignore both nicks and hosts
  688.         if user.nick == i or i in user.host:
  689.             return
  690.     #if not isowner(user):
  691.     #    return
  692.  
  693.     command = text[0].lower()
  694.     for i in command_list:
  695.         if (command == i[0] or i[0] == "*") and len(i) > 3:
  696.             if i[3] == "*":
  697.                 Enabled = True
  698.                 for j in i[3:]:
  699.                     if channel == j and not isowner(user):
  700.                         Enabled = False
  701.                 if Enabled:
  702.                     i[1](text, user, server, channel)
  703.             else:
  704.                 commandEnabled = False
  705.                 for j in i[3:]:
  706.                     if channel == j or j == "*" or isowner(user):
  707.                         commandEnabled = True
  708.                 if commandEnabled:
  709.                     i[1](text, user, server, channel)
  710.  
  711. command_add(["*", command_badwordsearch, "Searches all messages for badwords", "##powder-bots"])
  712. command_add(["!echo", command_echo, "Repeats text", "##powder-bots", "#botters", "##jacob1", "##boxmein", "#chat"])
  713. command_add(["!mod", command_mod, "Gives a link to jacob1's Mod", "*"])
  714. command_add(["!ban", command_ban, "(!ban <nick|hostmask> [<length>]) Bans a user", "#powder", "##powder-bots", "##jacob1"])
  715. command_add(["!unban", command_unban, "(!unban <nick|hostmask>) Unbans a user", "#powder", "##powder-bots", "##jacob1"])
  716. command_add(["!stab", command_stab, "(!stab <nick|hostmask> [<length>]) Quiets a user", "#powder", "##powder-bots", "##jacob1"])
  717. command_add(["!unstab", command_unstab, "(!unstab <nick|hostmask>) Unquiets a user", "#powder", "##powder-bots", "##jacob1"])
  718. command_add(["$ban", command_ban, "($ban <nick|hostmask> [<length>]) Bans a user", "#powder"])
  719. command_add(["$unban", command_unban, "($unban <nick|hostmask>) Unbans a user", "#powder"])
  720. command_add(["$stab", command_stab, "($stab <nick|hostmask> [<length>]) Quiets a user", "#powder"])
  721. command_add(["$unstab", command_unstab, "($unstab <nick|hostmask>) Unquiets a user", "#powder"])
  722. command_add(["!badwords", command_badwords, "(!badwords list|add|remove|clear [<word>])", "##powder-bots"])
  723. command_add(["$badwords", command_badwords, "($badwords list|add|remove|clear [<word>])", ""])
  724. command_add(["!potato", command_potato, "I'm a potato", "##powder-bots", "##jacob1", "#chat"])
  725. command_add(["!list", command_list2, "Lists all commands available in the channel", "*", "##TPT-DieWelle"])
  726. command_add(["!help", command_help, "(!help <command>) Shows help for a command", "*", "##TPT-DieWelle"])
  727. command_add(["!enable", command_enable, "Enables a command, jacob1 only", ""])
  728. command_add(["!disable", command_disable, "Disables a command, jacob1 only", ""])
  729. command_add(["!ignore", command_ignore, "Ignores a user, jacob1 only", ""])
  730. command_add(["!unignore", command_ignore, "Unignores a user, jacob1 only", ""])
  731. command_add(["!ping", command_ping, "PONG", "*", "##TPT-DieWelle"])
  732. command_add(["!vote", command_vote, "(!vote yes|no|start|end|info)", "*"])
  733. command_add(["!sgs", command_sgs, "sends a command to StewieGriffinSub to be run", "*", "#powder"])
  734. command_add(["!hostmask", command_hostmask, "returns your hostmask", "*"])
  735.  
  736. command_add(["!test", command_test, "random command for testing", ""])
  737.  
  738. # Hooks
  739. def hook_unload(text, user, server, channel):
  740.     xchat.unhook(hooks[0])
  741.     xchat.unhook(hooks[1])
  742.     xchat.unhook(hooks[2])
  743.     xchat.unhook(hooks[3])
  744.     xchat.unhook(hooks[4])
  745.     xchat.unhook(hooks[5])
  746.     xchat.unhook(hooks[6])
  747.     xchat.unhook(hooks[7])
  748.     xchat.unhook(hooks[8])
  749.     xchat.unhook(hooks[9])
  750.     xchat.unhook(hooks[10])
  751.     print("*** Unloaded script")
  752.  
  753. def hook_unload2(userdata):
  754.     hook_unload("", "", "", "")
  755.  
  756. command_add(["!panic", hook_unload, "panic and disable all hooks", ""])
  757.  
  758. hooks = [ ]
  759. def hook_delay(userdata):
  760.     hooks.append(xchat.hook_print("Channel Message", main))
  761.     hooks.append(xchat.hook_print("Private Message", main))
  762.     hooks.append(xchat.hook_print("Private Message to Dialog", main))
  763.     hooks.append(xchat.hook_print("Channel Msg Hilight", main))
  764.     hooks.append(xchat.hook_print("Channel Action", main))
  765.     hooks.append(xchat.hook_print("Private Action to Dialog", main))
  766.     hooks.append(xchat.hook_print("Channel Action Hilight", main))
  767.     hooks.append(xchat.hook_print("Your Message", main))
  768.     hooks.append(xchat.hook_print("Your Action", main))
  769.     hooks.append(xchat.hook_print("Notice", notice_hook))
  770.    
  771.     hooks.append(xchat.hook_unload(hook_unload2))
  772.     global votes
  773.     votes = []
  774.  
  775. context = xchat.get_context()
  776. temptest = get_user(xchat.get_info("nick"), xchat.get_info("server"), "#powder")
  777. if temptest and temptest.host:
  778.     hook_delay("")
  779.     context.prnt("*** Loaded script")
  780. else:
  781.     xchat.hook_timer(6000, hook_delay)
  782.     xchat.hook_timer(3000, command_timer, "who #powder")
  783.     xchat.hook_timer(3000, command_timer, "who #powder-social")
  784.     xchat.hook_timer(3000, command_timer, "who ##powder-bots")
  785.     xchat.hook_timer(3000, command_timer, "who ##jacob1")
  786.     context.prnt("*** Loaded script")
  787. random.seed()
Advertisement
Add Comment
Please, Sign In to add comment