SHARE
TWEET

BOT

a guest Aug 14th, 2016 32 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. # YOU WILL NEED THE CH.PY TO RUN THIS BOT!
  4. # YOU CAN GET IT FROM HERE http://pastebin.com/MBwdSZsW
  5.  
  6. import ch
  7. import random
  8. import sys
  9. import os
  10. import re
  11. import time
  12. import json
  13. import urllib
  14. import traceback
  15. import __future__
  16. from urllib.request import urlopen
  17. import urllib
  18. import unicodedata
  19. import time
  20.  
  21.  
  22. ################################
  23. lockdown = False
  24. activated = True
  25. ################################
  26.  
  27. ################################
  28. ##File Stuff##
  29.  
  30. blacklist = dict()
  31. try:
  32.   f = open("blacklist.txt", "r")
  33.   blacklist = eval(f.read())
  34.   f.close()
  35. except:pass
  36.  
  37. mod = []
  38. file = open("mod.txt", 'r')
  39. for name in file.readlines():
  40.   if len(name.strip()) > 0 :
  41.     mod.append(name.strip())
  42. print("NOTICE: Mod list loaded.")
  43. file.close()
  44.  
  45. registered = []
  46. file = open("registered.txt", 'r')
  47. for name in file.readlines():
  48.   if len(name.strip()) > 0 :
  49.     registered.append(name.strip())
  50. print("NOTICE: Registered Users loaded.")
  51. file.close()
  52.  
  53. owner = []
  54. file = open("owner.txt", 'r')
  55. for name in file.readlines():
  56.   if len(name.strip()) > 0 :
  57.     owner.append(name.strip())
  58. print("NOTICE: Your Ownership loaded.")
  59. file.close()
  60.  
  61. rooms = []
  62. file = open("rooms.txt", 'r')
  63. for name in file.readlines():
  64.   if len(name.strip()) > 0 :
  65.     rooms.append(name.strip())
  66. print("NOTICE: Room list loaded.")
  67. file.close()
  68.  
  69. locks = []
  70. file = open("locks.txt", 'r')
  71. for name in file.readlines():
  72.   if len(name.strip()) > 0 :
  73.     locks.append(name.strip())
  74. print("NOTICE: Locked Rooms loaded.")
  75. file.close()
  76.  
  77. ##End##
  78. ################################
  79.  
  80. #############################################################
  81. ##========================Variables========================##
  82.  
  83. botname = "bLadyAnna" #Put your bot name here
  84.  
  85. botpassword = "hybot" #Put your bot password here
  86.  
  87. cek_mods = dict() #Don't mess with this variable. This one is related with *mods command.
  88.  
  89. error = ("Expectation failed.")    #Error message
  90.  
  91. command_list = ['help','wl/register','uwl/unregister','bl/blacklist','chain','ubl/unblacklist','unchain','rank','setrank','pm','broadcast','say','reverse/rsay','find','multichat','ban','unban','join','leave','lock','unlock','rooms','save','mods','activate','restrict','lockdown','wake']
  92.  
  93. prefix = "." ##You set the prefix here
  94.  
  95. GOOGLE_API_KEY = "AIzaSyAA_MhpqTqMG3su4BSt4k7_AyozaEkG_p4"
  96. BING_API_KEY = "bXMJ7CAYPDH5Fz8Hfut5XNhGY2N9xkwJR8fKsPlSU78"
  97.  
  98. DELAY_PER_CHAR_RESP = 0.09
  99.  
  100. DELAY_PER_CHR_READ = 0.1
  101.  
  102. ##===========================End===========================##
  103. #############################################################
  104.  
  105. #setting colors
  106.  
  107. def convert_to_ascii(s):
  108.   s_result = "";
  109.   sarr = s;
  110.   for i in range(0, len(sarr)):
  111.     if(ord(sarr[i]) < 128):
  112.       s_result += sarr[i]
  113.   return s_result
  114.  
  115. class TestBot(ch.RoomManager):
  116.   def onInit(self):
  117.     self.setNameColor("FF9966")
  118.     self.setFontColor("33CCFF")
  119.     self.setFontFace("1")
  120.     self.setFontSize(12)
  121.     self.enableBg()
  122.     self.enableRecording()
  123.  
  124.   def saveAll(self):
  125.     room = self._Room
  126.     f = open("owner.txt", "w")
  127.     f.write("\n".join(owner))
  128.     f.close()
  129.     f = open("mod.txt", "w")
  130.     f.write("\n".join(mod))
  131.     f.close()
  132.     f = open("registered.txt", "w")
  133.     f.write("\n".join(registered))
  134.     f.close()
  135.     f = open("blacklist.txt", "w")
  136.     f.write("\n".join(blacklist))
  137.     f.close()
  138.     f = open("locks.txt", "w")
  139.     f.write("\n".join(locks))
  140.     f.close()
  141.     f = open("rooms.txt", "w")
  142.     f.write("\n".join(self.roomnames))
  143.     f.close()
  144.  
  145.  
  146.  
  147.   def getAccess(self, room, user):
  148.     vroom = room
  149.     if user.name in owner and not user.name in blacklist: return 5
  150.     elif user.name in mod and not user.name in blacklist: return 4
  151.     elif user.name in registered and user.name in vroom.ownername and not user.name in blacklist: return 3
  152.     elif user.name in registered and user.name in vroom.modnames and not user.name in blacklist: return 2
  153.     elif user.name in registered and not user.name in vroom.ownername and not user.name in room.modnames and not user.name in blacklist: return 1
  154.     elif user.name in blacklist: return -1
  155.     else: return 0
  156.  
  157. #############################################
  158. ##connecting and disconnecting crap##
  159.  
  160.   def onConnect(self, room):
  161.     print("[+] Mad Hatter Connected to "+room.name)
  162.     for i in cek_mods: #Di onJoin
  163.       if len(cek_mods[i]) > 1:
  164.         rmm, rmd = json.loads(cek_mods[i])
  165.         self.getRoom(rmm).message("<br/>||<font color='#87ceeb'><b>OWNER</b></font>: <b>"+ (self.getRoom(rmd).ownername) +"</b> <br/>||<b>Mods</b>: "+", ".join(self.getRoom(rmd).modnames), True)
  166.         self.leaveRoom(rmd)
  167.         cek_mods.pop(i)
  168.       return
  169.  
  170.   def onReconnect(self, room):
  171.     print("[+] Mad Hatter Reconnected to "+room.name)
  172.  
  173.   def onDisconnect(self, room):
  174.     print("[+] Mad Hatter Disconnected from "+room.name)
  175.  
  176.   def onBan(self, room, user, target):
  177.     print(user.name+" got banned in "+room.name)
  178.  
  179. #  def onJoin(self, room, user):
  180. #    print("[+] "+user.name+" joined "+room.name)
  181. #    if not activated: return
  182. #    if user.name in owner:
  183. #      room.message("*Bows down to "+ user.name.title() +"*")
  184. #      return
  185. #    if self.getAccess(room, user) > 1 and not user.name in owner:
  186. #      room.message("Good Day "+user.name+".")
  187. #      return
  188. #    if int(room.usercount) > 20:
  189. #      return
  190. #    if self.getAccess(room, user) == 1 or self.getAccess(room, user) == 0:
  191. #      room.message(user.name+" has joined the room.")
  192. #      return
  193.  
  194.   def onConnectFail(self, room):
  195.     print("Pânico: Sala não encontrada!")
  196.     for i in cek_mods: #Di onJoin
  197.       if len(cek_mods[i]) > 1:
  198.         rmm, rmd = json.loads(cek_mods[i])
  199.         self.getRoom(rmm).message("Such room doesn't exist")
  200.         cek_mods.pop(i)
  201.       return
  202.  
  203.  
  204.  
  205. ##End##
  206. #############################################
  207.  
  208. #############################################
  209. ##setting up commands##
  210.  
  211.   def onMessage(self, room, user, message):
  212.       if user == self.user:
  213.           return
  214.       global activated
  215.       global lockdown
  216.       global prefix
  217.       global owner
  218.       global mod
  219.       global registered
  220.       try:
  221.         if room.getLevel(self.user) > 0:
  222.           print("[%s]\033[94m[MSG]\033[0m\033[31m[Rank %s]\033[0m\033[41m[%s][%s] %s: %s" % (time.strftime("%d/%m/%y- %H:%M:%S", time.localtime(time.time())), self.getAccess(room, user), room.name, message.ip, user.name.title(), message.body))
  223.         else:
  224.           print("[%s]\033[94m[MSG]\033[0m\033[31m[Rank %s]\033[0m\033[41m[%s][User_IP: Null] %s: %s" % (time.strftime("%d/%m/%y- %H:%M:%S", time.localtime(time.time())), self.getAccess(room, user), room.name, user.name.title(), message.body))
  225.       except:
  226.         pass
  227.       if user.name.startswith("#") or user.name.startswith("!"):return
  228.       if self.user == user: return
  229.       if user.name in blacklist: return
  230.       if self.getAccess(room, user) > 0:
  231.         if not activated and self.getAccess(room, user) < 4: return #return, if not activated and user rank is less than 4.
  232.       ##Persona | You design a good personality for your bot in this part
  233.       def SendMessage(msg):
  234.           time.sleep(DELAY_PER_CHAR_RESP * len(msg));
  235.           room.message(msg);
  236.           return;
  237.  
  238.       comm = message.body.split(" ")
  239.       cc = comm[0];
  240.       master = "Hyreos";
  241.       sentence = convert_to_ascii( message.body.lower() );
  242.       #time.sleep(DELAY_PER_CHR_READ*len(sentence))
  243.       if not "ladyanna" in sentence:
  244.           if comm[0] == "calcule":
  245.               expression = ""
  246.               comm[0] = "";
  247.               for i in range(len(comm)):
  248.                   expression += comm[i];
  249.                   SendMessage("O resultado é: " + str( eval( expression ) ) + ".")
  250.           elif ("quem" in sentence and " o " in sentence and "mestre" in sentence):
  251.               SendMessage("Meu mestre é o Hyreos, cujo eu sou completamente devotada.")
  252.           elif ("ta" in sentence or "tá" in sentence) and "bugada" in sentence:
  253.               talk = [ "Por quê meu mestre é uma mau programador.", "Por quê meu mestre deveria ter me programador melhor", "Por quê meu mestre faltou as aulas de Python. ;-;", "Por que meu mestre é um fraco." ]
  254.               SendMessage(talk[random.randint(0, len(talk)-1)]);
  255.           elif ("viada" in sentence or "maldita" in sentence or "cachorra" in sentence or "idiota" in sentence or "puta" in sentence or "cadela" in sentence or "besta" in sentence):
  256.               talk = [ "Quieto, faça um bem para a humanidade e se mate.", "Escória.", "Verme nojento", "Cale a boca.", "Você merece a morte, humano nojento." ]
  257.               SendMessage(talk[random.randint(0, len(talk)-1)]);
  258.           elif ("Hyreos" in sentence and (" é " in sentence or " está " in sentence) and ("carente" in sentence or "idiota" in sentence or "besta" in sentence or "fresco" in sentence or "estranho" in sentence)):
  259.               talk = ["Pense duas vezes antes de ofender o meu mestre, seu baka!", "Quieto, escória.", "Besta, não zombe de meu mestre.", "Meu mestre ainda vai dominar o mundo!"]
  260.               SendMessage(remover_acentos( talk[random.randint(0, len(talk)-1)]) );
  261.           elif ("a" in sentence or "o" in sentence) and " é " in sentence and " não?" in sentence:
  262.               SendMessage("Concordo. >.<")
  263.           #return
  264.       elif "ladyanna" in sentence and len(sentence) < len("@bladyanna")+3:
  265.           talk = [ "Sim?", "Oi.", "?" ]
  266.           SendMessage(talk[random.randint(0, len(talk)-1)])
  267.       elif "obrigada" in sentence or "valew" in sentence or "valeu" in sentence or "obg" in sentence or "vlw" in sentence:
  268.           talk = [ "De nada. >.<", "É sempre bom ser útil.", "Não tem de quer." ]
  269.           SendMessage(talk[random.randint(0, len(talk)-1)])
  270.       elif "mal criada" in sentence or "deselegante" in sentence:
  271.           if user.name.title() == "Hyreos":
  272.               SendMessage("Me desculpe, mestre, LadyAnna é sempre tão descuidada, me desculpe mesmo.")
  273.           else:
  274.               SendMessage("Me desculpe, mas só o mestre pode me corrigir.")
  275.       elif "oi" in sentence:
  276.           if user.name.title() == "Hyreos":
  277.               SendMessage("Olá, mestre. <3")
  278.           else:
  279.               talk = [ "Oi", "Olá, " + user.name.title() + "." ]
  280.               SendMessage(talk[random.randint(0, len(talk)-1)])
  281.       elif ("viada" in sentence or "maldita" in sentence or "cachorra" in sentence or "idiota" in sentence or "puta" in sentence or "cadela" in sentence or "besta" in sentence):
  282.           talk = [ "Quieto, faça um bem para a humanidade e se mate.", "Escória.", "Verme nojento", "Cale a boca.", "Você merece a morte, humano nojento." ]
  283.           SendMessage(talk[random.randint(0, len(talk)-1)]);
  284.       elif "linda" in sentence or "fofa" in sentence or "perfeita" in sentence:
  285.           talk = [ "Own, obrigado! <3", "Obrigado. <3", "Obrigado, " + user.name.title() + "!" ]
  286.           SendMessage(talk[random.randint(0, len(talk)-1)])
  287.       elif "ei" in sentence:
  288.           talk = [ "Oi, como eu poderia ajudar?", "@" + user.name.title() + ", Sim?", "?" ]
  289.           SendMessage(talk[random.randint(0, len(talk)-1)]);
  290.       elif("me" in sentence and "ama" in sentence):
  291.           if(user.name.title() == master):
  292.               talk = [ "Sim, mestre eu te amo.", "Mestre, eu existo por você...", "Sim." ]
  293.               SendMessage(talk[random.randint(0, len(talk)-1)]);
  294.           else:
  295.               talk = [ "Não.", "Nah.", "Nunca." ]
  296.               SendMessage(talk[random.randint(0, len(talk)-1)]);
  297.       elif ("te" in sentence or "ti" in sentence) and " amo" in sentence:
  298.           if(user.name.title() != master):
  299.               talk = [ "Eu não.", "Sério? Então recomendo que se mate...", "Eu não sou real, compreenda." ]
  300.               SendMessage(talk[random.randint(0, len(talk)-1)]);
  301.           else:
  302.               msgToSend = "Mestre, eu também te amo, irei devotar cada byte meu, cada instrução processada, somente a você, e apenas você. <3"
  303.               SendMessage(msgToSend)
  304.       else:
  305.           SendMessage("Me desculpe, LadyAnna não é muito inteligente e não pode entender isso. >.<")
  306.       ##Commands | You design great commands for your bot in this part
  307.       if message.body[0] == prefix: #prefix usage in this line (for this case I use "*" as prefix)
  308.           data = message.body[1:].split(" ", 1) #This part splits message body into [0]prefix and [1:]data ([1:] <- this means the message body's second character and after) and data will be split into 2 (cmd(data[0]), args(data[1])) which is very usefull. (Many thanks to TryHardHusky)
  309.           if len(data) == 2: #If there are more than 1 data (This is where we will get args)
  310.               cmd, args = data[0], data[1] #the first data (data[0]) will be the cmd (specified command) and the next data will be args (it doesn't matter how many word next to the cmd, It'd eventually be args)
  311.           else: #If there is only 1 data (No args)
  312.               cmd, args = data[0], "" #the arg will simply be "" (Empty)
  313.           cmd == cmd.lower()
  314.  
  315.           ##Activating and Inactivating Bot
  316.  
  317.           if cmd == "desligar":
  318.               if self.getAccess(room, user) > 0:
  319.                   self.saveAll()
  320.                   room.message("Meu mestre malvado me desligou, tchau.")
  321.                   self.setTimeout(3, self.stop, )
  322.               else:
  323.                   return
  324.           if cmd =="profile":
  325.               print ("intercepted")
  326.               name=args
  327.               pdata = urlopen("http://st.chatango.com/profileimg/"+args[:1]+"/"+args[1:2]+"/"+args+"/mod1.xml")
  328.               pread= str(pdata.read())
  329.               if "<img style" in pread:
  330.                   room.message(args+" is not (yet) a chatango username.")
  331.               else:
  332.                   trash , pclean=pread.split("<body>",1)
  333.                   pclean , trash=pclean.split("</body>",1)
  334.                   room.message(urllib.parse.unquote(''+pclean+''"<br>"), True)
  335.           if cmd == "youtube" and len(args) > 0:
  336.               #FEITO PELO DEUS HYREOS \O/
  337.               s_result = "";
  338.               sarr = args;
  339.               for i in range(0, len(sarr)):
  340.                 if(ord(sarr[i]) < 128):
  341.                   s_result += sarr[i]
  342.              
  343.               site= "https://www.googleapis.com/youtube/v3/search?part=id&q=" + s_result.replace(" ", "%20")  + "&type=video&key=AIzaSyAA_MhpqTqMG3su4BSt4k7_AyozaEkG_p4"
  344.               response = urlopen(site).read()
  345.               json_response = json.loads(response.decode())
  346.               print("json loaded")
  347.               if(len(json_response["items"]) > 0):
  348.                   vId = json_response["items"][0]["id"]["videoId"]
  349.                   room.message("https://www.youtube.com/watch?v=" + vId)
  350.           if cmd == "ligar":
  351.               if self.getAccess(room, user) > 0: return
  352.               activated = True
  353.               room.message("Estou ativada e pronta para dar todo meu amor ao mestre. <3")
  354.  
  355.           if cmd == "restrict":
  356.               if self.getAccess(room, user) < 4: return
  357.               activated = False
  358.               room.message("Estou restringida, ;-;")
  359.  
  360.           if not activated and self.getAccess(room, user) < 5: return #Ignore user with rank lower than 5 when not activated
  361.           if lockdown and self.getAccess(room, user) < 4: return #Ignore user with rank lower than 4 when in lockdown
  362.  
  363.           if cmd == "help": #Help command (It will show the bot's version, user's rank status, user's room level, and Available commands)
  364.             version = "Example Version" #You set the bot's version manually in this line
  365.             rank = 0
  366.             moded = "no"
  367.             rank = self.getAccess(room, user)
  368.             if room.getLevel(user) > 0:
  369.               moded = "yes"
  370.             if rank > 1:
  371.               room.message("<font color='#FF8C00'><b>"+self.user.name+"</b></font>(<font color='#B8860B'><b>"+version+"</b></font>)<br/>"+user.name.title()+" - [<font color='#FF0000'><b>Rank "+str(rank)+"</b></font>] - Moded [<b>"+moded+"</b>]<br/>cmds: use [%s] as prefix [%s]"% (prefix, ", ".join(command_list)), True)
  372.             if rank == 0:
  373.               moded = "Null"
  374.               if room.getLevel(user) > 0:
  375.                 moded = "Moded"
  376.               room.message("<font color='#FF8C00'><b>"+self.user.name+"</b></font>(<font color='#B8860B'><b>"+version+"</b></font>)<br/>"+user.name.title()+" - [<font color='#FF0000'><b>Unregistered</b></font>] - [<b>"+moded+"</b>]<br/>cmds: use [%s] as prefix [%s]"% (prefix, ", ".join(['help','wl','uwl'])), True)
  377.  
  378.           if self.getAccess(room, user) == 0 and cmd == "wl" or cmd == "register" or cmd == "reg": #First cmd for unwhitelisted user.
  379.             if args == "":
  380.               registered.append(user.name) #To put user.name in whitelist
  381.               room.message("Você acabou de ser registrado como um usuário.")
  382.             else:
  383.               if args in registered:
  384.                 room.message(args.title()+" já foi registrado por outro. D;")
  385.                 return
  386.               if args in room.usernames:
  387.                 registered.append(args)
  388.                 room.message("Pronto!, "+args.title()+" esta agora registrado! <3")
  389.               else:
  390.                 room.message("I don't see "+args.title()+" here.")
  391.  
  392.           if self.getAccess(room, user) > 0 and cmd == "uwl" or cmd == "unregister" or cmd == "unreg":
  393.             if user.name in registered:
  394.               registered.remove(user.name)
  395.             if user.name in mod:
  396.               mod.remove(user.name)
  397.             room.message("Success, You unregistered yourself.")
  398.  
  399.           if self.getAccess(room, user) < 1: return # This is to filter the command section | return, If user is not whitelisted.
  400.  
  401.   ##################################################################################################################
  402.   ##=======================================  Commands for rank 2+  ===============================================##
  403.  
  404.           if cmd == "setrank" and self.getAccess(room, user) == 5:
  405.             help_output = "Usage : ~setrank [usertarget] [number]<br/>Example : ~setrank gayman 1]"
  406.             if args == "":
  407.               room.message(help_output, True)
  408.             if args != "":
  409.   #           try:
  410.               args = args.lower()
  411.               target, rank = args.split(" ", 1)
  412.               target = str(target)
  413.               rank = int(rank)
  414.               available_rank = [-1,0,1,4,5]
  415.               if not rank in available_rank:
  416.                 room.message("Type a propper rank number.")
  417.                 return
  418.               if rank == 1:
  419.                 if target in registered:
  420.                   room.message(target.title()+" is already a Player.")
  421.                   return
  422.                 if target in blacklist:
  423.                   blacklist.pop(target)
  424.                 if target in owner:
  425.                   owner.remove(target)
  426.                 if target in mod:
  427.                   mod.remove(target)
  428.                 registered.append(target)
  429.                 room.message(target.title()+"'s rank is set to: "+str(rank)+" [Player]")
  430.               if rank == 4:
  431.                 if target in mod:
  432.                   room.message(target.title()+" is already a Moderator.")
  433.                   return
  434.                 if target in blacklist:
  435.                   blacklist.pop(target)
  436.                 if target in owner:
  437.                   owner.remove(target)
  438.                 if target in registered:
  439.                   registered.remove(target)
  440.                 mod.append(target)
  441.                 room.message(target.title()+"'s rank is set to: "+str(rank)+" [Moderator]")
  442.               if rank == 5:
  443.                 if not user.name == "tsuid": return #put your name there (if user.name == "yourname" and user.name == "anothername":) To prevent other Owners(in this case is Co-Owners) to set user's rank to Co-Owner.
  444.                 if target in owner:
  445.                   room.message(target.title()+" is already a Co-Owner.")
  446.                   return
  447.                 if target in blacklist:
  448.                   blacklist.pop(target)
  449.                 if target in registered:
  450.                   registered.remove(target)
  451.                 if target in mod:
  452.                   mod.remove(target)
  453.                 owner.append(target)
  454.                 room.message(target.title()+"'s rank is set to: "+str(rank)+" [Owner]")
  455.               if rank == 0:
  456.                 if not user.name == "tsuid": return #put your name there (if user.name == "yourname" and user.name == "anothername":) To prevent your account(s) from being unwhitelisted by your Co-Owner.
  457.                 if target in owner:
  458.                   owner.remove(target)
  459.                 if target in blacklist:
  460.                   blacklist.pop(target)
  461.                 if target in registered:
  462.                   registered.remove(target)
  463.                 if target in mod:
  464.                   mod.remove(target)
  465.                 room.message(target.title()+"'s rank is set to: "+str(rank))
  466.               if rank == -1:
  467.                 if target == "tsuid": return #put your name there (if target == "yourname" and target == "anothername":) To prevent your account(s) from being blacklisted.
  468.                 if target in blacklist:
  469.                   room.message(target.title()+" is already blacklisted.<br/>Reason: %s"% blacklist[target])
  470.                   return
  471.                 blacklist.update({target:"Annoying reason."})
  472.                 room.message(target.title()+"'s rank is set to: "+str(rank)+" [Fugitive]")
  473.   #           except:
  474.   #             room.message(help_output, True)
  475.  
  476.           if cmd == "lockdown": #This is to lock commands for user with rank lower than 4
  477.             if self.getAccess(room, user) < 4: return
  478.             if lockdown: return
  479.             room.message("Command is Locked.")
  480.             lockdown = True
  481.  
  482.           if cmd == "wake": #This is to unlock the command lockdown
  483.             if self.getAccess(room, user) < 4: return
  484.             if not lockdown: return
  485.             room.message("Command is unlocked.")
  486.             lockdown = False
  487.  
  488.           if cmd == "bl" or cmd == "blacklist":
  489.             if args == "":
  490.               if len(blacklist) < 0:
  491.                 room.message("Blacklist: None")
  492.                 return
  493.               black_users = ["#redperson"]
  494.               for i in blacklist:
  495.                 black_users.append(i)
  496.               room.message("Blacklist: %s."% (", ".join(black_users)))
  497.             if len(args.split(" ")) > 0:
  498.               if len(args.split(" ", 1)) == 2:
  499.                 target, reason = args.split(" ", 1)
  500.                 target = target.lower()
  501.               if len(args.split(" ", 1)) == 1:
  502.                 target = args.lower()
  503.             if self.getAccess(room, ch.User(target)) == 5: return #to prevent owner and co-owners from blacklisted
  504.             if self.getAccess(room, ch.User(target)) >=4 and self.getAccess(room, user) == 4: #To prevent bot moderators from banning another moderator or even owners
  505.               room.message("You don't have the permission to do that")
  506.               return
  507.             if target in blacklist:
  508.               room.message(target.title()+"'s status: Blacklisted<br/>Reason: <i>%s</i>"% (blacklist[args]), True)
  509.             if target not in blacklist and len(args) > 1:
  510.               if self.getAccess(room, user) < 4: return
  511.               if len(reason) < 10:
  512.                 room.message("Reason is too short. put minimal 10 characters.")
  513.                 return
  514.               blacklist.update({str(target):str(reason)})
  515.               room.message(target.title()+" is blacklisted.<br/>"+user.name.title()+"'s Reason: "+reason, True)
  516.  
  517.           if cmd == "unblacklist" or cmd == "ubl":
  518.             if self.getAccess(room, user) < 4: return
  519.             if args == "": return
  520.             args = args.lower()
  521.             if args not in blacklist:
  522.               room.message(args.title()+" is not blacklisted.")
  523.               return
  524.             if args in mod and self.getAccess(room, user) < 5:
  525.               room.message("You don't have permission to unblacklist that user.")
  526.               return
  527.             blacklist.pop(args)
  528.             room.message(args.title()+" is unblacklisted.")
  529.  
  530.           if cmd == "unchain":
  531.             if self.getAccess(room, user) < 4: return
  532.             if args == "": return
  533.             args = args.lower()
  534.             if args not in blacklist:
  535.               room.message(args.title()+" is not chained.")
  536.               return
  537.             if args in mod and self.getAccess(room, user) < 5:
  538.               room.message("You don't have permission to unchain that user.")
  539.               return
  540.             blacklist.pop(args)
  541.             room.message(args.title()+" is unchained.")
  542.  
  543.           if cmd == "chain":
  544.             if args == "":
  545.               if len(blacklist) < 0:
  546.                 room.message("Chained: None")
  547.                 return
  548.               black_users = ["#esperguy"]
  549.               for i in blacklist:
  550.                 black_users.append(i)
  551.               room.message("Chained: %s."% (", ".join(black_users)))
  552.             if len(args.split(" ")) > 0:
  553.               if len(args.split(" ", 1)) == 2:
  554.                 target, reason = args.split(" ", 1)
  555.                 target = target.lower()
  556.               if len(args.split(" ", 1)) == 1:
  557.                 target = args.lower()
  558.             if target in blacklist and len(args) == 1:
  559.               room.message(target.title()+"'s status: Chained<br/>Reason: <i>%s</i>"% (blacklist[args]), True)
  560.             if target not in blacklist and len(args) > 1:
  561.               if self.getAccess(room, user) < 4: return
  562.               if len(reason) < 10:
  563.                 room.message("Reason is too short. put minimal 10 characters.")
  564.                 return
  565.               blacklist.update({target:reason})
  566.               room.message(target.title()+" is Chained.<br/>"+user.name.title()+"'s Reason: <i>%s</i>"% (reason), True)
  567.  
  568.  
  569.           if cmd == "lock":
  570.             if self.getAccess(room, user) < 2:
  571.               room.message("No.")
  572.               return
  573.             if args in locks:
  574.               room.message("It's locked already.")
  575.               return
  576.             if args in self.roomnames:
  577.               if self.getAccess(room, user) > 3:
  578.                 locks.append(args)
  579.                 room.message("locked <b>%s</b>" % args, True)
  580.               else: room.message("You don't have permission to do that.")
  581.             if args == "":
  582.               if room.name in locks:
  583.                 room.message("It's locked already.")
  584.                 return
  585.               locks.append(room.name)
  586.               room.message("locked <b>%s</b>" % room.name, True)
  587.             if args not in self.roomnames:
  588.               if args == "": return
  589.               room.message("I haven't joined %s."% args)
  590.               return
  591.  
  592.           if cmd == "unlock":
  593.             if self.getAccess(room, user) < 2: return
  594.             if args in self.roomnames:
  595.               if args in locks:
  596.                 if self.getAccess(room, user) > 3:
  597.                   locks.remove(args)
  598.                   room.message("unlocked <b>%s</b>" % args, True)
  599.                 else: room.message("You don't have permission to do that.")
  600.               else:
  601.                 room.message("It's not even locked.")
  602.                 return
  603.             if args == "":
  604.               if room.name in locks:
  605.                 locks.remove(room.name)
  606.                 room.message("unlocked <b>%s</b>" % room.name, True)
  607.               else:
  608.                 room.message("It's not even locked.")
  609.                 return
  610.             if args not in self.roomnames:
  611.               if args == "": return
  612.               room.message("I haven't joined %s"% args)
  613.               return
  614.  
  615.           if cmd == "ban":
  616.             if room.getLevel(user) > 0:
  617.               if room.getLevel(self.user) > 0:
  618.                 room.banUser(ch.User(args))
  619.                 room.message(args.title()+" is banned")
  620.               else:
  621.                 room.message("I'm not even a mod here")
  622.             else:
  623.               room.message("You don't have permission")
  624.  
  625.           if cmd == "unban":
  626.             if args == "": return
  627.             args = args.lower()
  628.             if room.getLevel(user) > 0:
  629.               if room.getLevel(self.user) > 0:
  630.                 if ch.User(args) not in room.getBanlist():
  631.                   room.message(args.title()+" is not even banned.")
  632.                   return
  633.                 room.unban(ch.User(args))
  634.                 room.message(args.title()+" is unbanned")
  635.               else:
  636.                 room.message("I'm not even a mod here")
  637.             else:
  638.               room.message("You don't have permission")
  639.  
  640.           if cmd == "broadcast":
  641.               if self.getAccess(room, user) > 3:
  642.                   for room in self.rooms:
  643.                       room.message("Broadcast from - <b>"+user.name + "</b>: "+args, True)
  644.               else:
  645.                   room.message("You don't have permission.")
  646.  
  647.  
  648.           if cmd == "join": #This command is free for all registered user (rank 1+) to use
  649.             if args == "": return
  650.             if args in self.roomnames:
  651.               room.message("I'm there already.")
  652.             else:
  653.               self.joinRoom(args)
  654.               room.message("*Joins "+args.title()+"*")
  655.  
  656.           if cmd == "leave":
  657.             if self.getAccess(room, user) > 1:
  658.               if args == "":
  659.                 room.message("Okay, I'm leaving this room.")
  660.                 self.setTimeout(2, self.leaveRoom, room.name)
  661.               else:
  662.                 if self.getAccess(room, user) < 4: return
  663.                 self.leaveRoom(args)
  664.                 room.message("I'm leaving "+args.title())
  665.             else:
  666.               room.message("You don't have permission.")
  667.  
  668.           if cmd == "save" and self.getAccess(room, user) >= 4:
  669.             self.saveAll()
  670.             room.message("Database has been saved.")
  671.  
  672.           if (cmd == "eval") and self.getAccess(room, user) == 5: #DO NOT MESS WITH THIS COMMAND IF YOU DON'T KNOW WHAT YOU'RE DOING (This is a vital command)
  673.             ret = eval(args)
  674.             if ret == None:
  675.               room.message("Done.")
  676.               return
  677.             room.message(str(ret))
  678.  
  679.  
  680.   ##=======================================  Commands for rank 2+  ===============================================##
  681.   ##=============================================== End ==========================================================##
  682.   ##################################################################################################################
  683.  
  684.  
  685.           if cmd == ("say"):
  686.               if args:
  687.                 room.message(args)
  688.               else:
  689.                 room.message("What to say ?")
  690.  
  691.           if cmd == "reverse" or cmd == "rsay": #Reversed arguments
  692.             if args:
  693.               room.message(args[::-1])
  694.             else:
  695.               room.message("Fook off"[::-1])
  696.  
  697.  
  698.           elif cmd == "cmds":
  699.             if self.getAccess(room, user) < 1: return
  700.             room.message("some commands you can use, with [%s] as prefix [%s]"% (prefix, ", ".join(command_list)))
  701.  
  702.  
  703.           if cmd == "pm" and len(args) > 1:
  704.               name, msg = args.split(" ", 1)
  705.               self.pm.message(ch.User(name.lower()), msg+" - from "+user.name)
  706.               room.message('Sent to <font size="15"><font color="#FF9966"><b>%s</b></font></font>' % name, True)
  707.  
  708.          ##Checking levels and ranks stuff
  709.           elif cmd == "level":
  710.             if args == "":
  711.               level = room.getLevel(user)
  712.               if level == 1:
  713.                 title = "Moderator"
  714.               if level == 2:
  715.                 title = "OWNER"
  716.               if level == 0:
  717.                 title = "Slave"
  718.               room.message("Your room level is: %s [%s]" %(level,title))
  719.             else:
  720.               level = room.getLevel(ch.User(args))
  721.               if level == 1:
  722.                 title = "Moderator"
  723.               if level == 2:
  724.                 title = "OWNER"
  725.               if level == 0:
  726.                 title = "Slave"
  727.               room.message("%s's room level is: %s [%s]" %(args.title(), level, title))
  728.  
  729.  
  730.           elif cmd == "rank":
  731.             if args == "":
  732.               rank = self.getAccess(room, user)
  733.               if rank == 1:
  734.                 title = "Player"
  735.                 room.message("Your rank is: <font color='#7cfc00'><b>%s</b></font> [<font color='#7cfc00'>%s</font>]" % (rank, title), True)
  736.               if rank == 2:
  737.                 title = "Room Mod"
  738.                 room.message("Your rank is: <font color='#7cfc00'><b>%s</b></font> [<font color='#7cfc00'>%s</font>]" % (rank, title), True)
  739.               if rank == 3:
  740.                 title = "Room Admin"
  741.                 room.message("Your rank is: <font color='#7cfc00'><b>%s</b></font> [<font color='#7cfc00'>%s</font>]" % (rank, title), True)
  742.               if rank == 4:
  743.                 title = "Moderator"
  744.                 room.message("Your rank is: <font color='#0000ff'><b>%s</b></font> [<font color='#fffaf0'><b>%s</b></font>]" % (rank, title), True)
  745.               if rank == 5:
  746.                 title = "Owner"
  747.                 room.message("Your rank is: <font color='#c0c0c0'><b>%s</b></font> [<font color='#87ceeb'><b>%s</b></font>]" % (rank, title), True)
  748.             else:
  749.                 rank = self.getAccess(room, ch.User(args))
  750.                 if rank == 0:
  751.                   room.message(args+" is unregistered.")
  752.                 if rank == 1:
  753.                   title = "Player"
  754.                   room.message(args+"'s rank is: <font color='#7cfc00'><b>%s</b></font> [<font color='#7cfc00'>%s</font>]" % (rank, title), True)
  755.                 if rank == 2:
  756.                   title = "Room Mod"
  757.                   room.message(args+"'s rank is: <font color='#7cfc00'><b>%s</b></font> [<font color='#7cfc00'>%s</font>]" % (rank, title), True)
  758.                 if rank == 3:
  759.                   title = "Room Admin"
  760.                   room.message(args+"'s rank is: <font color='#7cfc00'><b>%s</b></font> [<font color='#7cfc00'>%s</font>]" % (rank, title), True)
  761.                 if rank == 4:
  762.                   title = "Moderator"
  763.                   room.message(args+"'s rank is: <font color='#0000ff'><b>%s</b></font> [<font color='#fffaf0'><b>%s</b></font>]" % (rank, title), True)
  764.                 if rank == 5:
  765.                   title = "Owner"
  766.                   room.message(args + "'s rank is: <font color='#c0c0c0'><b>%s</b></font> [<font color='#87ceeb'><b>%s</b></font>]" % (rank, title), True)
  767.  
  768.  
  769.           elif cmd == "mods":
  770.             args = args.lower()
  771.             if args == "":
  772.               room.message("<br/>||<font color='#87ceeb'><b>OWNER</b></font>: <u>"+ (room.ownername) +"</u> <br/>||<b>Mods</b>: "+", ".join(room.modnames), True)
  773.               return
  774.             if args in self.roomnames:
  775.                 modask = self.getRoom(args).modnames
  776.                 owner = self.getRoom(args).ownername
  777.                 room.message("<br/>||<font color='#87ceeb'><b>OWNER</b></font>: <u>"+ (owner) +"</u> <br/>||<b>Mods</b>: "+", ".join(modask), True)
  778.             else:
  779.                self.joinRoom(args)
  780.                cek_mods[user.name] = json.dumps([room.name,args])
  781.  
  782.  
  783.           ##Some certain commands for rank 1+
  784.  
  785.  
  786.           if cmd == ("find") and len(args) > 0:
  787.             name = args.split()[0].lower()
  788.             if not ch.User(name).roomnames:
  789.               room.message("dont see them. ^^")
  790.             else:
  791.               room.message("%s is curently in <b>%s</b> >_>" % (args, ", ".join(ch.User(name).roomnames)), True)
  792.           if cmd == "multichat":
  793.             room.message("http://ch.pew.im/chat/?"+args)
  794.           if cmd == "rooms":
  795.             room.message("||i'm in : <b>%s</b> ||" % (", ".join(self.roomnames)), True)
  796.  
  797.  
  798. def onUserCountChange(self, room):
  799.     print(room.name+" - Current Users: " + str(room.usercount))
  800.  
  801. #  def onLeave(self, room, user):
  802. #    print("[+] "+user.name+" left "+room.name)
  803. #    if room.usercount >= 20:
  804. #      return
  805. #    room.message(user.name+" has left the room.")
  806.  
  807. def onFloodWarning(self, room):
  808.   room.reconnect()
  809.   room.setSilent(True)
  810.   self.setTimeout(15, room.setSilent, False)
  811.   self.setTimeout(16, room.message, "I'm back.")
  812.   print("[+] Reconnecting...")
  813.  
  814. def onMessageDelete(self, room, user, msg):
  815.   print("MESSAGE DELETED: " + user.name + ": " + msg.body)
  816.  
  817. def onPMMessage(self, pm, user, body):
  818.   print("PM - "+user.name+": "+body)
  819.   pm.message(user, "I'm a Bot Created by 0rx. Please PM my owner instead!")
  820.  
  821. def hexc(e):
  822.   et, ev, tb = sys.exc_info()
  823.   if not tb: print(str(e))
  824.   while tb:
  825.     lineno = tb.tb_lineno
  826.     fn = tb.tb_frame.f_code.co_filename
  827.     tb = tb.tb_next
  828.   print("(%s:%i) %s" % (fn, lineno, str(e)))
  829.  
  830. if __name__ == "__main__":
  831.    try:
  832.      os.system("clear")
  833.      TestBot.easy_start(rooms, botname, botpassword)
  834.    except KeyboardInterrupt:
  835.      print("Console initiated a kill.")
  836.    except Exception as e:
  837.      hexc(e)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top