-
Notifications
You must be signed in to change notification settings - Fork 4
Working prototype #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
13487d7
0ed0442
9112498
45f6762
3767097
65cd6fb
78720bc
8cf74d6
1c4726f
a4db058
0a5e1e8
661a58a
95bf845
4584661
33cc86d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| 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()); | ||
|
|
||
| // 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(); | ||
| 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()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <?php | ||
| declare(strict_types=1); | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to enforce PHP7 strict mode?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea I think we talked about that, just forgot ;)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
| } | ||
| 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)); | ||
| } | ||
| } |
| 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); | ||
| } | ||
| } |
| 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); | ||
| } | ||
| } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 :)