Posted: Mon Sep 03, 2007 6:43 am Post subject: I really want help writing a trivia bot
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 = "*****";
#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)) {
}
}
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;
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." );
}
}
### !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;
#$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
}
### 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;
}
}
}
$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}");
}
### !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." );
}
}
$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." );
}
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." );
}
}
### !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;
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.");
}
}
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);
# }
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);
}
}
}
#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 "") {
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;
}
}
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);
}
}
}
}
}
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?
Posted: Thu Sep 06, 2007 1:18 pm Post subject: Reply to all posters so far in this topic
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
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
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?