Howsya

Mixbot

Feb 13th, 2012
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 15.54 KB | None | 0 0
  1. <?php
  2. class mixed extends irccallback {
  3.  
  4.   var $helpMessageLock=array();
  5.   var $statusMessageLock=array();
  6.  
  7.   function statusUnlock($data) {
  8.     $this->statusMessageLock[$data['unlockThis']]=false;
  9.   }
  10.  
  11.   function helpUnlock($data) {
  12.     $this->helpMessageLock[$data['unlockThis']]=false;
  13.   }
  14.  
  15.   function mixedPrivateMessage($data) {
  16.       global $db;
  17.       $owner = $this->irc->getNick($data[0]);
  18.       //$this->irc->messageTo($this->channel, 'I got the message!');
  19.  
  20.  
  21.       switch ($data[3]) {
  22.         case ':!start':
  23.           //               date   time  avail  isok
  24.           $BOOL_CHECK = array(false, false, false, false);
  25. //          if(count($data)==4) {
  26.           if(count($data)>=4) {
  27.             if(isset($data[4])) {
  28.               $players=(int)$data[4];
  29.               if($players<12) $players=12;
  30.               if($players>20) $players=20;
  31.             }
  32.             else {
  33.                  $players=$this->irc->cfg['max_players'];
  34.             }
  35.  
  36.             $timestamp=-1;
  37.  
  38.             $uref=base_convert(time(),10,16);
  39.  
  40.                $q=$db->getBuilder();
  41.                $q->add('id');
  42.                $q->where('timestamp', $timestamp);
  43.             $q->whereString('channel', $this->channel);
  44.                $q->where('active', true);
  45.                $q->goSelect('bot_match');
  46.                $db->execute($q);
  47.  
  48.                $query=$db->makeArray();
  49.  
  50.                if(count($query)==0) {
  51.                  $BOOL_CHECK[0]=true;
  52.                  $BOOL_CHECK[1]=true;
  53.                  $BOOL_CHECK[2]=true;
  54.                }
  55.                else {
  56.               $this->irc->messageTo($this->channel, 'Mixed match already setup.');
  57.                }
  58.           }
  59.           if($BOOL_CHECK[0] && $BOOL_CHECK[1] && $BOOL_CHECK[2]) {
  60.                $BOOL_CHECK[3]=true;
  61.           }
  62.  
  63.           if($BOOL_CHECK[3]) {
  64.                $q=$db->getBuilder();
  65.                $q->addString('reference', $uref);
  66.             $q->addString('owner', $owner);
  67.                $q->add('timestamp', $timestamp);
  68.                $q->add('max_players', $players);
  69.             $q->addString('channel', $this->channel);
  70.                $q->add('active', true);
  71.               $q->goInsert('bot_match');
  72.                $db->execute($q);
  73.             $this->irc->messageTo($this->channel, 'Mixed created for '.$players.' players. Starting when full.');
  74.           }
  75.           //$this->callbackTOPIC($data);
  76.         break;
  77.  
  78.         case ':!finish':
  79.           if(count($data)==4) {
  80.                $timestamp=-1;
  81.                $q=$db->getBuilder();
  82.                $q->add('id');
  83.                $q->add('owner');
  84.             $q->where('timestamp', $timestamp);
  85.             $q->whereString('channel', $this->channel);
  86.             $q->where('active', 1);
  87.                $q->goSelect('bot_match');
  88.                $db->execute($q);
  89.                $query=$db->makeArray();
  90.             $this->debug($query['id']);
  91.                if(count($query)>0) {
  92.               $this->debug('REQUEST Finish By: '.$owner);
  93.               $validOwner = false;
  94.               $validOwner |= $this->irc->isOp($this->channel, $owner);
  95.               $validOwner |= ($query[0]['owner']==$owner)?true:false;
  96.  
  97.               if($validOwner) {
  98.                  $q=$db->getBuilder();
  99.                  $q->add('timestamp', time());
  100.                  $q->add('active', 0);
  101.                  $q->where('id', $query[0]['id']);
  102.                  $q->goUpdate('bot_match');
  103.                  $db->execute($q);
  104.                  $this->irc->messageTo($this->channel, 'Mixed finished.');
  105.               }
  106.                }
  107.                else {
  108.              $this->irc->messageTo($this->channel, 'No unfinished Mixed found.');
  109.                }
  110.           }
  111.         break;
  112.  
  113.         case ':!debug': {
  114.           $data[0] = base_convert(time(),10,36) .'[email protected]';
  115.         }
  116.         case ':!add':
  117.           if(count($data)==4) {
  118.                $timestamp=-1;
  119.                $q=$db->getBuilder();
  120.                $q->add('reference');
  121.                $q->add('max_players');
  122.             $q->where('timestamp', $timestamp);
  123.             $q->whereString('channel', $this->channel);
  124.             $q->where('active', 1);
  125.                $q->goSelect('bot_match');
  126.                $db->execute($q);
  127.                $query=$db->makeArray();
  128.                //Valid Match?
  129.             if(count($query)>0) {
  130.               $max_players = $query[0]['max_players'];
  131.               $max_subs = $this->irc->cfg['max_subs'];
  132.  
  133.               $this->debug('NICKNAME: '.$owner);
  134.               $q=$db->getBuilder();
  135.               $q->add('id');
  136.               $q->whereString('name', $owner);
  137.               $q->whereString('reference', $query[0]['reference']);
  138.               $q->goSelect('bot_players');
  139.               $db->execute($q);
  140.  
  141.               $this->debug('>> CURRENT SQL COUNT [Is player already in]: '. $db->count());
  142.  
  143.               if($db->count()!=false) {
  144.                 $this->irc->messageTo($this->channel, 'You are already signed to the mix. Dont be a t00l');
  145.                 break;
  146.               }
  147.  
  148.               // Get Enrolled Player count
  149.               $q=$db->getBuilder();
  150.               $q->add('id');
  151.               $q->whereString('reference', $query[0]['reference']);
  152.               $q->where('isSub', 0);
  153.               $q->goSelect('bot_players');
  154.               $db->execute($q);
  155.               $cur_count = $db->count();
  156.  
  157.               // Get Enrolled Player count
  158.               $q=$db->getBuilder();
  159.               $q->add('id');
  160.               $q->whereString('reference', $query[0]['reference']);
  161.               $q->where('isSub', 1);
  162.               $q->goSelect('bot_players');
  163.               $db->execute($q);
  164.               $sub_count = $db->count();
  165.  
  166.               if($cur_count<$max_players) {
  167.                 //Add to team
  168.                 $q=$db->getBuilder();
  169.                 $q->addString('name', $owner);
  170.                 $q->addString('reference', $query[0]['reference']);
  171.                 $q->add('isSub', 0);
  172.                 $q->add('timestamp',time());
  173.                 $q->goInsert('bot_players');
  174.                 $db->execute($q);
  175.                 $this->irc->messageTo($this->channel, 'Congratulations '.$owner.' you have been added to the mixed. Players: ['.($cur_count+1).'/'.$max_players.'][SUB: '.$sub_count.'/'.$max_subs.']');
  176.               } else {
  177.                 //Can I add to sub?  if so, add to sub list...
  178.                 if($sub_count<$max_subs) {
  179.                   $q=$db->getBuilder();
  180.                   $q->addString('name', $owner);
  181.                   $q->addString('reference', $query[0]['reference']);
  182.                   $q->add('isSub', 1);
  183.                   $q->add('timestamp',time());
  184.                   $q->goInsert('bot_players');
  185.                   $db->execute($q);
  186.                   $this->irc->messageTo($this->channel, 'Congratulations '.$owner.' you have been added to the reserves for the mixed. Players: ['.$cur_count.'/'.$max_players.'][SUB: '.($sub_count+1).'/'.$max_subs.']');
  187.                 } else {
  188.                   //Sorry, its full!
  189.                   $this->irc->messageTo($this->channel, 'Im sorry '.$owner.' this mixed is full. Im sure another will be setup up again soon. Players: ['.$max_players.'/'.$max_players.'][SUB: '.$max_subs.'/'.$max_subs.']');
  190.                 }
  191.               }
  192.             }
  193.             else {
  194.               $this->irc->messageTo($this->channel, 'No mixed currently active.');
  195.             }
  196.              }
  197.         break;
  198.  
  199.  
  200.         case ':!del':
  201.           if(count($data)==4) {
  202.                $timestamp=-1;
  203.                $q=$db->getBuilder();
  204.                $q->add('reference');
  205.             $q->add('max_players');
  206.             $q->whereString('channel', $this->channel);
  207.             $q->where('timestamp', $timestamp);
  208.             $q->where('active', 1);
  209.                $q->goSelect('bot_match');
  210.  
  211.                $db->execute($q);
  212.  
  213.                $query=$db->makeArray();
  214.  
  215.             if(count($query)>0) {
  216.               $max_players = $query[0]['max_players'];
  217.               $max_subs = $this->irc->cfg['max_subs'];
  218.               //Get count...
  219.               //Get Enrolled Player count
  220.               $q=$db->getBuilder();
  221.               $q->add('id');
  222.               $q->whereString('reference', $query[0]['reference']);
  223.               $q->where('isSub', 0);
  224.               $q->goSelect('bot_players');
  225.               $db->execute($q);
  226.               $cur_count = $db->count();
  227.  
  228.               // Get Enrolled Player count
  229.               $q=$db->getBuilder();
  230.               $q->add('id');
  231.               $q->whereString('reference', $query[0]['reference']);
  232.               $q->where('isSub', 1);
  233.               $q->goSelect('bot_players');
  234.               $db->execute($q);
  235.               $sub_count = $db->count();
  236.  
  237.               //Find me!
  238.               $q=$db->getBuilder();
  239.               $q->whereString('reference', $query[0]['reference']);
  240.               $q->whereString('name', $owner);
  241.               $q->limit(1);
  242.               $q->goSelect('bot_players');
  243.               $db->execute($q);
  244.               //Player in the mix?
  245.               if($db->count()==0) {
  246.                 $this->irc->messageTo($this->channel, 'You are currently not signed to the mix.');
  247.                 break;
  248.               }
  249.               else {
  250.                 $wasSub = $db->direct('isSub');
  251.                 $wasPlayerID = $db->direct('id');
  252.  
  253.                 //remove this player
  254.                 $q=$db->getBuilder();
  255.                 $q->where('id', $wasPlayerID);
  256.                 $q->goDelete('bot_players');
  257.                 $q->limit(1);
  258.                 $db->execute($q);
  259.  
  260.                 $this->irc->messageTo($this->channel, ' Brave brave Sir '.$owner.' you have been successfully removed from the mixed.');
  261.  
  262.                 //Was this player part of the main list?  If so, can we upgrade a sub?
  263.                 if($wasSub==0) {
  264.                   $q=$db->getBuilder();
  265.                   $q->add('id');
  266.                   $q->add('name');
  267.                   $q->whereString('reference', $query[0]['reference']);
  268.                   $q->where('isSub',1);
  269.                   $q->sort('timestamp', 'ASC');
  270.                   $q->limit(1);
  271.                   $q->goSelect('bot_players');
  272.                   $db->execute($q);
  273.  
  274.                   if($db->count()>0) {
  275.                     $theSub = $db->data(0);
  276.                     $this->irc->messageTo($this->channel, 'Congratulations '.$theSub['name'].' you have been moved from \'SUBS\'. Players: ['.($cur_count).'/'.$max_players.'][SUB: '.($sub_count-1).'/'.$max_subs.']');
  277.                     $q=$db->getBuilder();
  278.                     $q->add('isSub',0);
  279.                     $q->whereString('id', $theSub['id']);
  280.                     $q->goUpdate('bot_players');
  281.                     $db->execute($q);
  282.                   }
  283.                 }
  284.               }
  285.             }
  286.             else {
  287.               $this->irc->messageTo($this->channel, 'No mixed currently active.');
  288.             }
  289.           }
  290.         break;
  291.  
  292.         case ':!status':
  293.           $final_message=array();
  294.           $this->debug('>>PRIVMSG [Command found= '.$data[3].']');
  295.  
  296.           $outputTo = $owner;
  297.           if(isset($data[4])) {
  298.             if(strcmp('p', $data[4])==0) {
  299.                $outputTo = $this->channel;
  300.              }
  301.           }
  302.          
  303.           if(!isset($this->statusMessageLock[$outputTo])) $this->statusMessageLock[$outputTo]=false;
  304.           if($this->statusMessageLock[$outputTo]===false) {
  305.             if(count($data)>=4) {
  306.               $this->statusMessageLock[$outputTo]=true;
  307.               $timestamp=-1;
  308.               $q=$db->getBuilder();
  309.               $q->add('reference');
  310.               $q->add('max_players');
  311.               $q->whereString('channel', $this->channel);
  312.               $q->where('timestamp', $timestamp);
  313.               $q->where('active', 1);
  314.                  $q->goSelect('bot_match');
  315.                  $db->execute($q);
  316.                  $query=$db->makeArray();
  317.  
  318.               if($db->count()>0) {
  319.                 $q=$db->getBuilder();
  320.                    $q->add('name');
  321.                    $q->add('isSub');
  322.                 $q->whereString('reference', $query[0]['reference']);
  323.                 $q->sort('id','ASC');
  324.                    $q->goSelect('bot_players');
  325.                    $db->execute($q);
  326.                    $query2 = $db->makeArray();
  327.  
  328.                    if($db->count()>0) {
  329.  
  330.                   $player_count=0;
  331.                   $sub_count=0;
  332.                      $msg='';
  333.                      $temp=array();
  334.                   foreach($query2 as $p) {
  335.                     if($p['isSub']==0) {
  336.                       $temp[] = $p['name'];
  337.                       $player_count+=1;
  338.                     }
  339.                   }
  340.                   $msg=implode(', ', $temp);
  341.                   $this->irc->messageTo($outputTo, 'Players ['.$player_count.'/'.$query[0]['max_players'].']: '.$msg, 1.5);
  342.  
  343.                   $msg='';
  344.                      $temp=array();
  345.                   foreach($query2 as $p) {
  346.                     if($p['isSub']==1) {
  347.                       $temp[] = $p['name'];
  348.                       $sub_count+=1;
  349.                     }
  350.                   }
  351.                   $msg=implode(', ', $temp);
  352.                   $last = $this->irc->messageTo($outputTo, 'Subs ['.$sub_count.'/'.$this->irc->cfg['max_subs'].']: '.$msg, 1.5);
  353.                 }
  354.                 else {
  355.                   $last = $this->irc->messageTo($outputTo, 'No signed players to current mixed.');
  356.                 }
  357.               }
  358.               else {
  359.                 $last = $this->irc->messageTo($outputTo, 'No mixed currently active.');
  360.               }
  361.                }
  362.                $this->irc->office->dispatch($last + 4, $this, 'statusUnlock', '',array('unlockThis'=>$outputTo));
  363.              }
  364.         break;
  365.  
  366.         case ':!help':
  367.  
  368.           $outputTo = $owner;
  369.           if(isset($data[4])) {
  370.             if(strcmp('p', $data[4])==0) {
  371.                $outputTo = $this->channel;
  372.              }
  373.           }
  374.  
  375.           if(!isset($this->statusMessageLock[$outputTo])) $this->statusMessageLock[$outputTo]=false;
  376.           if($this->statusMessageLock[$outputTo]===false) {
  377.             $this->helpMessageLock[$outputTo]=true;
  378.             $hlpstr = array(
  379.                             '!start [x] - Start a mixed. Default is 16, you can optionally specify player count',
  380.                             '!finish - Cancel/Finish a mixed.',
  381.                             '!add - sign up for a game.',
  382.                             '!del - remove from a game.',
  383.                             '!status [p]- show status of mixed, p = channel message',
  384.                             '!help [p]- Your looking at it!, p = channel message',
  385. //                            '!schedule {date} - show a list of available mixed. if {date} is set displays for entered date.',
  386. //                            '!signed <id> - shows a list of signed up players for a specified mixed'
  387.                             );
  388.             //$delay=0;
  389.             foreach($hlpstr as $message) {
  390.                $last = $this->irc->messageTo($outputTo, $message, 1.2);
  391.             }
  392.             $this->irc->office->dispatch($last+1, $this, 'helpUnlock', '' ,array('unlockThis'=>$outputTo));
  393.           }
  394.         break;
  395.       }
  396.   }
  397.  
  398.   function adminDeletePlayer($data) {
  399.     if(!$this->irc->isOp($this->channel,$data['who'])) return;
  400.     $pass=array();
  401.     $pass[0]=$data['toDelete'];
  402.     $pass[1]='something';
  403.     $pass[2]='channel';
  404.     $pass[3]=':!del';
  405.     $this->mixedPrivateMessage($pass);
  406.   }
  407.  
  408.   function function2($data) {
  409.     $this->irc->messageTo($data['who'],' You just added yourself to the ' . $this->channel . ' mixed!');
  410.   }
  411.  
  412.   function onInit() {
  413.     $this->registerCallback('PRIVMSG', 'mixedPrivateMessage');
  414.   }
  415. }
  416. ?>
Advertisement
Add Comment
Please, Sign In to add comment