Skip to content
This repository was archived by the owner on Jan 28, 2024. It is now read-only.

Add functionality to send message to channel after connecting #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions src/Philip/Philip.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,13 +389,39 @@ public function isAdmin($user)

/**
* Starts the IRC bot.
*
* @param string $msg Send message to specified channel
*/
public function run()
public function run($msg = '')
{
if ($this->connect()) {
$this->login();
$this->join();
$this->listen();
if(!empty($msg))
{
$this->msg($msg);
$this->listen(true);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this conditional can be simplified to something more like:

if (!empty($msg)) {
    $this->msg($msg)
}

$this->listen(true)

} else {
$this->listen(false);
}
}
}

/**
* Send message to channel
*
* @param string $msg Send message to specified channel
*/
private function msg($msg)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe consider naming this method something less generic than msg()?

{
foreach ($this->config['channels'] as $channel) {
if (is_array($channel)) {
foreach($channel as $chan => $pass) {
$this->send(Response::msg($chan, $msg));
}
} else {
$this->send(Response::msg($channel, $msg));
}
}
}

Expand Down Expand Up @@ -474,8 +500,10 @@ private function join()

/**
* Driver of the bot; listens for messages, responds to them accordingly.
*
* @param boolean $runOnce Run bot once after sucessfully sending message
*/
private function listen()
private function listen($runOnce = false)
{
do {
$data = fgets($this->socket, 512);
Expand All @@ -491,7 +519,12 @@ private function listen()

// Skip processing if the incoming message is from the bot
if ($request->getSendingUser() === $this->config['nick']) {
continue;
if($runOnce)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make this PSR-1 and PSR-2 compliant. Example: a space between the if and the (, opening braces on the same line for control structures, etc)

{
$this->askStop = true;
} else {
continue;
}
}

$event = new Event($request);
Expand Down