getSource() public method

Returns the channel name if the event occurred in a channel or the user nick if the event was a private message directed at the bot by a user.
public getSource ( ) : string
return string
Beispiel #1
0
 /**
  * Tests that the user nick is returned as the event source if the event
  * is a private message to the bot from a user.
  *
  * @return void
  */
 public function testGetSourceWithUser()
 {
     $expected = 'nick';
     $hostmask = $this->getMockHostmask($expected);
     $this->event->setHostmask($hostmask);
     $this->event->setType('privmsg');
     $this->event->setArguments(array($expected, 'text'));
     $actual = $this->event->getSource();
     $this->assertSame($expected, $actual);
 }
Beispiel #2
0
 /**
  * Checks for an expected karma response.
  *
  * @param Phergie_Event_Request $event    Event containing the karma
  *                                        request
  * @param string                $term     Karma term
  * @param string                $response Portion of the response
  *                                        message following the term
  *                                        from the original event
  *
  * @return void
  */
 private function checkForKarmaResponse($event, $term, $response)
 {
     $text = $event->getNick() . ': ' . $response;
     $this->assertEmitsEvent('privmsg', array($event->getSource(), $text));
     $this->plugin->onCommandKarma($term);
 }
Beispiel #3
0
 /**
  * log
  *
  * Wrapper method on the logging that adds in additional features, such as error handling
  *  and retrying the long living database connection in case it dropped.
  *
  * @param Phergie_Event_Request $event The event we are operating on
  * @param string $nick Who did this?
  * @param string $message What was said?
  * @author Eli White <*****@*****.**>
  * @return void
  */
 protected function log(Phergie_Event_Request $event, $nick, $message = NULL)
 {
     // Because of repeated logic, this is a 'two loop max loop'
     $attempts = 1;
     // Number of times we'll retry a failed connection here.
     $immediate = false;
     while ($attempts > 0) {
         // If we start off failed, go ahead and try to connect:
         if ($this->failed) {
             $attempts--;
             $retry = $this->getConfig('logging.retry', 300);
             if ($immediate || $retry + $this->failed < time()) {
                 if ($this->failed = $this->_connectDB() ? false : time()) {
                     $this->doPrivmsg($event->getSource(), "WARNING: DB connection for Logging Plugin has failed.  " . "Retrying in {$retry} seconds");
                 } else {
                     $this->doPrivmsg($event->getSource(), "NOTICE: DB connection for Logging Plugin reestablished.");
                 }
             }
         }
         // Now if we aren't failed, attempt it, break the loop if it works, else repeat
         if (!$this->failed) {
             if ($this->_log($event, $nick, $message)) {
                 break;
             } else {
                 $this->failed = $immediate = true;
             }
         }
     }
 }