And here's the DOS message I get when trying to send an alert:
Quote:
Use of uninitialized value in string at commands/alert.pl line 7. Can't call method "set_name" on an undefined value at commands/alert.pl line 7. Press any key to continue . . .
I hope someone can help me with this, I believe the code was originally for the other bot template on this site so tried changing it a bit.
The 2nd question is:
How can I make an Owner for my bot if you know what I mean. The template comes with $admin and $adminonly but when I try $owner and $owneronly it works for anyone.
Here's my bot.pl:
Code:
<br />#ADMIN'S SCREENNAME (for admin-only commands):<br />$owner = 'vorx@vorx.co.uk';<br /><br />$admin = 'helder@alexispro.com';<br /><br /><br /><br />##############################<br />##############################<br />##############################<br />##############################<br /><br />#Use the local library.<br />use lib "./lib";<br /><br />#Use the module File-Basename so that the script can be called from anywhere.<br />use File::Basename;<br />chdir(dirname($0));<br /><br />#Seed the random number generator.<br />srand time;<br /><br />#Put the admin's screenname in a text file so we can get it easily later.<br />open (DATA, ">admin.txt");<br />print DATA "$admin";<br />close(DATA);<br /><br />open (DATA, ">owner.txt");<br />print DATA "$owner";<br />close(DATA);<br />
And when I want a command to be owner only, I add $owneronly = 1 to the command but it still lets anyone use the command.
Joined: 03 May 2006 Posts: 2292 Location: Colorado
Posted: Tue Dec 30, 2003 2:18 pm Post subject:
Adding $owneronly, only sets a variable called $owneronly to equal one. If you don't do anything else with that value later then it will have no effect on the execution.
As far as mangling that command to work with this msn and bot template, its very hard to tell since you have a combined bot. When you decide to combine two or more templates in that manner you should have a solid background and understanding first. Either way you are using a variable called $msn when you have no such variable in that command. To figure it out, find where the command is called at and see what variables are being sent to it. Then we can help you more from there. (hint: look in commands.pl or something similar) _________________ Eric256
Proud previous owner and current admin of Bot-depot.com
I see what you mean about the variable, and I've looked in command.pl but $msn isn't in the file at all. Here's my command.pl:
Code:
<br />################################<br /># WIRED BOTS<br />#<br /># commands($victim‚$msg);<br />#<br /># desc: This sub decides whether a message is a command or not.<br /># It first grabs $victim and $msg.<br /># Then it opens the commands dir, checks the file names and sees<br /># if there is a match. <br /># If it is a command, goto that command to recieve a reply.<br /># Otherwise, return with 'notcommand' and $command equal to 0.<br /># recv: $victim‚$msg<br /># sends: $command,$reply<br />################################<br /><br />sub commands {<br /><br /> #Get the victim and his message.<br /> $victim = shift;<br /> $msg = shift;<br /> $self = shift;<br /> <br /> #Set the default values.<br /> $reply = "";<br /> $command = 0;<br /><br /> #Check the message against the list of commands.<br /> opendir(DIR, "./commands");<br /> foreach $file (sort(grep(!/^\./, readdir(DIR)))) {<br /> $file =~ s/\.(.*)//g;<br /> if ($command == 0) {<br /> if ($msg =~ /^\:$file/i) {<br /> $command = 1;<br /> $reply = &{$file}($victim,$msg,$self);<br /> }<br /> }<br /> }<br /> closedir(DIR);<br /><br /> #If the reply hasn't been set from a command, it isn't a command.<br /> if ($reply eq "") {<br /> # $reply = "notcommand";<br /> }<br /><br /> #Give back a boolean and the reply.<br /> return $command,$reply;<br />}<br />1;<br />
I thought the alert command would work with $msn because it's in my bot.pl file but I don't know how to use it in the alert.pl command in my previous post.
There is no other references to $msn in the bot.pl file and I checked the other files such as on_im, log_im and command.pl and again there is no reference to $msn there.
I'm sorry if i'm not explaining this very well but I can't understand how bot.pl can use $msn if it's not declared elsewhere.
that is what is calling your actual alert command.
The alert sub needs to be in a file called alert.pl in the commands directory.
Code:
<br />sub alert {<br /> my ($victim,$msg,$self) = @_; # get the stuff passed by commands.pl<br /> <br /> open( FILE, "oldname.txt" );<br /> $oldname = <FILE>;<br /> close(FILE);<br /> <br /> # the $1 following here may not be set to anything you expect. try using $msg instead adn working with it<br /> $self->set_name("$1"); # changed $msn to $self, which should work<br /> $self->set_status("HDN");<br /> $self->set_status("NLN");<br /> $self->set_name("$oldname");<br /><br /> #send a confirmination messages <br /> return "Alert ($1) sent!";<br />}<br />1;<br />
This will NOT work but it is stepping in the right direction. You still need to use $msg to see what the person said to see what to change the name to. _________________ Eric256
Proud previous owner and current admin of Bot-depot.com
Joined: 03 May 2006 Posts: 2292 Location: Colorado
Posted: Tue Dec 30, 2003 3:37 pm Post subject:
Try changing the last line (the "return blah") line to
Code:
return "here is there message: $msg";
and see what it says when you say alert. That should give you the idea. _________________ Eric256
Proud previous owner and current admin of Bot-depot.com
I was thinking to make it show the message maybe something like this: [/CODE] $self->set_name("$msg"); [/CODE] But then I thought it'd show :alert hi? aswell because I typed that.
Joined: 03 May 2006 Posts: 2292 Location: Colorado
Posted: Tue Dec 30, 2003 3:54 pm Post subject:
The $1 i'm assumming you picked up from some where else. It actualy means the first thing matched in a regex.
So if you had
Code:
<br />sub alert {<br /> my ($victim,$msg,$self) = @_; # get the stuff passed by commands.pl<br /> <br /> open( FILE, "oldname.txt" );<br /> $oldname = <FILE>;<br /> close(FILE);<br /> <br /> if ($msg =~ /^:alert (.*)$/) <br /> { <br /> # $1 now contains what was in the location of (.*)<br /> $self->set_name("$1"); # changed $msn to $self, which should work<br /> $self->set_status("HDN");<br /> $self->set_status("NLN");<br /> $self->set_name("$oldname");<br /> #send a confirmination messages <br /> return "Alert ($1) sent!";<br /> }<br /> else<br /> {<br /> return "Alert Failed. ($msg) did not match";<br /> } <br /><br />}<br />1;<br />
the =~ means we want to do a regex match. The /^:alert (.*)$/ is the regex. Broken down, ^ means start at the begging. Then its going to match ":alert ". The parenthesis mean to put whatever you match inside them into $1 (for the first set, $2 for the second, etc). the . means any character and the * means any number of whatever the previous regex was. Finaly the $ means to match to the end fo the line.
So all to gether it is looking for something that starts with ":alert " and is followed by anything all the way to the end of the line.
Good Luck! _________________ Eric256
Proud previous owner and current admin of Bot-depot.com
Usually when the bot replies with a number, something is wrong (if you notice, the number is usually the number of symbols in a variable, either in your $msg or in the bot's $reply)
I think I know how to get your $msn variable into your command.
In the on_im.pl file, it gets a variable near the top called $self. Further down there's code like this:
Code:
my $isacommand = commands($victim,$msg)<br />if ($isacommand == 0) {
Where the sub is called, commands($victim,$msg), change that to commands($victim,$msg,$self)
And in commands.pl add this part:
Quote:
sub commands { my ($victim,$msg,$self) = (shift,shift,shift)
If there's already a line that gets $victim and $msg from the shift, just replace that line with the one above.
<br />sub on_im {<br /> my ($self, $victim, $name, $msg) = @_;<br /> <br /> #Make sure the victim's screenname contains no spaces and is lowercase.<br /> $victim = lc($victim);<br /> $victim =~ s/ //g;<br /><br /> #Filter all HTML out of the message.<br /> $msg =~ s/<(.|\n)+?>//g;<br /><br /> #Check the message against the list of commands.<br /> ($isacommand,$reply) = commands($victim,$msg,$self);<br /><br /> #If it's not a command...<br /> if ($isacommand != 1) {<br /><br /> #Put what you want your bot to normally do here.<br /> #Hint: It's better to put it in a sub, so you can easily edit it later.<br /> <br /> #Right now, it's set up to grab a thought from a database.<br /> #$reply = mess($victim,$msg);<br /><br /> }<br /><br /> #Log this IM.<br /> log_im($victim,$msg,$handle,$reply);<br /><br /> #Send the reply.<br /> $self->sendmsg("$reply") unless ($reply eq "");<br />}<br />1;<br />
I'm not sure about what you said because I think mine may be slightly different. Could you explain a bit more please?
I do get these on my DOS Window but the bot doesn't shut down or anything.
It prints this to the DOS Window after I do the :alert Message Command:
Quote:
Use of uninitialized value in concatenation (.) or string at extras/log_im.pl li ne 27. Use of uninitialized value in string eq at handlers/on_im.pl line 48.
Hope you can shed some light on the problem.
Here's lines 25 - 28 of my log_im.pl file:
Code:
<br /> #Write it to a log in the logs folder.<br /> open (DATA, ">>logs/$victim.txt");<br /> print DATA "<$victim> $msg\n<$screenname> $reply\n";<br /> close(DATA);<br />
And here is lines 44 - 49 of my on_im.pl file:
Code:
<br /> #Log this IM.<br /> log_im($victim,$msg,$handle,$reply);<br /><br /> #Send the reply.<br /> $self->sendmsg("$reply") unless ($reply eq "");<br />}<br />
Ah. Yeah, I remember I used to get those messages all the time. They're no big deal, though. They're like the messages that go "Variable $WHATEVER only used once. Possible typo in file.pl line 5", it's just a concern but not a real problem.
Anyway, let me know if you managed to get $msn all the way to your command file.