Aluf

Bot chatango

Jan 18th, 2015
564
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 33.83 KB | None | 0 0
  1. # python imports
  2. #bot by Aluf
  3. ##########################################################
  4. import ch
  5. import random
  6. import sys
  7. import os
  8. import re
  9. import cgi
  10. import traceback
  11. import time
  12. import urllib
  13. import datetime
  14. import binascii
  15. #import youtube
  16. #import helperCmd
  17. import json
  18. ################
  19. ###########################################################
  20. #ENDS HERE
  21. ###########################################################
  22. # Something witty
  23. ###########################################################
  24. #VARS
  25. ###########################################################
  26. lockdown = False
  27. ##################
  28. # TIMER STUFF #
  29. startTime = time.time()
  30. ################
  31. #STATUS
  32. #######
  33. filename = "status.txt"
  34. file = open(filename, 'w')
  35. print("[INF]Setting status to online...")
  36. time.sleep(2)
  37. file.write("Online")
  38. file.close()
  39. #
  40.  
  41. #definitions
  42. dictionary = dict() #volatile... of course...
  43. f = open("definitions.txt", "r") # read-only
  44. print("[INF]Loading Definitions...")
  45. time.sleep(1)
  46. for line in f.readlines():
  47.         try:
  48.                 if len(line.strip())>0:
  49.                         word, definition, name = json.loads(line.strip())
  50.                         dictionary[word] = json.dumps([definition, name])
  51.         except:
  52.                 print("[ERR]Cant load definition: %s" % line)
  53. f.close()
  54.  
  55. #OWNER#
  56. spermitted = []
  57. f = open("spermitted.txt", "r") # read-only
  58. print("[INF]Loading Supermasters...")
  59. time.sleep(1)
  60. for name in f.readlines():
  61.         if len(name.strip())>0: spermitted.append(name.strip())
  62. f.close()
  63. # END #
  64.  
  65. #MASTERS#
  66. permitted = []
  67. f = open("permitted.txt", "r") # read-only
  68. print("[INF]Loading Masters...")
  69. time.sleep(1)
  70. for name in f.readlines():
  71.         if len(name.strip())>0: permitted.append(name.strip())
  72. f.close()
  73. # END #
  74.  
  75. #HALF MASTERS#
  76. hpermitted = []
  77. f = open("hpermitted.txt", "r") # read-only
  78. print("[INF]Loading Half Masters....")
  79. time.sleep(1)
  80. for name in f.readlines():
  81.         if len(name.strip())>0: hpermitted.append(name.strip())
  82. f.close()
  83. #END #
  84.  
  85. #WHITELIST#
  86. whitelist = []
  87. f = open("whitelist.txt", "r") # read-only
  88. print("[INF]Loading Whitelists...")
  89. time.sleep(1)
  90. for name in f.readlines():
  91.         if len(name.strip())>0: whitelist.append(name.strip())
  92. f.close()
  93. #END #
  94.  
  95. #ROOMS#
  96. rooms = []
  97. f = open("rooms.txt", "r") # read-only
  98. print("[INF]Loading Rooms...")
  99. time.sleep(1)
  100. for name in f.readlines():
  101.         if len(name.strip())>0: rooms.append(name.strip())
  102. f.close()
  103. #END#
  104. ###########################################################
  105. ## Thu 14 Apr 2011 00:05:52 BST
  106. ###########################################################
  107. if sys.version_info[0] > 2:
  108.         import urllib.request as urlreq
  109. else:
  110.         import urllib2 as urlreq
  111.  
  112. dancemoves = [
  113.         "(>^.^)> (>^.^<) <(^.^)>",
  114. ]
  115. activated = False # Disabled on default
  116. prefix = ";" # command prefix for some commands
  117.  
  118. def getUptime():
  119.     """
  120.    Returns the number of seconds since the program started.
  121.    """
  122.     # do return startTime if you just want the process start time
  123.     return time.time() - startTime
  124.  
  125. #SYSTEM UPTIME
  126. def uptime():
  127.  
  128.      try:
  129.          f = open( "/proc/uptime" )
  130.          contents = f.read().split()
  131.          f.close()
  132.      except:
  133.         return "Cannot open uptime file: /proc/uptime"
  134.  
  135.      total_seconds = float(contents[0])
  136.  
  137.      # Helper vars:
  138.      MINUTE  = 60
  139.      HOUR    = MINUTE * 60
  140.      DAY     = HOUR * 24
  141.  
  142.      # Get the days, hours, etc:
  143.      days    = int( total_seconds / DAY )
  144.      hours   = int( ( total_seconds % DAY ) / HOUR )
  145.      minutes = int( ( total_seconds % HOUR ) / MINUTE )
  146.      seconds = int( total_seconds % MINUTE )
  147.  
  148.      # Build up the pretty string (like this: "N days, N hours, N minutes, N seconds")
  149.      string = ""
  150.      if days > 0:
  151.          string += str(days) + " " + (days == 1 and "day" or "days" ) + ", "
  152.      if len(string) > 0 or hours > 0:
  153.          string += str(hours) + " " + (hours == 1 and "hour" or "hours" ) + ", "
  154.      if len(string) > 0 or minutes > 0:
  155.          string += str(minutes) + " " + (minutes == 1 and "minute" or "minutes" ) + ", "
  156.      string += str(seconds) + " " + (seconds == 1 and "second" or "seconds" )
  157.  
  158.      return string;
  159.  
  160. class TestBot(ch.RoomManager):
  161.         def onInit(self):
  162.                 self.setNameColor("A9F")
  163.                 self.setFontColor("540")
  164.                 self.setFontFace("1")
  165.                 self.setFontSize(11)
  166.                 self.enableBg()
  167.                 self.enableRecording()
  168.                
  169.         def getAccess(self, user):
  170.                 if user.name in spermitted: return 4
  171.                 elif user.name in permitted: return 3
  172.                 elif user.name in hpermitted: return 2
  173.                 elif user.name in whitelist: return 1
  174.                 else: return 0
  175.        
  176.         def onConnect(self, room):
  177.                 print("[INF] Connected to %s" % room.name)
  178.        
  179.         def onReconnect(self, room):
  180.                 print("[INF] Reconnected to %s" % room.name)
  181.        
  182.         def onDisconnect(self, room):
  183.                 print("[INF] Disconnected to %s" % room.name)
  184.                
  185.         def onJoin(self, room, user):
  186.                         if self.getAccess(user) >= 4:
  187.                                 room.message("-jumps up- waves at " + user.name + "^^")
  188.                         #elif self.getAccess(user) >= 3:#              
  189.                                 #room.message("ohai master " + user.name + " ^^")#
  190.                         #elif self.getAccess(user) >= 2:#              
  191.                                 #room.message("huggles half master " + user.name + " ^^")#
  192.        
  193.         def onMessage(self, room, user, message):
  194.                 # make global (if they will be changed in commands)
  195.                 global activated
  196.                 global lockdown
  197.                 ## print to console
  198.                 if room.getLevel(self.user) > 0: # if bot is mod
  199.                         print("[%s]\033[94m[MSG]\033[0m\033[31m[LVL %s]\033[0m[%s][%s] %s: %s" % (time.strftime("%d/%m/%y- %H:%M:%S", time.localtime(time.time())), self.getAccess(user), room.name, message.ip, user.name, message.body)) # with ip
  200.                 else:
  201.                         print("[%s]\033[94m[MSG]\033[0m\033[31m[LVL %s]\033[0m[%s] %s: %s" % (time.strftime("%d/%m/%y- %H:%M:%S", time.localtime(time.time())), self.getAccess(user), room.name, user.name, message.body)) # with ip # without ip
  202.                 if self.user == user: return # ignore self
  203.                 if self.getAccess(user) == 0: return # ignore non-whitelisted
  204.                 if self.getAccess(user) < 4 and lockdown: return #ignore everyone when in lockdown
  205.                 #split message into command and args
  206.                 data = message.body.split(" ", 1)
  207.                 if len(data) > 1:
  208.                         cmd, args = data[0], data[1] # if command and args
  209.                 else:
  210.                         cmd, args  = data[0], ""# if command and no args
  211.                
  212.                
  213.                 # implied command?
  214.                 if len(cmd) > 0:
  215.                         if cmd[0] == prefix:
  216.                                 used_prefix = True
  217.                                 cmd = cmd[1:]
  218.                         else: used_prefix = False
  219.                 else: return
  220.                
  221.                 # call bot name, activate if deactivated (bot)
  222.                 if (cmd == room.user.name or cmd =="Sheswolf" or cmd =="SHESWOLF") and len(args) == 0:
  223.                         if not activated and self.getAccess(user) < 2: return
  224.                         responce = ["yesh master? %s" % user.name, "hello chosen one", "o-o yesh?", "hi ^^"]
  225.                         room.message(random.choice(responce))
  226.                         activated = True
  227.  
  228.                 # call bot name with command after
  229.                 elif cmd == room.user.name and len(args) != 0:
  230.                         activated = True
  231.                         used_prefix = True
  232.                         data = args.split(" ", 1)
  233.                         if len(data) > 1:
  234.                                 cmd, args = data[0], data[1] # if command and args
  235.                         else:
  236.                                 cmd, args  = data[0], "" # if command and no args
  237.  
  238.                 # not activated, no commands
  239.                 if not activated: return
  240.                
  241.                 # hide/deactive bot (hide)
  242.                 if cmd == "hide" and self.getAccess(user) >= 2: # level 2+
  243.                         activated = False
  244.                         room.message(cgi.escape("I ish hiding >_> %s" % user.name))
  245.                
  246.                 #eval
  247.                 elif cmd == "eval" and self.getAccess(user) >= 4: # level 4+
  248.                         try:
  249.                                 ret = eval(args)
  250.                                 room.message(str(repr(ret)+" ^-^"))
  251.                         except:
  252.                                 room.message("failed to evaluate")
  253.                        
  254.                 # hello (hello bot)
  255.                 #elif (used_prefix or args.find(room.user.name)) and (cmd == "hello" or cmd == "hi" or cmd =="sup"):#
  256.                         #room.message("sup %s" % user.name)#          
  257.  
  258.                 # message delay in seconds (delay 10)
  259.                 elif used_prefix and cmd == "delay":
  260.                         self.setTimeout(int(args), room.message, "heh that was %s of bordem >_>" % args)
  261.                
  262.                 # server uptime (uptime)
  263.                 elif used_prefix and cmd == "uptime":
  264.                         room.message("sys uptime: %s" % uptime())
  265.                 # server uptime (uptime)
  266.                 elif used_prefix and cmd == "sut":
  267.                         room.message("I have been playing for: %s" % getUptime())
  268.  
  269.                 # heart/ily (<3 bot, ily bot)
  270.                 elif (used_prefix or args.find(room.user.name)) and (cmd == "<3" or cmd == "ily"):
  271.                         room.message(random.choice(["<3 u too %s" % user.name, "Wonders over to %s and sits besides them o-o" % user.name,]))
  272.  
  273.                 # kill bot (eeps)
  274.                 elif used_prefix and cmd == "eeps" and self.getAccess(user) >= 4:
  275.                         if user.name.lower() == "sorchmaster":
  276.                                 room.message("Mutters something before leaving")
  277.                                 time.sleep(1)                          
  278.                                 self.stop()
  279.                         else:
  280.                                 room.message("wish i could =/")
  281.                 # Save stuffs
  282.                 elif used_prefix and cmd == "sav":
  283.                         if user.name in spermitted or permitted:
  284.                                 room.message("I ish saved everything ^^")
  285.                                 time.sleep(1)                          
  286.                                 print("[SAV] Saving Definitions..")
  287.                                 f = open("definitions.txt", "w")
  288.                                 for word in dictionary:
  289.                                         definition, name = json.loads(dictionary[word])
  290.                                         f.write(json.dumps([word, definition, name])+"\n")
  291.                                 f.close()
  292.                                 print("[SAV] Saving SuperMasters..")
  293.                                 f = open("spermitted.txt", "w")
  294.                                 f.write("\n".join(spermitted))
  295.                                 f.close()
  296.                                 print("[SAV] Saving Masters..")
  297.                                 f = open("permitted.txt", "w")
  298.                                 f.write("\n".join(permitted))
  299.                                 f.close()
  300.                                 print("[SAV] Saving HalfMasters..")
  301.                                 f = open("hpermitted.txt", "w")
  302.                                 f.write("\n".join(hpermitted))
  303.                                 f.close()
  304.                                 print("[SAV] Saving Whitelist..")
  305.                                 f = open("whitelist.txt", "w")
  306.                                 f.write("\n".join(whitelist))
  307.                                 f.close()
  308.                                 print("[SAV] Saving Rooms..")
  309.                                 f = open("rooms.txt", "w")
  310.                                 f.write("\n".join(rooms))
  311.                                 f.close()
  312.                                 print("[SAV] Saving Whitelist..")
  313.                                 f = open("whitelist.txt", "w")
  314.                                 f.write("\n".join(whitelist))
  315.                                 f.close()
  316.                         else:
  317.                                 room.message("wish i could =/")
  318.  
  319.  
  320.                 # cookie responce (cookie?)
  321.                 elif cmd =="cookie?":
  322.                         room.message(random.choice(["yesh" , "sure ^^" , "no ty =/" , "O_O gimme" , "cookie...YESH" , "^^" , "COOKIE" , "-noms cookie- thankies"]))
  323.  
  324.  
  325.                
  326.                 #what room
  327.                 elif cmd=="whatroom":
  328.                         room.message("<b>%s</b> this is <b>http://%s.chatango.com</b>" % (user.name, room.name), True)
  329.  
  330.                 #bye
  331.                 elif used_prefix and cmd == "bye":
  332.                                 room.message("awww bye " + user.name + " =(")
  333.                 # half masters
  334.                 elif used_prefix and cmd == "hmasters":
  335.                         if len(args) >= 3:
  336.                                 do, name = args.lower().split(" ", 1)
  337.                                 if self.getAccess(ch.User(name)) > 3 or self.getAccess(user) < 2:
  338.                                         room.message("no. =/")
  339.                                         return
  340.                                 if do == "add":
  341.                                         if name in hpermitted: room.message("%s is already a hmaster. ^^" % name, True)
  342.                                         else:
  343.                                                 hpermitted.append(name)
  344.                                                 room.message("it has been done. ^^ remember do not add people that abuse me ^^", True)
  345.                                 elif do == "remove":
  346.                                         if name not in hpermitted: room.message("%s is not a hmaster. ^^" % name, True)
  347.                                         else:
  348.                                                 hpermitted.remove(name)
  349.                                                 room.message("it has been done. ^^ sowwy =/", True)
  350.                                 else:
  351.                                         room.message("what? >.>", True)
  352.                         else:
  353.                                 if len(hpermitted) == 0: room.message("I have no half masters. ^^", True)
  354.                                 else: room.message("my half masters are: <b>%s</b> They is better than you ....Jelly?" % ", ".join(hpermitted), True)
  355.                 # room add
  356.                 elif used_prefix and cmd == "room":
  357.                         if len(args) >= 3:
  358.                                 do, name = args.lower().split(" ", 1)
  359.                                 if self.getAccess(ch.User(name)) > 4 or self.getAccess(user) < 4:
  360.                                         room.message("no. =/")
  361.                                         return
  362.                                 if do == "add":
  363.                                         if name in rooms: room.message("%s in my list. ^^" % name, True)
  364.                                         else:
  365.                                                 rooms.append(name)
  366.                                                 room.message("it has been done. ^^ I ish there ^^", True)
  367.                                                 self.joinRoom(name)
  368.                                 elif do == "remove":
  369.                                         if name not in rooms: room.message("%s is not in my list =/. ^^" % name, True)
  370.                                         else:
  371.                                                 rooms.remove(name)
  372.                                                 room.message("it has been done. ^^ sowwy =/", True)
  373.                                                 self.leaveRoom(name)
  374.                                 else:
  375.                                         room.message("what? >.>", True)
  376.                         else:
  377.                                 if len(rooms) == 0: room.message("hell i have no rooms how is this possible. ^^", True)
  378.                                 else: room.message("Please use my rooms command use botteh rooms")
  379.                 # masters
  380.                 elif used_prefix and cmd == "masters":
  381.                         if len(args) >= 3:
  382.                                 do, name = args.lower().split(" ", 1)
  383.                                 if self.getAccess(ch.User(name)) > 3 or self.getAccess(user) <= 3:
  384.                                         room.message("no. =/")
  385.                                         return
  386.                                 if do == "add":
  387.                                         if name in permitted: room.message("%s is already a master. ^^" % name, True)
  388.                                         else:
  389.                                                 permitted.append(name)
  390.                                                 room.message("it has been done. ^^ remember do not add people that abuse me ^^", True)
  391.                                 elif do == "remove":
  392.                                         if name not in permitted: room.message("%s is not a master. ^^" % name, True)
  393.                                         else:
  394.                                                 permitted.remove(name)
  395.                                                 room.message("it has been done. ^^ sowwy =/", True)
  396.                                 else:
  397.                                         room.message("what? >.>", True)
  398.                         else:
  399.                                 if len(permitted) == 0: room.message("I have no masters. ^^", True)
  400.                                 else: room.message("my masters are: <b>%s</b> Your all just awesomes ^^" %  ", ".join(permitted), True)
  401.  
  402.                 # whitelist
  403.                 elif used_prefix and cmd == "whitelist":
  404.                         if len(args) >= 3:
  405.                                 do, name = args.lower().split(" ", 1)
  406.                                 if self.getAccess(ch.User(name)) > 2:
  407.                                         room.message("no. =/")
  408.                                         return
  409.                                 if do == "add":
  410.                                         if self.getAccess(user) >= 2:
  411.                                                 if name in whitelist:
  412.                                                         room.message("%s is already whitelisted. ^^" % name, True)
  413.                                                 else:
  414.                                                         whitelist.append(name)
  415.                                                         room.message("it has been done. ^^ remember do not add people that abuse me ^^")
  416.                                         else:
  417.                                                 room.message("%s it has not been possible to connect your call please hang up and try again" % user.name)
  418.                                 elif do == "remove":
  419.                                         if self.getAccess(user) <= 1:
  420.                                                 room.message("no. =/")
  421.                                                 return
  422.                                         if name not in whitelist: room.message("%s is not whitelisted. ^^" % name, True)
  423.                                         else:
  424.                                                 whitelist.remove(name)
  425.                                                 room.message("it has been done. ^^ sowwy =/", True)
  426.                                 else:
  427.                                         room.message("what? >.>", True)
  428.                         else:
  429.                                 if len(whitelist) == 0: room.message("I have no whitelisted members. ^^", True)
  430.                                 elif len(whitelist) == 1: room.message("I have 1 whitelisted member. ^^", True)
  431.                                 else: room.message("I have %s whitelisted members. ^^" % len(whitelist), True)
  432.                                
  433.                 # bot rooms
  434.                 elif (used_prefix and cmd == "whereiam" or cmd =="rooms"):
  435.                         room.message("I can be found in: <b>%s</b>" % ",".join(rooms),True)
  436.                
  437.                 # user count
  438.                 elif used_prefix and cmd == "howmany":
  439.                         room.message("i see: " + str(room.usercount))
  440.  
  441.                 # help command
  442.                 elif (used_prefix and cmd == "help"):
  443.                         room.message("<a href=\"http://endor.sorch.info/botteh/\" target=\"_blank\"><b>Command list</b></a> Follow me on <a href=\"http://twitter.com/followbotteh/\" target=\"_blank\"><b>Twitter<b></a>", True)
  444.  
  445.                 # join room
  446.                 elif (used_prefix and cmd == "goto" or cmd == "aport")  and len(args) > 0:
  447.                         if user.name in permitted or spermitted:
  448.                                 print("[INF] Joining %s..." % args.split()[0])
  449.                                 self.joinRoom(args.split()[0])
  450.                                 room.message("k there. ^^")
  451.  
  452.                 # say
  453.                 elif (used_prefix and cmd == "say")  and len(args) > 0:
  454.                         if self.getAccess(user) >= 1:
  455.                                 room.message("<b>%s</b> -%s-" % (args, user.name), True)
  456.                         else:
  457.                                 room.message("no. ^^")
  458.  
  459.                 # what access
  460.                 elif used_prefix and cmd == "lvl":
  461.                         if len(args) >= 3:
  462.                                 do, name = args.lower().split(" ", 1)
  463.                                 if self.getAccess(ch.User(name)) > 4 or self.getAccess(user) < 2:
  464.                                         room.message("no. =/")
  465.                                         return
  466.                                 if do == "check":
  467.                                         if name in whitelist: room.message("%s is level 1. ^^" % name, True)
  468.                                         else:
  469.                                                 if name in permitted: room.message("%s is level 3" % name, True)
  470.                                                 elif name in hpermitted: room.message("%s is level 2" % name, True)
  471.                                                 elif name in spermitted: room.message("%s is level 4 O.o" % name, True)
  472.                                                 elif name not in whitelist: room.message("%s is level 0" % name, True)
  473.                 # lockdown
  474.                 elif (used_prefix and cmd == "lockdown"):
  475.                         if self.getAccess(user) == 4:
  476.                                 if len(args.split()) > 0 and args.split()[0].lower() == "release":
  477.                                         lockdown = False
  478.                                         room.message("lets play. ^^")
  479.                                         filename ="status.txt"
  480.                                         print("[INF]Setting status to normal mode...")
  481.                                         file = open(filename, 'w')
  482.                                         file.write("Online")
  483.                                         file.close()
  484.                                 else:
  485.                                         lockdown = True
  486.                                         filename = "status.txt"
  487.                                         file = open(filename, 'w')
  488.                                         print("[INF]Setting status to lockdown...")
  489.                                         file.write("in Lockdown mode")
  490.                                         file.close()
  491.                                         room.message("I ish locked down. ^^")
  492.                                        
  493.                         else:
  494.                                 room.message("no. ^^")
  495.  
  496.                 # kill
  497.                 elif (used_prefix and cmd == "kill")  and len(args) > 0:
  498.                         if self.getAccess(user) >= 1:
  499.                                 room.message("*RAWR* KEELS %s xD" % args)
  500.                         else:
  501.                                 room.message("no. ^^")
  502.                 # kill
  503.                 elif (used_prefix and cmd == "huggle" or cmd =="hug")  and len(args) > 0:
  504.                         if self.getAccess(user) >= 1:
  505.                                 room.message("*HUGGLES* %s" % args)
  506.                         else:
  507.                                 room.message("no. ^^")
  508.                 # fake find
  509.                 elif (used_prefix and cmd == "locate") and len(args) > 0:
  510.                         if self.getAccess(user) >= 1:
  511.                                 name = args.split()[0].lower()
  512.                                 if not ch.User(name).roomnames:  room.message("dont see them. ^^")
  513.                                 else: room.message("%s they are in <b>%s</b> >_>" % (user.name, ", ".join(ch.User(name).roomnames)), True)
  514.                         else:
  515.                                 room.message("no. ^^")
  516.                 # give cookie
  517.                 elif (used_prefix and cmd == "givecookie")  and len(args) > 0:
  518.                                 room.message("gives %s a cookie ^^" % args)
  519.  
  520.                         elif cmd =="8ball":
  521.                         room.message(random.choice(["Signs point to yes." , "No." , "Yep.", "Reply hazy, lemme sober up.","Probably, yeah.","Nope.","As I see it, yes.","You may rely on it.","Fucking 8 balls, how do they work?","Outlook not so good.","It is decidedly so.","Better not tell you now.","Very doubtful.","It is certain.","I dunno. What am I, a mind reader?","Most likely.","Just keep spamming it, bro.","Use more lube and try again.","Outlook good.","Don't count on it.","Does Wolf masturbate to Asuka?","It is unknowable, like Bleak's face.","Why are you asking me?"]))
  522.                
  523.  
  524.                 # leave room
  525.                 elif (used_prefix and cmd == "leave" or cmd == "ninjafy") and len(args) > 0:
  526.                         if user.name in permitted or spermitted:
  527.                                 self.leaveRoom(args)
  528.                                 room.message("k gone. ^^")
  529.                         else:
  530.                                 room.message("no. ^^")
  531.  
  532.                 # give cookie
  533.                 elif (used_prefix and cmd == "define")  and len(args) > 0:
  534.                         try:
  535.                                 word, definition = args.split(":", 1)
  536.                                 word = word.lower()
  537.                         except:
  538.                                 word = args.split()[0].lower()
  539.                                 definition = ""
  540.                         if len(word.split()) > 1:
  541.                                 room.message("error: no phrases")
  542.                                 return
  543.                         if len(args.split()) > 1 and args.lower().split()[1] == "remove":
  544.                                 if word in dictionary:
  545.                                         definition, name = json.loads(dictionary[word])
  546.                                         if name == user.name or self.getAccess(user) >= 3:
  547.                                                 del dictionary[word]
  548.                                                 room.message("removed")
  549.                                                 return
  550.                                         else:
  551.                                                 room.message("error: no access")
  552.                                                 return
  553.                                 else:
  554.                                         room.message("<b>%s</b> is not yet defined you can define it by typing <b>botteh define %s: meaning</b>" % args, True)
  555.                         elif len(definition) > 0: #if there's a colon somewhere
  556.                                 if word in dictionary:
  557.                                         room.message("<b>%s</b> erm... thats already defined. You can not define it again >_>" % user.name, True)
  558.                                 else:
  559.                                         dictionary[word] = json.dumps([definition, user.name])
  560.                                         room.message(word + ": " + definition + "- " + user.name)
  561.                         else:
  562.                                 if word in dictionary:
  563.                                         definition, name = json.loads(dictionary[word])
  564.                                         room.message(word + ": " + definition + " - " + name)
  565.                                 else:
  566.                                         room.message("<b>%s</b> is not yet defined you can define it by saying <b>botteh define %s: meaning</b>  ^^" % (args, args), True)
  567.  
  568.        
  569.                 # dance
  570.                 elif (used_prefix and cmd == "dance"):
  571.                         if self.getAccess(user) >= 1:
  572.                                 for i, msg in enumerate(dancemoves):
  573.                                         self.setTimeout(i / 2, room.message, msg)
  574.                         else:
  575.                                 room.message("no dances for you >_>")
  576.    
  577.                 # youtube search
  578.                 elif (used_prefix and cmd == "tube" or used_prefix and cmd == "ytb"):
  579.                         search = args.split()
  580.                         def everything_between(text,begin,end):
  581.                                 idx1=text.find(begin)
  582.                                 idx2=text.find(end,idx1)
  583.                                 return ' '.join(text[idx1+len(begin):idx2].strip().split())
  584.                         try:
  585.                                 raw = str(urllib.request.urlopen("http://gdata.youtube.com/feeds/api/videos?vq=%s&racy=include&orderby=relevance&max-results=1" % "+".join(search)).read())
  586.                                 id = helperCmd.everything_between(raw,'http://www.youtube.com/watch?v=','&amp;')
  587.                                 info = youtube.Video(id)
  588.                                 link = "http://www.youtube.com/watch?v="+id
  589.                                 room.message("%s, i found: \"%s\" by %s. %s" % (user.name, info.get_title()[:50], info.get_auth()[:50], link), True)
  590.                         except:
  591.                                 room.message("Error: Nothing found for %s =/" % args)                                          
  592.  
  593.                 #                                              
  594.                 # Persona
  595.                 #
  596.                 #redo "split message into command and args"
  597.                 data = message.body.split(" ", 1)
  598.                 if len(data) > 1:
  599.                         cmd, args = data[0], args # if command and args
  600.                 else:
  601.                         cmd, args  = data[0], ""# if command and no args
  602.                 # butterfly responce (8|8)
  603.                 if cmd =="8|8":
  604.                         room.message(random.choice(["Omg sexy *chases* ^w^" , "woah" , "I want one =/" , "O_O -watches-" , "O.o -touchs-" , "^^" , "oooo"]))
  605.  
  606.                 elif cmd == "><>":
  607.                         room.message(random.choice(["eeee fishes ^^" , "o.o fish" , "I want one =/" , "waves at fishy ^^" , "O.o -touchs-" , "^^" , "oooo fish"]))
  608.                
  609.                 def onFloodWarning(self, room):
  610.                         room.reconnect()
  611.        
  612.        
  613.                 def onUserCountChange(self, room):
  614.                         print("users: " + str(room.usercount))
  615.  
  616.                
  617. ########################################################################################
  618. # Bot username password and rooms
  619. ########################################################################################
  620. def hexc(e):
  621.         et, ev, tb      = sys.exc_info()
  622.         if not tb: print(str(e))
  623.         while tb:
  624.                 lineno = tb.tb_lineno
  625.                 fn      = tb.tb_frame.f_code.co_filename
  626.                 tb      = tb.tb_next
  627.         print("(%s:%i) %s" % (fn, lineno, str(e)))
  628.        
  629. if __name__ == "__main__":
  630.         error = 0
  631.         try:
  632.                 os.system("clear") # clear console on launch
  633.                 TestBot.easy_start(rooms, "QZ", "19ps12")
  634.         except KeyboardInterrupt:
  635.                 print("[ERR] Console initiated a kill.")
  636.         except Exception as e:
  637.                 print("[ERR] Fatal error.")
  638.                 error = 1
  639.                 hexc(e)
  640.         print("[SAV] Saving Definitions..")
  641.         f = open("definitions.txt", "w")
  642.         for word in dictionary:
  643.                 definition, name = json.loads(dictionary[word])
  644.                 f.write(json.dumps([word, definition, name])+"\n")
  645.         f.close()
  646.         print("[SAV] Saving SuperMasters..")
  647.         f = open("spermitted.txt", "w")
  648.         f.write("\n".join(spermitted))
  649.         f.close()
  650.         print("[SAV] Saving Masters..")
  651.         f = open("permitted.txt", "w")
  652.         f.write("\n".join(permitted))
  653.         f.close()
  654.         print("[SAV] Saving HalfMasters..")
  655.         f = open("hpermitted.txt", "w")
  656.         f.write("\n".join(hpermitted))
  657.         f.close()
  658.         print("[SAV] Saving Whitelist..")
  659.         f = open("whitelist.txt", "w")
  660.         f.write("\n".join(whitelist))
  661.         f.close()
  662.         print("[SAV] Saving Rooms..")
  663.         f = open("rooms.txt", "w")
  664.         f.write("\n".join(rooms))
  665.         f.close()
  666. #STATUS
  667. #
  668.         filename = "status.txt"
  669.         f = open(filename, 'w')
  670.         print ("[INF] Setting status offline...")
  671.         f.write("Offline")
  672.         f.close()
  673. #
  674.  
  675.         if error == 1:
  676.                 print("Waiting 10 seconds for you to read the error..")
  677.                 time.sleep(10)
  678.         print("[INF] Shutting down..")
  679. ########################################################################################
Advertisement
Add Comment
Please, Sign In to add comment