Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 29.73 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Module: RandomQuote
  4.  *
  5.  * This module provides functionality for some randomness. That description
  6.  * might be random, but that's precisely the purpose of this module; being
  7.  * random. Basically, what it does is monitoring a channel and storing the last
  8.  * x messages in that channel (x can get configured). Then, after a random time
  9.  * interval, the Timer gets called and one of those messages is repeated in the
  10.  * channel. This can result in funny situations, which might liven up a dead
  11.  * channel.
  12.  *
  13.  * This module is completely configuration-less, so just plug it into your bot
  14.  * and start spamming channels, but be sure to ask for the channel founder's
  15.  * permission. I'm not responsible for your bot getting banned for annoying
  16.  * behaviour.
  17.  *
  18.  * @author Mr. Bondt <mrbondt@goldenak.eu>
  19.  */
  20. class RandomQuote extends ModuleBase
  21. {
  22.        
  23.         /**
  24.          * Array of channels where this module will be activated in.
  25.          */
  26.         private $m_aChannels;
  27.        
  28.         /**
  29.          * This array contains the timestamp of the last message in every
  30.          * channel.
  31.          */
  32.         private $m_aLastMessage;
  33.        
  34.         /**
  35.          * This is timestamp of the last time the timer has run.
  36.          */
  37.         private $m_nLastRun;
  38.        
  39.         /**
  40.          * Associative array with the last 100 messages of every channel this
  41.          * module is active in.
  42.          */
  43.         private $m_aMessages;
  44.        
  45.         /**
  46.          * The timer ID of the current active timer, if there is one.
  47.          */
  48.         private $m_sTimerId;
  49.        
  50.         /**
  51.          * The number of messages we should store for each enabled channel.
  52.          */
  53.         private $m_nMessages;
  54.        
  55.         /**
  56.          * The prefix for the Evaluation module. We save this here so we can
  57.          * ignore message beginning with this.
  58.          */
  59.         private $m_sEvalPrefix;
  60.  
  61.     /**
  62.      * This array will define if there's actually being talked in the channel.
  63.      */
  64.     private $m_aTalkInfo;
  65.        
  66.         /**
  67.          * The constructor readies the module for use.
  68.          */
  69.         public function __construct ()
  70.         {
  71.                 if (!is_dir ('Data/RandomQuote'))
  72.                 {
  73.                         mkdir ('Data/RandomQuote');
  74.                 }
  75.                
  76.                 $aConf = Configuration :: getInstance () -> get ('Owners');
  77.                 $this -> m_sEvalPrefix = $aConf ['Prefix'];
  78.         $this -> m_aTalkInfo = array ();
  79.                
  80.                 $this -> setNumMessages (100);
  81.                 $this -> load ();
  82.                
  83.                 // Set up timer.
  84.                 $this -> setupTimer ();
  85.         }
  86.        
  87.         /**
  88.          * The destructor saves the until saved messages to file.
  89.          */
  90.         public function __destruct ()
  91.         {
  92.                 $this -> save ();
  93.         }
  94.        
  95.         /**
  96.          * Loads up the channels where this module should be activated in.
  97.          */
  98.         public function load ()
  99.         {
  100.                 // Convert the old format to the new format, assume the first
  101.                 // configured network.
  102.                 $aNetworks       = array_keys (Configuration :: getInstance () -> get ('Networks'));
  103.                 $sDefaultNetwork = $aNetworks [0];
  104.                
  105.                 $this -> m_aChannels = array ();
  106.                
  107.                 if (file_exists ('Data/RandomQuote/Channels.dat'))
  108.                 {
  109.                         $this -> m_aChannels = unserialize (file_get_contents ('Data/RandomQuote/Channels.dat'));
  110.                 }
  111.                
  112.                 foreach ($this -> m_aChannels as $iIndex => $sChannel)
  113.                 {
  114.                         if (strpos ($sChannel, ':') !== false)
  115.                         {
  116.                                 list ($sNetwork, $sChannel) = explode (':', $sChannel);
  117.                         }
  118.                         else
  119.                         {
  120.                                 // Backward compatibility.
  121.                                 $sNetwork = $sDefaultNetwork;
  122.                                
  123.                                 if (file_exists ('Data/RandomQuote/Messages_' . $sChannel . '.txt'))
  124.                                 {
  125.                                         // Rename it
  126.                                         rename (
  127.                                                 'Data/RandomQuote/Messages_' . $sChannel . '.txt',
  128.                                                 'Data/RandomQuote/Messages_' . $sNetwork . ',' . $sChannel . '.txt'
  129.                                         );
  130.                                 }
  131.                                
  132.                                 $this -> m_aChannels [$iIndex] = $sNetwork . ':' . $sChannel;
  133.                         }
  134.                        
  135.                         $sFilename = 'Data/RandomQuote/Messages_' . $sNetwork . ',' . $sChannel . '.txt';
  136.                         if (file_exists ($sFilename))
  137.                         {
  138.                                 $this -> m_aMessages [$sNetwork][$sChannel] = file ($sFilename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  139.                         }
  140.                 }
  141.                
  142.                 $tsTime = time ();
  143.                 foreach ($this -> m_aChannels as $sChannel)
  144.                 {
  145.                         $this -> m_aLastMessage [$sChannel] = $tsTime;
  146.                        
  147.                         // This should be fine now, as it's fixed in the previous loop.
  148.                         list ($sNetwork, $sChannel) = explode (':', $sChannel);
  149.                        
  150.                         if (!isset ($this -> m_aMessages [$sNetwork]))
  151.                         {
  152.                                 $this -> m_aMessages [$sNetwork] = array ();
  153.                         }
  154.                        
  155.                         if (!isset ($this -> m_aMessages [$sNetwork][$sChannel]))
  156.                         {
  157.                                 $this -> m_aMessages [$sNetwork][$sChannel] = array ();
  158.                         }
  159.                 }
  160.                
  161.                 // Save any corrections made.
  162.                 $this -> save ();
  163.                
  164.                 // Prevents spamming in a channel after just starting.
  165.                 $this -> m_nLastRun = $tsTime;
  166.         }
  167.        
  168.         /**
  169.          * Saves the channels where this module should be used.
  170.          */
  171.         public function save ()
  172.         {
  173.                 file_put_contents ('Data/RandomQuote/Channels.dat', serialize ($this -> m_aChannels));
  174.                 foreach ($this -> m_aChannels as $sChannel)
  175.                 {
  176.                         list ($sNetwork, $sChannel) = explode (':', $sChannel);
  177.                         file_put_contents (
  178.                                 'Data/RandomQuote/Messages_' . $sNetwork . ',' . $sChannel . '.txt',
  179.                                 implode (PHP_EOL, $this -> m_aMessages [$sNetwork][$sChannel])
  180.                         );
  181.                 }
  182.         }
  183.        
  184.         /**
  185.          * Returns the number of messages we're storing to use in random
  186.          * messages.
  187.          *
  188.          * @return integer
  189.          */
  190.         public function getNumMessages ()
  191.         {
  192.                 return $this -> m_nMessages;
  193.         }
  194.        
  195.         /**
  196.          * This method sets the number of messages we're storing for each
  197.          * channel, which can be used to spam a random quote once in a while.
  198.          *
  199.          * @param integer $nMessages The number of messages to store.
  200.          */
  201.         public function setNumMessages ($nMessages)
  202.         {
  203.                 $this -> m_nMessages = $nMessages;
  204.         }
  205.        
  206.         /**
  207.          * Enables this module for the given channel.
  208.          *
  209.          * @param string $sNetwork The network on which this channel resides.
  210.          * @param string $sChannel The channel to add.
  211.          * @return boolean
  212.          */
  213.         public function addChannel ($sNetwork, $sChannel)
  214.         {
  215.                 $sChannel = strtolower ($sChannel);
  216.                 if ($this -> isChannelAdded ($sNetwork, $sChannel))
  217.                 {
  218.                         return false;
  219.                 }
  220.                
  221.                 $this -> m_aChannels [] = $sNetwork . ':' . $sChannel;
  222.                 $this -> m_aMessages [$sNetwork][$sChannel] = array ();
  223.                 $this -> m_aLastMessage [$sNetwork . ':' . $sChannel] = 0;
  224.                
  225.                 $this -> save ();
  226.                 return true;
  227.         }
  228.        
  229.         /**
  230.          * Disables this module for the given channel. If $bDelMessages is true
  231.          * (default), the stored messages for the given channel will be deleted.
  232.          *
  233.          * @param string $sNetwork The network on which this channel resides.
  234.          * @param string $sChannel The channel to remove.
  235.          * @param boolean $bDelMessages Whether to delete the stored messages.
  236.          * @return boolean
  237.          */
  238.         public function removeChannel ($sNetwork, $sChannel, $bDelMessages = true)
  239.         {
  240.                 $sChannel = strtolower ($sChannel);
  241.                 if (!$this -> isChannelAdded ($sNetwork, $sChannel))
  242.                 {
  243.                         return false;
  244.                 }
  245.                
  246.                 $bDone = false;
  247.                 foreach ($this -> m_aChannels as $nIndex => $sListedChannel)
  248.                 {
  249.                         if ($sListedChannel == $sNetwork . ':' . $sChannel)
  250.                         {
  251.                                 unset ($this -> m_aChannels [$nIndex]);
  252.                                 if ($bDelMessages)
  253.                                 {
  254.                                         unset ($this -> m_aMessages [$sNetwork][$sChannel]);
  255.                                 }
  256.                                 $bDone = true;
  257.                                 break;
  258.                         }
  259.                 }
  260.                
  261.                 $this -> save ();
  262.                 return $bDone;
  263.         }
  264.        
  265.         /**
  266.          * Checks whether this module is active in the given channel.
  267.          *
  268.          * @param string $sNetwork The network on which this channel resides.
  269.          * @param string $sChannel The channel to check.
  270.          * @return boolean
  271.          */
  272.         public function isChannelAdded ($sNetwork, $sChannel)
  273.         {
  274.                 $sChannel = strtolower ($sChannel);
  275.                
  276.                 return in_array ($sNetwork . ':' . $sChannel, $this -> m_aChannels);
  277.         }
  278.        
  279.         /**
  280.          * This method saves the message that has appeared in the given channel
  281.          * for use as a possible random message. It'll also replace the bot's
  282.          * own nickname with the nickname of the person who sent the message.
  283.          *
  284.          * @param string $sNetwork The network on which this channel resides.
  285.          * @param string $sChannel The channel where the message appeared in.
  286.          * @param string $sMessage The message itself.
  287.          * @param string $sOwnNickname The bot's own nickname.
  288.          */
  289.         private function addMessage ($sNetwork, $sChannel, $sNickname, $sMessage, $sOwnNickname)
  290.         {
  291.                 $sChannel = strtolower ($sChannel);
  292.                 if (!$this -> isChannelAdded ($sNetwork, $sChannel))
  293.                 {
  294.                         return;
  295.                 }
  296.                
  297.                 if (strlen ($sMessage) > 1 && ($sMessage [0] == '!' || $sMessage [0] == '.'))
  298.                 {
  299.                         // It's a command, skip it. It may very well be (or is) a command of this bot.
  300.                         return;
  301.                 }
  302.                
  303.                 if (substr ($sMessage, 0, strlen ($this -> m_sEvalPrefix)) == $this -> m_sEvalPrefix)
  304.                 {
  305.                         // This is meant for the Evaluation module, skip it.
  306.                         return;
  307.                 }
  308.                
  309.                 // Replace bot's name with name of person who said it
  310.                 // First replace all caps bot's name with all caps person's name.
  311.                 $sMessage = str_replace (strtoupper ($sOwnNickname), strtoupper ($sNickname), $sMessage);
  312.                 // Also replace all lowercase, just to be perfect.
  313.                 $sMessage = str_replace (strtolower ($sOwnNickname), strtolower ($sNickname), $sMessage);
  314.                 // Not gonna bother with BrEeZeR talk.
  315.                 $sMessage = str_ireplace ($sOwnNickname, $sNickname, $sMessage);
  316.                
  317.                 // We want unique messages in the buffer, but respond to non-unique messages as well.
  318.                 $this -> m_aLastMessage [$sNetwork . ':' . $sChannel] = time ();
  319.                
  320.                 // Prevent adding the same messages (like when someone is spamming).
  321.                 // This is probably slow, but I don't care, since it works fine.
  322.                 if (in_array ($sMessage, $this -> m_aMessages [$sNetwork][$sChannel]))
  323.                 {
  324.                         return;
  325.                 }
  326.                
  327.                 // Add the message to the beginning, so we can shave the old messages of.
  328.                 array_unshift ($this -> m_aMessages [$sNetwork][$sChannel], $sMessage);
  329.                
  330.                 if (count ($this -> m_aMessages [$sNetwork][$sChannel]) > $this -> m_nMessages)
  331.                 {
  332.                         // Remove all messages above a certain index. This makes changes in the number of messages possible.
  333.                         for ($i = $this -> m_nMessages; $i < count ($this -> m_aMessages [$sNetwork][$sChannel]); $i ++)
  334.                         {
  335.                                 unset ($this -> m_aMessages [$sNetwork][$sChannel][$i]);
  336.                         }
  337.                 }
  338.         }
  339.        
  340.         /**
  341.          * This method will setup the timer for the next random message. The
  342.          * timer will always set up with a timeout between 7.5 and 15 minutes.
  343.          */
  344.         private function setupTimer ()
  345.         {
  346.                 $this -> m_sTimerId = Timer :: Create
  347.                 (
  348.                         array ($this, 'runTimer'),
  349.                         mt_rand(450 , 900) * 1000,
  350.                         false
  351.                 );
  352.  
  353.         foreach ($this -> m_aTalked as $sChan => $bTalked)
  354.         {
  355.             $this -> m_aTalked [$sChan] = false;
  356.         }
  357.         }
  358.        
  359.         /**
  360.          * This method will call the run() method and setup the timer for the
  361.          * next round of randomness.
  362.          */
  363.         public function runTimer ()
  364.         {
  365.                 $this -> save ();
  366.                 $this -> run ();
  367.                 $this -> setupTimer ();
  368.         }
  369.        
  370.         /**
  371.          * Spams every enabled channel with a random message.
  372.          */
  373.         public function run ()
  374.         {
  375.                 $this -> save ();
  376.                
  377.                 foreach ($this -> m_aChannels as $sChannel)
  378.                 {
  379.                         list ($sNetwork, $sChannel) = explode (':', $sChannel);
  380.                        
  381.                         // Have there been messages since the last time we spammed?
  382.                         if ($this -> m_aLastMessage [$sNetwork . ':' . $sChannel] < $this -> m_nLastRun)
  383.                         {
  384.                                 continue;
  385.                         }
  386.                        
  387.                         // Do we have enough messages to be serious?
  388.                         if (count ($this -> m_aMessages [$sNetwork][$sChannel]) < 3)
  389.                         {
  390.                                 continue;
  391.                         }
  392.                        
  393.                         $pBot = BotManager :: getInstance () -> offsetGet ('network:' . $sNetwork . ' channel:' . $sChannel);
  394.                         if ($pBot instanceof BotGroup)
  395.                         {
  396.                                 if (count ($pBot) == 0)
  397.                                 {
  398.                                         // No bots found.
  399.                                         echo 'Could not find a bot in ' . $sChannel . ' on ' . $sNetwork . PHP_EOL;
  400.                                         continue;
  401.                                 }
  402.                                 else
  403.                                 {
  404.                                         $pBot = $pBot -> seek (0);
  405.                                 }
  406.                         }
  407.                        
  408.                         // We start at index 2 because we don't want a repetition of one of the last messages.
  409.                         $nIndex   = mt_rand (2, count ($this -> m_aMessages [$sNetwork][$sChannel]) - 1);
  410.                         $sMessage = $this -> m_aMessages [$sNetwork][$sChannel][$nIndex];
  411.  
  412.             if ($this -> m_aTalked [$sChannel])
  413.                             $pBot -> send ('PRIVMSG ' . $sChannel . ' :' . $sMessage);
  414.                        
  415.                         // Call Pisg logging module, if it exists.
  416.                         if (class_exists ('Pisg'))
  417.                         {
  418.                                 $pPisg = ModuleManager :: getInstance () -> offsetGet ('Pisg');
  419.                                 if ($pPisg instanceof ModuleBase)
  420.                                 {
  421.                                         if (substr ($sMessage, 0, 8) == chr (1) . 'ACTION ')
  422.                                         {
  423.                                                 $pPisg -> onCTCP ($pBot, $sChannel, $pBot ['Nickname'], 'ACTION', substr ($sMessage, 8, -1));
  424.                                         }
  425.                                         else
  426.                                         {
  427.                                                 $pPisg -> onChannelPrivmsg ($pBot, $sChannel, $pBot ['Nickname'], $sMessage);
  428.                                         }
  429.                                 }
  430.                         }
  431.                        
  432.                         // Remove the message from the array, this prevents us from spammin' it again.
  433.                         unset ($this -> m_aMessages [$sNetwork][$sChannel][$nIndex]);
  434.                        
  435.                         // Make sure the indexes are following eachother up so that we can still use mt_rand ().
  436.                         $this -> m_aMessages [$sNetwork][$sChannel] = array_values ($this -> m_aMessages [$sNetwork][$sChannel]);
  437.                 }
  438.                
  439.                 $this -> m_nLastRun = time ();
  440.         }
  441.        
  442.         /**
  443.          * Handles some basic commands for this module, but will mostly
  444.          * be storing messages that occured in a channel which this module
  445.          * is active in.
  446.          *
  447.          * @param Bot $pBot The bot which received the message.
  448.          * @param string $sChannel The channel in which the message was received.
  449.          * @param string $sNickname The nickname from whom we got the message.
  450.          * @param string $sMessage The message itself.
  451.          */
  452.         public function onChannelPrivmsg (Bot $pBot, $sChannel, $sNickname, $sMessage)
  453.         {
  454.         // Is the channel active?
  455.         if ($this -> isChannelAdded ($pBot ['Network'], $sChannel))
  456.         {
  457.             if (!isset ($this -> m_aTalked [$sChannel]))
  458.                 $this -> m_aTalked [$sChannel] = true;
  459.             else
  460.                 $this -> m_aTalked [$sChannel] = true;
  461.         }
  462.  
  463.                 // Handle commands.
  464.                 list ($sTrigger, $sParams) = Util:: parseMessage ($sMessage);
  465.                
  466.                 if ($sMessage [0] == '!')
  467.                 {
  468.                         switch ($sTrigger)
  469.                         {
  470.                                 /**
  471.                                  * Force an execution.
  472.                                  */
  473.                                 case '!runrandom':
  474.                                 {
  475.                                         $pEval = ModuleManager :: getInstance () -> offsetGet ('Evaluation');
  476.                                         if (!$pEval -> checkSecurity ($pBot, 9999)) {
  477.                                                 // Not the (logged in) owner.
  478.                                                 return false;
  479.                                         }
  480.                                        
  481.                                         $this -> run ();
  482.                                         return;
  483.                                 }
  484.                                
  485.                                 /**
  486.                                  * Add a new channel which we're expected to spam.
  487.                                  */
  488.                                 case '!addrandomchan':
  489.                                 {
  490.                                         $pEval = ModuleManager :: getInstance () -> offsetGet ('Evaluation');
  491.                                         if (!$pEval -> checkSecurity ($pBot, 9999))
  492.                                         {
  493.                                                 return false;
  494.                                         }
  495.                                        
  496.                                         if ($sParams == null || substr ($sParams, 0, 1) != '#')
  497.                                         {
  498.                                                 $pBot -> send ('PRIVMSG ' . $sChannel . ' :10Usage: !addrandomchan Channel');
  499.                                         }
  500.                                         else
  501.                                         {
  502.                                                 if ($this -> addChannel ($pBot ['Network'], $sParams))
  503.                                                 {
  504.                                                         $pBot -> send ('PRIVMSG ' . $sChannel . ' :3Success: Channel ' . $sParams . ' added.');
  505.                                                 }
  506.                                                 else
  507.                                                 {
  508.                                                         $pBot -> send ('PRIVMSG ' . $sChannel . ' :4Error: Channel ' . $sParams . ' is already added.');
  509.                                                 }
  510.                                         }
  511.                                         return;
  512.                                 }
  513.                                
  514.                                 /**
  515.                                  * People might get tired of this too. But that's okay,
  516.                                  * with this command one is able to remove the functionality.
  517.                                  */
  518.                                 case '!delrandomchan':
  519.                                 case '!removerandomchan':
  520.                                 {
  521.                                         $pEval = ModuleManager :: getInstance () -> offsetGet ('Evaluation');
  522.                                         if (!$pEval -> checkSecurity ($pBot, 9999))
  523.                                         {
  524.                                                 return false;
  525.                                         }
  526.                                        
  527.                                         if ($sParams == null || substr ($sParams, 0, 1) != '#')
  528.                                         {
  529.                                                 $pBot -> send ('PRIVMSG ' . $sChannel . ' :10Usage: !removerandomchan Channel');
  530.                                         }
  531.                                         else
  532.                                         {
  533.                                                 if ($this -> removeChannel ($pBot ['Network'], $sParams))
  534.                                                 {
  535.                                                         $pBot -> send ('PRIVMSG ' . $sChannel . ' :3Success: Channel ' . $sParams . ' removed.');
  536.                                                 }
  537.                                                 else
  538.                                                 {
  539.                                                         $pBot -> send ('PRIVMSG ' . $sChannel . ' :4Error: Channel ' . $sParams . ' is not added.');
  540.                                                 }
  541.                                         }
  542.                                         return;
  543.                                 }
  544.                                
  545.                                 /**
  546.                                  * Just want to pause the module? That's cool, use this command.
  547.                                  * Note that new messages aren't stored.
  548.                                  *
  549.                                  * 22-11-2009: disabled since it just doesn't make sense without continuing to store messages.
  550.                                  */
  551.                                 /*case '!pauserandom':
  552.                                 {      
  553.                                         $pEval = ModuleManager :: getInstance () -> offsetGet ('Evaluation');
  554.                                         if (!$pEval -> checkSecurity ($pBot, 9999))
  555.                                         {
  556.                                                 return false;
  557.                                         }
  558.                                        
  559.                                         if ($sParams == null || substr ($sParams, 0, 1) != '#')
  560.                                         {
  561.                                                 $pBot -> send ('PRIVMSG ' . $sChannel . ' :10Usage: !pauserandom Channel');
  562.                                         }
  563.                                         else
  564.                                         {
  565.                                                 if ($this -> removeChannel ($pBot ['Network'], $sParams, false))
  566.                                                 {
  567.                                                         $pBot -> send ('PRIVMSG ' . $sChannel . ' :3Success: Channel ' . $sParams . ' stopped.');
  568.                                                 }
  569.                                                 else
  570.                                                 {
  571.                                                         $pBot -> send ('PRIVMSG ' . $sChannel . ' :4Error: Channel ' . $sParams . ' is not added.');
  572.                                                 }
  573.                                         }
  574.                                         return;
  575.                                 }*/
  576.                                
  577.                                 /**
  578.                                  * Get an overview of all the channels we're currently active in.
  579.                                  */
  580.                                 case '!listrandomchan':
  581.                                 {
  582.                                         $sMessage = '10* RandomQuote module active in (' . count ($this -> m_aChannels) . '): ';
  583.                                         foreach ($this -> m_aChannels as $sListedChannel)
  584.                                         {
  585.                                                 $sMessage .= $sListedChannel . ', ';
  586.                                         }
  587.                                        
  588.                                         $pBot -> send ('PRIVMSG ' . $sChannel . ' :' . substr ($sMessage, 0, -2));
  589.                                         return;
  590.                                 }
  591.                                
  592.                                 /**
  593.                                  * Show some basic statistics.
  594.                                  */
  595.                                 case '!randomstats':
  596.                                 {
  597.                                         $sChannel = strtolower ($sChannel);
  598.                                        
  599.                                         if ($this -> isChannelAdded ($pBot ['Network'], $sChannel))
  600.                                         {
  601.                                                 $pBot -> send
  602.                                                 (
  603.                                                         'PRIVMSG ' . $sChannel . ' :10* Stats for ' . $sChannel . ': Number of messages: ' .
  604.                                                         count ($this -> m_aMessages [$pBot ['Network']][strtolower ($sChannel)]) .
  605.                                                         ' - Last message stored: ' . Util :: formatTime (time () - $this -> m_aLastMessage [$pBot ['Network'] . ':' . $sChannel], true) . ' ago'
  606.                                                 );
  607.                                         }
  608.                                         return;
  609.                                 }
  610.                         }
  611.                 }
  612.                
  613.                 if ($this -> isChannelAdded ($pBot ['Network'], $sChannel))
  614.                 {
  615.                         // Add the received message to the list.
  616.                         $this -> addMessage ($pBot ['Network'], $sChannel, $sNickname, $sMessage, $pBot ['Nickname']);
  617.                 }
  618.         }
  619.        
  620.         /**
  621.          * In order to catch the /me message as well, we're going to have to
  622.          * parse the ACTION messages, because of a limitation in the Nuwani
  623.          * framework. This will be done in this very method. The type ($sType)
  624.          * we're looking for is ACTION.
  625.          *
  626.          * @param Bot $pBot The bot which received the message.
  627.          * @param string $sChannel The channel in which the message was received.
  628.          * @param string $sNickname The nickname from whom we got the message.
  629.          * @param string $sType The CTCP type.
  630.          * @param string $sMessage The message itself.
  631.          */
  632.         public function onCTCP (Bot $pBot, $sChannel, $sNickname, $sType, $sMessage)
  633.         {
  634.                 if (strtoupper ($sType) == 'ACTION' && $this -> isChannelAdded ($pBot ['Network'], $sChannel))
  635.                 {
  636.                         $this -> addMessage ($pBot ['Network'], $sChannel, $sNickname, chr (1) . 'ACTION ' . $sMessage . chr (1), $pBot ['Nickname']);
  637.                 }
  638.         }
  639. }
  640. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement