when receiving a msg...?

Back to PHP-IRC Support

Page: 1  
From User Message Body
Juice
Post #107
Member
Date: 2:38 am, Feb 20 2006
Posts: 40


ok, when the bot receives a message, you had me use
Code
        if ($this->ircClass->getNick() == $line['to'])

in order for the bot to react.

Now, what do i do to make the bot check to see if the sender is actually in the same channel as the bot prior to the bot reacting to the msg?

Have a Great Day!

Juice
Administrator
http://ww4.GameSoda.net
Manick
Post #108 - Reply to (#107) by Juice
user avatar
Admin
Date: 3:49 am, Feb 20 2006
Posts: 223


Code
$this->ircClass->isOnline($line['fromNick'], $line['to'])


--Manick
PHP-IRC Developer
Juice
Post #109
Member
Date: 7:19 pm, Feb 20 2006
Posts: 40


I can't figure it out. I tried to replace the old line with the new one, I tried to put the second one as an if after the first one. I don't know. How do I use this second line? Do I use it with the first on or instead of it?

Have a Great Day!

Juice
Administrator
http://ww4.GameSoda.net
Manick
Post #110 - Reply to (#109) by Juice
user avatar
Admin
Date: 8:59 pm, Feb 20 2006
Posts: 223


Well, you can first do the first line, then the second one to see if they're on the channel:

Code
if ($this->ircClass->getNick() == $line['to'])
{
  return; //he's messaging me.  I only respond to channel
}
if (!$this->ircClass->isOnline($line['fromNick'], $line['to']))
{
  return; //he's not on the channel, but he's messaging the channel
}

Although this would work, I am very puzzled as to why you would need this. Most networks have channels created automatically with +n which makes it impossible for someone not on the channel to message the channel. The second if statement there would only be needed if this was not the case.

If the user gets past the first if-statement, then you can simply just test $line['to'] to see if it equals the channel that you want the trigger to be available for. For instance:

Code
if (irc::myStrToLower($line['to']) != "#my-chan")
{
  return; //I only respond to requests on #my-chan
}


--Manick
PHP-IRC Developer
Juice
Post #116 - Reply to (#110) by Manick
Member
Date: 12:23 pm, Feb 24 2006
Posts: 40


OK, I'm going to give this a try.

My channel does have the +n which required the user to be in the channel to send a message to the channel, however, the bot does not have this feature.

The bot will receive a message from anyone who sends a pm to it, whether they are in the same channel or not.

I want the bot to respond to private messages, but not if they come from someone who is not in the channel with the bot.

I have found that this line works for me:
Code
            if ($this->ircClass->isOnline($line['fromNick'], $chan))

I define $chan earlier in the code to be the channel the game is started in.

Whereas, the line you gae me:
Code
if (!$this->ircClass->isOnline($line['fromNick'], $line['to']))

was slightly wrong.

The $line['to'] is the bots nick when the message is being pm'd to the bot. Which means the person sending the message would have to be in a channel with the same name as the bot.

I thank you for your help, for without what you have given me, it would have taken me much, much longer to find what I needed. Thank you.

Have a Great Day!

Juice
Administrator
http://ww4.GameSoda.net
Manick
Post #120 - Reply to (#116) by Juice
user avatar
Admin
Date: 5:07 pm, Feb 24 2006
Posts: 223


Ahhhh okay. I understand what you were doing now. I mis-interpreted.

Glad you figured it out though! :-)

--Manick
PHP-IRC Developer
   

Back to PHP-IRC Support