Fooksie

EMboxxxxy

Sep 19th, 2013
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name            EMbot
  3. // @description     Join any game, add ?bot to the URL to activate.
  4. // @match           http://www.epicmafia.com/game/*?bot
  5. // ==/UserScript==
  6.  
  7. //Welcome back
  8. EMjack=String(function() {
  9.  
  10.     //Variables
  11.     users={}
  12.     meet=null
  13.     master=null
  14.     kicktimer=0
  15.  
  16.     //Locate the socket
  17.     socket=io.sockets["http://www.epicmafia.com:80"].namespaces[""]
  18.  
  19.     //Breaking into that $scope
  20.     socket.log=function(message,classes) {
  21.         this.$events.message[0](JSON.stringify([["msg",{
  22.             msg:message,
  23.             type:classes
  24.             }]]))
  25.         }
  26.  
  27.     //Extend the socket
  28.     socket.sendcmd=function(cmd,data) {
  29.         this.send(JSON.stringify([cmd,data]))
  30.         }
  31.  
  32.     //Extend it some more
  33.     socket.sendchat=function(message) {
  34.         //socket.log(message)
  35.         this.sendcmd("<",{
  36.             meet:meet,
  37.             msg:"output: "+message
  38.             })
  39.         }
  40.  
  41.     //Search and demystify
  42.     socket.socket.onDisconnect=function() {
  43.         setInterval(function() {
  44.             $.ajax({url:"/game/find?page=1",method:"get"}).success(function(json) {
  45.                 json.data.some(function(table) {
  46.                     if(table.status_id===0&&!table.password) {
  47.                         window.location="/game/"+table.id+"?bot"
  48.                         return true
  49.                         }
  50.                     })
  51.                 })
  52.             },5000)
  53.         }
  54.  
  55.     //Plug in
  56.     socket.on("message",function(packet) {
  57.         var i,
  58.             cmd,
  59.             data
  60.         packet=JSON.parse(packet)
  61.         for(i=0;i<packet.length;i++) {
  62.             cmd=packet[i][0],
  63.             data=packet[i][1]
  64.             switch(cmd) {
  65.                 case "auth":
  66.                     socket.log("Running EMboxxxxy")
  67.                     break
  68.                 case "round":
  69.                     if(data.state===-1) {
  70.                         socket.sendcmd("leave")
  71.                         }
  72.                     break
  73.                 case "users":
  74.                     users=data.users
  75.                     Object.defineProperty(users,"alive",{
  76.                         value:function(self) {
  77.                             var x,
  78.                                 output=[]
  79.                             for(x in this) {
  80.                                 if(!this[x].dead&&(x!==user||self)) {
  81.                                     output.push(x)
  82.                                     }
  83.                                 }
  84.                             return output
  85.                             }
  86.                         })
  87.                     break
  88.                 case "join":
  89.                     users[data.user]=data.data
  90.                     break
  91.                 case "leave":
  92.                     delete users[data.user]
  93.                     break
  94.                 case "kick":
  95.                     users[data.user].dead=true
  96.                     break
  97.                 case "kill":
  98.                     users[data.target].dead=true
  99.                     break
  100.                 case "<":
  101.                     if(i!==packet.length-1||data.user===user) break
  102.                     var match
  103.                     commands.forEach(function(command) {
  104.                         match=command.regex.exec(data.msg)
  105.                         if(match!==null) {
  106.                             match.shift()
  107.                             command.callback.apply(data,match)
  108.                             }
  109.                         })
  110.                     break
  111.                 case "speech":
  112.                     if(data.type==="contact") {
  113.                         socket.log("The roles are... "+data.data.join(", "))
  114.                         }
  115.                     break
  116.                 case "meet":
  117.                     socket.sendcmd("point",{
  118.                         meet:data.meet,
  119.                         target:data.basket[0]
  120.                         })
  121.                     if(data.meet==="mafia"||data.meet==="thief") {
  122.                         users.alive().forEach(function(who) {
  123.                             if(!data.choosedata[who]) {
  124.                                 socket.log(who+" is your partner!")
  125.                                 }
  126.                             })
  127.                         }
  128.                     break
  129.                 case "point":
  130.                     users[data.user].voted=!data.unpoint
  131.                     break
  132.                 case "countdown":
  133.                     clearTimeout(kicktimer)
  134.                     kicktimer=setTimeout(function() {
  135.                         socket.sendcmd("kick")
  136.                         },data.totaltime)
  137.                     break
  138.                 case "start_input":
  139.                     if(true) break
  140.                     socket.sendcmd("input",{
  141.                         id:data.id,
  142.                         input:{
  143.                             player:autobomb.constructor===String?autobomb:users.alive().random()
  144.                             }
  145.                         })
  146.                     break
  147.                 }
  148.             }
  149.         })
  150.  
  151.     //Get acquainted
  152.     var commands=[
  153.         {   regex:/^boxxy info/i,
  154.             callback:function(data) {
  155.                
  156.                 }
  157.             },
  158.         {   regex:/^(?:he?i?ll?o|hii?i?|heyy?a?|(?:wh?at)?.?s ?up)/i,
  159.             callback:function(data) {
  160.                 if(users[data.user].greeted) return
  161.                 socket.sendchat(parse("(hii?|h(e|i)yy?a?)!? (:3|^_^)?"))
  162.                 users[data.user].greeted=true
  163.                 }
  164.             },
  165.         {   regex:/at least one of (\w+), (\w+), (\w+)/i,
  166.             callback:function(data,A,B,C) {
  167.                 var choice
  168.                 [A,B,C].forEach(function(name) {
  169.                     if(users[name]!==undefined&&!users[name].dead) {
  170.                         choice=name
  171.                         return true
  172.                         }
  173.                     return false
  174.                     })
  175.                 if(choice!==undefined) {
  176.                     socket.sendcmd("point",{
  177.                         meet:data.meet,
  178.                         target:choice
  179.                         })
  180.                     }
  181.                 }
  182.             }
  183.         ]
  184.  
  185.     //Varietize
  186.     function parse(string) {
  187.         string=String(string)
  188.             .replace(parse.var,function(match,what) {
  189.                 return eval(what)
  190.                 })
  191.             .replace(parse.ran,function(match,word) {
  192.                 return Math.random()<0.4?word:""
  193.                 })
  194.         while(string.match(parse.group)) {
  195.             string=string.replace(parse.group,function(match,message,random) {
  196.                 if(random===undefined||Math.random()<0.4) {
  197.                     return message.split("|").random()
  198.                     }
  199.                 return ""
  200.                 })
  201.             }
  202.         return string
  203.         }
  204.     parse.var=/\$(\w+(?:(?:\.\w+)+)?)/g
  205.     parse.ran=/([^()\\])\?/g
  206.     parse.group=/\(([^()]+)\)(\?)?/g
  207.  
  208.     //MiniLib
  209.     Array.prototype.random=function() {
  210.         return this[Math.floor(Math.random()*this.length)]
  211.         }
  212.  
  213.     })
  214.  
  215. //Jack-in
  216. script=document.createElement("script")
  217. script.textContent="("+EMjack+")()"
  218. document.body.appendChild(script)
Advertisement
Add Comment
Please, Sign In to add comment