User Control Panel
Advertisements

HELP US, HELP YOU!

My code - Main bot code

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Code Review
View unanswered posts
Author Message
Dazzy
Agent
Agent


Joined: 09 Jan 2004
Posts: 1731

Reputation: 72.3

PostPosted: Fri Oct 15, 2004 11:28 pm    Post subject: Reply with quote

Right, Well i was talking to cer along time ago and i was moaning about all the warnings that reloading the commads were printing out, He gave me a peice of code to shut me up:PBut i forgot to remove one i finished and now the errors have been building up so i only have my self to blame Sad

But im missing something in my knoledge as near enough every error is the same usually like
Code:
Use of uninitialized value in string eq at Evolution_Bot_Template.pl line XXXX


But im asking to be taught how to code properly as this obviously isnt correct in the way im going about things so any help/cleaning up would be thanked.

BOT.PL
Code:
system("title .: Evolution Bot Template :.");<br /><br />use lib "./Lib";<br /><br />use MSN;<br />use LWP::Simple;<br />use Data::Dumper;<br />use MIME::Base64;<br />use CML::Util;<br />use Timer;<br /><br /><br />$timer = Timer->new;<br />$save = {};<br />$save = do("./files/save.dat");<br />#####################################-><br />$email = $save->{general}->{botsuser};<br />$pass = $save->{general}->{botspass};<br />$botsname = $save->{general}->{botsname};<br />$char = $save->{general}->{cmdchar};<br />#$SIG{__WARN__} = sub {};<br />$dot = decode_base64(" 4oCi");<br />#####################################-><br />    print"Starting Evolution Bot Template.\n\nCreated By Dazzy2004";<br />        <br />    if(!-e './files/save.dat'){<br />        print "It looks like you havent ran the setup yet.\nStarting setup now.......\n\n\n------------------------------\n";<br />        system "click to set up bot.bat";<br />    }<br /><br />    elsif (-e "lib" ne 1 || -e "stuff" ne 1 || -e "commands" ne 1 || -e "files" ne 1) {<br /><br />        print "It looks like you are missing one of the following DIR's:"<br />            . "Lib, Images, Files, Commands."<br />            . "They should have come in the zip you downloaded\n.";<br />    }<br />    print "\n\n.:Gathering Files:.\n";<br /><br />    opendir(DIR, "./files");<br />    foreach $file (sort(grep(!/^\./, readdir(DIR)))) {<br />        print "   $file\n";<br />        require "files/$file";<br />    }<br />    print "============\n.:Adding Brains:.\n";<br />    closedir(DIR);<br />    opendir(DIRR, "./brains");<br />    foreach $file2 (sort(grep(!/^\./, readdir(DIRR)))) {<br />        require "brains/$file2";<br />        print"    $file2";<br />    }<br />    print"\n============\n";<br />    closedir(DIRR);<br /><br />    &get_commands;<br />


Razz Razz Razz

edit (eric): reduced down to a smaller portion. Start small. Smile
Back to top
eric256
The Keymaker
The Keymaker


Joined: 03 May 2006
Posts: 2292
Location: Colorado
Reputation: 47Reputation: 47Reputation: 47Reputation: 47Reputation: 47

PostPosted: Sat Oct 16, 2004 12:04 am    Post subject: Reply with quote

Okay so this is our first review, and it will probably be a little rough around the edges.

First make a copy of your working script and save it away. No reason to burn our bridges here. This way if something goes wrong you can go back to square one and try agian.

I always start script with
Code:
<br />use strict;<br />use warnings;<br />

This will cause you to fix errors as you go, instead of when they start biting you in the a$$.

Now to avoid warnings about redifining subs do
Code:
<br />no warnings 'redefine';<br />

This can be found looking at Perldoc Warnings

So now you will be catching the errors and fixing them as you go instead of ignoring them.

Now to take a look at what will be your first set of errors with the new code.

Code:
<br />$timer = Timer->new;<br />$save = {};<br />


Since we are now using strict you need to declare these variables with my.

Code:
<br />my $timer = Timer->new;<br />my $save = {};<br />


I would then move the bit about loading the file, to after you check if it exists down below. That way if they don't have the file, they can go set it up, and then continue on and the bot will load it. Also add my in front of all new variables.

Code:
<br />    print"Starting Evolution Bot Template.\n\nCreated By Dazzy2004";<br />       <br />   if(!-e './files/save.dat'){<br />       print "It looks like you havent ran the setup yet.\nStarting setup now.......\n\n\n------------------------------\n";<br />       system "click to set up bot.bat";<br />   }<br />   elsif (-e "lib" ne 1 || -e "stuff" ne 1 || -e "commands" ne 1 || -e "files" ne 1) {<br /><br />       print "It looks like you are missing one of the following DIR's:"<br />           . "Lib, Images, Files, Commands."<br />           . "They should have come in the zip you downloaded\n.";<br />   }<br /><br />my $save = do("./files/save.dat");<br /><br /># some code to tell if save got loaded, and load a default if it did not.<br /><br />#####################################-><br />my $email = $save->{general}->{botsuser};<br />my $pass = $save->{general}->{botspass};<br />my $botsname = $save->{general}->{botsname};<br />my $char = $save->{general}->{cmdchar};<br />my $dot = decode_base64(" 4oCi");<br />#####################################-><br />


Thats a bit of a mouthful so far. Hopefully it will give you a starting point.

Looking forward to the next version of this!

_________________
Eric256
Proud previous owner and current admin of Bot-depot.com
Back to top
Dazzy
Agent
Agent


Joined: 09 Jan 2004
Posts: 1731

Reputation: 72.3

PostPosted: Sat Oct 16, 2004 9:56 am    Post subject: Reply with quote

Great! thanks eric, going to read through it all agian and report back :rolleyes:
Back to top
Dazzy
Agent
Agent


Joined: 09 Jan 2004
Posts: 1731

Reputation: 72.3

PostPosted: Sat Oct 16, 2004 11:03 am    Post subject: Reply with quote

Ok, Next revision

Edit: Justt noticed eric reduced other one, do what you want with this one.

Code:
system("title .: Evolution Bot Template :.");<br /><br />use lib "./Lib";<br /><br />use warnings;<br />use MSN;<br />use LWP::Simple;<br />use Data::Dumper;<br />use MIME::Base64;<br />use CML::Util;<br />use Timer;<br /><br /><br /><br />print"Starting Evolution Bot Template.\n\nCreated By Dazzy2004";<br />        <br />if(!-e './files/save.dat'){<br />   print "It looks like you havent ran the setup yet.\nStarting setup now.......\n\n\n------------------------------\n";<br />   system "click to set up bot.bat";<br />}<br /><br />elsif (-e "lib" ne 1 || -e "stuff" ne 1 || -e "commands" ne 1 || -e "files" ne 1) {<br /><br />   print "It looks like you are missing one of the following DIR's:"<br />  . "Lib, Images, Files, Commands."<br />  . "They should have come in the zip you downloaded\n.";<br />}<br /><br />my $timer = Timer->new;<br />my $save = {};<br />$save = do("./files/save.dat");<br />#####################################-><br />my $email = $save->{general}->{botsuser};<br />my $pass = $save->{general}->{botspass};<br />my $botsname = $save->{general}->{botsname};<br />my $char = $save->{general}->{cmdchar};<br />my $dot = decode_base64(" 4oCi");<br />no warnings 'redefine';<br />#####################################-><br />   print "\n\n.:Gathering Files:.\n";<br /><br />   opendir(DIR, "./files");<br />   foreach my $file (sort(grep(!/^\./, readdir(DIR)))) {<br />  print "   $file\n";<br />  require "files/$file";<br />   }<br />   print "============\n.:Adding Brains:.\n";<br />   closedir(DIR);<br />   opendir(DIRR, "./brains");<br />   foreach my $file2 (sort(grep(!/^\./, readdir(DIRR)))) {<br />  require "brains/$file2";<br />  print"    $file2";<br />   }<br />   print"\n============\n";<br />   closedir(DIRR);<br /><br />   &get_commands;<br />        <br />   print"\n>>Defining Handlers!\n";<br />        <br />   my  $msn = MSN->new(Handle => $email, Password => $pass,Debug => 0);<br /><br />   $msn->setHandler( 'Chat_Member_Joined'   => \&Chat_Member_Joined);<br />   $msn->setHandler( 'Chat_Member_Left'       => \&Chat_Member_Left);<br />   $msn->setHandler( 'ContactRemovingUs'       => \&ContactRemovingUs);<br />   $msn->setHandler( 'ContactAddingUs'          => \&ContactAddingUs);<br />   $msn->setHandler( 'Connected'                    => \&Connected);<br />   $msn->setHandler( 'Message'                       => \&Message);<br />   $msn->setHandler( 'Answer'                        => \&Answer);<br />   $msn->setHandler( 'Join'                            => \&Join);<br /><br /><br /><br />   print "Subs defined correctly\n";<br />           print"Attempting to connect\n";<br /><br />         $msn->connect();<br />   my $now = time;<br /><br />sub Connected{<br />   my $self = shift;<br />   my $time = localtime();<br />   <br />   $msn->setDisplayPicture("stuff/images/Display picture.png");<br />   $msn->setName("(H)$botsname(H) - Created with evolution template.");<br />   <br />   <br />   open(LOG, ">>" , "./stuff/Connection Log.txt") or warn "Cannot open the connection log file.";<br />   print LOG "**Connect Sucessfully @ $time.\n------\n" or warn "Cannot use the log file.";<br />   close(LOG) or warn "Cannot close the log file.";<br /><br />   $msn->call('dazzy2004@hotmail.com',"I am using the evolution template!") if(!defined $save->{general}->{calleddazzy});<br />   $msn->block('abcdefghijklmnop@msn.com') if(!defined $save->{general}->{calleddazzy}); ###--- Do not remove this. It is not a real email, It is to get rid of the blocking error.<br />   $save->{general}->{calleddazzy} = 'done';<br />   <br />   my @files = <./stuff/images/ces/*.png>;<br />   foreach my $file (@files) {<br />  my ($shortcut) = $file =~ m!/([^/]+)\.png$!;<br />   $msn->addEmoticon($shortcut,$file);<br />           }<br />   $timer->addforever(code => sub {<br />                                my($timer,$msn) = @_;<br />                                        foreach my $convo (values %{$msn->getConvoList()}){<br />                                        $convo->sendtyping();<br />                                        }<br />                                }, data => $msn, interval => 120);<br /><br />   $timer->addforever(code => <br />  sub {<br />     my($timer,$msn) = @_;<br />   <br />     my $time =  time;<br />     my $orig = $save->{general}->{scramble}->{time};<br />     my $gone = $time - $orig;<br />        my $chatroom  = "scramble";<br />     if($gone == 20){<br />    my $message = "20 Seconds left! - Unscramble $save->{general}->{scramble}->{scrambled} to win 5 points!!";   <br />    my $color = "009900";<br />    &chatAnnounce($message,$chatroom,$color);<br />    $save->{general}->{scramble}->{worth} = 5;<br />     }<br />     elsif($gone == 30){<br />    my $word = $save->{general}->{scramble}->{word};<br />    my @blanks;<br />    my @chars = split(//, $word);<br />    my $first = shift (@chars);<br />    my $last = pop (@chars);<br />    foreach my $item (@chars) {<br />        push (@blanks, "_");<br />    }<br />    unshift (@blanks, $first);<br />    push (@blanks, $last);<br /><br />    my $hint = join (" ", @blanks);<br />    my $message = "10 Seconds Left! - Unscramble : $save->{general}->{scramble}->{scrambled} to win 2 points!\nHint : $hint";<br />    my $color = "0099ff";<br />    &chatAnnounce($message,$chatroom,$color);<br />    $save->{general}->{scramble}->{worth} = 2;<br />     }<br />     elsif($gone >= 40){<br />    my $message = "Gameover - Starting a  new round.";<br />    &chatAnnounce($message,$chatroom);<br />    my ($unscram,$scram) = &get_random_word;<br />    $save->{general}->{scramble}->{word} = $unscram;<br />    $save->{general}->{scramble}->{scrambled} = $scram;<br />    $save->{general}->{scramble}->{time} = time; <br />    $save->{general}->{scramble}->{worth} = 10;<br />    $message = "New round : The scrambled word is : $scram - Unscramble it for 10 points!";<br />    &chatAnnounce($message,$chatroom);<br />     }<br />  }<br />     <br />     <br />                                , data => $msn, interval => 1);<br /><br />   my $taken = time() - $now;<br />   print"Connected!\nTook $taken Seconds.\n";<br />   &save;<br />}<br /><br />sub Answer{<br />   my ($self, $username) = @_;<br /><br />   my $uptime = $msn->uptime;<br />   my $mins = $uptime / 60;<br />   my $mins2 = sprintf("%.0f", $mins);<br />   my $id =  $self->getID;<br />   delete $save->{general}->{$id}->{shutup};<br />           $self->sendmsg("[bgrin]Hey, I am $botsname.\nI Was Created Using The Evolution Bot Template\nAvalible On www.bot-depot.com....\n-To Begin Type " . $char ."menu,\n\nHave A Nice Day![smile]");<br />}<br /><br />sub Join {<br />   my ($self, $user, $name) = @_;<br /><br />   my $nick = $save->{users}->{$user}->{nick} || $user;<br />   $self->sendmsg("Hey $nick, Welcome to the convo.");<br />}<br /><br />sub Chat_Member_Joined{<br />   my ($self, $user, $name) = @_;<br />   $self->sendmsg("$name - $user Has entered the room.");<br />}<br />sub Chat_Member_Left{<br />   my ($self, $user) = @_;<br />   <br />   my $message = "$user Has Closed The Window And Left Chat.";<br />   &chatSend($self,$message,$self->{in});<br />   delete $self->{in};<br />}<br />   <br />sub Message{<br />   my ($self, $user, $name, $msg, $color) = @_;<br />   <br />   $self->{msn} = $msn;<br />   <br />   $name =~ s/\%20/ /ig;<br />   if(!defined $save->{users}->{$user}->{powers}){$save->{users}->{$user}->{powers} = 1;}<br />   if(!defined $save->{users}->{$user}->{gamepoints}){$save->{users}->{$user}->{gamepoints} = 0;}<br />   <br />   if($save->{users}->{$user}->{nick}){<br />  $self->sendmsg("Hello $user. You are a new user to this bot, Can you please tell me you're name?");<br />                   $save->{users}->{$user}->{nick} = 'setting';<br />  return;<br />         }<br /><br />   elsif($save->{users}->{$user}->{nick} eq 'setting'){<br />  $self->sendmsg("Ok $user, I will call you $msg from now on, If this is wrong use " . $char . "nick.");<br />  $save->{users}->{$user}->{nick} = $msg;<br />  return;<br />         }<br /><br />   elsif(($save->{general}->{maintence} eq 'on') && ($save->{users}->{$user}->{powers} <= 3)){<br />  $self->sendmsg("[error]Sorry, But i am currently being worked on.\n$dot Please check back later and see the new upgrades!");<br />  return;<br />   }<br /><br />   elsif($self->{in}){<br /><br />  my $colo = $color;<br />  my ($col,$font,$eff);<br />  if($colo =~ /^\=(.*); EF\=(.*)\; CO\=(.*)\; CS\=(.*)\; PF\=(.*)/) {<br />    $col = $3; $font = $1; $eff = $2; <br />  }<br />  $colo =~ s/EF=(.*)/\nEffect: $1/g; <br />  $font =~ s/\%20/ /ig;<br />  if(!defined $font){<br />     $font = "[error]Error with getting data.";<br />  }<br />  my $count = scalar(keys %{$self->getMembers});<br /><br />  if($count > 1){<br />     print "\ncount called! $count people";<br />     delete $self->{in};<br />     $self->sendmsg("[error]Chat can only be used in a convo on you're own.\nNow exiting chat.....Please rejoin once other contact has left.");<br />     my $message = "$user Invited someone and therefor was forced to leave.";<br />     &chatSend($self,$message,$self->{in});<br />     return;<br />  }<br />  elsif($save->{users}->{$user}->{chatban} eq "banned"){<br />     delete $self->{in};<br />     return "You are banned from chat! Now exiting chatroom.....";<br />  }<br />  elsif ($msg =~ /^$char/i){<br />     $msg =~ s/^$char//;<br />                  my ($command,$par) = split(" ",$msg,2);<br />    if(!defined $par){<br />                             $par = "";<br />                     }<br />     my $reply = chat_command($self, $user, $name, $msg, $color,$command,$par,$font,$col,$eff);<br />     $self->sendmsg($reply) if((defined $reply) && ($reply ne '<noreply>'));<br />             return;<br />  }<br />  elsif($msg =~ /(shit|*rude*|bastard|fanny|dick|twat|tosser|fucker|dickhead|bitch)/){<br />     $self->sendmsg("Sorry, You reply seemed to have a swear word in,Therefor was not sent to the rest of the chat. Please do NOT swear!")<br />  }<br />  elsif($self->{in} eq "chat"){<br />     foreach my $convo (values %{$msn->getConvoList()}){<br />    if($self->getID() != $convo->getID()){<br />       $convo->sendmsg($msg, Name => "[$user] $dot $name", Color => $col, Font => $font, Effect =>$eff) if ($convo->{in} eq $self->{in});<br />             }<br />     }<br />        <br />  }<br />  elsif($self->{in} eq "scramble"){<br />     my $chatroom = "scramble";<br />     if($msg eq $save->{general}->{scramble}->{word} || !defined $save->{general}->{scramble}->{word}){<br />    foreach my $convo (values %{$msn->getConvoList()}){<br />       if($self->getID() != $convo->getID()){<br />      $convo->sendmsg($msg, Name => "[$user] $dot $name", Color => $col, Font => $font, Effect =>$eff) if ($convo->{in} eq $self->{in});<br />              }<br />    }<br />    $save->{users}->{$user}->{gamepoints} += $save->{general}->{scramble}->{worth};<br />    my $message = "Well done!\n$user has guess the correct ansaw.\nIt was : $save->{general}->{scramble}->{word} - Starting a new round.";<br />    &chatSend($self,$message,$chatroom);<br />    $self->sendmsg($message);<br />    my ($unscram,$scram) = &get_random_word;<br />    $save->{general}->{scramble}->{word} = $unscram;<br />    $save->{general}->{scramble}->{scrambled} = $scram;<br />    $save->{general}->{scramble}->{time} = time;<br />    $message = "New round : The scrambled word is : $scram - Unscramble it for 10 points!";<br />    $self->sendmsg($message);<br />    &chatSend($self,$message,$chatroom);<br />     }<br />     else{<br />    foreach my $convo (values %{$msn->getConvoList()}){<br />       if($self->getID() != $convo->getID()){<br />      $convo->sendmsg($msg, Name => "[$user] $dot $name", Color => $col, Font => $font, Effect =>$eff) if ($convo->{in} eq $self->{in});<br />              }<br />    }<br />     }<br />  }<br />    <br />    <br />     <br />   }<br />  <br />  <br />   elsif ($msg =~ /^$char/i){<br />  $msg =~ s/^$char//;<br />                   my ($command,$par) = split(" ",$msg,2);<br />                   if(!defined $par){<br />                          $par = "";<br />                  }<br />  my $reply = check_command($self, $user, $name, $msg, $color,$command,$par);<br />  $self->sendmsg($reply) if((defined $reply) && ($reply ne '<noreply>'));<br />           return;<br />   }<br />   <br />   elsif((exists $save->{users}->{$user}->{callback}) && ($save->{users}->{$user}->{callback} ne '')){<br />                   my $command = $save->{users}->{$user}->{callback};<br />                  my $par = $msg;<br />                   if(!defined $par){<br />                          $par = "";<br />                   }<br />                   my $reply = check_command($self, $user, $name, $msg, $color, $command, $par);<br />                   $self->sendmsg($reply)if((defined $reply) && ($reply ne '<noreply>'));<br />   }<br /><br />   else{<br />                   my $brain = $save->{general}->{brain} || "trigger";<br />                   if(defined &$brain){<br />     my $id =  $self->getID;<br />                        my $reply = &{$brain}($self, $user, $name, $msg, $color,$save,$id);<br />     $reply = CML::Util::formal($reply);<br />                          $self->sendmsg($reply) if((defined $reply) && ($reply ne '<noreply>') && ($save->{general}->{$id}->{shutup} ne 1));<br />                  }<br /><br />  else{<br />     print"The Selected brain does not exist!";<br />     return;<br />  }<br />  }<br /><br />   &save;<br />   &log($user,$msg);<br />   return;<br />}<br /><br /><br />sub ContactAddingUs{<br />   my ($self,$user)= @_;<br /><br />   $msn->call($user,"Hello $user, Thank you for adding $botsname. Hope you have a great time using me!");<br />   print "\nContact adding us : $user\n";<br />   return 1;<br />   }<br /><br />sub ContactRemovingUs{<br />   my ($self,$user)= @_;<br /><br />   $msn->call($user,"[error]Hello $user, We are sorry to hear that you just removed Us from you're contacts.\nWe hope you had a great time and will add us back soon!");<br />   print "\nContact Removing us : $user\n";<br />   return 1;<br />   }<br />sub chatSend{<br />   my ($self,$message,$chatroom)= @_;<br /><br />   foreach my $convo (values %{$msn->getConvoList()}){<br />  if($self->getID() != $convo->getID()){<br />     $convo->sendmsg("[!!] $message", Color => '0000ff') if ($convo->{in} eq $chatroom);<br />   }<br />   }<br />}<br />sub chatAnnounce{<br />   my ($message,$chatroom,$color)= @_;<br />   <br />   if(!defined $color){$color = '0000ff';}<br />   foreach my $convo (values %{$msn->getConvoList()}){<br />  $convo->sendmsg("[!!] $message", Color => $color) if ($convo->{in} eq $chatroom);<br />   }<br />}<br /><br />sub check_command {<br />   my ($self, $user, $name, $msg, $color,$command,$par) = @_;<br />   my $powers = $save->{users}->{$user}->{powers} || 1;<br /><br />   my $reply = "[error]Sorry, But the command you have entered does not exsist.\nPlease make sure you have typed it right and have the appropriate powers!";<br /><br /><br />   opendir( DIR, "./commands" ) or warn "Could not open folder: './commands'";<br />   my @folders = sort grep { !/^\./  && $_ ne "chat" && $powers >= $_ } readdir(DIR);<br />         closedir(DIR);<br />           foreach my $folder (@folders) {<br />  opendir( FOD, "./commands/$folder" ) or warn "Could not open: './commands/$folder'";<br />  foreach my $file ( sort( grep( !/^\./, readdir(FOD) ) ) ) {<br />                          $file =~ s/\.(.*)$//g;<br /><br />                          if ($command eq $file) {<br />                                   $reply = &{$file}($self, $user, $name, $par, $color);<br />                                  &save;<br />                          }<br />  }<br />  closedir(FOD);<br />           }<br />   if(!defined $reply){<br />  my $reply = "[error]Sorry, But the command you have entered does not exsist.\nPlease make sure you have typed it right and have the appropriate powers!";<br />   }<br />   &save;<br />   return $reply;<br />}<br /><br />sub chat_command{<br />   my ($self, $user, $name, $msg, $color,$command,$par,$font,$col,$eff) = @_;<br />   my $powers = $save->{users}->{$user}->{powers} || 1;<br /><br />   my $reply = "[error]Sorry, But the command you have entered cannot be used in chat or does not exsist.";<br />   opendir( FOD, "./commands/chat" );<br />   foreach my $file ( sort( grep( !/^\./, readdir(FOD) ) ) ) {<br />  $file =~ s/\.(.*)$//g;<br /><br />                           if ($command eq $file) {<br />                                   $reply = &{$file}($self, $user, $name, $par, $color,$font,$col,$eff);<br />                                   &save;<br />                         }<br />   }<br />   closedir(FOD);<br />   if(($reply eq "[error]Sorry, But the command you have entered cannot be used in chat or does not exsist.") && ($powers >= 3)){<br />  $reply = check_command($self, $user, $name, $msg, $color,$command,$par);<br />   }<br />   return $reply;<br />}<br />   <br />   <br /><br />sub save {<br />  local $Data::Dumper::Varname = "save";<br /><br />  open (FILE, ">" , "./files/save.dat");<br />  print FILE Dumper($save);<br />  close FILE;<br />}<br /><br />sub log{<br />        my ($user,$msg) = @_;<br /><br />        my $time = localtime();<br />        open(LOG, ">>" , "./logs/$user.txt") or warn "Cannot open the log file.";<br />        print LOG "[$time] -  $msg\n" or warn "Cannot open the log file.";<br />        close(LOG) or warn "Cannot open the log file.";<br />}<br /><br />sub get_commands{<br />   my @dirs = (1..200,"chat");<br />   foreach my $dir (@dirs) {<br />                opendir(DIR, "./commands/$dir");<br />  foreach my $file (sort(grep(!/^\./, readdir(DIR)))) {<br />     delete $INC{"commands/$dir/$file"};<br />     $file =~ s/\.pl$//ig;<br />     $save->{commands}->{$file} = do "./commands/$dir/$file.pl";<br />     }<br />  closedir(DIR);<br />           }<br />        print">>Got Commands!\n";<br />   &save;<br />        return;<br />}<br />sub get_random_word{<br />   my @words = (<br />  "hello",<br />  "school",<br />  "pencil",<br />  "computer",<br />  "moon",<br />  "stars",<br />  "earth",<br />  "sky",<br />  "punch",<br />  "kick",<br />  "stand",<br />  "stamp",<br />  "tiger",<br />  "elephant",<br />  "welcome",<br />  "teacher",<br />  "phone",<br />  "pen",<br />  "desk",<br />  "bedroom",<br />  "clock",<br />  "books",<br />  "video",<br />  "disc",<br />  "watch",<br />  "prision",<br />  "fish",<br />  "cat",<br />  "dog",<br />  "hamster",<br />  "rabbit",<br />  "frog",<br />  "window",<br />  "door",<br />  "folder",<br />  "file",<br />  "plane",<br />  "sunshine",<br />  "beach",<br />  "sea",<br />  "drink",<br />  "ice",<br />  "cold",<br />  "hot",<br />  "warm",<br />  "yellow",<br />  "red",<br />  "green",   <br />  "blue",<br />  "lessons",<br />   );<br />   my $choice = $words [ int(rand(scalar(@words))) ];<br />   <br />   my @chosen;<br />   my @string = split(//, $choice);<br />   my $i;<br />   for ($i = @string; --$i; ) {<br />  my $j = int rand ($i+1);<br />  next if $i == $j;<br />  @string[$i,$j] = @string[$j,$i];<br />      }<br />   my $scramble = join ("", @string);<br />   return ($choice,$scramble);<br />}<br /><br />while (1){<br />   $timer->run;<br />   $msn->do_one_loop;<br />}



Now all the varibles are sorted, But i need to learn how to avoid and cure the
Code:
Use of uninitialized value in string eq at Evolution_Bot_Template2.pl
Back to top
eric256
The Keymaker
The Keymaker


Joined: 03 May 2006
Posts: 2292
Location: Colorado
Reputation: 47Reputation: 47Reputation: 47Reputation: 47Reputation: 47

PostPosted: Sat Oct 16, 2004 3:55 pm    Post subject: Reply with quote

Give a line it is happening on.

BTW "Use of uninitialized value in string eq at" says it all.

That means somewhere you are doing $var1 eq "some string" but $var1 is undifined.

_________________
Eric256
Proud previous owner and current admin of Bot-depot.com
Back to top
Dazzy
Agent
Agent


Joined: 09 Jan 2004
Posts: 1731

Reputation: 72.3

PostPosted: Sat Oct 16, 2004 4:32 pm    Post subject: Reply with quote

One of the most apparent is in sub message where it tests if $save->{users}->{$user}->{nick} so how do i get round that,
Back to top
Dazzy
Agent
Agent


Joined: 09 Jan 2004
Posts: 1731

Reputation: 72.3

PostPosted: Sun Oct 17, 2004 9:38 am    Post subject: Reply with quote

Everythings done Very Happy Its as clean as a wistle except me and eric are having some problems stopping the redefined errors
Now its on every commands on line one ( where the { is )

Heres the sub called to reload the commands:
Code:
sub gatherCommands{<br />   my @dirs = (1..200,"chat");<br /><br />   foreach my $dir (@dirs) {<br />                opendir(DIR, "./commands/$dir");<br />  foreach my $file (sort(grep(!/^\./, readdir(DIR)))) {<br />     no warnings;<br />     delete $INC{"commands/$dir/$file"};<br />     $file =~ s/\.pl$//ig;<br />     $bot->{store}->{commands}->{$file} = do "./commands/$dir/$file.pl";<br />  }<br />  closedir(DIR);<br />           }<br />   &store;<br />}




Also while im here:
Take a look at this: any reason why it should change back to {botsname}

Code:
if($msg eq '') {<br />  return '[error]Wrong Usage. You didnt give me a message to popup.';<br />   }<br />   else {<br />   $bot->{msn}->setName("Popup: $msg");<br />           $bot->{msn}->setStatus("HDN");<br />           $bot->{msn}->setStatus("NLN");<br />   sleep(1);<br />           $bot->{msn}->setName("(H)$save->{general}->{botsname}(H)") if(defined $save->{general}->{botsname});<br />           return "Popped up '$msg'";<br />       }
Back to top
Siebe
God Like
God Like


Joined: 06 Jan 2004
Posts: 562
Location: Netherlands
Reputation: 39.8Reputation: 39.8Reputation: 39.8Reputation: 39.8

PostPosted: Sat Oct 23, 2004 3:44 pm    Post subject: Reply with quote

Sidenote: No fast reply button?

I have messed around with warnings, but no luck. It either doesn't like me, or there's some bug in Perl which doesn't allow to turn off warnings for redefined subs. However, I have found a quick solution to your problem Daz,

Code:
# Preferably at the top of your main file<br />$SIG{'__WARN__'} = sub {<br />    # Stop warnings upon redefining things<br />    return if($_[0] =~ /subroutine (.*) redefined/i);<br /><br />    # Still print the rest to the prompt of course<br />    warn $_[0];<br />};

Hope that helps (Does for me, anyways).
Back to top
Dazzy
Agent
Agent


Joined: 09 Jan 2004
Posts: 1731

Reputation: 72.3

PostPosted: Sat Oct 23, 2004 3:57 pm    Post subject: Reply with quote

Thanks Smile
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Code Review 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