User Control Panel
Advertisements

HELP US, HELP YOU!

I really want help writing a trivia bot

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Code Help
View unanswered posts
Author Message
jman27
Newbie
Newbie


Joined: 19 May 2006
Posts: 3

Reputation: 4.7Reputation: 4.7Reputation: 4.7Reputation: 4.7

PostPosted: Mon Sep 03, 2007 6:43 am    Post subject: I really want help writing a trivia bot Reply with quote

Hey guys,
I have a word game bot. But, I want to also be able to have a trivia bot . I havent been able to code one. Will anyone help me. Here is my current bot code:
Code:
#!/usr/bin/perl
use Net::OSCAR qw(:standard);
my $screenname = "jman278bot";
my $password = "*****";


#########################
#########################


$beginningHTML = "<html><body bgcolor=\"#D8DADD\"><font color=\"#3F76AA\">";
$endHTML = "</font></html>";
$commands = "Commands so far: !top10, !rankme, !rank SCREENAME, !suggest MESSAGE, !repeat, !commands, !arbiters, !create TEAMNAME PASSWORD, !join TEAMNAME PASSWORD, !team TEAMNAME, !top10teams, !banrequest SN --- Arbiters only: !ban SCREENAME, !unban SCREENAME, !banlist, !invite SN  Admin commands: !ban SCREENAME, !unban SCREENAME, !banlist, !invite SN, !triallog, !im SN MESSAGE, !message MESSAGE, !away MESSAGE, !set MESSAGE, !requests ";
$resetTimer = 1;




#join this room after signing on
sub join_room {
  $oscar->chat_join("words", 5);
}


#need the chat variable to invite people
sub set_chat{
  $chat = @_[2];
  &execute;
}


#cause the bugger prints really fast
sub pause {
  my $pauseStartTime;
  $oscar->do_one_loop();
  $pauseStartTime = int(time());
  while (int(time()) < ($pauseStartTime + 2)) {
  }
}


sub pause1 {
  my $pauseStartTime;
  $oscar->do_one_loop();
  $pauseStartTime = int(time());
  while (int(time()) < ($pauseStartTime + 1)) {
  }
}


sub im_in {
  my($oscar, $sender, $message, $is_away) = @_;
  $message =~ s/<(.|\n)+?>//g;
  $sender =~ s/ //g;
  print "[AWAY] " if $is_away;
  print "$sender: $message\n";
  $IMed = 0;
 
  $person_banned = 0;
  foreach (keys %banned) {
    if($sender =~ /$_/i) {
      if ($banned{$_} == 1) {
        $person_banned = 1;
        last;
      }
    }
  }
$person_arbiter = 0;
  foreach (keys %arbiter) {
    if($sender =~ /$_/i) {
      if ($arbiter{$_} == 1) {
        $person_arbiter = 1;
        last;
      }
    }
  }

  if ($person_banned != 1) {
    ### !create TEAMNAME PASSWORD ###
     if(lc $message =~ /(!create) (.*) (.*)/i) {
       $IMed = 1;
       $nameToSearch = $from;
       &find_match_in_team_players;
   
       chomp($teamPassword = $3);
       $teamFound = 0;
        
       foreach (keys %team_scores) {
         if (/$2/i) {
           $teamFound = 1;
           last;
         }
       }
        
       if($teamFound) {
         $oscar->send_im($sender, "$beginningHTML Sorry, team $2 already exists!");
       }
       else {
         $team_scores{$2} = 0;
         $team_password{$2} = $teamPassword;
         delete $team_players{$nameToSearch};
         $team_players{$nameToSearch} = $2;
         $oscar->send_im($sender, "$beginningHTML Team \"$2\" has been successfully created with password \"$teamPassword\"");
       }
     }

### Load Arbiters ###
$arbiterFile = "./arbiters.txt";
    open ARBITER, $arbiterFile or die "Cannot open $arbiter for read :$!";;
 
  while (<ARBITER>) {
    if($_ ne "") {
      chomp($arbiterPlayer = $_);
      $arbiter{$arbiterPlayer} = 1;
      undef $arbiterPlayer;
    }
  }
  close ARBITER;

  ###########################
  ### load banned players ###
  ###########################
  $bannedFile = "./banned.txt";
  open BANNED, $bannedFile or die "Cannot open $banned for read :$!";;
 
  while (<BANNED>) {
    if($_ ne "") {
      chomp($bannedPlayer = $_);
      $banned{$bannedPlayer} = 1;
      undef $bannedPlayer;
    }
  }
  close BANNED;



     
 
### !triallog ###
 if(lc $message eq "!triallog") {
      if (lc $sender eq "calverthalldrum") {
    $IMed = 1;
    $alogFile="./trialarbiterlog.txt";
   
    open(ALOG, $alogFile);
    $alog= <ALOG>;
    $alogs =read(ALOG, $buffer, 1088888);
    $oscar->send_im($sender, "$beginningHTML Here is who the trial arbiters banned: $buffer." );
    close (BANLIST);
    }
   else{
   $oscar->send_im($sender, "$beginningHTML You can not use this command because you are not an arbiter." );
       }
      }

### !invite SN ###
 if(lc $message =~ /(!invite) (.*)/i) {
 if ($arbiter{lc $sender} == 1) {
 $IMed = 1;
 $chat->invite($2, "Come and play");
 $oscar->send_im($sender, "$beginningHTML $2 has been invited.");
  }
else{
$oscar->send_im($sender, "$beginningHTML Only arbiters may use this command.");
}
}
      
      
    ### !banlist ###
    if(lc $message eq "!banlist") {
       if ($arbiter{lc $sender} == 1) {
    $IMed = 1;
    $banlistFile="./banned.txt";
    open(BANLIST, $banlistFile);
    $banlist= <BANLIST>;
    $banlists =read(BANLIST, $buffer, 256);
    $oscar->send_im($sender, "$beginningHTML Banned are:  $banlist $buffer" );
    close (BANLIST);
    }
   else{
   $oscar->send_im($sender, "$beginningHTML You can not use this command because you are not an arbiter." );
       }
      }
   
       ### !join TEAMNAME PASSWORD ###
     if(lc $message =~ /(!join) (.*) (.*)/i) {
       $IMed = 1;
       $nameToSearch = $from;
       &find_match_in_team_players;
        
       $teamFound = 0;
            
       foreach (keys %team_scores) {
         if (/$2/i) {
           $theTeamName = $_;
           $teamFound = 1;
           last;
         }
       }
       if($teamFound) {
         if($3 eq $team_password{$theTeamName}) {
           delete $team_players{$nameToSearch};
           $team_players{$nameToSearch} = $2;
           $oscar->send_im($sender, "$beginningHTML You have successfully joined team $2");
         }
         else {
           $oscar->send_im($sender, "$beginningHTML Password for team $2 is incorrect.");
         }       
       }
       else {
         $oscar->send_im($sender, "$beginningHTML Team $2 was not found");
       }
    }
### !message MESSAGE ###
if(lc $message =~ /(!message) (.*)/i) {
if ($sender eq "calverthalldrum") {
$IMed = 1;
      $chat->chat_send ("$beginningHTML $2", NOREFLECT);
    }
      }
### !set MESSAGE ###
if(lc $message =~ /(!set) (.*)/i) {
if ($sender eq "calverthalldrum") {
$IMed = 1;
   $oscar->set_info ($2);
   $oscar->send_im($sender, "$beginningHTML $from, the profile has been set as : $2.");
     }
   }

### !away MESSAGE ###
if(lc $message =~ /(!away) (.*)/i) {
if ($sender eq "calverthalldrum") {
$IMed = 1;
   $oscar->set_away ("$beginningHTML $2", NOREFLECT);
   $oscar->send_im($sender, "$beginningHTML $from, the profile has been set as : $2.");
     }
   }

### !leave ###
if(lc $message eq "!leave") {
  if (lc $sender eq "calverthalldrum") {
  $IMed = 1;
  $chat->chat_leave;

}
  }




### !im sn MESSAGE ###
if(lc $message =~ /(!im) (.*) (.*)/i) {
 if ($sender eq "calverthalldrum") {
 $IMed = 1;
 $oscar->send_im($2, "$beginningHTML $3");
 $oscar->send_im($sender, "$beginningHTML $from, your message to $2 has been sent as : $3.");
 }
  }
   
    if ($sender eq "kaioshin00" & !$IMed) { #so I can speak for the bot
      $chat->chat_send ("$beginningHTML $message</font></html>", NOREFLECT);
    }
    else {
      if(!$IMed) {
        $chat->invite($sender, "Come and play");
      }
    }
  }
}


