Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
"php": "^7.0"
},
"require-dev": {
"phpunit/phpunit": "^5.1",
"hamcrest/hamcrest-php": "^1.2",
"phpunit/phpunit": "~5.1.0",
"hamcrest/hamcrest-php": "~1.2.0",
"phpunit/php-token-stream": "~1.4.8",
"scrutinizer/ocular": "~1.3",
"squizlabs/php_codesniffer": "~2.5"
},
Expand Down
16 changes: 8 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions run.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
declare(strict_types=1);

use PHPOxford\SpiresIrc\Irc\Connection;
use PHPOxford\SpiresIrc\Irc\Message;
use PHPOxford\SpiresIrc\Irc\User;
use PHPOxford\SpiresIrc\IrcClient;
use PHPOxford\SpiresIrc\Plugins\Greetings;
use PHPOxford\SpiresIrc\Plugins\PingPong;
use PHPOxford\SpiresIrc\Plugins\Time;
use PHPOxford\SpiresIrc\Plugins\Welcome;

require_once 'vendor/autoload.php';

error_reporting(E_ALL);

/* Allow the script to hang around waiting for connections. */
set_time_limit(0);

/* Turn on implicit output flushing so we see what we're getting as it comes in. */
ob_implicit_flush();

$client = new IrcClient(
new Connection(
'#phpoxford',
// '##martinsbottesting',
'irc.freenode.com'
),
new User(
'spires',
'spires',
'Spires ALPHA'
)
);

$client->connect();


// Ping Pong
$client->addPlugin(new PingPong());
Copy link
Member

Choose a reason for hiding this comment

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

Possibly not something for this PR but should our bot use some sort of autoloading pattern for plugins?

Copy link
Author

Choose a reason for hiding this comment

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

Don't have an idea on how that would work now, but it sounds like a thing to look into :)


// Welcome users
$client->addPlugin(new Welcome());

// (hi|hello|hey) spires
$client->addPlugin(new Greetings());

// !spires what time is it?
$client->addPlugin(new Time());


$client->run();
Empty file removed src/EMPTY
Empty file.
24 changes: 24 additions & 0 deletions src/Irc/Commands/Base.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);

namespace PHPOxford\SpiresIrc\Irc\Commands;

use PHPOxford\SpiresIrc\Irc\Message\Command as CommandInterface;

abstract class Base implements CommandInterface
{
/**
* @var string
*/
protected $command;

public function command() : string
{
return $this->command;
}

public function __toString() : string
{
return trim($this->command() . ' ' . $this->params());
}
}
35 changes: 35 additions & 0 deletions src/Irc/Commands/Command.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);

Copy link
Member

Choose a reason for hiding this comment

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

Do we want to enforce PHP7 strict mode? declare(strict_types=1);

Copy link
Author

Choose a reason for hiding this comment

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

Yea I think we talked about that, just forgot ;)

Copy link
Author

Choose a reason for hiding this comment

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

Strict mode is on! Now it's getting serious ;p

namespace PHPOxford\SpiresIrc\Irc\Commands;

use PHPOxford\SpiresIrc\Irc\Message\Command as CommandInterface;

class Command extends Base implements CommandInterface
{
/**
* @var string
*/
protected $command;

/**
* @var string
*/
protected $params;

public function __construct(string $command, string $params = null)
{
$this->command = $command;
$this->params = $params ?: '';
}

public static function fromParams(string $params) : self
{
// TODO: Implement fromParams() method.
}

public function params() : string
{
return $this->params;
}
}
55 changes: 55 additions & 0 deletions src/Irc/Commands/Join.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);

namespace PHPOxford\SpiresIrc\Irc\Commands;

use PHPOxford\SpiresIrc\Irc\Message\Command as CommandInterface;

class Join extends Base implements CommandInterface
{
/**
* @var string
*/
protected $command = 'JOIN';

/**
* @var string[]
*/
private $channels;

/**
* @var string[]
*/
private $keys;

public function __construct(array $channels, array $keys = null)
{
$this->channels = $channels;
$this->keys = $keys ?? [];
}

public static function fromParams(string $params) : self
{
$arguments = explode(' ', $params);

$channels = explode(',', $arguments[0]);
$keys = isset($arguments[1]) ? explode(',', $arguments[1]) : [];

return new static($channels, $keys);
}

public function channels() : array
{
return $this->channels;
}

public function keys() : array
{
return $this->keys;
}

public function params() : string
{
return trim(implode(',', $this->channels) . ' ' . implode(',', $this->keys));
}
}
55 changes: 55 additions & 0 deletions src/Irc/Commands/Ping.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);

namespace PHPOxford\SpiresIrc\Irc\Commands;

use PHPOxford\SpiresIrc\Irc\Message\Command as CommandInterface;

class Ping extends Base implements CommandInterface
{
/**
* @var string
*/
protected $command = 'PING';

/**
* @var string
*/
private $server1;

/**
* @var string
*/
private $server2;

public function __construct(string $server1, string $server2 = null)
{
$this->server1 = $server1;
$this->server2 = $server2 ?? '';
}

public static function fromParams(string $params) : self
{
$servers = explode(' ', $params);

$server1 = ltrim($servers[0], ':');
$server2 = ltrim(($servers[1] ?? ''), ':');

return new static($server1, $server2);
}

public function server1() : string
{
return $this->server1;
}

public function server2()
{
return $this->server2;
}

public function params() : string
{
return trim($this->server1 . ' ' . $this->server2);
}
}
55 changes: 55 additions & 0 deletions src/Irc/Commands/Pong.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);

namespace PHPOxford\SpiresIrc\Irc\Commands;

use PHPOxford\SpiresIrc\Irc\Message\Command as CommandInterface;

class Pong extends Base implements CommandInterface
{
/**
* @var string
*/
protected $command = 'PONG';

/**
* @var string
*/
private $server;

/**
* @var string
*/
private $server2;

public function __construct(string $server, string $server2 = null)
{
$this->server = $server;
$this->server2 = $server2 ?? '';
}

public static function fromParams(string $params) : self
{
$servers = explode(' ', $params);

$server = ltrim($servers[0], ':');
$server2 = ltrim(($servers[1] ?? ''), ':');

return new static($server, $server2);
}

public function server() : string
{
return $this->server;
}

public function server2()
{
return $this->server2;
}

public function params() : string
{
return trim($this->server . ' ' . $this->server2);
}
}
Loading