Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name EMbot
- // @description Join any game, add ?bot to the URL to activate.
- // @match http://www.epicmafia.com/game/*?bot
- // ==/UserScript==
- //Welcome back
- EMjack=String(function() {
- //Variables
- users={}
- meet=null
- master=null
- kicktimer=0
- //Locate the socket
- socket=io.sockets["http://www.epicmafia.com:80"].namespaces[""]
- //Breaking into that $scope
- socket.log=function(message,classes) {
- this.$events.message[0](JSON.stringify([["msg",{
- msg:message,
- type:classes
- }]]))
- }
- //Extend the socket
- socket.sendcmd=function(cmd,data) {
- this.send(JSON.stringify([cmd,data]))
- }
- //Extend it some more
- socket.sendchat=function(message) {
- //socket.log(message)
- this.sendcmd("<",{
- meet:meet,
- msg:"output: "+message
- })
- }
- //Search and demystify
- socket.socket.onDisconnect=function() {
- setInterval(function() {
- $.ajax({url:"/game/find?page=1",method:"get"}).success(function(json) {
- json.data.some(function(table) {
- if(table.status_id===0&&!table.password) {
- window.location="/game/"+table.id+"?bot"
- return true
- }
- })
- })
- },5000)
- }
- //Plug in
- socket.on("message",function(packet) {
- var i,
- cmd,
- data
- packet=JSON.parse(packet)
- for(i=0;i<packet.length;i++) {
- cmd=packet[i][0],
- data=packet[i][1]
- switch(cmd) {
- case "auth":
- socket.log("Running EMboxxxxy")
- break
- case "round":
- if(data.state===-1) {
- socket.sendcmd("leave")
- }
- break
- case "users":
- users=data.users
- Object.defineProperty(users,"alive",{
- value:function(self) {
- var x,
- output=[]
- for(x in this) {
- if(!this[x].dead&&(x!==user||self)) {
- output.push(x)
- }
- }
- return output
- }
- })
- break
- case "join":
- users[data.user]=data.data
- break
- case "leave":
- delete users[data.user]
- break
- case "kick":
- users[data.user].dead=true
- break
- case "kill":
- users[data.target].dead=true
- break
- case "<":
- if(i!==packet.length-1||data.user===user) break
- var match
- commands.forEach(function(command) {
- match=command.regex.exec(data.msg)
- if(match!==null) {
- match.shift()
- command.callback.apply(data,match)
- }
- })
- break
- case "speech":
- if(data.type==="contact") {
- socket.log("The roles are... "+data.data.join(", "))
- }
- break
- case "meet":
- socket.sendcmd("point",{
- meet:data.meet,
- target:data.basket[0]
- })
- if(data.meet==="mafia"||data.meet==="thief") {
- users.alive().forEach(function(who) {
- if(!data.choosedata[who]) {
- socket.log(who+" is your partner!")
- }
- })
- }
- break
- case "point":
- users[data.user].voted=!data.unpoint
- break
- case "countdown":
- clearTimeout(kicktimer)
- kicktimer=setTimeout(function() {
- socket.sendcmd("kick")
- },data.totaltime)
- break
- case "start_input":
- if(true) break
- socket.sendcmd("input",{
- id:data.id,
- input:{
- player:autobomb.constructor===String?autobomb:users.alive().random()
- }
- })
- break
- }
- }
- })
- //Get acquainted
- var commands=[
- { regex:/^boxxy info/i,
- callback:function(data) {
- }
- },
- { regex:/^(?:he?i?ll?o|hii?i?|heyy?a?|(?:wh?at)?.?s ?up)/i,
- callback:function(data) {
- if(users[data.user].greeted) return
- socket.sendchat(parse("(hii?|h(e|i)yy?a?)!? (:3|^_^)?"))
- users[data.user].greeted=true
- }
- },
- { regex:/at least one of (\w+), (\w+), (\w+)/i,
- callback:function(data,A,B,C) {
- var choice
- [A,B,C].forEach(function(name) {
- if(users[name]!==undefined&&!users[name].dead) {
- choice=name
- return true
- }
- return false
- })
- if(choice!==undefined) {
- socket.sendcmd("point",{
- meet:data.meet,
- target:choice
- })
- }
- }
- }
- ]
- //Varietize
- function parse(string) {
- string=String(string)
- .replace(parse.var,function(match,what) {
- return eval(what)
- })
- .replace(parse.ran,function(match,word) {
- return Math.random()<0.4?word:""
- })
- while(string.match(parse.group)) {
- string=string.replace(parse.group,function(match,message,random) {
- if(random===undefined||Math.random()<0.4) {
- return message.split("|").random()
- }
- return ""
- })
- }
- return string
- }
- parse.var=/\$(\w+(?:(?:\.\w+)+)?)/g
- parse.ran=/([^()\\])\?/g
- parse.group=/\(([^()]+)\)(\?)?/g
- //MiniLib
- Array.prototype.random=function() {
- return this[Math.floor(Math.random()*this.length)]
- }
- })
- //Jack-in
- script=document.createElement("script")
- script.textContent="("+EMjack+")()"
- document.body.appendChild(script)
Advertisement
Add Comment
Please, Sign In to add comment