Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace FishGUI;
- use Gui\Application;
- use Gui\Components\Button;
- use Gui\Components\InputText;
- use Gui\Components\TextArea;
- use IRC\Event\Listener;
- use IRC\Event\Message\MessageReceiveEvent;
- use IRC\Event\Message\MessageSendEvent;
- use IRC\IRC;
- use IRC\Plugin\PluginBase;
- class FishGUI extends PluginBase implements Listener{
- /**
- * @var Application
- */
- private $application;
- /**
- * @var TextArea
- */
- private $chat;
- /**
- * @var InputText
- */
- private $channel;
- public function onLoad(){
- $this->getEventHandler()->registerEvents($this, $this->plugin);
- include_once($this->getDataPath()."vendor/autoload.php");
- $application = new Application(["title" => $this->getConnection()->getAddress(),
- "width" => 500,
- "height" => 500]);
- $application->setVerboseLevel(0);
- $application->on('start', function() use ($application) {
- $this->chat = (new TextArea())
- ->setLeft(0)
- ->setTop(0)
- ->setWidth(360)
- ->setHeight(450);
- $text = (new InputText())
- ->setLeft(100)
- ->setTop(450)
- ->setWidth(250);
- $send = (new Button())
- ->setLeft(350)
- ->setTop(450)
- ->setWidth(100)
- ->setValue('Send');
- $this->channel = (new InputText())
- ->setLeft(0)
- ->setTop(450)
- ->setWidth(100);
- $send->on('click', function() use ($text) {
- $this->sendText($text);
- });
- });
- $application->getLoop()->addPeriodicTimer(0.01, function(){
- IRC::getInstance()->cycle();
- });
- $this->application = $application;
- $application->run();
- }
- public function sendText(InputText $text){
- $this->getConnection()->sendData("PRIVMSG ".$this->channel->getValue()." :".$text->getValue());
- $this->chat->setValue($this->chat->getValue()."\n".time()." <".$this->channel->getValue()." ".$this->connection->getNick()."> ".$text->getValue());
- $text->setValue("");
- }
- public function onMessageReceiveEvent(MessageReceiveEvent $event){
- $this->chat->setValue($this->chat->getValue()."\n".time()." <".$event->getChannel()->getName()." ".$event->getUser()->getNick()."> ".$event->getMessage());
- }
- public function onMessageSendEvent(MessageSendEvent $event){
- $this->chat->setValue($this->chat->getValue()."\n".time()." <".$event->getChannel()->getName()." ".$this->getConnection()->getNick()."> ".$event->getMessage());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement