Advertisement
Guest User

Untitled

a guest
Jul 1st, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. <?php
  2.  
  3. namespace FishGUI;
  4.  
  5. use Gui\Application;
  6. use Gui\Components\Button;
  7. use Gui\Components\InputText;
  8. use Gui\Components\TextArea;
  9. use IRC\Event\Listener;
  10. use IRC\Event\Message\MessageReceiveEvent;
  11. use IRC\Event\Message\MessageSendEvent;
  12. use IRC\IRC;
  13. use IRC\Plugin\PluginBase;
  14.  
  15. class FishGUI extends PluginBase implements Listener{
  16.  
  17. /**
  18. * @var Application
  19. */
  20. private $application;
  21.  
  22. /**
  23. * @var TextArea
  24. */
  25. private $chat;
  26.  
  27. /**
  28. * @var InputText
  29. */
  30. private $channel;
  31.  
  32. public function onLoad(){
  33. $this->getEventHandler()->registerEvents($this, $this->plugin);
  34. include_once($this->getDataPath()."vendor/autoload.php");
  35. $application = new Application(["title" => $this->getConnection()->getAddress(),
  36. "width" => 500,
  37. "height" => 500]);
  38. $application->setVerboseLevel(0);
  39. $application->on('start', function() use ($application) {
  40. $this->chat = (new TextArea())
  41. ->setLeft(0)
  42. ->setTop(0)
  43. ->setWidth(360)
  44. ->setHeight(450);
  45. $text = (new InputText())
  46. ->setLeft(100)
  47. ->setTop(450)
  48. ->setWidth(250);
  49. $send = (new Button())
  50. ->setLeft(350)
  51. ->setTop(450)
  52. ->setWidth(100)
  53. ->setValue('Send');
  54. $this->channel = (new InputText())
  55. ->setLeft(0)
  56. ->setTop(450)
  57. ->setWidth(100);
  58.  
  59. $send->on('click', function() use ($text) {
  60. $this->sendText($text);
  61. });
  62. });
  63.  
  64. $application->getLoop()->addPeriodicTimer(0.01, function(){
  65. IRC::getInstance()->cycle();
  66. });
  67.  
  68. $this->application = $application;
  69. $application->run();
  70. }
  71.  
  72. public function sendText(InputText $text){
  73. $this->getConnection()->sendData("PRIVMSG ".$this->channel->getValue()." :".$text->getValue());
  74. $this->chat->setValue($this->chat->getValue()."\n".time()." <".$this->channel->getValue()." ".$this->connection->getNick()."> ".$text->getValue());
  75. $text->setValue("");
  76. }
  77.  
  78. public function onMessageReceiveEvent(MessageReceiveEvent $event){
  79. $this->chat->setValue($this->chat->getValue()."\n".time()." <".$event->getChannel()->getName()." ".$event->getUser()->getNick()."> ".$event->getMessage());
  80. }
  81.  
  82. public function onMessageSendEvent(MessageSendEvent $event){
  83. $this->chat->setValue($this->chat->getValue()."\n".time()." <".$event->getChannel()->getName()." ".$this->getConnection()->getNick()."> ".$event->getMessage());
  84. }
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement