User Control Panel
Advertisements

HELP US, HELP YOU!

$1 not working!

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl
View unanswered posts
Author Message
m6246
Newbie
Newbie


Joined: 08 Jul 2005
Posts: 15

Reputation: 10.4

PostPosted: Mon Jul 11, 2005 7:13 pm    Post subject: $1 not working! Reply with quote

ok this might be a stupid question but i just cant get it to work..

sub Message
{
my( $self, $username, $name, $message, %style ) = @_;

if ($message =~ /^hi$/i ){
$message = "hello $1!";
$self->sendMessage( $message, %style );
}
}

everywhere on this forum i see $1 being used to print the nickname of the user that sent the message.. but it wont work for me. nor do $2....$n

so can someone explain what im doin wrong and what the $1 stands for or is referring to anyways?
Back to top
darkmonkey
The Merovingian
The Merovingian


Joined: 18 Apr 2004
Posts: 2557
Location: London, England
Reputation: 39.3Reputation: 39.3Reputation: 39.3Reputation: 39.3
votes: 7

PostPosted: Mon Jul 11, 2005 7:57 pm    Post subject: Reply with quote

$1 is a wildcard, and is taken from (.*), and other wildcards (google).

Your IF statement should include (.*):
Code:

if ($message =~ /^hi (.*)$/i ){
my $reply = "hello $1!";
$self->sendMessage($reply, %style );
}


It also sends $reply at the end instead of $message, which will reduce errors.

_________________
~ Josh
[ Need bot hosting on a dedicated server? PM me. ]
Back to top
Cheater
Senior Member
Senior Member


Joined: 10 Jun 2005
Posts: 236

Reputation: 15.8Reputation: 15.8

PostPosted: Mon Jul 11, 2005 8:15 pm    Post subject: Reply with quote

No, he wants to get the SN of the user. I know in net::oscar, you have to define a variable to store the name. Is your bot aim or msn. Because all DM's example will do is:

User: Hello Bot
Bot: hello Bot

Since Bot is in place of the wild card (.*). Check the documentation for the perl module you are using to connect to aim. If it is net::oscar and you need help, you can PM me or IM me. If it is MSN, I can't help you.
Back to top
darkmonkey
The Merovingian
The Merovingian


Joined: 18 Apr 2004
Posts: 2557
Location: London, England
Reputation: 39.3Reputation: 39.3Reputation: 39.3Reputation: 39.3
votes: 7

PostPosted: Mon Jul 11, 2005 8:25 pm    Post subject: Reply with quote

sending $name will be the screenname, and $username will be the email, in MSN.

$reply = "Hello $name"; # That's the screenname
$reply = "Hello $username"; # Email

_________________
~ Josh
[ Need bot hosting on a dedicated server? PM me. ]
Back to top
Cheater
Senior Member
Senior Member


Joined: 10 Jun 2005
Posts: 236

Reputation: 15.8Reputation: 15.8

PostPosted: Mon Jul 11, 2005 8:36 pm    Post subject: Reply with quote

Code:
sub im_in {
                my($oscar, $client, $msg, $is_away) = @_;
      $msg =~ s/<(.|\n)+?>//g;
      if ($msg =~ /^hi$/i ){
      $reply = "hello $client!";
      }
      $oscar->send_typing_status ($client,TYPINGSTATUS_STARTED);
      sleep(3);
      $oscar->send_im ($client,$reply);
      $oscar->send_typing_status ($client,TYPINGSTATUS_FINISHED);
}


In the code above, $client is the SN of the person. $msg is the message sent to the bot. You can ignore $is_away. The line after that simply removes html from the message so you don't get all the font tags sent to the bot. After that is your if statement. I just replaced $1 with $client. Next, the bot sends a typing status (the message at the bottom of the window that says he started typing). Then he sleeps. Then he sends the message. And finally, he clears the typing status. This code will only work if you have net::oscar and AIM. If you do have that, $oscar MUST be the variable assigned to the net::oscar session. You can change the varialbe names for the other stuff. Also, CPan has a nice documentation on Net::oscar
Back to top
m6246
Newbie
Newbie


Joined: 08 Jul 2005
Posts: 15

Reputation: 10.4

PostPosted: Mon Jul 11, 2005 8:36 pm    Post subject: Reply with quote

ok, but how do i get the username of the message that was sent then? *edit oh first im gonna read all the replies that have been posted in the meantime.. Wink *

ok first of all i want to create an MSN bot not AIM, secondly Im using the Quad mirror template from which im building the bot from scratch.

I tried the $username and $user before but they are empty variables.


Last edited by m6246 on Mon Jul 11, 2005 8:39 pm; edited 1 time in total
Back to top
Cheater
Senior Member
Senior Member


Joined: 10 Jun 2005
Posts: 236

Reputation: 15.8Reputation: 15.8

PostPosted: Mon Jul 11, 2005 8:38 pm    Post subject: Reply with quote

Code:
my($oscar, $client, $msg, $is_away) = @_;

$client can be changed to any variable. That variable holds the SN of the person who sent the message.
Back to top
eric256
The Keymaker
The Keymaker


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

PostPosted: Mon Jul 11, 2005 9:40 pm    Post subject: Reply with quote

Cheater wrote:
Code:
my($oscar, $client, $msg, $is_away) = @_;

$client can be changed to any variable. That variable holds the SN of the person who sent the message.


He said he is making an MSN bot so this doesn't help him. The code you are refering to is AIM code. However Darkmonkey appears to have already helped him.

_________________
Eric256
Proud previous owner and current admin of Bot-depot.com
Back to top
Cheater
Senior Member
Senior Member


Joined: 10 Jun 2005
Posts: 236

Reputation: 15.8Reputation: 15.8

PostPosted: Mon Jul 11, 2005 10:03 pm    Post subject: Reply with quote

If you look at his post, it was edited. It was different when I made my post. And the code DM posted would not return the Name of the person. It would return the word after hi.

User: Hi Bot
Bot: Hello Bot
Back to top
m6246
Newbie
Newbie


Joined: 08 Jul 2005
Posts: 15

Reputation: 10.4

PostPosted: Mon Jul 11, 2005 11:07 pm    Post subject: Reply with quote

yeah it works now guys, thanks for the help!
Back to top
eric256
The Keymaker
The Keymaker


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

PostPosted: Tue Jul 12, 2005 1:16 am    Post subject: Reply with quote

Cheater wrote:
If you look at his post, it was edited. It was different when I made my post. And the code DM posted would not return the Name of the person. It would return the word after hi.

User: Hi Bot
Bot: Hello Bot


Darkmonkeys 1st post did that, his second fixed the error.

_________________
Eric256
Proud previous owner and current admin of Bot-depot.com
Back to top
darkmonkey
The Merovingian
The Merovingian


Joined: 18 Apr 2004
Posts: 2557
Location: London, England
Reputation: 39.3Reputation: 39.3Reputation: 39.3Reputation: 39.3
votes: 7

PostPosted: Tue Jul 12, 2005 9:45 am    Post subject: Reply with quote

M6246: This line:
Code:
my( $self, $username, $name, $message, %style ) = @_;


Is passing all the variables you need, in the order they are being sent. If you changed $username to $user in that line, then $user would hold the email address of the user. That's the same with any of those variables, which can be changed to anything, as long as the order is the same.

_________________
~ Josh
[ Need bot hosting on a dedicated server? PM me. ]
Back to top
alienz
Almost An Agent
Almost An Agent


Joined: 22 Mar 2004
Posts: 1436
Location: Mars
Reputation: 55.7

PostPosted: Tue Jul 12, 2005 7:26 pm    Post subject: Reply with quote

darkmonkey wrote:
M6246: This line:
Code:
my( $self, $username, $name, $message, %style ) = @_;


Is passing all the variables you need, in the order they are being sent. If you changed $username to $user in that line, then $user would hold the email address of the user. That's the same with any of those variables, which can be changed to anything, as long as the order is the same.


It was staring at you in the face the entire time right in the code, pay attention. You never stopped to wonder what $username was for? LOL

_________________
Check out Botworld! A dev resource for things bot.
Downloads, articles, news, fourm and more.
http://botworld.marzopolis.com
Back to top
m6246
Newbie
Newbie


Joined: 08 Jul 2005
Posts: 15

Reputation: 10.4

PostPosted: Tue Jul 12, 2005 8:22 pm    Post subject: Reply with quote

well yeah I tried before, but then they seemed empty... but all of a sudden they work now Very Happy must have done somethin wrong
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl 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