SHARE
TWEET

RTLBot 10-8-15

fire219 Dec 27th, 2015 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """
  2.  ______    _______  ___      _______  _______  _______
  3. |    _ |  |       ||   |    |  _    ||       ||       |
  4. |   | ||  |_     _||   |    | |_|   ||   _   ||_     _|
  5. |   |_||_   |   |  |   |    |       ||  | |  |  |   |  
  6. |    __  |  |   |  |   |___ |  _   | |  |_|  |  |   |  
  7. |   |  | |  |   |  |       || |_|   ||       |  |   |  
  8. |___|  |_|  |___|  |_______||_______||_______|  |___|  
  9.  
  10. RTLBot -- Heavily Modified version of H2Bot, designed for use on ##rtlsdr on Freenode
  11.  
  12. RTLBot and H2Bot designed and built by fire219 (Matthew Petry)
  13.  
  14. """
  15.  
  16. # librarieslibrarieslibraries.
  17. import socket
  18. import time
  19. import random
  20. import os
  21. import thread
  22. import smtplib
  23. import urllib2
  24. import json
  25. import datetime
  26. import pickle
  27.  
  28. # variables you can touch      
  29. server = "chat.freenode.net" # IRC network
  30. channel = "#redditcfb" # Channel
  31. botnick = "RTLBot" # Bot's nick
  32. curses = ['fuck', 'shit', 'damn', 'dammit', 'cunt', 'tits', 'bitch', ' cock ', 'dick', 'jizz', 'nigger', 'queer', 'slut', 'twat', 'whore', 'pussy', ' hell ', 'spick', 'wetback', 'dike', 'bastard', 'towelhead', 'clit', 'douche', 'bugger', ' fuk ', '$hit', 'godverdomme', 'miljaardeju', 'kut', 'klote', 'verdomme', 'godver', 'nondedju', 'mieljaar', 'tering', 'sodemieter', 'merde', 'conneries', 'branleur', 'connard', 'schwanz', 'arsch', 'hurensohn', 'verdammt', 'puta', 'foda', ] #Profanity list for swear filter (used on first run)
  33. cursesns = ['fuck', 'shit', 'damn', 'dammit', 'cunt', 'tits', 'bitch', 'cock', 'dick', 'jizz', 'nigger', 'queer', 'slut', 'twat', 'whore', 'pussy', 'hell', 'spick', 'wetback', 'dike', 'bastard', 'towelhead', 'clit', 'douche', 'bugger', 'fuk', '$hit', 'godverdomme', 'miljaardeju', 'kut', 'klote', 'verdomme', 'godver', 'nondedju', 'mieljaar', 'tering', 'sodemieter', 'merde', 'conneries', 'branleur', 'connard', 'schwanz', 'arsch', 'hurensohn', 'verdammt', 'puta', 'foda',] #No-spaces profanity list for swear filter stage 2 (used on first run)  
  34. selfref = ['h2bot', 'himself', 'hisself', 'itself', 'dick', 'cock', 'hydrobot', 'hydrogenbot', ' its ', 'thyself'] #Self (and bad thing) references for fun commands
  35. log = 1 #create log file?
  36. filelocation = "C:\\Users\\Matthew\\Documents\\hydrobot" #where to create bot files
  37. password = "hydrobotmasterrace"
  38. utc_datetime = datetime.datetime.utcnow()
  39. #--------------DO NOT TOUCH----------------------------
  40.  
  41. swearfilter = 0
  42. timelimit = 0
  43. funcommands = 1
  44. ircmsg = ""
  45. tbanned = dict()
  46. seenlist = dict()
  47. tbanned2 = []
  48. mods = []
  49. L1off = []
  50. L2off = []
  51. L3off = []
  52. alloff= dict()
  53. date = time.strftime("%m_%d_%Y")
  54. swearcount = 0
  55. chanready = 0
  56. threadsrunning = 0
  57. #------------END NO TOUCHIE AREA-----------------------
  58.  
  59. print("RTLBot is starting up!")
  60. starttime=utc_datetime.strftime("%a, %d %b %Y %H:%M:%S")
  61. print("Startup time: "+starttime)
  62. #log initialization
  63. if log == 1:
  64.  if os.path.isfile(filelocation+'/log '+ date) == True:
  65.    print("We already have a log for today -- appending messages to it.")   
  66.    logw = open(filelocation+'/log '+ date, 'a')
  67.    logw.write('---LOG CONTINUED---\n')
  68.  
  69.  else:
  70.    print("We do not have a log for today. Creating a new one.")
  71.    logw = open(filelocation+'/log '+ date, 'w')
  72.    logw.write('---LOG STARTED---\n')
  73.  
  74.  
  75. #swear filter offenders file initialization
  76.  
  77. if os.path.isfile(os.path.normpath(filelocation+'/swfile')) == True:
  78.     print("Swear filter file exists")
  79.     pass
  80. else:
  81.  print("Creating swear filter file")
  82.  swf = open(os.path.normpath(filelocation+'/swfile'), 'w')
  83.  swf.write("{}")
  84.  swf = open(os.path.normpath(filelocation+'/swfile'), 'w')
  85.    
  86. #tempban file initialization  
  87. if os.path.isfile(os.path.normpath(filelocation+'/tbanned')) == True:
  88.  print("Tempban file 1 exists. Trying to load contents.")
  89.  tbf = open(os.path.normpath(filelocation+'/tbanned'), 'r+')
  90.  tbanned = tbf.read()
  91.  tbanned = tbanned.strip("[]")
  92.  tbanned = eval(tbanned)
  93.  print("Ban data loaded:"+str(tbanned))
  94.  tbf.close()
  95. else:
  96.  print("Creating tempban file 1")
  97.  tbf = open(os.path.normpath(filelocation+'/tbanned'), 'w')
  98.  tbf.write("{}")
  99.  tbf = open(os.path.normpath(filelocation+'/tbanned'), 'r+')
  100.  
  101. if os.path.isfile(os.path.normpath(filelocation+'/tbanned2')) == True:
  102.  print("Tempban file 2 exists. Trying to load contents.")  
  103.  tbf2 = open(os.path.normpath(filelocation+'/tbanned2'), 'r+')
  104.  tbanned2 = tbf2.read()
  105.  tbanned2 = tbanned2.strip("[]")
  106.  tbanned2 = tbanned2.replace("'", " ")
  107.  tbanned2 = tbanned2.strip(",")
  108.  tbanned2 = tbanned2.split()
  109.  print("Ban data loaded:"+str(tbanned2))
  110.  tbf.close()
  111. else:
  112.  print("Creating tempban file 2")
  113.  tbf2 = open(os.path.normpath(filelocation+'/tbanned2'), 'w')
  114.  tbf.write("[]")
  115.  tbfw = open(os.path.normpath(filelocation+'/tbanned2'), 'r+')
  116.  
  117.  
  118.  
  119. #--------------ABSOLUTELY NO TOUCHIE UNLESS YOU KNOW WHAT YOU'RE DOING-------------------
  120. ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  121. ircsock.connect((server, 6667))
  122. ircsock.send("USER "+ botnick +" "+ botnick +" "+ botnick +" :RTL2832 DVB Dongle \n") # user authentication
  123. time.sleep(2)
  124. ircsock.send("NICK "+ botnick +"\n")
  125. #--------------END NO TOUCHIE ZONE-------------------------------------------------------
  126.  
  127. def stringdetect(string): #basic string detection
  128.   if ircmsg.find(string) != -1:
  129.     return True
  130.   else:
  131.     return False
  132.  
  133. def ping(): # IRC PING responder
  134.  
  135.   ircsock.send("PONG :" + ircmsg.strip("PING :") + "/n")
  136.   print("PONG :" + ircmsg.strip("PING :"))
  137.   joinchan(channel)
  138.  
  139.  
  140. def joinchan(chan): # This function is used to join channels.
  141.   ircsock.send("JOIN "+ chan +"\n")
  142.  
  143. def hello(): # This function responds to a user that inputs "Hello <botnick>"
  144.   ircsock.send("PRIVMSG "+ channel +" :Hello!\n")
  145.  
  146. def rand(number): #random number gen
  147.  try:
  148.   rand = random.randint(1, int(number))
  149.   print(number)
  150.   ircsock.send("PRIVMSG "+ channel +" :Random Selection: " + str(rand) + "\n")
  151.  except:
  152.   pass
  153.   ircsock.send("PRIVMSG "+ channel +" :Bad information given. \n")
  154.  
  155. def rand2(randstring): #random character chooser
  156.  try:
  157.   rand = random.choice(randstring)
  158.   ircsock.send("PRIVMSG "+ channel +" :Random Selection: " + rand + "\n")
  159.  except:
  160.   pass
  161.   ircsock.send("PRIVMSG "+ channel +" :Bad information given. \n")
  162.  
  163. def intro(): #introduction to H2
  164.   ircsock.send("PRIVMSG "+ channel +" :Hello! I am RTLBot, a helper bot for ##rtlsdr. I am built by fire219 (Matthew Petry), based on the previous H2Bot script. Thanks to Kyle Farwell for access to his kotori.me VPS, where I am being hosted. :)\n")
  165.  
  166.  
  167.  
  168. def slapuser(user): #slap user
  169.      ircsock.send("PRIVMSG "+ channel +" :\x01ACTION slaps " + user + " with a large robotic trout!\x01\n")
  170.      
  171. def ewuser(user): # ew user
  172.      ircsock.send("PRIVMSG "+ channel +" :Ew, "+ user +"! \n")
  173.  
  174. def suckuser(user): #vacuum cleaner, hehe
  175.      ircsock.send("PRIVMSG "+ channel +" :\x01ACTION sucks "+ user +" up with a vacuum cleaner!\x01\n")
  176.      
  177.      
  178. def opfindrun(): #find channel ops
  179.     opfind = ircmsg
  180.     opfindr = opfind.index("353 "+botnick)
  181.     opfind = opfind[opfindr:]
  182.     opfindr = opfind.index(channel)
  183.     opfind = opfind[opfindr:]
  184.     opfind2 = len(channel) + 1
  185.     opfind = opfind[opfind2:]
  186.     opfind = opfind[1:]
  187.     opfindr = opfind.index(":")
  188.     opfind = opfind[:opfindr]
  189.     opfind = opfind[:-2]
  190.     opfind = opfind.split(' ')
  191.     print(opfind)
  192.     opparse = 0
  193.     try:
  194.      for x in range(0, len(opfind)):
  195.         if opfind[opparse].find("@") == -1:
  196.             opfind.pop(opparse)
  197.             x = x + 1
  198.             oparse = opparse + 1
  199.         else:
  200.             tempop = opfind[opparse]            
  201.             tempop = tempop.replace("@", "")
  202.             mods.append(tempop)
  203.             opfind.pop(opparse)            
  204.             x = x + 1
  205.             oparse = opparse + 1       
  206.     except IndexError:
  207.         print()
  208.     print(mods)
  209.     mods.append("fire219")     
  210.     chanready = "yes"
  211.     seenlist = dict()
  212.     seenlist.clear()
  213.     print("Channel is ready!")
  214.  
  215. def help(ircmsg): #basic command help
  216.     ircmsg = ircmsg[1:]
  217.     ircmsgr = ircmsg.index("!")
  218.     ircmsg = ircmsg[:ircmsgr]  
  219.     ircsock.send("PRIVMSG "+ ircmsg +" :RTLBot Help\n")    
  220.     ircsock.send("PRIVMSG "+ ircmsg +" :-----------\n")
  221.     ircsock.send("PRIVMSG "+ ircmsg +" :'Hello RTLBot' - RTLBot says hello back \n")
  222.     ircsock.send("PRIVMSG "+ ircmsg +" :RB intro - Introduction \n")
  223.     ircsock.send("PRIVMSG "+ ircmsg +" :RB randomize <text> - selects a random character out of <text> \n")
  224.     ircsock.send("PRIVMSG "+ ircmsg +" :RB randomnum <end number> - Selects a random number from 1 to <end number> \n")
  225.     ircsock.send("PRIVMSG "+ ircmsg +" :RB slap <user> - slaps user with a fish \n")
  226.     ircsock.send("PRIVMSG "+ ircmsg +" :RB ew <user> - shows your disgust for a user \n")
  227.     ircsock.send("PRIVMSG "+ ircmsg +" :RB suck <user> - not quite what you think \n")
  228.     ircsock.send("PRIVMSG "+ ircmsg +" :RB curtime - shows the current time in the timezone H2 is running from (usually Central) \n")
  229.     ircsock.send("PRIVMSG "+ ircmsg +" :RB easy - Be a smartass and tell them how easy something was. \n") 
  230.     ircsock.send("PRIVMSG "+ ircmsg +" :RB seen <user> - What was the most recent time this user was seen? \n")    
  231.  
  232. def adminhelp(ircmsg): #admin command help
  233.     ircmsg = ircmsg[1:]
  234.     ircmsgr = ircmsg.index("!")
  235.     ircmsg = ircmsg[:ircmsgr]  
  236.     ircsock.send("PRIVMSG "+ ircmsg +" :RTLBot Admin Help\n")    
  237.     ircsock.send("PRIVMSG "+ ircmsg +" :-----------\n")
  238.     ircsock.send("PRIVMSG "+ ircmsg +" :'RB sw on/off' - swearfilter toggle \n")
  239.     ircsock.send("PRIVMSG "+ ircmsg +" :'RB fun on/off' - FUNction toggle \n")
  240.     ircsock.send("PRIVMSG "+ ircmsg +" :'RB shutdown' - shutdown H2Bot \n")
  241.     ircsock.send("PRIVMSG "+ ircmsg +" :'RB tban <user> M-D_h:m' - tempban \n")
  242.     ircsock.send("PRIVMSG "+ ircmsg +" :'RB tkban <user> M-D_h:m' - tempban + kick \n")    
  243.    
  244. def selfharmdetect(string, actionmsg1, actionmsg2, self=selfref): #detects if the user is trying to issue a command against the bot.
  245.     if any(word in string.lower() for word in self):
  246.         user = string[1:]
  247.         print(user)
  248.         ircmsgr = user.index("!")
  249.         print(user)
  250.         user = user[:ircmsgr]
  251.         print(user)
  252.         ircsock.send("PRIVMSG " + channel + actionmsg1 + user + actionmsg2)
  253.    
  254.         return False
  255.     else:
  256.         return True
  257.  
  258. def stringSplit(string, text, position): #gets the parameter the user passed and returns it
  259.     stringreq = string
  260.     stringreqr = stringreq.index(text)
  261.     print(stringreqr)
  262.     stringreq = stringreq[stringreqr:]
  263.     print(stringreq)
  264.     stringreq = stringreq[position:]
  265.     print(stringreq)
  266.     stringreq = stringreq.strip('\n\r')
  267.     print(stringreq)
  268.     return stringreq
  269.    
  270. def functionTimer(string, timelimit): #checks that the functions arent being used too often
  271.     if timelimit > 0:
  272.         string = string[1:]
  273.         print(string)
  274.         string = string.index("!")
  275.         print(string)
  276.         string = string[:ircmsgr]
  277.         print(string)
  278.         ircsock.send("NOTICE "+ string +" :A FUNction has been used recently. Please wait a while before trying again. " + str(timelimit) + " cycles left. \n")
  279.         return False
  280.     else:  
  281.         timelimit = 10
  282.         return True
  283.  
  284. def wrongarg(receive, expect): # wrong number of arguments handler
  285.     ircsock.send("PRIVMSG "+channel+" :Error: Expected "+expect+" arguments, received "+receive+".\n")
  286.  
  287. def unbanloop(): #tempban parse 'n unban MULTITHREAD EDITION :O
  288.   while True:
  289.    try:
  290.     tbanparse = 0
  291.     for x in xrange(0, len(tbanned2)):
  292.      #print("unban time "+tbanned[tbanned2[tbanparse]])
  293.      #print("current time "+time.strftime("%m-%d_%H:%M"))
  294.      curtime = time.strftime("%m-%d_%H:%M")
  295.      cmonth = time.strftime("%m")
  296.      if cmonth[0] == '0':
  297.       cmonth = cmonth[1:]
  298.      cday = time.strftime("%d")
  299.      if cday[0] == '0':
  300.       cday = cday[1:]    
  301.      chour = time.strftime("%H")
  302.      if chour[0] == '0':
  303.       chour = chour[1:]  
  304.      cmin = time.strftime("%M")
  305.      if cmin[0] == '0':
  306.       cmin = cmin[1:]  
  307.      curtime = str(cmonth+"-"+cday+"_"+chour+":"+cmin)
  308.      if tbanned[tbanned2[tbanparse]] == curtime:
  309.             tbf2 = open(filelocation+'/tbanned2', 'w')
  310.             tbf = open(filelocation+'/tbanned', 'w')
  311.             ircsock.send("MODE "+ channel +" -b "+tbanned2[tbanparse]+"\n")
  312.             temp=tbanned2[tbanparse]
  313.             tbanned.pop(temp)
  314.             ircsock.send("PRIVMSG "+ channel +" :User "+tbanned2[tbanparse]+" is unbanned.\n")
  315.             tbanned2.pop(tbanparse)
  316.             tbf.write(str(tbanned))
  317.             tbf2.write(str(tbanned2))
  318.             tbf.close()
  319.             tbf2.close()       
  320.      tbanparse = tbanparse + 1 
  321.  
  322.    except KeyError:
  323.         tbf2 = open(filelocation+'/tbanned2', 'w')
  324.         tbanned2.pop(tbanparse)
  325.         tbf2.write(str(tbanned2))
  326.         tbf2.close()
  327.         tbanparse = tbanparse + 1
  328.         print("We hit an error, but we're still purring along!")
  329.  
  330. def swtimeout(name): #swearfilter timeout
  331.     time.sleep(600)
  332.     alloff.pop(name)
  333.     swf = open(filelocation+'swfile', 'w')
  334.     swf.write(str(alloff))
  335.     swf.close()    
  336. """
  337. def seenlistloader(): #load seenlist from file
  338.     if os.path.isfile(os.path.normpath(filelocation+'/seenlist')) == True:
  339.         print("Last seen dictionary exists. Trying to load contents.")
  340.         seenlistf = open(os.path.normpath(filelocation+'/seenlist'), 'rb+')
  341.         if (seenlistf.read() == ""):
  342.             print("Dictionary is empty. Continuing with blank list.")
  343.         else:  
  344.             seenlist = pickle.load(seenlistf)
  345.             print("Dictionary loaded:"+str(seenlist))
  346.     else:
  347.             print("Creating last seen dictionary")
  348.             seenlistf = open(os.path.normpath(filelocation+'/seenlist'), 'wb')
  349.             seenlist = dict()
  350. """
  351.    
  352. while True: # Be careful with these! it might send you to an infinite loop
  353.   ircmsg = ircsock.recv(2048) # receive data from the server
  354.   ircmsg = ircmsg.strip('\n\r') # removing any unnecessary linebreaks.
  355.   print(ircmsg) # Here we print what's coming from the server
  356.   if log == 1:
  357.     if not "PING :" in ircmsg:
  358.         logw = open(filelocation+'/log '+ date, 'a')
  359.         logw.write(utc_datetime.strftime("%d %b %Y %H:%M:%S")+":  "+ircmsg+'\n')
  360.         logw.close()   
  361.  
  362.  
  363.   if stringdetect("353 "+botnick):
  364.     opfindrun()
  365.  
  366.   if stringdetect("This nickname is registered"):
  367.     ircsock.send("PRIVMSG NickServ :identify "+password+"\n")
  368.    
  369.   if stringdetect(":"+botnick+" MODE "+botnick+" :+i"):
  370.     joinchan(channel)  
  371.    
  372.  
  373.    
  374.   if stringdetect(":Hello "+ botnick): # If we can find "Hello Mybot" it will call the function hello()
  375.     hello()
  376.  
  377.   if stringdetect("PING :"): # if the server pings us then we've got to respond!
  378.     ping()
  379.  
  380.   if stringdetect(":RB intro"):
  381.     intro()  
  382.  
  383.   if stringdetect(":RB locate"):
  384.     locateuser(stringSplit(ircmsg, "locate", 7))
  385.  
  386.   if funcommands == 1:    
  387.     if stringdetect("RB randomize"): #checks if this command was used
  388.       if functionTimer(ircmsg, timelimit): #checks if the time limit is up
  389.        rand2(stringSplit(ircmsg, "randomize", 10)) #runs the function rand2 with the players parameter
  390.     if stringdetect("RB randomnum"):
  391.       if functionTimer(ircmsg, timelimit):
  392.        rand(stringSplit(ircmsg, "randomnum", 10))
  393.     if stringdetect(":RB slap"):
  394.       if functionTimer(ircmsg, timelimit):
  395.         if selfharmdetect(ircmsg, " :\x01ACTION slaps ", " with a large robotic trout for thinking I am dumb! \x01\n"):
  396.          slapuser(stringSplit(ircmsg, "slap", 5))
  397.  
  398.     if stringdetect(":RB ew"):
  399.       if functionTimer(ircmsg, timelimit):
  400.         if selfharmdetect(ircmsg, " :Ew, ", ". I'm not that stupid! :P \n"):
  401.          ewuser(stringSplit(ircmsg, "ew ", 3))
  402.     if stringdetect(":RB suck"):
  403.       if functionTimer(ircmsg, timelimit):
  404.         if selfharmdetect(ircmsg, " :Um no", ". I'm not that stupid! :P \n"):
  405.          suckuser(stringSplit(ircmsg, "suck", 5))
  406.  
  407.   if stringdetect(":is this the real life"):
  408.     ircsock.send("PRIVMSG "+ channel +" :Is this just fantasy?\n")
  409.    
  410.   if stringdetect(":RB easy"):
  411.     ircsock.send("PRIVMSG "+ channel +" :That was easy. http://goo.gl/bnUZS7 \n")
  412.    
  413.   if stringdetect(":RB help"):
  414.     help(ircmsg)
  415.  
  416.   if stringdetect(":RB curtime"):
  417.     ircsock.send("PRIVMSG "+ channel +" :"+time.strftime("%m-%d_%H:%M")+"\n")
  418.    
  419.   if swearfilter == 1:
  420.    
  421.    if any(word in ircmsg.lower() for word in curses):
  422.     swearmessage = ircmsg.lower()
  423.     swearmessage = swearmessage[1:]
  424.     swearmessager = swearmessage.index(":")
  425.     swearmessage = swearmessage[swearmessager:]
  426.     swearmessage = swearmessage[1:]
  427.    
  428.     ircmsg = ircmsg[1:]
  429.     print(ircmsg)
  430.     ircmsgr = ircmsg.index("!")
  431.     print(ircmsg)
  432.     ircmsg = ircmsg[:ircmsgr]
  433.     print(ircmsg)
  434.     try:
  435.         sweartally = alloff[ircmsg]
  436.     except KeyError:
  437.         sweartally = 0
  438.         thread.start_new_thread(swtimeout, (ircmsg,))
  439.         print("New Timeout thread started.")
  440.     swearmessage = swearmessage.split(" ")
  441.     print(swearmessage)
  442.     swearparse = 0
  443.  
  444.     for word in swearmessage:
  445.         if any(word in swearmessage[swearparse] for word in curses):
  446.             sweartally = sweartally + 1
  447.             swearparse = swearparse + 1
  448.         else:
  449.             swearparse = swearparse + 1
  450.    
  451.  
  452.     alloff[ircmsg] = sweartally
  453.     swf = open(filelocation+'swfile', 'w')
  454.     swf.write(str(alloff))
  455.     swf.close()
  456.     if sweartally > 6:
  457.         opparse = 0
  458.         for x in xrange(0, len(mods)):
  459.             ircsock.send("NOTICE "+mods[opparse]+" :Hey "+mods[opparse]+", "+ircmsg+" has continued using profanity.\n")
  460.             opparse = opparse + 1      
  461.         ircsock.send("NOTICE "+ ircmsg +" :"+ircmsg+", the chat mods have been alerted again.\n")  
  462.     elif sweartally == 6:
  463.         opparse = 0
  464.         for x in xrange(0, len(mods)):
  465.             ircsock.send("NOTICE "+mods[opparse]+" :Hey "+mods[opparse]+", "+ircmsg+" has reached the profanity limit.\n")
  466.             opparse = opparse + 1  
  467.         ircsock.send("NOTICE "+ ircmsg +" :"+ircmsg+", the chat mods have been alerted. Action will be taken as deemed necessary.\n")      
  468.     elif sweartally == 5:
  469.         ircsock.send("NOTICE "+ ircmsg +" :"+ircmsg+", stop cursing immediately. You have cursed "+str(sweartally)+" times in the last hour. Further offenses will be immediately brought to the attention of a moderator.\n")
  470.     elif sweartally >= 3:  
  471.         ircsock.send("NOTICE "+ ircmsg +" :"+ircmsg+", please do not curse. You have cursed "+str(sweartally)+" times in the last hour. \n")
  472.  
  473.    
  474.   if stringdetect(":RB sw on"):
  475.    secr = ircmsg.index("PRIVMSG")
  476.    ircmsg = ircmsg[:secr]
  477.    if any(word in ircmsg for word in mods):  
  478.     swearfilter = 1  
  479.     ircsock.send("PRIVMSG "+ channel +" :Swear warning on. Current setting: six strikes every 10 minutes.\n")
  480.  
  481.   if stringdetect(":RB sw off"):
  482.    secr = ircmsg.index("PRIVMSG")
  483.    ircmsg = ircmsg[:secr]
  484.    if any(word in ircmsg for word in mods):
  485.     swearfilter = 0  
  486.     ircsock.send("PRIVMSG "+ channel +" :Swear warning off. Someone complained enough to make fire219 turn it off. \n")
  487.    
  488.   if stringdetect(":RB fun on"):
  489.    secr = ircmsg.index("PRIVMSG")
  490.    ircmsg = ircmsg[:secr]
  491.    if any(word in ircmsg for word in mods):  
  492.     funcommands = 1  
  493.     ircsock.send("PRIVMSG "+ channel +" :FUNctions on.\n")
  494.  
  495.    
  496.   if stringdetect(":ping"):
  497.     ircsock.send("PRIVMSG "+ channel +" :Shut the fuck up.\n")
  498.    
  499.   if stringdetect(":RB shutdown"):
  500.    secr = ircmsg.index("PRIVMSG")
  501.    ircmsg = ircmsg[:secr]
  502.    secret = ['Doctor']
  503.    if any(word in ircmsg for word in mods):
  504.         ircsock.send("PRIVMSG "+ channel +" :'Good night', says the moon.\n")
  505.         ircsock.send("QUIT :RTLBot -- The modbot of #starmade")
  506.         print("Bot is shutting down. ZZZZZZZzzzzzz..... ")
  507.         time.sleep(1)
  508.         os._exit(1)
  509.    else:
  510.         ircsock.send("PRIVMSG "+ channel +" :You are not authorized to shut me down. You must be a channel operator.\n")
  511.    
  512.   if stringdetect(":RB fun off"):
  513.    secr = ircmsg.index("PRIVMSG")
  514.    ircmsg = ircmsg[:secr]
  515.    if any(word in ircmsg for word in mods):
  516.     funcommands = 0
  517.     ircsock.send("PRIVMSG "+ channel +" :FUNctions off.\n")    
  518.    
  519.   if stringdetect(":RB tban"):
  520.    sec = ircmsg
  521.    secr = ircmsg.index("PRIVMSG")
  522.    sec = sec[:secr]
  523.    if any(word in sec for word in mods):  
  524.     tban = ircmsg
  525.     tbanr = tban.index("tban")
  526.     print(tbanr)
  527.     tban = tban[tbanr:]
  528.     tban = tban[5:]
  529.     tban = tban.strip('\n\r')
  530.     tban = tban.split(" ")
  531.     if len(tban) == 1:
  532.       wrongarg(1 , 2)
  533.     tbanned[tban[0]] = tban[1]
  534.     tbanned2.append(tban[0])    
  535.     ircsock.send("PRIVMSG "+ channel +" :User "+tban[0]+" banned until "+tban[1]+"\n")
  536.     ircsock.send("MODE "+ channel +" +b "+tban[0]+"\n")
  537.     print(tbanned)
  538.     print(tbanned2)
  539.     tbf2 = open(filelocation+'tbanned2', 'w')
  540.     tbf = open(filelocation+'tbanned', 'w')
  541.     tbf.write(str(tbanned))
  542.     tbf2.write(str(tbanned2))
  543.     tbf.close()
  544.     tbf2.close()   
  545.     tban = []
  546.  
  547.   if stringdetect(":RB tkban"):
  548.    sec = ircmsg
  549.    secr = ircmsg.index("PRIVMSG")
  550.    sec = sec[:secr]
  551.    if any(word in sec for word in mods):  
  552.     tban = ircmsg
  553.     tbanr = tban.index("tkban")
  554.     print(tbanr)
  555.     tban = tban[tbanr:]
  556.     tban = tban[6:]
  557.     tban = tban.strip('\n\r')
  558.     tban = tban.split(" ")
  559.     if len(tban) == 1:
  560.       wrongarg(1 , 2)
  561.     tbanned[tban[0]] = tban[1]
  562.     tbanned2.append(tban[0])    
  563.     ircsock.send("PRIVMSG "+ channel +" :User "+tban[0]+" banned until "+tban[1]+"\n")
  564.     ircsock.send("MODE "+ channel +" +b "+tban[0]+"\n")
  565.     ircsock.send("KICK "+ channel +" "+tban[0]+"\n")   
  566.     print(tbanned)
  567.     print(tbanned2)
  568.     tbf2 = open(filelocation+'tbanned2', 'w')
  569.     tbf = open(filelocation+'tbanned', 'w')
  570.     tbf.write(str(tbanned))
  571.     tbf2.write(str(tbanned2))
  572.     tbf.close()
  573.     tbf2.close()   
  574.     tban = []
  575.  
  576.   if stringdetect("slaps "+botnick):
  577.     ircmsg = ircmsg[1:]
  578.     print(ircmsg)
  579.     ircmsgr = ircmsg.index("!")
  580.     print(ircmsg)
  581.     ircmsg = ircmsg[:ircmsgr]
  582.     print(ircmsg)
  583.     ircsock.send("PRIVMSG "+ channel +" :\x01ACTION returns " + ircmsg + " the favor with a large robotic trout!\x01\n")
  584.  
  585.   if stringdetect("slapped "+botnick):
  586.     ircmsg = ircmsg[1:]
  587.     print(ircmsg)
  588.     ircmsgr = ircmsg.index("!")
  589.     print(ircmsg)
  590.     ircmsg = ircmsg[:ircmsgr]
  591.     print(ircmsg)
  592.     ircsock.send("PRIVMSG "+ channel +" :\x01ACTION returns " + ircmsg + " the favor with a large robotic trout!\x01\n")      
  593.  
  594.   if timelimit > 0:
  595.    timelimit = timelimit - 1
  596.    
  597.   if stringdetect(":RB adminhelp"):
  598.    secr = ircmsg.index("PRIVMSG")
  599.    ircmsg = ircmsg[:secr]
  600.    if any(word in ircmsg for word in mods):
  601.      adminhelp(ircmsg)
  602.      
  603.   if stringdetect(":RB weather"):
  604.     wloc = stringSplit(ircmsg, "weather", 8)
  605.     if (wloc == "" or wloc == "\n"):
  606.         ircsock.send("PRIVMSG "+ channel +" :Usage -- RB weather <location> \n")
  607.         ircsock.send("PRIVMSG "+ channel +" :<location> can be a US zip code, IATA airport code, city (format 'FL/Orlando' or 'France/Paris') or lat/long coordinates. \n")
  608.     else:  
  609.         wreq = urllib2.urlopen('http://api.wunderground.com/api/561a25f41f6ebf72/geolookup/conditions/q/'+wloc+'.json')
  610.         json_string = wreq.read()
  611.         parsed_json = json.loads(json_string)
  612.         city = parsed_json['location']['city']
  613.         temperature = parsed_json['current_observation']['temperature_string']
  614.         wind = parsed_json['current_observation']['wind_string']
  615.         weather = parsed_json['current_observation']['weather']
  616.         ircsock.send("PRIVMSG "+ channel +" :Weather in "+city+" is "+weather+ " with a temperature of "+temperature+" and wind is "+wind+". (RTLBot weather is powered by Weather Underground)\n")
  617.  
  618.   if stringdetect(":RB seen"):
  619.     seensubj = stringSplit(ircmsg, "seen", 5)
  620.     print(seenlist)
  621.     if (seensubj == "" or seensubj == "\n"):
  622.         ircsock.send("PRIVMSG "+ channel +" :Usage -- RB seen <user> \n")
  623.         ircsock.send("PRIVMSG "+ channel +" :Find the last time that <user> was seen (since RTLBot's last startup) \n")
  624.     else:  
  625.         try:
  626.             ircsock.send("PRIVMSG "+ channel +" :User "+seensubj+" was last seen at "+seenlist[seensubj]+" UTC \n")
  627.         except:
  628.             ircsock.send("PRIVMSG "+ channel +" :User "+seensubj+" has not been seen since RTLBot's last startup ("+starttime+")\n")
  629.    
  630.  
  631.  
  632.  
  633.   try: 
  634.         newmsg = ircmsg
  635.         newmsgr = newmsg.index("!")
  636.         newmsg = newmsg[:newmsgr]
  637.         newmsg = newmsg[1:]
  638.         utc_datetime = datetime.datetime.utcnow()
  639.         seenlist[newmsg] = utc_datetime.strftime("%a, %d %b %Y %H:%M:%S")  
  640.  
  641.   except:
  642.         continue
  643.        
  644.  
  645.  
  646.   if threadsrunning == 0:
  647.    if mods != []: #activate tempban threads and do final var cleanup
  648.     thread.start_new_thread(unbanloop,())
  649.     print("Tempban thread running!")
  650.     #seenlistloader()
  651.     threadsrunning = 1
  652. """
  653.   if (mods != []):
  654.     seenlistf = open(os.path.normpath(filelocation+'/seenlist'), 'wb')
  655.     pickle.dump(seenlist, seenlistf)  
  656.     seenlistf.close()
  657. """
RAW Paste Data
Top