function monokoBot_PrimeDice($username, $password) { /* * Initiating primedice objects */ $botAccount = new \mdSite\SiteClasses\PrimeDice(); // getting login success $loginSuccess = $botAccount->login($username, $password); // checking if login was successful if ($loginSuccess) { // will store each message object $map = null; /* * Initiating Bot */ $mkBot = new \mdBot\MonokoBot(new siteInterface($botAccount), false, false); $mkBot->setDatabase('pduserhistory'); // set permissions $mkBot->setOwner(720406); $mkBot->setAccount($botAccount->userId(), $username); /* * Socket Stuff */ $socket = new \mdSite\phpWS\WebSocket(); // $botAccount->chat('Preparing connection...', array('user' => 'Coolio')); // listening to chat $socket->listen('wss://sockets.primedice.com/socket.io/?EIO=3&transport=websocket', $botAccount->socketPrepare(), function ($frame) use($mkBot, $botAccount) { // json decode frame $map = json_decode($frame); // if frame is to do with chat if ($map[0] == 'msg' || $map[0] == 'pm') { // if frame is a chat message if (!$map[1]->prefix || $map[1]->prefix == 'PM') { // map message to bot $mkBot->receiveMessage(array('userId' => $map[1]->userid, 'user' => $map[1]->username, 'isMod' => $map[1]->admin == 'A' || $map[1]->admin == 'M', 'time' => strtotime($map[1]->timestamp), 'msg' => $map[1]->message), !!($map[1]->prefix == 'PM')); } if ($map[1]->prefix == 'BOT' && $map[1]->username == 'Tipsy') { // get message details $msg = explode(' ', $map[1]->message); $msgL = count($msg); // map tip to bot $mkBot->receiveTip(array('userId' => $botAccount->nameLookup($msg[0]), 'user' => $msg[0], 'balance' => $msg[3] / 100000000, 'toUserId' => $botAccount->nameLookup($msg[$msgL - 1]))); } } $mkBot->update(); }); if (!$mkBot->exited()) { // shut down bot $mkBot->exitOut(); // start up bot monokoBot_PrimeDice($username, $password); } } }
function monokoBot_MagicalDice($username, $password) { /* * Initiating magical dice objects */ $botAccount = new \mdSite\SiteClasses\MagicalDice(); // getting login success $loginSuccess = $botAccount->login($username, $password); // checking if login was successful if ($loginSuccess) { // will store each message object $map = null; /* * Initiating Bot */ $mkBot = new \mdBot\MonokoBot(new siteInterface($botAccount), false, false); $mkBot->setDatabase('mduserhistory'); // set permissions $mkBot->setOwner(608); $mkBot->setAccount($botAccount->userId(), $username); /* * Socket Stuff */ $socket = new \mdSite\PhpWS\WebSocket(); // listening to chat $socket->listen('wss://ws.magicaldice.com/socket.io/?EIO=3&transport=websocket', $botAccount->socketPrepare(), function ($frame) use($mkBot) { // if frame is not empty if ($frame != '3') { // json decode frame $map = json_decode($frame); // if frame is to do with chat if ($map[0] == 'chat') { // if frame is a chat message if ($map[1]->type == 'text' || $map[1]->type == 'private') { // map message to bot $mkBot->receiveMessage(array('userId' => $map[1]->from->user_id, 'user' => $map[1]->from->user_name, 'isMod' => $map[1]->from->user_permissions == 11 || $map[1]->from->user_permissions == 8, 'time' => $map[1]->time, 'msg' => $map[1]->msg), !!($map[1]->type == 'private')); } if ($map[1]->type == 'tip') { // map tip to bot $mkBot->receiveTip(array('userId' => $map[1]->from->user_id, 'user' => $map[1]->from->user_name, 'balance' => $map[1]->tip->amount, 'toUserId' => $map[1]->tip->user_id)); } } $mkBot->update(); } }); if (!$mkBot->exited()) { // shut down bot $mkBot->exitOut(); // start up bot monokoBot_MagicalDice($username, $password); } } }