sub execute {
  my $scores;
  my $printed = 0;
  &pause;&pause;
  $chat->chat_send ("$beginningHTML Now starting a new game ... </font></html>", NOREFLECT);
 
  ##########################
  ### load the scores up ###
  ##########################
  $scores="./scores.txt";
 
  open SCORES, $scores or die "Cannot open $scores for read :$!";;
 
  while (<SCORES>) {
    @array=split /\|/,$_;
    if($array[0] ne "\n") {
      $allPlayers{$array[0]}=$array[1];
      chomp($teamName = $array[2]);
      if ($teamName ne "") {
        $team_players{$array[0]}=$teamName;
        undef $teamName;
      }
    }
  }
  close SCORES;
 
 
 
  ######################################
  ######### load team scores ###########
  ######################################
  # team_players{SN} = teamName        #
  # team_scores{teamName} = 1323       #
  # team_password{teamName} = whatever #
  ######################################
 
  $teams = "./teams.txt";
  open TEAMS, $teams or die "Cannot open $teams for read :$!";
   
  while (<TEAMS>) {
    @array=split /\|/,$_;
    if($_ ne "" && $_ ne "\n" && $array[0] ne "\n") {
      $team_scores{$array[0]} = $array[1];
      chomp($thePassword = $array[2]);
      $team_password{$array[0]} = $thePassword;
      undef $thePassword;
    }
  }
  close TEAMS;
 
 
  #foreach (keys %team_players) {
  #  print "team_players{$_} is $team_players{$_}\n";
  #}
 
  #foreach (keys %team_scores) {
  #  print "team_scores{$_} is $team_scores{$_}\n";
  #}
 
  #foreach (keys %team_password) {
  #  print "team_password{$_} is $team_password{$_}\n";
  #}
   
  &Sort;
 
 
  &pause;&pause;
  $updateInfoCounter = 0;
  while (1) {
    $oscar->do_one_loop();
   
    #ask a question
    undef @playersThisRound;
    &pause;&pause;&pause;
    &ask_question;
       
    $printed = 0;
    $printed2 = 0;
    $startTime = int(time());
    while (int(time()) < ($startTime + 60)) {
      $oscar->do_one_loop();
      $questioning = 1;
      if (int(time()) == ($startTime + 30)) {
        if (!$printed) {
          $chat->chat_send ("$beginningHTML 30 seconds are left.", NOREFLECT);
          $printed = 1;
        }
      }
      if (int(time()) == ($startTime + 45)) {
        if (!$printed2) {
          $chat->chat_send ("$beginningHTML 15 seconds are left.</font></html>", NOREFLECT);
          $printed2 = 1;
        }
      }
    }
    $chat->chat_send ("Time is up!", NOREFLECT);


    #post questioning processing
    $oscar->do_one_loop();
    $questioning = 0;
    undef @answersThisRound;
    undef %scoresThisRound;             #used for sorting scores of current round
    undef %validAnswersThisRound;   #stores each players valid answer
    foreach $player (@playersThisRound) {
      $outputString = "";
      undef @validString;       #each player gets his own valid string
     
      foreach $answer (@$player) {   #string all of the guesses together
        $outputString .= " $answer";
      }
     
      &check_output_string;
     
      $correctAnswers = "";
      $counter = 0;
      foreach $answer (@validString) {
        $correctAnswers .= " $answer";
        $counter++;
      }
      if ($counter) {
        @score = split //, $correctAnswers;
        $theScore = ($#score-$counter+1)*$multiplier;
        $screename = "";
        foreach (keys %allPlayers) {
          if (lc $_ eq lc $player) {
            $screename = $_;
            last;
          }
        }
        if ($screename eq "") {
          $allPlayers{$player}=0;
          $screename = $player;
        }
        $scoresThisRound{$screename} = $theScore;
        $validAnswersThisRound{$screename} = $correctAnswers;
       
        #$allPlayers{$screename} += $theScore;
        #&pause1;
        #$chat->chat_send ("$beginningHTML $player got: $correctAnswers (+$theScore | total $allPlayers{$screename})", NOREFLECT);
      }
      undef @$player;   #remove the player for the next round
    }
   
    foreach (sort { $scoresThisRound{$a} <=> $scoresThisRound{$b} } keys %scoresThisRound) {
      $allPlayers{$_} += $scoresThisRound{$_};
      $nameToSearch = $_;
      &find_match_in_team_players;     
      $teamName = $team_players{$nameToSearch};
      if ($teamName ne "") {
        $team_scores{$teamName} += $scoresThisRound{$_};
        &pause;
        $chat->chat_send ("$beginningHTML $_ got: $validAnswersThisRound{$_} (+$scoresThisRound{$_} | total $allPlayers{$_} | team $teamName: $team_scores{$teamName})", NOREFLECT);
        undef $teamName;
      }
      else {
        &pause;
        $chat->chat_send ("$beginningHTML $_ got: $validAnswersThisRound{$_} (+$scoresThisRound{$_} | total $allPlayers{$_})", NOREFLECT);
      }
    }
    &pause;

    ### find the winner -- this is probably the worst implementation but w/e ###
    foreach (sort { $scoresThisRound{$b} <=> $scoresThisRound{$a} } keys %scoresThisRound) {
      $winner = $_;
      last;
    }

    if ($winner ne "") {
      $allPlayers{$winner} += $bonus;
      &pause;
      $chat->chat_send ("$beginningHTML Well done $winner, you get the round bonus of $bonus points. Your score is now $allPlayers{$winner}.", NOREFLECT);
    }
    undef $winner;


    ######################################
    ### Post Question Messages Go Here ###
    ######################################

    $messageNumber = int(rand 10);

    if ($messageNumber == 0) {
      &pause;
      &topTen;
      &pause;
    }
   
    if ($messageNumber == 1) {
     &pause;
     $chat->chat_send ("$beginningHTML The scores had to be reset because of technical difficulties. ", NOREFLECT);
     &pause;
    }
   
    if ($messageNumber == 2) {
      &pause;
      $chat->chat_send ("$beginningHTML To suggest a word to be added to the dictionary, or anything else, type !suggest MESSAGE", NOREFLECT);
      &pause;
    }
   
    if ($messageNumber == 3) {
      &pause;
      $chat->chat_send ("$beginningHTML Please do not cheat (if you are clever enough to figure out a way to). Cheaters will be banned!", NOREFLECT);
      &pause;
    }
   
    if ($messageNumber == 4) {
      &pause;
      $chat->chat_send ("$beginningHTML Please resolve all issues with the arbiters. ", NOREFLECT);
      &pause;
    }
   
    if ($messageNumber == 5) {
      &pause;
      $chat->chat_send("$beginningHTML $commands", NOREFLECT);
    }
   
    if ($messageNumber == 6) {
      &pause;
      $chat->chat_send("$beginningHTML You can guess UP TO 3 words per line. Hopefully. If I'm working right.", NOREFLECT);
      &pause;
    }
   
    if ($messageNumber == 7) {
      &pause;
      $chat->chat_send("$beginningHTML There was a problem with the teams. Please rejoin the team you were previously on. The password should be the same..", NOREFLECT);
      &pause;
    }
   
    if ($messageNumber == 8) {
      &pause;
      &topTenTeams;
      &pause;
    }
   
    if ($messageNumber == 9) {
      &pause;
      $chat->chat_send("$beginningHTML First Place = $numberOne", NOREFLECT);
      &pause;
    }
   
    $updateInfoCounter++;
    if ($updateInfoCounter == 2) { #store scores every 2 rounds
      &updateScores;
      $updateInfoCounter = 0;
    }
   }
}


#if someone says something during a question, push it on their stack
sub push {
  my($oscar, $from, $chat, $message) = @_;
  my($teamName, $teamPassword, $teamFound);
  $oscar->do_one_loop();
  $message =~ s/<(.|\n)+?>//g;   #remove HTML junk
  $from =~ s/ //g;       #remove whitespace from name
  ##########################################################
  $person_banned = 0;
  foreach (keys %banned) {
    if($from =~ /$_/i) {
      if ($banned{$_} == 1) {
        $person_banned = 1;
        last;
      }
    }
  }
   
  if ($person_banned != 1) { #ignore banned people
    ### !rankme ###
    if(lc $message eq "!rankme") {
      &Sort;
      $screename = "";
      foreach (keys %sortedScores) {
        if (lc $_ eq lc $from) {
          $screename = $_;
          last;
        }
      }
     
      $currentRank = $sortedScores{$screename};
      foreach (keys %sortedScores) {
        if ($sortedScores{$_} == ($currentRank-1)) {
          $ahead = $_;
          last;
        }
      }
      foreach (keys %sortedScores) {
        if ($sortedScores{$_} == ($currentRank+1)) {
          $behind = $_;
          last;
        }
      }
   
      $difference = $allPlayers{$ahead} - $allPlayers{$screename};
      $sum = $allPlayers{$screename} - $allPlayers{$behind};
      $oscar->send_im($from, "$beginningHTML $from: You are ranked $currentRank with a score of $allPlayers{$screename}. You need $difference points to catch up to $ahead, who has $allPlayers{$ahead} points. You are $sum points ahead of $behind, who has $allPlayers{$behind} points");
    }
   
    ### !rank SCREENAME ###
    if(lc $message =~ /(!rank) (.*)/i) {
      &Sort;
      $screename = "";
      foreach (keys %sortedScores) {
        if (lc $_ eq lc $2) {
          $screename = $_;
          last;
        }
      }
      $oscar->send_im($from, "$beginningHTML $from: $2 is ranked $sortedScores{$screename} with a score of $allPlayers{$screename}");
    }
   
    ### !top10  ###
    if(lc $message eq "!top10") {
      &topTen;
    }   
   
                     
    ### !repeat ###
    if(lc $message eq "!repeat") {
      if ($questionCategory == 1 || $questionCategory == 6) {
        $chat->chat_send ("$beginningHTML List words containing the following letters: @char", NOREFLECT);
      }
      elsif($questionCategory == 2) {
        $chat->chat_send ("$beginningHTML Rearrange any number of the letters of the following to form a real word: $questionMessage", NOREFLECT);
      }
      elsif($questionCategory == 3) {
        $chat->chat_send ("$beginningHTML List words that start with '$char[0]' and end with '$char[1]'", NOREFLECT);
      }
      elsif($questionCategory == 4) {
        $chat->chat_send ("$beginningHTML List words that have the following sequence: $char[0]$char[1]$char[2]$char[3]$char[4]" , NOREFLECT);
      }
      elsif($questionCategory == 5) {
        $chat->chat_send ("$beginningHTML List any $wordLength letter words that have the letter '$char'", NOREFLECT);
      }
    }
   
    ### !suggest MESSAGE ###
    if(lc $message =~ /(!suggest) (.*)/i) {
      $myfile = "suggestions.txt";
      open (MYFILE, ">>$myfile");
      print MYFILE "$from: $2\n";
      close (MYFILE);
      $oscar->send_im($from, "$beginningHTML $from: Thank you for your suggestion: $2");
    }


### !banlist ###
    if(lc $message eq "!banlist") {
       if ($arbiter{lc $from} == 1) {
    $banlistFile="./banned.txt";
    open(BANLIST, $banlistFile);
    $banlist= <BANLIST>;
    $banlists =read(BANLIST, $buffer, 256);
    $oscar->send_im($from, "$beginningHTML Banned are:  $banlist $buffer" );
    close (BANLIST);
    }
   else{
   $oscar->send_im($from, "$beginningHTML You can not use this command because you are not an arbiter." );
       }
      }
 
### !signoff  ###
   if(lc $message eq "!signoff") {
       if ($arbiter{lc $sender} == 1) {
    $IMed = 1;
   $oscar->signoff;
        }
       }
                   
 
   
### trial arbiter !ban SN ###
if(lc $message =~ /(!ban) (.*)/i) {
 if (lc $from eq "megamatrixman2" || lc $from eq lc "ichrist7" || lc $from eq lc "drummerdude2368"|| lc $from eq lc "justinsova121") {

      $myfile = "./trialarbiterlog.txt";
      open (MYFILE, ">>$myfile");
      print MYFILE "$from: $2 was banned by $from\n";
      close (MYFILE);
      $chat->chat_send("$beginningHTML Sorry $2, but you are now banned." , NOREFLECT);
    }
     }
 ### trial arbiter !unban SN ###
 if(lc $message =~ /(!unban) (.*)/i) {
 if (lc $from eq "megamatrixman2"|| lc $from eq lc "ichrist7" || lc $from eq lc "drummerdude2368"|| lc $from eq lc "justinsova121") {
 $chat->chat_send("$beginningHTML $2 has been unbanned." , NOREFLECT);
 }
  }
 ### !triallog ###
 if(lc $message eq "!triallog") {
      if (lc $from eq "calverthalldrum") {
    $alogFile="./trialarbiterlog.txt";
   
    open(ALOG, $alogFile);
    $alog= <ALOG>;
    $alogs =read(ALOG, $buffer, 1088888);
    $oscar->send_im($from, "$beginningHTML Here is who the trial arbiters banned: $alog $buffer." );
    close (ALOG);
    }
   else{
   $oscar->send_im($from, "$beginningHTML You can not use this command because you are not an arbiter." );
       }
      }

    ### !banrequest SN ###
if(lc $message =~ /(!banrequest) (.*)/i) {
      $myfile = "./banrequest.txt";
      open (MYFILE, ">>$myfile");
      print MYFILE "$2: ban request by $from\n";
      close (MYFILE);
      $oscar->send_im($from, "$beginningHTML Your request to ban $2 has been sent." );
    }
     

### !requests ###
 if(lc $message eq "!requests") {
      if (lc $from eq "calverthalldrum") {
    $dlogFile="./banrequest.txt";
   
    open(DLOG, $dlogFile);
    $dlog= <DLOG>;
    $dlogs =read(DLOG, $buffer, 1088888);
    $oscar->send_im($from, "$beginningHTML Here is who have been requested to be banned: $dlog $buffer." );
    close (DLOG);
    }
   else{
   $oscar->send_im($from, "$beginningHTML You can not use this command because you are not an arbiter." );
       }
      }

    ### !commands ###
    if(lc $message eq "!commands") {
      $chat->chat_send("$beginningHTML $commands", NOREFLECT);
    }

### !arbiter SN ###
   if(lc $message =~ /(!arbiter) (.*)/i) {
 if (lc $from eq "calverthalldrum") {
      $myfile = "./arbiters.txt";
      open (MYFILE, ">>$myfile");
      print MYFILE "$2\n" if $arbiter{$2} == 0;
      close (MYFILE);
      $chat->chat_send("$beginningHTML $2 is now an arbiter." , NOREFLECT);
    }
 }
### Load Arbiters ###
$arbiterFile = "./arbiters.txt";
    open ARBITER, $arbiterFile or die "Cannot open $arbiter for read :$!";;
 
  while (<ARBITER>) {
    if($_ ne "") {
      chomp($arbiterPlayer = $_);
      $arbiter{$arbiterPlayer} = 1;
      undef $arbiterPlayer;
    }
  }
  close ARBITER;

### !remove SN ###
if(lc $message =~ /(!remove) (.*)/i) {
  if(lc $from eq "calverthalldrum") {

       $person_arbiter = 0;
        foreach (keys %arbiter) {
             if($2 =~ /$_/i) {
               if ($arbiter{$_} == 1) {
                 $arbiterPlayer = $_;
                 $person_arbiter = 1;
                 last;
               }
             }
        }
    if ($person_arbiter) {
          $arbiter{$arbiterPlayer}==0;
          $chat->chat_send ("$beginningHTML $2 has been removed." , NOREFLECT);
          &pause1;
        }
        else {
          $chat->chat_send ("$beginningHTML $2 is currently not an arbiter." , NOREFLECT);
          &pause1;
        }
        undef $arbiterPlayer; undef $person_arbiter;
      } 
    }
### Load Arbiters ###
$arbiterFile = "./arbiters.txt";
    open ARBITER, $arbiterFile or die "Cannot open $arbiter for read :$!";;
 
  while (<ARBITER>) {
    if($_ ne "") {
      chomp($arbiterPlayer = $_);
      $arbiter{$arbiterPlayer} = 1;
      undef $arbiterPlayer;
    }
  }
  close ARBITER;
   
    ### !ban SN ###
    if(lc $message =~ /(!ban) (.*)/i) {
      if ($arbiter{lc $from} == 1) {
        #$chat->chat_send("someone said !ban ", NOREFLECT);
        #can't ban arbiters
        $found = 0;
        #$chat->chat_send("$from wants to ban $2", NOREFLECT);
        if($arbiter{$2} != 1) {
          if ($banned{lc $2} == 1) {
            $chat->chat_send ("$beginningHTML No need to go overboard, $2 is already banned." , NOREFLECT);
            &pause1;
          }
          else {
            $banned{lc $2} = 1;
            $chat->chat_send ("$beginningHTML Sorry $2, but you are now banned." , NOREFLECT);
            &pause1;
          }
          undef $found;
        }
      } 
    }
   
### !ban me ###
if(lc $message eq "!ban me") {
   if ($arbiter{lc $from} == 1) {
            $banned{lc $from} = 1;
            $chat->chat_send ("$beginningHTML Sorry $from, but you are now banned." , NOREFLECT);
            &pause1;
          }
      }
   
### !unban SN ###
    if(lc $message =~ /(!unban) (.*)/i) {
       if ($arbiter{lc $from} == 1) {
       $person_banned = 0;
        foreach (keys %banned) {
             if($2 =~ /$_/i) {
               if ($banned{$_} == 1) {
                 $bannedPlayer = $_;
                 $person_banned = 1;
                 last;
               }
             }
        }
        if ($person_banned) {
          $banned{$bannedPlayer} = 0;
          $chat->chat_send ("$beginningHTML $2 has been unbanned." , NOREFLECT);
          &pause1;
        }
        else {
          $chat->chat_send ("$beginningHTML $2 is currently not banned. But whatever floats your boat." , NOREFLECT);
          &pause1;
        }
        undef $bannedPlayer; undef $person_banned;
      } 
    }
   
   
    ### !arbiters ###
    if(lc $message eq "!arbiters") {
    $arbiterFile="./arbiters.txt";
   
    open(ARBITER, $arbiterFile);
    $arbiter= <ARBITER>;
    $arbiters =read(ARBITER, $buffer, 1088888);
    $chat->chat_send("$beginningHTML The arbiters are: $arbiter $buffer." );
    close (ARBITER);
    }
 
   
    ### !invite SN ###
 if(lc $message =~ /(!invite) (.*)/i) {
 if ($arbiter{lc $from} == 1) {
 $chat->invite($2, "Come and play");
 $oscar->send_im($from, "$beginningHTML $2 has been invited.");
  }
else{
$oscar->send_im($from, "$beginningHTML Only arbiters may use this command.");
}
}

 
   
    ### !create TEAMNAME PASSWORD ###
    if(lc $message =~ /(!create) (.*) (.*)/i) {
      $nameToSearch = $from;
      &find_match_in_team_players;

      chomp($teamPassword = $3);
      $teamFound = 0;
     
      foreach (keys %team_scores) {
        if (/$2/i) {
          $teamFound = 1;
          last;
        }
      }
     
      if($teamFound) {
        $oscar->send_im($from, "$beginningHTML Sorry, team $2 already exists!");
      }
      else {
        $team_scores{$2} = 0;
        $team_password{$2} = $teamPassword;
        delete $team_players{$nameToSearch};
        $team_players{$nameToSearch} = $2;
        $oscar->send_im($from, "$beginningHTML Team \"$2\" has been successfully created with password \"$teamPassword\"");
      }
    }
   
   
    ### !join TEAMNAME PASSWORD ###
    if(lc $message =~ /(!join) (.*) (.*)/i) {
      $nameToSearch = $from;
      &find_match_in_team_players;
     
      $teamFound = 0;
         
      foreach (keys %team_scores) {
        if (/$2/i) {
          $theTeamName = $_;
          $teamFound = 1;
          last;
        }
      }
      if($teamFound) {
        if($3 eq $team_password{$theTeamName}) {
          delete $team_players{$nameToSearch};
          $team_players{$nameToSearch} = $2;
          $oscar->send_im($from, "$beginningHTML You have successfully joined team $2");
        }
        else {
          $oscar->send_im($from, "$beginningHTML Password for team $2 is incorrect.");
        }       
      }
      else {
        $oscar->send_im($from, "$beginningHTML Team $2 was not found");
      }
    }
   
   
   
    ### !team TEAMNAME ###
    if(lc $message =~ /(!team) (.*)/i) {
      undef $members; undef $currentRank; undef $teamName;
                   
      foreach (keys %team_players) {
        if (lc $team_players{$_} eq lc $2) {
          $members .= "$_ ";
        }
      }
      if ($members ne "") {
        &SortTeams;
           foreach (keys %sortedTeamScores) {
             if (lc $_ eq lc $2) {
              $teamName = $_;
               last;
             }
           }
              
           $currentRank = $sortedTeamScores{$teamName};
           foreach (keys %sortedTeamScores) {
             if ($sortedTeamScores{$_} == ($currentRank-1)) {
               $ahead = $_;
               last;
             }
           }
           $difference = $team_scores{$ahead} - $team_scores{$teamName};
           if ($currentRank != 1) {
             $chat->chat_send("$beginningHTML Team $teamName is ranked $currentRank with a score of $team_scores{$teamName}, and is $difference points behind team $ahead. The members are: $members");
        }
        else {
             $chat->chat_send("$beginningHTML Team $teamName is ranked $currentRank with a score of $team_scores{$teamName}. The members are: $members");         
        }
      }
    }         
     #  if ($members ne "") {
     #    $chat->chat_send ("$beginningHTML Team $2: $output" , NOREFLECT);
     #  }
   
   
   
    ### !top10teams ###
    if(lc $message eq "!top10teams") {
      &topTenTeams;
    }
   
 
    $message =~ s/\W/ /g; #get rid of anything thats not a character
    $lineLimitCounter = 0;
   
    if($questioning) {
      #$chat->chat_send ("pushing a message", NOREFLECT);
      @words = split /\s+/,$message;
      foreach $guess (@words) {
        $repeatedWord = 0;
        for ($ii=0; $ii < ($#answersThisRound+1); $ii++) {
          if(lc $guess eq $answersThisRound[$ii]) {
            $repeatedWord = 1;
            last;
          }
        }
        if(!$repeatedWord) {
          if ($lineLimitCounter < 3) {
            push(@answersThisRound, lc $guess);
            push(@$from, lc $guess);
            $lineLimitCounter++;
          }
        }
      }
   
      $last = 0;
      foreach $player (@playersThisRound) {
        if ($player eq $from) {   #to avoid duplicates
          $last = 1;
          last;
        }
      }
      if (!$last) {
        push(@playersThisRound, $from);   #add to the players this round
      }
    }
  }
}


#ask a question
sub ask_question {
  my $questions;
  my $questionNumber;
 
  &pause;&pause;
 
  undef $questionCategory;
  $questionCategory = int(rand 6) + 1;
 
  if ($questionCategory == 1) {
    $questions="./questions.txt";
    $questionNumber = int(rand 240) + 1;
  }
  elsif ($questionCategory == 2) {
    $questions= "./anagrams.txt";
    $questionNumber = int(rand 200) + 1;
  }
  elsif ($questionCategory == 3) {
    $questions="./btoa.txt";
    $questionNumber = int(rand 200) + 1;
  }
  elsif ($questionCategory == 4) {
    $questions="./group.txt";
    $questionNumber = int(rand 200) + 1;
  }
  elsif ($questionCategory == 5) {
    $questions="./wordlength.txt";
    $questionNumber = int(rand 78) + 1;
  }
  elsif ($questionCategory == 6) {
   undef $multiplier; undef @char;
    &generateRandomCharacter;
    $char[0] = $var;
    &generateRandomCharacter;
    $char[1] = $var;
    &generateRandomCharacter;
   $char[2] = $var;
  }
 
  if($questionCategory != 6) {
    open QUESTIONS, $questions or die "Cannot open $questions for read :$!";;
 
    undef @theQuestion;
    undef $questionMessage;
    undef @char;
 
    while (<QUESTIONS>) {
      if ($. == $questionNumber) {
        if($questionCategory == 1) {
         @theQuestion=split /\|/,$_;
         $multiplier = $theQuestion[0];
         @char = @theQuestion[1 ..$#theQuestion]; # @char should have the letters to be matched
         $. = 1;
         last;
        }
        elsif($questionCategory == 2) {
          @char = split //, $_;
          $multiplier = 2;
          $. = 1;
          last;
        }
        elsif($questionCategory == 3) {
          /(\w)(\w)/i;
          @char = ($1, $2);
          $multiplier = 2;
          $. = 1;
          last;
        }
        elsif($questionCategory == 4) {
          @char = split //, $_;
          $multiplier = 2;
          $. = 1;
          last;
        }
        elsif($questionCategory == 5) {
          @theQuestion=split / /,$_;
          $wordLength = $theQuestion[0];
          $char = $theQuestion[1];
          chomp($multiplier = $theQuestion[2]);
          $. = 1;
          last;
        }
      }
    }
    close (QUESTIONS);
  } 
  foreach $letter (@char) {
    $questionMessage .= " $letter";
  }
 
 
  $bonusGenerator = int(rand 35) + 1;
 
  if ($bonusGenerator == 1) {
    $bonus = 500;
  }
  elsif ($bonusGenerator == 2) {
    $bonus = 1000;
  }
  elsif ($bonusGenerator == 3) {
    $bonus = 1500;
  }
elsif ($bonusGenerator == 4) {
    $bonus = 15000;
  }
elsif ($bonusGenerator == 5) {
    $bonus = 100000;
  }
  else {
    $bonus = 50;
  }
 
  if ($bonus ne 50) {
    $chat->chat_send ("$beginningHTML This round has a bonus of $bonus points!", NOREFLECT);
    &pause1;
  }
 
 
  if ($questionCategory == 1) {
    &check_vowel_round;
    if (!$vowelRound) {
      $chat->chat_send ("QUESTION #$questionNumber($multiplier): List words containing the following letters: @char", NOREFLECT);
    }
    else {
      $chat->chat_send ("VOWEL ROUND #$questionNumber($multiplier): List words containing the following letters: @char", NOREFLECT);
    }
  }
  elsif($questionCategory == 2) {
    $chat->chat_send ("ANAGRAM #$questionNumber($multiplier): Rearrange any number of the letters of the following to form a real word: $questionMessage", NOREFLECT);
  }
  elsif($questionCategory == 3) {
    $chat->chat_send ("START\/END #$questionNumber($multiplier): List words that start with '$char[0]' and end with '$char[1]'", NOREFLECT);
  }
  elsif($questionCategory == 4) {
    $chat->chat_send ("GROUP #$questionNumber($multiplier): List words that have the following sequence: $char[0]$char[1]$char[2]$char[3]$char[4]" , NOREFLECT);
  }
  elsif($questionCategory == 5) {
     $chat->chat_send ("WORD LENGTH #$questionNumber($multiplier): List any $wordLength letter words that have the letter '$char'" , NOREFLECT);
  }
  elsif ($questionCategory == 6) {
    &check_vowel_round;
    if (!$vowelRound) {
      $chat->chat_send ("QUESTION ($multiplier): List words containing the following letters: @char", NOREFLECT);
    }
    else {
      $chat->chat_send ("VOWEL ROUND ($multiplier): List words containing the following letters: @char", NOREFLECT);
    } 
  }
}



sub check_vowel_round {
  foreach $character (@char) {
    if ($character eq "a" || $character eq "e" || $character eq "i" || $character eq "o" || $character eq "u" || $character eq "y" && $character ne "\n") {
      $vowelRound = 1;
    }
    else {
      $vowelRound = 0;
      last;
    }
  }
}


sub generateRandomCharacter {
  $index = int(rand 26);
   $var = "a";
   for($ii = 0; $ii < $index; $ii++) {
     $var++;
   }
   
   if ($var eq $char[0] || $var eq $char[1]) {
     &generateRandomCharacter;
   }
   
   if ($var eq "a" || $var eq "e" || $var eq "i" || $var eq "l" || $var eq "n" || $var eq "o" || $var eq "r" || $var eq "s" || $var eq "t" || $var eq "u") {
     $multiplier += 1;
   }
   elsif ($var eq "b" || $var eq "c" || $var eq "d" || $var eq "g" || $var eq "m" || $var eq "p") {
     $multiplier += 2;
   }
   elsif ($var eq "f" || $var eq "h" || $var eq "k" || $var eq "y") {
     $multiplier += 3;
   }
   elsif ($var eq "j" || $var eq "v" || $var eq "w") {
     $multiplier += 4;
   }
   else {
     $multiplier += 5;
   }
}





#check if a guess is valid and is a real word
sub check_output_string {
  @words = split /\s+/,$outputString;
  foreach $guess (@words) {
    if($guess ne "") {

      $numberMatched = 0;       
      @characters = split //,$guess;
      @duplicate = @char;
      $valid = 0;
     
      if($questionCategory == 1 || $questionCategory == 6) {
        foreach $character (@characters) {
          #$chat->chat_send ("checking to see if - $character - in word - $guess - matches a letter", NOREFLECT);
          for ($ii=0; $ii <= $#duplicate; $ii++) {
            chomp($temporary = $duplicate[$ii]);
            if (lc $character eq lc $temporary) {
              $numberMatched++;
              $duplicate[$ii] = "";
            }
          }
        }
        if ($numberMatched == ($#char+1)) {
          $valid = 1;
        }
        else {
          $valid = 0;
        }
      }
     
      elsif($questionCategory == 2) {
        $valid = 1;
        foreach $character (@characters) {
        #$chat->chat_send ("checking to see if - $character - in word - $guess - matches a letter", NOREFLECT);
          $matchedLetter = 0;
          for($ii = 0; $ii <= $#duplicate; $ii++) {
            if (lc $character eq $duplicate[$ii]) {
              $matchedLetter = 1;
              $duplicate[$ii] = "";
              last;
            }
          }
          if (!$matchedLetter) {
            $valid = 0;
            last;
          }
        }
      }
     
      elsif($questionCategory == 3) {
        #$chat->chat_send("check to see if $characters[0] is equal to $char[0] and $characters[$#characters] is equal to $char[1]", NOREFLECT);
        if (lc $characters[0] eq $char[0] & lc $characters[$#characters] eq $char[1]) {
          $valid = 1;
        }
        else {
          $valid = 0;
        }
      }

      elsif($questionCategory == 4) {
        for($ii=0; $ii < scalar(@characters)-1; $ii++) {
          if ($characters[$ii] eq $char[0]) {
            $theIndex = $ii;
            for($jj=1; $jj < scalar(@char)-1; $jj++) {
              $theIndex++;
              if ($characters[$theIndex] eq $char[$jj]) {
                $valid = 1;
              }
              else {
                $valid = 0;
                last;
              }
            }
            if ($valid == 1) {
              last;
            }
          }
        }
      }
     
      elsif($questionCategory == 5) {
        $valid = 0;
        if(scalar(@characters) == $wordLength) {
          for($jj = 0; $jj < scalar(@characters); $jj++) {
            if($characters[$jj] eq $char) {
              $valid = 1;
              last;
            }
          }
        }
      }
     
      if ($valid) { #if this is a valid word
        $stop = 0;
        undef $dictionary;
       
       
        if (-e "./words/new/$characters[0]$characters[1].txt") {
              $dictionary="./words/new/$characters[0]$characters[1].txt";
                      
               #$chat->chat_send ("looking in $dictionary", NOREFLECT);     
                    
               open DICTIONARY, $dictionary or die "Cannot open $dictionary for read :$!";;
               while (<DICTIONARY>) {   
                 @line = split //, $_;
                 @currentLine = split /\s+/,$_;
                 foreach $word (@currentLine) {
                   if (lc $word eq lc $guess) {
                     #$chat->chat_send ("Found word in dictionary", NOREFLECT);
                     push(@validString, $guess);
                     $stop = 1;
                     last;
                   } 
                 }
                 if ($stop) {
                   $. = 1;
                   last;   #no need to continue the search if we've already found the word
                 }
              }
          close(DICTIONARY);
        }
      }
    }
  }
}


sub Sort {
  $jj = 0;
  foreach (sort { $allPlayers{$b} <=> $allPlayers{$a} } keys %allPlayers) {
    $jj++;
    if ($jj == 1) {
      $numberOne = $_;
    }
    $sortedScores{$_}="$jj";
  }
}


sub SortTeams {
  $jj = 0;
  foreach (sort { $team_scores{$b} <=> $team_scores{$a} } keys %team_scores) {
    $jj++;
    $sortedTeamScores{$_}="$jj";
  }
}


sub topTen {
  &pause;
  $chat->chat_send ("$beginningHTML Top 10 scores so far:", NOREFLECT);
  &pause1;
  $topTenMessage = "";
  $index = 1;
  foreach (sort { $allPlayers{$b} <=> $allPlayers{$a} } keys %allPlayers) {
    if ($index <= 10) {
      $topTenMessage .= "($index) $_: $allPlayers{$_}  ";
      $index++;
    }
    else { last; }
  }
 
  $chat->chat_send ("$beginningHTML $topTenMessage", NOREFLECT);
  &pause;
}

sub topTenTeams {
  &pause;
  $chat->chat_send ("$beginningHTML Top 10 teams so far:", NOREFLECT);
  &pause1;
  $topTenMessage = "";
  $index = 1;
  foreach (sort { $team_scores{$b} <=> $team_scores{$a} } keys %team_scores) {
    if ($index <= 10) {
      $topTenMessage .= "($index) $_: $team_scores{$_}  ";
      $index++;
    }
    else { last; }
  }
 
  $chat->chat_send ("$beginningHTML $topTenMessage", NOREFLECT);
  &pause;
}

sub find_match_in_team_players { #this deals with people changing screename formatting
  foreach (keys %team_players) {
    if (/$nameToSearch/i) {
      $nameToSearch = $_;
      last;
    }
  }
}


sub updateScores {
  $myfile = "scores.txt";
  open (MYFILE, ">$myfile");
  foreach (keys %allPlayers) {
    $currentPlayer = $_;
    if($allPlayers{$currentPlayer} ne "") {
      while (($player,$team)=each %team_players) {
        if (lc $currentPlayer eq lc $player) {
          $currentTeam = $team;
          last;
        }
      }
      print MYFILE "$currentPlayer|$allPlayers{$currentPlayer}|$currentTeam\n";
      undef $currentTeam; undef $code; undef $name; undef $currentPlayer; undef $team; undef $player;
    }
  }
  close (MYFILE);
 
  $myfile = "banned.txt";
  open (MYFILE, ">$myfile");
  foreach (keys %banned) {
    if($banned{$_} ne "" && $banned{$_} != 0 && $banned{$_} ne "\n") {
      print MYFILE "$_\n";
    }
  }
  close (MYFILE);
 
  $myfile = "teams.txt";
  open (MYFILE, ">$myfile");
    foreach (keys %team_scores) {
      print MYFILE "$_|$team_scores{$_}|$team_password{$_}\n"; 
    }
  close (MYFILE);
}


sub chat_closed {
  print @_[3];
  &updateScores;
  &join_room;
  &set_chat;
  &execute;
}

$oscar = Net::OSCAR->new();
$oscar->set_callback_signon_done (\&join_room);
$oscar->set_callback_im_in(\&im_in);
$oscar->set_callback_chat_joined(\&set_chat);
$oscar->set_callback_chat_im_in (\&push);
$oscar->set_callback_chat_closed (\&chat_closed);

$oscar->signon($screenname, $password);

while(1) {
  $oscar->do_one_loop();
  # Do stuff
}
Back to top
Ajar
Newbie
Newbie


Joined: 21 Aug 2007
Posts: 2


PostPosted: Wed Sep 05, 2007 3:54 am    Post subject: Reply with quote

Hey!

Unfortunately I think this place is abandoned! A ghost town! I wrote a question about a script, not only did I not get an answer, the script and like 1/2 the others available for download vanished shortly after...

Go figure...

I'll mess with your bot for fun some... I wish I had some direction for you on that trivia bot... seems they exist but everyone into writing these bots has vanished altogether... their sites are gone, scripts for dl are gone...

Its sad when you go through the posts and there are literally thousands of posts of these guys working on these things!

Quick question... Do you have any idea how to send a message back to a connected chat room, not from an OSCAR event?

Example...

During the:

while(1) {
$oscar->do_one_loop();
# Do stuff
}

I check a text file for a change... if it changes, I'd like to message the chat room. I can't figure out how to accomplish this... I see you've worked with this code alot more than I have so far... Any suggestions?

It looks like you've put alot of work in the word game bot... Do you have a set of basic text data files to with it that will get it working so I can play around with it?

Best regards,

Ajar
Back to top
JTW
God Like
God Like


Joined: 07 Mar 2004
Posts: 579
Location: Maidstone
Reputation: 67.1
votes: 4

PostPosted: Thu Sep 06, 2007 1:18 pm    Post subject: Reply to all posters so far in this topic Reply with quote

Hey this place is indeed pretty much dead. I still come round every now and then so il try and lend a hand but i normaly do msn bots so im not sure how good my help will be


@ jman27
I recommend creating several subs i.e.
startround
- Open file
- Pick Random Line
- Close file
- On random line picked earlier split answer from question
- Store Answer for use when a message is recived
- Save question end time
- Send question to trivia room

In a sub you call fairly requally but not more than 1ce a second.
-Is save time for question over?
(yes) - Send message to chat room saying no one guessed correct answer.
- Delete saved answer
- Call startround();
(No) - Do nothing

When you recive a message
- Make sure person is in trivia room
- Is their message the answer?
(Yes) - Send message to room saying that $user has correct answer
- Award points or whatever you want to do
- Delete saved answer
- Call startround();

If you need any help just ask and i will do my best to help you. And Good Luck

@ Ajar
I will put some templates and stuff on my site http://www.jt-online.co.uk/botservices/ for you

I would advise you not to check the textfile during the while loop as this will cuase it to be opened read and shut many times a second ( therefore slowing your bot down) instead i recommend using mattaustins timer module it should be reasonably easy to setup and use. You may only want to check say every 5 seconds which would obviously speed up your bot. As for sending a message to the chat room I am not sure how this is done as I have never had or used an aim bot before. If you provide me with a link to your previous topic i will try my best to help you.

JT

_________________
"Help us, Help you" - BotDepot
Back to top
mat007
Almost An Agent
Almost An Agent


Joined: 12 Jan 2004
Posts: 1375

Reputation: 15.8Reputation: 15.8
votes: 2

PostPosted: Sun Sep 16, 2007 4:03 pm    Post subject: Reply with quote

Bots used to be the "thing", everybody wanted one. But people got bored of them, I think the only ones left now are bots ran by companies (like SmarterChild). I think in a few years we'll probably see the bot scene revitalised.

This place would be better as a wiki (i.e. start fresh, dump the forum.) MediaWiki actually has some limited forum functionality as well (via an addon/extension).

Ajar wrote:
Hey!

Unfortunately I think this place is abandoned! A ghost town! I wrote a question about a script, not only did I not get an answer, the script and like 1/2 the others available for download vanished shortly after...

Go figure...

I'll mess with your bot for fun some... I wish I had some direction for you on that trivia bot... seems they exist but everyone into writing these bots has vanished altogether... their sites are gone, scripts for dl are gone...

Its sad when you go through the posts and there are literally thousands of posts of these guys working on these things!

Quick question... Do you have any idea how to send a message back to a connected chat room, not from an OSCAR event?

Example...

During the:

while(1) {
$oscar->do_one_loop();
# Do stuff
}

I check a text file for a change... if it changes, I'd like to message the chat room. I can't figure out how to accomplish this... I see you've worked with this code alot more than I have so far... Any suggestions?

It looks like you've put alot of work in the word game bot... Do you have a set of basic text data files to with it that will get it working so I can play around with it?

Best regards,

Ajar
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Code Help All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group