0rx

Try 2

0rx
Dec 2nd, 2013
637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 12.80 KB | None | 0 0
  1. ########################################################################
  2. ########################################################################
  3. ##### File: HatterBot version 1.4.0                                #####
  4. ##### by: 0rx                                                      #####
  5. ##### http://remaire.chatango.com                  #####
  6. ##### http://tango-hyoo.chatango.com                   #####
  7. ##### This bot script is made with the help of some great friends  #####
  8. ##### with that, this bot is made for educational purposes only.   #####
  9. ##### You're free to copy this script as long as you credit those  #####
  10. ##### people below.                                                #####
  11. ##### Credits:    - Poeticartist1 (Owner of Nadashiki)             #####
  12. #####             - TryHardHusky(Horny Bot Maker)                  #####
  13. #####             - 0rx(Author)                                    #####
  14. #####             - Agunq(Fellow Bot Maker)                        #####
  15. #####             - Peoples from [email protected]         #####
  16. ########################################################################
  17. ########################################################################
  18.  
  19.  
  20. ## YOU WILL NEED THE CH.PY TO RUN THIS BOT!
  21. ## YOU CAN GET IT FROM HERE http://pastebin.com/MBwdSZsW
  22.  
  23. import ch
  24. import random
  25. import sys
  26. import os
  27. import re
  28. import cgi
  29. import codecs
  30. import traceback
  31. import time
  32. import datetime
  33. import urllib
  34. import binascii
  35. import youtube
  36. import helperCmd
  37. import json
  38. import cmds
  39. import __future__
  40.  
  41. ##############################################################
  42. lockdown = False
  43. activated = True
  44. ##############################################################
  45. ## Timer Stuff ###############################################
  46.  
  47. startTime = time.time()
  48.  
  49. ##     End     ###############################################
  50. ##############################################################
  51.  
  52.  
  53. ##############################################################
  54. ## File Stuff ################################################
  55.  
  56. ## PMLOG
  57. filename = "pmlog.txt"#the text file you need to have in same place as bot
  58. pmlog=[]
  59. f = open(filename, 'r') #open status.txt and make a writing variable called file
  60. print("[INFO]LOADING PMLOG")#print to console
  61. time.sleep(1)#pause for one second
  62. for name in f.readlines():
  63.   if len(name.strip())>0: pmlog.append(name.strip())
  64. f.close()#close the file
  65.  
  66.  
  67. ## Nicknames
  68. nicks=dict()#empty list
  69. f=open ("Nicks.txt","r")#r=read w=right
  70. print ("[INF]Loading Nicks...")#print
  71. time.sleep(1)
  72. for line in f.readlines():#loop through eachline and read each line
  73.     try:#try code
  74.         if len(line.strip())>0:#strip the whitespace checkgreater than 0
  75.             user , nick = json.loads(line.strip())
  76.             nicks[user] = json.dumps(nick)
  77.     except:
  78.         print("[Error]Can't load nick %s" % line)
  79.  
  80. ## definitions
  81. dictionary = dict() #volatile..
  82. f = open("definitions.txt", 'r') #read-only
  83. print("[INF]Loading Definitions...")
  84. time.sleep(1)
  85. for line in f.readlines():
  86.   try:
  87.     if len(line.strip())>0:
  88.       word, definitions, name = json.loads(line.strip())
  89.       dictionary[word] = json.dumps([definitions, name])
  90.   except:
  91.     print("{ERROR]Cant load Definitions: %s" % line)
  92. f.close()
  93.  
  94. ## Locks##
  95. locks = []
  96. f = open("locks.txt", 'r')
  97. time.sleep(1)
  98. for name in f.readlines():
  99.   if len(name.strip())>0: locks.append(name.strip())
  100. f.close()
  101.  
  102. ##OWNER##
  103. spermitted = []
  104. f = open("spermitted.txt", "r") #read-only
  105. print("[INF]Loading Supreme Masters...")
  106. time.sleep(1)
  107. for name in f.readlines():
  108.   if len(name.strip())>0: spermitted.append(name.strip())
  109. f.close()
  110.  
  111. ##MODS##
  112. permitted = []
  113. f = open("permitted.txt", "r")
  114. print("[INF]Loading Mods...")
  115. time.sleep(1)
  116. for name in f.readlines():
  117.   if len(name.strip())>0: permitted.append(name.strip())
  118. f.close()
  119.  
  120. ##Arch-Knights##
  121. hpermitted = []
  122. f = open("hpermitted.txt", "r") #read-only
  123. print("[INF]Loading Arch-Knights....")
  124. time.sleep(1)
  125. for name in f.readlines():
  126.   if len(name.strip())>0: hpermitted.append(name.strip())
  127. f.close()
  128.  
  129. ##Players##
  130. whitelist = []
  131. f = open("whitelist.txt", "r") #read-only
  132. print("[INF]Loading Players...")
  133. time.sleep(1)
  134. for name in f.readlines():
  135.   if len(name.strip())>0: whitelist.append(name.strip())
  136. f.close()
  137.  
  138. ##Peeps##
  139. friend = []
  140. f = open("friend.txt", "r") # read-only
  141. print("[INF]Loading Friends...")
  142. time.sleep(1)
  143. for name in f.readlines():
  144.   if len(name.strip())>0: whitelist.append(name.strip())
  145. f.close()
  146.  
  147. ##Rooms##
  148. rooms = []
  149. f = open("rooms.txt", "r") #read-only
  150. print("[INF]Loading Rooms...")
  151. time.sleep(1)
  152. for name in f.readlines():
  153.   if len(name.strip())>0: rooms.append(name.strip())
  154. f.close()
  155.  
  156. blacklist = ['botteh','mechabot','nadashiki','aqunq','justhoax','ragebot','illogic']
  157. specials = ['senops','sarashiki23','ampunganz','galaksi2','dovion','frizki']
  158.  
  159. def saveNicks():
  160.     print("[SAVE] SAVING NICKS...")
  161.     f = open("Nicks.txt", "w")
  162.     for user in nicks:
  163.         nick = json.loads(nicks[user])
  164.         f.write(json.dumps([user, nick])+"\n")
  165.     f.close()
  166.    
  167. def sntonick(username):
  168.     user = username.lower()
  169.     if user in nicks:
  170.         nick = json.loads(nicks[user])
  171.         return nick
  172.     else:
  173.         return user
  174. ## End #######################################################
  175. ##############################################################
  176.  
  177.  
  178. ##############################################################
  179. ## Define Stuff ##############################################
  180.  
  181.  
  182. ## End #######################################################
  183. ##############################################################
  184.  
  185. ##############################################################
  186. ########          Mon Nov 18 2013 22:15:33 WIB        ########
  187. ##############################################################
  188.  
  189. if sys.version_info[0] > 2:
  190.   import urllib.request as urlreq
  191. else:
  192.   import urllib2 as urlreq
  193.  
  194.  
  195. ##############################################################
  196. ## Time Stuff ################################################
  197.  
  198. def getUptime():
  199.   """
  200.  Returns the number of seconds since the programs started.
  201.  """
  202.   #do return startTime if you want the process start time
  203.  
  204.   return time.time() - startTime
  205.  
  206. ## System Uptime
  207. def uptime():
  208.  
  209.   try:
  210.     f = open( "/proc/uptime")
  211.     contents = f.read().split()
  212.     f.close()
  213.   except:
  214.     return "Cannot open uptime file"
  215.  
  216.   total_seconds = float(contents[0])
  217.  
  218.   ## Helper vars:
  219.   MINUTE = 60
  220.   HOUR = MINUTE * 60
  221.   DAY = HOUR * 24
  222.  
  223.   ## Get the days, hours, etc:
  224.   days = int( total_seconds / DAY )
  225.   hours = int( ( total_seconds % DAY ) / HOUR )
  226.   minutes = int( ( total_seconds % HOUR ) / MINUTE )
  227.   seconds = int( total_seconds % MINUTE )
  228.  
  229.   ## Build up the pretty string (like this: "N days. N hours, N minutes, N seconds")
  230.   string = ""
  231.   if days > 0:
  232.     string += str(days) + " " + (days == 1 and "day" or "days" ) + ", "
  233.   if len(string) > 0 or hours > 0:
  234.     string += str(hours) + " " + (hours == 1 and "hour" or "hours" ) + ", "
  235.   if len(string) > 0 or minutes > 0:
  236.     string += str(minutes) + " " + (minutes == 1 and "minute" or "minutes" ) + ", "
  237.   string += str(seconds) + " " + (seconds == 1 and "second" or "seconds" )
  238.  
  239.   return string;
  240.  
  241. ## End #########################################################
  242. ################################################################
  243.  
  244. ################################################################  
  245. ## Important TestBot Class #####################################
  246. class TestBot(ch.RoomManager):
  247.  
  248. ## Setting Font Format and Colors
  249.   def onInit(self):
  250.     self.setNameColor("FF9966")
  251.     self.setFontColor("33CCFF")
  252.     self.setFontFace("1")
  253.     self.setFontSize(11)
  254.     self.enableBg()  
  255.     self.enableRecording()
  256.    
  257. ## Rank Configs
  258.   def getAccess(self, user):
  259.     if user.name in spermitted: return 5
  260.     elif user.name in permitted: return 4
  261.     elif user.name in hpermitted: return 3
  262.     elif user.name in whitelist: return 2
  263.     elif user.name in friend: return 1
  264.     else: return 0
  265.  
  266. ##############################################################
  267. ## Connecting and Disconnecting crap #########################
  268.  
  269.   def onConnect(self, room):
  270.     print("[+] Mad Hatter Connected to "+room.name)
  271.    
  272.   def onReconnect(self, room):
  273.     print("[+] Mad Hatter Reconnected to "+room.name), room.message("Reconnected")
  274.    
  275.   def onDisconnect(self, room):
  276.     print("[+] Mad Hatter Disconnected from "+room.name)
  277.    
  278.   def onJoin(self, room, user):
  279.     print("[+] "+user.name+" joined "+room.name)
  280.     if lockdown: return
  281.     if self.getAccess(user) == 5:
  282.       time.sleep(2)
  283.       room.message("*Bows down to "+ user.name +"*")
  284.       return
  285.    # if self.getAccess(user) == 3:
  286.     #  time.sleep(2)
  287.      # room.message("Arch Knight is present")
  288.       #return
  289.    # elif self.getAccess(user) == 4 and not user.name == "ramielsama":
  290.     #  time.sleep(2)
  291.      # room.message("Wellcome back "+sntonick(user.name)+" !!", True)
  292.       #return
  293.     elif user.name == "ramielsama":
  294.       time.sleep(2)
  295.       room.message("Wellcome back "+sntonick(user.name)+" ! *Hugs and kisses My Fallen Angel*", True)
  296.       return
  297.   def onConnectFail(self, room):
  298.     print("[ERR} Room Not Found")
  299.      
  300.   def onBan(self, room, user, target):
  301.     print("someone got banned in "+room.name)
  302.  
  303. ## End #######################################################
  304. ##############################################################
  305.  
  306. ##############################################################
  307. ## Setting up Commands #######################################
  308.  
  309.   def onMessage(self, room, user, message):
  310.     global activated
  311.     global lockdown
  312.     ## rpg game
  313.     global rpgbool
  314.     global monster
  315.     global monsterlife
  316.     global rpgbattleactive
  317.     global bosslist
  318.     global boss
  319.     global bosslife
  320.     #Print to console
  321.     if room.getLevel(self.user) > 0:
  322.       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.title(), message.body))
  323.     else:
  324.       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.title(), message.body))
  325.  
  326.     ##roomlog
  327.     roomlog.append("[%s]\033[LVL %s]\033[%s] %s: %s" % (time.strftime("%d/%m/%y- %H:%M:%S", time.localtime(time.time())), self.getAccess(user), room.name, user.name.capitalize(), message.body))
  328.  
  329.     if self.user == user: return #ignore self(bot)
  330.  
  331.     if "wl me" == message.body:
  332.       if room.getLevel(user) < 1 and self.getAccess(user) == 0:
  333.         friend.append(user.name)
  334.         room.message(user.name+" can use me now. ^^")
  335.       else: room.message("You're silly >_>")
  336.     if "descend" in message.body:
  337.       if self.getAccess(user) < 4:
  338.         if user.name == "ramielsama":
  339.           permitted.append(user.name)
  340.           room.message("A Fallen Angel descends to earth :o")
  341.           if user.name in friend:
  342.             friend.remove(user.name)
  343.           if user.name in whitelist:
  344.             whitelist.remove(user.name)
  345.         if user.name == "xmothra":
  346.           spermitted.append(user.name)
  347.           room.message("Here comes my mighty creator :o")
  348.           if user.name in friend:
  349.             friend.remove(user.name)
  350.           if user.name in whitelist:
  351.             whitelist.remove(user.name)
  352.         else: return
  353.       else: return
  354.  
  355.     if "test" == message.body or "Test" == message.body or "tes" == message.body or "Tes" == message.body:
  356.       room.message("Test request has been granted, you may test it now :)")
  357.  
  358.     if self.getAccess(user) == 0 and not room.getLevel(user) >= 1: return #ignore non-whitelisted users except room mods/owners
  359.     if self.getAccess(user) < 4 and not activated: return #ignore everyone when in lockdown
  360.     if user.name in blacklist: return #ignore blacklisted user
  361.     if self.getAccess(user) < 3 and not room.getLevel(user) < 1 and room.name in locks: return #ignore rank 1 and 2 when room locked
  362.  
  363.     if message.body[0] == "'" or message.body[0] == ":": #prefix part in this line
  364.         data = message.body[1:].split(" ", 1)
  365.         if len(data) == 2:
  366.           cmd, args = data[0], data[1]
  367.         else:
  368.           cmd, args = data[0], ""
  369.  
  370.         if lockdown and self.getAccess(user) < 4: return
  371.  
  372.         # Nick
  373.         elif (cmd == "nick"):
  374.           try:
  375.             if args:
  376.               nicks[user.name]=json.dumps(args)
  377.               room.message (user.name+" will now be called "+args ,True)
  378.               saveNicks()
  379.             if args == "":
  380.               room.message("type 'nick (your-new-nickname-here)")
  381.           except:
  382.             room.message("Sorry, but it seems that I failed to give you a nickname.")
Advertisement
Add Comment
Please, Sign In to add comment