Advertisement
Eeems

quote module

May 21st, 2011
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.15 KB | None | 0 0
  1. global $QUOTES;
  2. global $QMD5;
  3. if(!is_file('quotes.ini')){
  4.     $f = fopen('quotes.ini','w');
  5.     fwrite($f,"[quotes]\n0 = \"This is a quote!\"");
  6.     fclose($f);
  7. }
  8. $GLOBALS['QMD5'] = md5_file('quotes.ini');
  9. set_ini_array(parse_ini_file('quotes.ini',true),'QUOTES');
  10. function saveQ(){
  11.     write_ini_file($GLOBALS['QUOTES'],'quotes.ini',true);
  12.     $GLOBALS['QMD5'] = md5_file('quotes.ini');
  13. }
  14. function array_first_open($a){
  15.     for($i = 0;$i<count($a);$i++){
  16.         if(!isset($a[$i])){
  17.             return $i;
  18.         }
  19.     }
  20.     return count($a);
  21. }
  22. function M_quote($args,$ex){
  23.     if(md5_file('quotes.ini')!=$GLOBALS['QMD5']){
  24.  
  25.         $args['server']->out("-----Reloading Quote Database----");
  26.  
  27.         set_ini_array(parse_ini_file('quotes.ini',true),'QUOTES');
  28.         $GLOBALS['QMD5'] = md5_file('quotes.ini');
  29.  
  30.     }
  31.     $u = user($args['nick']);
  32.     switch($args['cmd']){
  33.         case '!quote':
  34.             if(count($GLOBALS['QUOTES']['quotes'])!=0){
  35.                 if(isset($ex[4])){
  36.                     if(isset($GLOBALS['QUOTES']['quotes'][$ex[4]])){
  37.                         $args['server']->reply("Quote ".$ex[4].": ".$GLOBALS['QUOTES']['quotes'][$ex[4]]);
  38.                     }else{
  39.                         $args['server']->reply("Quote ".$ex[4]." not found");
  40.                     }
  41.                 }else{
  42.                     $i = rand(0,count($GLOBALS['QUOTES']['quotes'])-1);
  43.                     $args['server']->reply("Quote ".$i.": ".$GLOBALS['QUOTES']['quotes'][$i]);
  44.                 }
  45.             }else{
  46.                 $args['server']->reply("Quote database is empty");
  47.             }
  48.         break;
  49.         case '!addquote':
  50.             if($u&&isset($u['active'])&&$u['rank']>=3){
  51.                 $msg = '';
  52.                 foreach($ex as $i => $v){
  53.                     if($i>4){
  54.                         $msg = $msg.' '.$v;
  55.                     }elseif($i == 4){
  56.                         $msg = $v;
  57.                     }
  58.                 }
  59.                 $GLOBALS['QUOTES']['quotes'][array_first_open($GLOBALS['QUOTES']['quotes'])] = $msg;
  60.                 saveQ();
  61.                 $args['server']->reply("Quote added");
  62.             }
  63.         break;
  64.         case '!removequote':
  65.             if($u&&isset($u['active'])&&$u['rank']>=3&&isset($ex[4])){
  66.                 unset($GLOBALS['QUOTES']['quotes'][$ex[4]]);
  67.                 saveQ();
  68.             }
  69.         break;
  70.         case '!countquotes':
  71.             $c = 0;
  72.             foreach($GLOBALS['QUOTES']['quotes'] as $i => $q){
  73.                 if(isset($GLOBALS['QUOTES']['quotes'][$i])){
  74.                     $c++;
  75.                 }
  76.             }
  77.             $args['server']->reply("Quote count: ".$c);
  78.         break;
  79.     }
  80. }
  81. regModule('quote','M_quote');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement