0rx

cellinux-bot-main.py (MAIN script for cellinux-bot)

0rx
Jun 9th, 2016
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 28.02 KB | None | 0 0
  1. ###################################################################################
  2. ###################################################################################
  3. ### file        :   cellinux-bot-main.py (main script)                          ###
  4. ### additionals :   1. xcmd.py     (http://pastebin.com/Hfrr5mKy)               ###
  5. ###                 2. ch.py       (EDITED ONEs) (http://pastebin.com/BeY3VeGf) ###
  6. ###                 3. coloring.py (http://pastebin.com/FFmX3HgM)               ###
  7. ###                 4. release.py  (http://pastebin.com/TuXe9DqZ)               ###
  8. ###                 5. xfunc.py    (http://pastebin.com/PMJAZvkh)               ###
  9. ###                 (ps: You'll need all additionals to run it)                 ###
  10. ###                                                                             ###
  11. ###                                                                             ###
  12. ### http://remaire.chatango.com                                                 ###
  13. ### http://tango-hyoo.chatango.com                                              ###
  14. ### If you would like help setting up your own bot, feel free to                ###
  15. ### send me a personal message on chatango.                                     ###
  16. ### --Many thanks for TryHardHusky and Poeticartist1--                          ###
  17. ###################################################################################
  18.  
  19.  
  20. import ch
  21. import imp
  22. import xcmd
  23. from xcmd import *
  24. import random
  25. import sys
  26. import os
  27. import re
  28. import time
  29. import json
  30. import urllib
  31. import traceback
  32. import __future__
  33.  
  34. ################################
  35. lockdown = False
  36. activated = True
  37. its_on    = True
  38. ################################
  39.  
  40. ################################
  41. ##File Stuff##
  42.  
  43. blacklist = xcmd.blacklist #Blacklist data will be loaded from xcmd module
  44.  
  45. ranker = xcmd.ranker ##User rank data will be loaded from xcmd module
  46.  
  47. rooms = xcmd.rooms #room channel data will be loaded from xcmd module
  48.  
  49. locks = xcmd.locks ##Locked room channel data will be loaded from xcmd module
  50.  
  51. ##End##
  52. ################################
  53.  
  54. #############################################################
  55. ##========================Variables========================##
  56.  
  57. botname      = xcmd.release.botname #Your bot's username will be loaded from xcmd.release module
  58.  
  59. botpassword  = xcmd.release.botpassword #Your bot's password will be loaded from xcmd.release module
  60.  
  61. botversion   = xcmd.botversion #Your bot's version will be loaded from xcmd.release module
  62.  
  63. botsys       = xcmd.botsys
  64.  
  65. botrelease   = xcmd.botrelease
  66.  
  67. cek_mods     = dict() #Don't mess with this variable. This one is related with *mods command.
  68.  
  69. error        = ("Expectation failed.")    #Error message
  70.  
  71. command_list = xcmd.command_list #Your bot's command list will be loaded from xcmd module
  72.  
  73. prefix       = xcmd.prefix #Your bot's prefix will be loaded from xcmd module
  74.  
  75. ##===========================End===========================##
  76. #############################################################
  77.  
  78. #setting colors
  79.  
  80. class TestBot(ch.RoomManager):
  81.   def onInit(self):
  82.     self.setNameColor("008b8b")
  83.     self.setFontColor("007fff")
  84.     self.setFontFace("1")
  85.     self.setFontSize(12)
  86.     self.enableBg()  
  87.     self.enableRecording()
  88.    
  89.   def saveAll(self):
  90.     room = self._Room
  91.     f = open("ranker.txt", "w")
  92.     f.write(str(ranker))
  93.     f.close()
  94.     f = open("blacklist.txt", "w")
  95.     f.write(str(blacklist))
  96.     f.close()
  97.     f = open("locks.txt", "w")
  98.     f.write("\n".join(locks))
  99.     f.close()
  100.     f = open("rooms.txt", "w")
  101.     f.write("\n".join(self.roomnames))
  102.     f.close()
  103.  
  104.  
  105.  
  106. #############################################  
  107. ##connecting and disconnecting crap##
  108.  
  109.   def onConnect(self, room):
  110.     print("[+] Mad Hatter Connected to "+room.name)
  111.     for i in cek_mods: #Di onJoin
  112.       if len(cek_mods[i]) > 1:
  113.         rmm, rmd = json.loads(cek_mods[i])
  114.         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)
  115.         self.leaveRoom(rmd)
  116.         cek_mods.pop(i)
  117.       return
  118.    
  119.   def onReconnect(self, room):
  120.     print("[+] "+self.name+" Reconnected to "+room.name)
  121.    
  122.   def onDisconnect(self, room):
  123.     print("[+] "+self.name+" Disconnected from "+room.name)
  124.    
  125.   def onBan(self, room, user, target):
  126.     print(user.name+" got banned in "+room.name)
  127.    
  128.   def onJoin(self, room, user, puid):
  129.     rank = 0
  130.     if user.name in ranker:
  131.       rank = ranker[user.name]
  132.     rank = str(rank)
  133.     print("[%s][NOTICE][Rank %s][%s]\r\n[+]%s Joined %s\r\n" % (time.strftime("%d/%m/%y- %H:%M:%S", time.localtime(time.time())),  rank, room.name, user.name.title(), room.name))
  134.  
  135.   def onConnectFail(self, room):
  136.     print("[ERR] Room Not Found")
  137.     for i in cek_mods: #Di onJoin
  138.       if len(cek_mods[i]) > 1:
  139.         rmm, rmd = json.loads(cek_mods[i])
  140.         self.getRoom(rmm).message("Such room doesn't exist")
  141.         cek_mods.pop(i)
  142.       return
  143.  
  144.  
  145.  
  146. ##End##
  147. #############################################
  148.  
  149. #############################################
  150. ##setting up commands##
  151.  
  152.   def onMessage(self, room, user, message):
  153.    try:
  154.     if user == self.user:
  155.         return
  156.    
  157.     global seth
  158.    
  159.     seth = self
  160.  
  161.     from xcmd import coloring
  162.  
  163.     from coloring import colorTest as ctp
  164.     from coloring import colorLite as clp
  165.     from coloring import colorBold as cbp
  166.    
  167.     def ct(col):
  168.         return ctp(seth, col)
  169.     def cl(col):
  170.         return clp(seth, col)
  171.     def cb(col):
  172.         return cbp(seth, col)
  173.    
  174.     global botversion
  175.     global botsys
  176.     global activated
  177.     global lockdown
  178.     global prefix
  179.     global owner
  180.     global mod
  181.     global registered
  182.     global its_on
  183.     self.saveAll()    
  184.     def urank(target):
  185.         if target not in ranker:
  186.             return 0
  187.         rank = ranker[target]
  188.         if rank == 1 and room.getLevel(ch.User(target)) == 1:
  189.             rank = 2
  190.         if rank == 1 and room.getLevel(ch.User(target)) == 2:
  191.             rank = 3
  192.         return rank
  193.     try:
  194.       if room.getLevel(self.user) > 0:
  195.         print("[%s][MSG][Rank %s][%s][User_IP: %s]\r\n%s: %s\r\n" % (time.strftime("%d/%m/%y- %H:%M:%S", time.localtime(time.time())), urank(user.name), room.name, message.ip, user.name.title(), message.body))
  196.       else:
  197.         print("[%s][MSG][Rank %s][%s][User_IP: NONE]\r\n%s: %s\r\n" % (time.strftime("%d/%m/%y- %H:%M:%S", time.localtime(time.time())), urank(user.name), room.name, user.name.title(), message.body))
  198.     except:
  199.       pass
  200.     if user == self.user: return
  201.    
  202.     if user.name.startswith("#") or user.name.startswith("!"):return
  203.     if self.user == user: return
  204.     if user.name in blacklist: return
  205.     if urank(user.name) > 0:
  206.       if not activated and urank(user.name) < 4: return #return, if not activated and user rank is less than 4.
  207.       ##Persona | You design a good personality for your bot in this part
  208.       if "hey" in message.body:
  209.           room.message("Yesh, " +message.body)
  210.       if "hello" == message.body.lower(): #for example if someone said "hello" in the chatroom
  211.           room.message("Hello "+user.name.title()) #the bot will answer with "Hello User1Name"
  212.       if "hi" == message.body.lower():
  213.           room.message("Hi "+user.name.title())
  214.       if message.body.lower() == self.user.name or message.body.lower() in ["cell", "celli", "linux", "cel", "shell"]:
  215.           tochi = random.choice(['Nope','Automated convo failed',cb('red!ERROR 401: ACCESS DENIED!'),cb("red!ERROR 403: UNAUTHORIZED!"),cb("red!ERROR 404: NOT FOUND!")])
  216.           room.message("@"+user.name+" - "+str(tochi), True)
  217.       if "please kill it" == message.body and urank(user.name) == 5:
  218.         its_on = False
  219.         self.stop()
  220.        
  221.     from xcmd import onMessage as ekses
  222.    
  223.     ##Commands | You design great commands for your bot in this part
  224.     if message.body[0] in prefix: #prefix usage in this line (for this case I use "*" as prefix)
  225.         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)
  226.         if len(data) == 2: #If there are more than 1 data (This is where we will get args)
  227.           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)
  228.         else: #If there is only 1 data (No args)
  229.           cmd, args = data[0], "" #the arg will simply be "" (Empty)
  230.         cmd == cmd.lower()
  231.  
  232.         ##Activating and Inactivating Bot
  233.         if cmd == "reload" and urank(user.name) == 5: ## THIS RELOAD CMD IS USED TO RELOAD xcmd MODULE!!!
  234.           try:
  235.             imp.reload(xcmd) ## USING IMP TO RELOAD xcmd MODULE
  236.             room.message("external commands reloaded")
  237.           except Exception as e:
  238.             room.message(str(e))
  239.             imp.reload(xcmd)
  240.         if cmd == "reboot" and urank(user.name) == 5: ## NOT REALLY A REBOOT CMD, JUST RECONNECTING WEBSOCKET
  241.             self.saveAll()
  242.             room.message("System will reboot in 5 second")
  243.             its_on = True
  244.             self.setTimeout(5, self.stop, )
  245.  
  246.         if cmd == "shutdown": ## THIS COMMAND IS USED FOR KILLING THE BOT'S MAIN PROCESS
  247.           if urank(user.name) == 5:
  248.             self.saveAll()
  249.             room.message("System Shutting Down")
  250.             its_on = False
  251.             self.setTimeout(3, self.stop, )
  252.  
  253.         if cmd == "activate":
  254.           if urank(user.name) < 4: return
  255.           activated = True
  256.           room.message("[Activated]")
  257.  
  258.         if cmd == "restrict":
  259.           if urank(user.name) < 4: return
  260.           activated = False
  261.           room.message("[Restricted]")
  262.  
  263.         if not activated and urank(user.name) < 5: return #Ignore user with rank lower than 5 when not activated
  264.         if lockdown and urank(user.name) < 4: return #Ignore user with rank lower than 4 when in lockdown
  265.        
  266.         if cmd == "help": #Help command (It will show the bot's version, user's rank status, user's room level, and Available commands)
  267.           rank = 0
  268.           moded = "no"
  269.           rank = urank(user.name)
  270.           if room.getLevel(user) > 0:
  271.             moded = "TRUE"
  272.           if rank > 1:
  273.             room.message(cb("kucrimson!"+botsys)+"("+cl("grey!"+str(botversion))+")<br/>"+user.name.title()+" - ["+cb("red!Rank "+str(rank))+"] - Moded [<b>"+moded+"</b>]<br/>cmds: use <b>[%s]</b> as prefix [%s]"% (", ".join(prefix), ", ".join(command_list)), True)
  274.           if rank == 0:
  275.             moded = "Null"
  276.             if room.getLevel(user) > 0:
  277.               moded = "True"
  278. #            room.message("<font color='#FF8C00'><b>"+botsys+"</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)), True)
  279.             room.message(cb("kucrimson!"+botsys)+"("+cl("grey!"+str(botversion))+")<br/>"+user.name.title()+" - ["+cb("white!Rank "+str(rank))+"] - Moded [<b>"+moded+"</b>]<br/>cmds: use <b>[%s]</b> as prefix [%s]"% (", ".join(prefix), ", ".join(['help','wl','uwl'])), True)
  280.          
  281.         if cmd in ["wl","reg","register","wl me"]: #First cmd for unwhitelisted user.
  282.           if urank(user.name) == 0 and args == "":
  283.             ranker.update({user.name:1}) #To put user.name in whitelist
  284.             room.message("Done, You're now a Registered as player.")
  285.           if urank(user.name) != 0 and args != "":
  286.             if args in ranker:
  287.               room.message(args.title()+" is already registered.")
  288.               return
  289.             if args in room.usernames:
  290.               ranker.update({args:1})
  291.               room.message("Done, "+args.title()+" is now Registered.")
  292.             else:
  293.               room.message("I don't see "+args.title()+" here.")
  294.          
  295.         if urank(user.name) > 0 and cmd == "uwl" or cmd == "unregister" or cmd == "unreg":
  296.           if urank(user.name) == 5:
  297.             return
  298.           if user.name in ranker:
  299.             ranker.pop(user.name)
  300.           room.message("Success, You unregistered yourself.")
  301.        
  302.         if urank(user.name) < 1: return # This is to filter the command section | return, If user is not whitelisted.
  303.        
  304.         ekses(self, room, user, message)
  305. ##################################################################################################################
  306. ##=======================================  Commands for rank 2+  ===============================================##
  307.        
  308.  
  309.         if cmd == "lockdown": #This is to lock commands for user with rank lower than 4
  310.           if urank(user.name) < 4: return
  311.           if lockdown: return
  312.           room.message("Command is Locked.")
  313.           lockdown = True
  314.  
  315.         if cmd == "wake": #This is to unlock the command lockdown
  316.           if urank(user.name) < 4: return
  317.           if not lockdown: return
  318.           room.message("Command is unlocked.")
  319.           lockdown = False
  320.          
  321.         if cmd == "bl" or cmd == "blacklist":
  322.           if args == "":
  323.             if len(blacklist) < 0:
  324.               room.message("Blacklist: None")
  325.               return
  326.             black_users = ["#redperson"]
  327.             for i in blacklist:
  328.               black_users.append(i)
  329.             room.message("Blacklist: %s."% (", ".join(black_users)))
  330.           if len(args.split(" ")) > 0:
  331.             if len(args.split(" ")) > 1:
  332.               target, reason = args.split(" ", 1)
  333.               target = target.lower()
  334.             if len(args.split(" ")) == 1:
  335.               target = args.lower()
  336.           if urank(args) == 5: return #to prevent owner and co-owners from blacklisted
  337.           if urank(args) >=4 and urank(user.name) == 4: #To prevent bot moderators from banning another moderator or even owners
  338.             room.message("You don't have the permission to do that")
  339.             return
  340.           if target in blacklist:
  341.             room.message(target.title()+"'s status: Blacklisted<br/>Reason: <i>%s</i>"% (blacklist[args]), True)
  342.           if target not in blacklist and len(args) > 1:
  343.             if urank(user.name) < 4: return
  344.             if len(reason) < 10:
  345.               room.message("Reason is too short. put minimal 10 characters.")
  346.               return
  347.             blacklist.update({str(target):str(reason)})
  348.             room.message(target.title()+" is blacklisted.<br/>"+user.name.title()+"'s Reason: "+reason, True)
  349.            
  350.         if cmd == "unblacklist" or cmd == "ubl":
  351.           if urank(user.name) < 4: return
  352.           if args == "": return
  353.           args = args.lower()
  354.           if args not in blacklist:
  355.             room.message(args.title()+" is not blacklisted.")
  356.             return
  357.           if args in mod and urank(user.name) < 5:
  358.             room.message("You don't have permission to unblacklist that user.")
  359.             return
  360.           blacklist.pop(args)
  361.           room.message(args.title()+" is unblacklisted.")
  362.            
  363.         if cmd == "unchain":
  364.           if urank(user.name) < 4: return
  365.           if args == "": return
  366.           args = args.lower()
  367.           if args not in blacklist:
  368.             room.message(args.title()+" is not chained.")
  369.             return
  370.           if args in mod and urank(user.name) < 5:
  371.             room.message("You don't have permission to unchain that user.")
  372.             return
  373.           blacklist.pop(args)
  374.           room.message(args.title()+" is unchained.")
  375.            
  376.         if cmd == "chain":
  377.           if args == "":
  378.             if len(blacklist) < 0:
  379.               room.message("Chained: None")
  380.               return
  381.             black_users = ["#esperguy"]
  382.             for i in blacklist:
  383.               black_users.append(i)
  384.             room.message("Chained: %s."% (", ".join(black_users)))
  385.           if len(args.split(" ")) > 0:
  386.             if len(args.split(" ", 1)) == 2:
  387.               target, reason = args.split(" ", 1)
  388.               target = target.lower()
  389.             if len(args.split(" ", 1)) == 1:
  390.               target = args.lower()
  391.           if target in blacklist and len(args) == 1:
  392.             room.message(target.title()+"'s status: Chained<br/>Reason: <i>%s</i>"% (blacklist[args]), True)
  393.           if target not in blacklist and len(args) > 1:
  394.             if urank(user.name) < 4: return
  395.             if len(reason) < 10:
  396.               room.message("Reason is too short. put minimal 10 characters.")
  397.               return
  398.             blacklist.update({target:reason})
  399.             room.message(target.title()+" is Chained.<br/>"+user.name.title()+"'s Reason: <i>%s</i>"% (reason), True)
  400.  
  401.  
  402.         if cmd == "lock":
  403.           if urank(user.name) < 2:
  404.             room.message("No.")
  405.             return
  406.           if args in locks:
  407.             room.message("It's locked already.")
  408.             return
  409.           if args in self.roomnames:
  410.             if urank(user.name) > 3:
  411.               locks.append(args)
  412.               room.message("locked <b>%s</b>" % args, True)
  413.             else: room.message("You don't have permission to do that.")
  414.           if args == "":
  415.             if room.name in locks:
  416.               room.message("It's locked already.")
  417.               return
  418.             locks.append(room.name)
  419.             room.message("locked <b>%s</b>" % room.name, True)
  420.           if args not in self.roomnames:
  421.             if args == "": return
  422.             room.message("I haven't joined %s."% args)
  423.             return
  424.  
  425.         if cmd == "unlock":
  426.           if urank(user.name) < 2: return
  427.           if args in self.roomnames:
  428.             if args in locks:
  429.               if urank(user.name) > 3:
  430.                 locks.remove(args)
  431.                 room.message("unlocked <b>%s</b>" % args, True)
  432.               else: room.message("You don't have permission to do that.")
  433.             else:
  434.               room.message("It's not even locked.")
  435.               return
  436.           if args == "":
  437.             if room.name in locks:
  438.               locks.remove(room.name)
  439.               room.message("unlocked <b>%s</b>" % room.name, True)
  440.             else:
  441.               room.message("It's not even locked.")
  442.               return
  443.           if args not in self.roomnames:
  444.             if args == "": return
  445.             room.message("I haven't joined %s"% args)
  446.             return
  447.  
  448.         if cmd == "ban":
  449.           if room.getLevel(user) > 0:
  450.             if room.getLevel(self.user) > 0:
  451.               room.banUser(ch.User(args))
  452.               room.message(args.title()+" is banned")
  453.             else:
  454.               room.message("I'm not even a mod here")
  455.           else:
  456.             room.message("You don't have permission")
  457.            
  458.         if cmd == "unban":
  459.           if args == "": return
  460.           args = args.lower()
  461.           if room.getLevel(user) > 0:
  462.             if room.getLevel(self.user) > 0:
  463.               if ch.User(args) not in room.getBanlist():
  464.                 room.message(args.title()+" is not even banned.")
  465.                 return
  466.               room.unban(ch.User(args))
  467.               room.message(args.title()+" is unbanned")
  468.             else:
  469.               room.message("I'm not even a mod here")
  470.           else:
  471.             room.message("You don't have permission")
  472.  
  473.         if cmd == "broadcast":
  474.             if urank(user.name) > 3:
  475.                 for room in self.rooms:
  476.                     room.message("Broadcast from - <b>"+user.name + "</b>: "+args, True)
  477.             else:
  478.                 room.message("You don't have permission.")
  479.        
  480.  
  481.         if cmd == "join": #This command is free for all registered user (rank 1+) to use
  482.           if args == "": return
  483.           if args in self.roomnames:
  484.             room.message("I'm there already.")
  485.           else:
  486.             self.joinRoom(args)
  487.             room.message("*Joins "+args.title()+"*")
  488.        
  489.         if cmd == "leave":
  490.           if urank(user.name) > 1:
  491.             if args == "":
  492.               room.message("Okay, I'm leaving this room.")
  493.               self.setTimeout(2, self.leaveRoom, room.name)
  494.             else:
  495.               if urank(user.name) < 4: return
  496.               self.leaveRoom(args)
  497.               room.message("I'm leaving "+args.title())
  498.           else:
  499.             room.message("You don't have permission.")
  500.            
  501.         if cmd == "save" and urank(user.name) >= 4:
  502.           self.saveAll()
  503.           room.message("Database has been saved.")
  504.          
  505.         if (cmd == "eval") and urank(user.name) == 5: #DO NOT MESS WITH THIS COMMAND IF YOU DON'T KNOW WHAT YOU'RE DOING (This is a vital command)
  506.           ret = eval(args)
  507.           if ret == None:
  508.             room.message("Done.")
  509.             return
  510.           room.message(str(ret))
  511.        
  512.         if cmd == "exec" and urank(user.name) == 5 and len(args):
  513.           var , val = args.split(" ", 1)
  514.           ret = exec('globals()["%s"] =  %s'% (var, val))
  515.           reap = eval(var)
  516.           room.message(args)
  517.  
  518.  
  519.  
  520. ##=======================================  Commands for rank 2+  ===============================================##
  521. ##=============================================== End ==========================================================##
  522. ##################################################################################################################
  523.  
  524.  
  525.         if cmd == ("say"):
  526.             if args:
  527.               room.message(args)
  528.             else:
  529.               room.message("What to say ?")
  530.              
  531.         if cmd == "reverse" or cmd == "rsay": #Reversed arguments
  532.           if args:
  533.             room.message(args[::-1])
  534.           else:
  535.             room.message("Fook off"[::-1])
  536.  
  537.  
  538.         elif cmd == "cmds":
  539.           if urank(user.name) < 1: return
  540.           room.message("some commands you can use, with [%s] as prefix [%s]"% (", ".join(prefix), ", ".join(command_list)))
  541.  
  542.  
  543.         if cmd == "pm" and len(args) > 1:
  544.             name, msg = args.split(" ", 1)
  545.             self.pm.message(ch.User(name.lower()), msg+" - from "+user.name)
  546.             room.message('Sent to <font size="15"><font color="#FF9966"><b>%s</b></font></font>' % name, True)
  547.  
  548.        ##Checking levels and ranks stuff  
  549.         elif cmd == "level":
  550.           if args == "":
  551.             level = room.getLevel(user)
  552.             if level == 1:
  553.               title = "Moderator"
  554.             if level == 2:
  555.               title = "OWNER"
  556.             if level == 0:
  557.               title = "Slave"
  558.             room.message("Your room level is: %s [%s]" %(level,title))
  559.           else:
  560.             level = room.getLevel(ch.User(args))
  561.             if level == 1:
  562.               title = "Moderator"
  563.             if level == 2:
  564.               title = "OWNER"
  565.             if level == 0:
  566.               title = "Slave"
  567.             room.message("%s's room level is: %s [%s]" %(args.title(), level, title))
  568.  
  569.  
  570.         elif cmd == "rank":
  571.           if args == "":
  572.             rank = urank(user.name)
  573.             if rank == 1:
  574.               title = "Player"
  575.               room.message("Your rank is: <font color='#7cfc00'><b>%s</b></font> [<font color='#7cfc00'>%s</font>]" % (rank, title), True)
  576.             if rank == 2:
  577.               title = "Room Mod"
  578.               room.message("Your rank is: <font color='#7cfc00'><b>%s</b></font> [<font color='#7cfc00'>%s</font>]" % (rank, title), True)
  579.             if rank == 3:
  580.               title = "Room Admin"
  581.               room.message("Your rank is: <font color='#7cfc00'><b>%s</b></font> [<font color='#7cfc00'>%s</font>]" % (rank, title), True)
  582.             if rank == 4:
  583.               title = "Moderator"
  584.               room.message("Your rank is: <font color='#0000ff'><b>%s</b></font> [<font color='#fffaf0'><b>%s</b></font>]" % (rank, title), True)
  585.             if rank == 5:
  586.               title = "Owner"
  587.               room.message("Your rank is: <font color='#c0c0c0'><b>%s</b></font> [<font color='#87ceeb'><b>%s</b></font>]" % (rank, title), True)
  588.           else:
  589.               rank = urank(args)
  590.               if rank == 0:
  591.                 room.message(args+" is unregistered.")
  592.               if rank == 1:
  593.                 title = "Player"
  594.                 room.message(args+"'s rank is: <font color='#7cfc00'><b>%s</b></font> [<font color='#7cfc00'>%s</font>]" % (rank, title), True)
  595.               if rank == 2:
  596.                 title = "Room Mod"
  597.                 room.message(args+"'s rank is: <font color='#7cfc00'><b>%s</b></font> [<font color='#7cfc00'>%s</font>]" % (rank, title), True)
  598.               if rank == 3:
  599.                 title = "Room Admin"
  600.                 room.message(args+"'s rank is: <font color='#7cfc00'><b>%s</b></font> [<font color='#7cfc00'>%s</font>]" % (rank, title), True)
  601.               if rank == 4:
  602.                 title = "Moderator"
  603.                 room.message(args+"'s rank is: <font color='#0000ff'><b>%s</b></font> [<font color='#fffaf0'><b>%s</b></font>]" % (rank, title), True)
  604.               if rank == 5:
  605.                 title = "Owner"
  606.                 room.message(args + "'s rank is: <font color='#c0c0c0'><b>%s</b></font> [<font color='#87ceeb'><b>%s</b></font>]" % (rank, title), True)
  607.                
  608.        
  609.         elif cmd == "mods":
  610.           args = args.lower()
  611.           if args == "":
  612.             room.message("<br/>||<font color='#87ceeb'><b>OWNER</b></font>: <u>"+ (room.ownername) +"</u> <br/>||<b>Mods</b>: "+", ".join(room.modnames), True)
  613.             return
  614.           if args in self.roomnames:
  615.               modask = self.getRoom(args).modnames
  616.               owner = self.getRoom(args).ownername
  617.               room.message("<br/>||<font color='#87ceeb'><b>OWNER</b></font>: <u>"+ (owner) +"</u> <br/>||<b>Mods</b>: "+", ".join(modask), True)
  618.           else:
  619.              self.joinRoom(args)
  620.              cek_mods[user.name] = json.dumps([room.name,args])
  621.  
  622.  
  623.         ##Some certain commands for rank 1+
  624.  
  625.        
  626.         if cmd == ("find") and len(args) > 0:
  627.           name = args.split()[0].lower()
  628.           if not ch.User(name).roomnames:
  629.             room.message("dont see them. ^^")
  630.           else:
  631.             room.message("%s is curently in <b>%s</b> >_>" % (args, ", ".join(ch.User(name).roomnames)), True)
  632.         if cmd == "multichat":
  633.           room.message("http://ch.pew.im/chat/?"+args)
  634.         if cmd == "rooms":
  635.           room.message("||i'm in : <b>%s</b> ||" % (", ".join(self.roomnames)), True)
  636.  
  637.  
  638.  
  639.    except Exception as e:
  640.          try:
  641.           et, ev, tb = sys.exc_info()
  642.           lineno = tb.tb_lineno
  643.           fn = tb.tb_frame.f_code.co_filename
  644.           room.message("[Error] %s Line %i - %s"% (fn, lineno, str(e)))
  645.           return
  646.          except:
  647.           room.message("Undescribeable error detected !!")
  648.           return
  649.  
  650.  
  651.   def onUserCountChange(self, room):
  652.     print(room.name+" - Current Users: " + str(room.usercount))
  653.  
  654.   def onLeave(self, room, user, puid):
  655.     rank = 0
  656.     if user.name in ranker:
  657.       rank = ranker[user.name]
  658.     rank = str(rank)
  659.     print("[%s][NOTICE][Rank %s][%s]\r\n[+]%s left %s\r\n" % (time.strftime("%d/%m/%y- %H:%M:%S", time.localtime(time.time())),  rank, room.name, user.name.title(), room.name))
  660.  
  661.   def onFloodWarning(self, room):
  662.     room.reconnect()
  663.     room.setSilent(True)
  664.     self.setTimeout(15, room.setSilent, False)
  665.     self.setTimeout(16, room.message, "I'm back.")
  666.     print("[+] Reconnecting...")
  667.  
  668.   def onMessageDelete(self, room, user, msg):
  669.     print("MESSAGE DELETED: " + user.name + ": " + msg.body)
  670.  
  671.   def onPMMessage(self, pm, user, body):
  672.     from xcmd import onPMMessage as pms
  673.     pms(self, pm, user, body)
  674.     print("PM - "+user.name+": "+body)
  675.  
  676. def hexc(e):
  677.   et, ev, tb = sys.exc_info()
  678.   if not tb: print(str(e))
  679.   while tb:
  680.     lineno = tb.tb_lineno
  681.     fn = tb.tb_frame.f_code.co_filename
  682.     tb = tb.tb_next
  683.   print("(%s:%i) %s" % (fn, lineno, str(e)))
  684.  
  685. if __name__ == "__main__":
  686.  while its_on:
  687.    try:
  688.      its_on = True
  689.      os.system("clear")
  690.      TestBot.easy_start(rooms, botname, botpassword)
  691.    except KeyboardInterrupt:
  692.      its_on = False
  693.      print("Console initiated a kill.")
  694.    except Exception as e:
  695.      its_on = True
  696.      hexc(e)
  697.      time.sleep(5)
Advertisement
Add Comment
Please, Sign In to add comment