User Control Panel
Advertisements

HELP US, HELP YOU!

2 Questions

 
Post new topic   Reply to topic    Bot Depot Forum Index -> MSN Protocol
View unanswered posts
Author Message
Vorx
Senior Member
Senior Member


Joined: 21 Dec 2003
Posts: 152

Reputation: 32Reputation: 32Reputation: 32

PostPosted: Tue Dec 30, 2003 1:51 pm    Post subject: Reply with quote

Hi, i'm using the Wiredbots Template.

the problems are:

1: My alert command doesn't work.

Here's the code I use in a sub in the command folder:
Code:
<br />sub alert {<br />$adminonly = 1;<br />my $self = shift;<br />open (FILE, "oldname.txt");<br />$oldname = <FILE>;<br />close(FILE);<br />$msn->set_name("$1");<br />$msn->set_status("HDN");<br />$msn->set_status("NLN");<br />$msn->set_name("$oldname");<br />#send a confirmination messages<br />return;<br />}<br />1;<br />


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.

I hope someone can help.

Thanks,
Nick
Back to top
eric256
The Keymaker
The Keymaker


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

PostPosted: Tue Dec 30, 2003 2:18 pm    Post subject: Reply with quote

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
Back to top
Vorx
Senior Member
Senior Member


Joined: 21 Dec 2003
Posts: 152

Reputation: 32Reputation: 32Reputation: 32

PostPosted: Tue Dec 30, 2003 3:15 pm    Post subject: Reply with quote

Hi and thanks for the quick reply.

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.

Here's the bit with $msn in bot.pl
Code:
<br />#Create a new MSN module instance.<br />my $msn = MSN->new('',Handle => $handle, Password => $password, Debug => 1);<br /><br />$msn->set_handler(Connected => \&Connected) and print "Defined Connect\n";<br />$msn->set_handler(Message   => \&Message) and print "Defined Message\n";<br />$msn->set_handler(Answer    => \&Answer)and print "Defined Answer\n";<br />$msn->set_handler(Join      => \&Join) and print "Defined Join\n\n";<br /><br />$msn->connect();<br /><br />while (1) {<br />   $msn->do_one_loop();<br />}<br /><br />sub Connected {<br />   print "sub Connected called.\n\n";<br />   my $self = shift;<br />   $msn->set_status('NLN');<br />   print "\n\nCalling the Admin!\n\n";<br />   $msn->call($owner,"BOTRIX is online");<br />}<br />


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.

Thanks again,
Nick
Back to top
eric256
The Keymaker
The Keymaker


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

PostPosted: Tue Dec 30, 2003 3:22 pm    Post subject: Reply with quote

Code:
<br />my $msn = MSN->new<br />


that is what creates the $msn variable. And though criptic ...

Code:
<br />$reply = &{$file}($victim,$msg,$self);<br />


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
Back to top
Vorx
Senior Member
Senior Member


Joined: 21 Dec 2003
Posts: 152

Reputation: 32Reputation: 32Reputation: 32

PostPosted: Tue Dec 30, 2003 3:35 pm    Post subject: Reply with quote

Thanks again Eric.

I tried the code anyway and when I type :alert message it just does the bot signing in thing so it doesn't change the text.

I'm not sure I understand what you mean about the $msg bit.

Do you mean the bit the person types after :alert is the $msg bit?

So would I have to write the message into the $msg variable or something?

Thanks,
Nick
Back to top
eric256
The Keymaker
The Keymaker


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

PostPosted: Tue Dec 30, 2003 3:37 pm    Post subject: Reply with quote

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
Back to top
Vorx
Senior Member
Senior Member


Joined: 21 Dec 2003
Posts: 152

Reputation: 32Reputation: 32Reputation: 32

PostPosted: Tue Dec 30, 2003 3:43 pm    Post subject: Reply with quote

Hi again,

Yeah it writes into Msn:
Quote:
Bot Says:
here is there message: :alert hi?


Can you tell me what the $1 is for in the
Code:
<br /> $self->set_name("$1"); <br />


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.
Back to top
eric256
The Keymaker
The Keymaker


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

PostPosted: Tue Dec 30, 2003 3:54 pm    Post subject: Reply with quote

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
Back to top
Vorx
Senior Member
Senior Member


Joined: 21 Dec 2003
Posts: 152

Reputation: 32Reputation: 32Reputation: 32

PostPosted: Tue Dec 30, 2003 3:56 pm    Post subject: Reply with quote

Thanks a lot Eric I appreciate all of your help Very Happy

EDIT

Hi again Eric.

The alert works fine but for some reason my bot always replies with "18".

Do you have any idea why this could be?

Thanks,
Nick

P.S - I'm using the code you posted before this post.

EDIT

I fixed it, and if anyone else has the same problem I did this:

Code:
<br />return "Alert ($1) sent!";<br />

Changed to:
Code:
<br />return;<br />


Simple as that Very Happy
Back to top
Nate
God Like
God Like


Joined: 12 Nov 2003
Posts: 553

Reputation: 41.3Reputation: 41.3Reputation: 41.3Reputation: 41.3

PostPosted: Tue Dec 30, 2003 8:37 pm    Post subject: Reply with quote

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.
Back to top
Vorx
Senior Member
Senior Member


Joined: 21 Dec 2003
Posts: 152

Reputation: 32Reputation: 32Reputation: 32

PostPosted: Tue Dec 30, 2003 8:46 pm    Post subject: Reply with quote

This is my on_im.pl file:

Code:
<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?
Back to top
Nate
God Like
God Like


Joined: 12 Nov 2003
Posts: 553

Reputation: 41.3Reputation: 41.3Reputation: 41.3Reputation: 41.3

PostPosted: Tue Dec 30, 2003 8:49 pm    Post subject: Reply with quote

Ok, it looks like you don't have to change anything in your on_im.pl file.

Code:
($isacommand,$reply) = commands($victim,$msg,$self)


Make sure those three variables are recieved in commands.pl at the shift, as I mentioned above.
Back to top
Vorx
Senior Member
Senior Member


Joined: 21 Dec 2003
Posts: 152

Reputation: 32Reputation: 32Reputation: 32

PostPosted: Tue Dec 30, 2003 8:55 pm    Post subject: Reply with quote

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 />
Back to top
Nate
God Like
God Like


Joined: 12 Nov 2003
Posts: 553

Reputation: 41.3Reputation: 41.3Reputation: 41.3Reputation: 41.3

PostPosted: Tue Dec 30, 2003 9:04 pm    Post subject: Reply with quote

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.
Back to top
Vorx
Senior Member
Senior Member


Joined: 21 Dec 2003
Posts: 152

Reputation: 32Reputation: 32Reputation: 32

PostPosted: Tue Dec 30, 2003 9:07 pm    Post subject: Reply with quote

Hi Nate, I think it's ok now the Alert command because it doesn't print any numbers on the DOS window as it used to.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> MSN Protocol 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