Net_SmartIRC
[ class tree: Net_SmartIRC ] [ index: Net_SmartIRC ] [ all elements ]

Source for file irccommands.php

Documentation is available at irccommands.php

  1. <?php
  2. /**
  3.  * $Id$
  4.  * $Revision$
  5.  * $Author$
  6.  * $Date$
  7.  *
  8.  * Copyright (c) 2002-2004 Mirco Bauer <meebey@meebey.net> <http://www.meebey.net>
  9.  *
  10.  * Full LGPL License: <http://www.gnu.org/licenses/lgpl.txt>
  11.  *
  12.  * This library is free software; you can redistribute it and/or
  13.  * modify it under the terms of the GNU Lesser General Public
  14.  * License as published by the Free Software Foundation; either
  15.  * version 2.1 of the License, or (at your option) any later version.
  16.  *
  17.  * This library is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  20.  * Lesser General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU Lesser General Public
  23.  * License along with this library; if not, write to the Free Software
  24.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  25.  */
  26.  
  27. abstract class Net_SmartIRC_irccommands
  28. {
  29.     /**
  30.      * sends a new message
  31.      *
  32.      * Sends a message to a channel or user.
  33.      *
  34.      * @see DOCUMENTATION
  35.      * @param integer $type specifies the type, like QUERY/ACTION or CTCP see 'Message Types'
  36.      * @param string $destination can be a user or channel
  37.      * @param mixed $messagearray the message
  38.      * @param integer $priority the priority level of the message
  39.      * @return boolean|Net_SmartIRC
  40.      * @api
  41.      */
  42.     public function message($type$destination$messagearray,
  43.         $priority = SMARTIRC_MEDIUM
  44.     {
  45.         if (!is_array($messagearray)) {
  46.             $messagearray = array($messagearray);
  47.         }
  48.  
  49.         switch ($type{
  50.             case SMARTIRC_TYPE_CHANNEL:
  51.             case SMARTIRC_TYPE_QUERY:
  52.                 foreach ($messagearray as $message{
  53.                     $this->send('PRIVMSG '.$destination.' :'.$message$priority);
  54.                 }
  55.                 break;
  56.  
  57.             case SMARTIRC_TYPE_ACTION:
  58.                 foreach ($messagearray as $message{
  59.                     $this->send('PRIVMSG '.$destination.' :'.chr(1).'ACTION '
  60.                         .$message.chr(1)$priority
  61.                     );
  62.                 }
  63.                 break;
  64.  
  65.             case SMARTIRC_TYPE_NOTICE:
  66.                 foreach ($messagearray as $message{
  67.                     $this->send('NOTICE '.$destination.' :'.$message$priority);
  68.                 }
  69.                 break;
  70.  
  71.             case SMARTIRC_TYPE_CTCP// backwards compatibility
  72.             case SMARTIRC_TYPE_CTCP_REPLY:
  73.                 foreach ($messagearray as $message{
  74.                     $this->send('NOTICE '.$destination.' :'.chr(1).$message
  75.                         .chr(1)$priority
  76.                     );
  77.                 }
  78.                 break;
  79.  
  80.             case SMARTIRC_TYPE_CTCP_REQUEST:
  81.                 foreach ($messagearray as $message{
  82.                     $this->send('PRIVMSG '.$destination.' :'.chr(1).$message
  83.                         .chr(1)$priority
  84.                     );
  85.                 }
  86.                 break;
  87.  
  88.             default:
  89.                 return false;
  90.         }
  91.  
  92.         return $this;
  93.     }
  94.  
  95.     // <IRC methods>
  96.     /**
  97.      * Joins one or more IRC channels with an optional key.
  98.      *
  99.      * @param mixed $channelarray 
  100.      * @param string $key 
  101.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  102.      * @return Net_SmartIRC 
  103.      * @api
  104.      */
  105.     public function join($channelarray$key = null$priority = SMARTIRC_MEDIUM)
  106.     {
  107.         if (!is_array($channelarray)) {
  108.             $channelarray = array($channelarray);
  109.         }
  110.  
  111.         $channellist implode(','$channelarray);
  112.  
  113.         if ($key !== null{
  114.             foreach ($channelarray as $idx => $value{
  115.                 $this->send('JOIN '.$value.' '.$key$priority);
  116.             }
  117.         else {
  118.             foreach ($channelarray as $idx => $value{
  119.                 $this->send('JOIN '.$value$priority);
  120.             }
  121.         }
  122.  
  123.         return $this;
  124.     }
  125.  
  126.     /**
  127.      * parts from one or more IRC channels with an optional reason
  128.      *
  129.      * @param mixed $channelarray 
  130.      * @param string $reason 
  131.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  132.      * @return Net_SmartIRC 
  133.      * @api
  134.      */
  135.     public function part($channelarray$reason = null,
  136.         $priority = SMARTIRC_MEDIUM
  137.     {
  138.         if (!is_array($channelarray)) {
  139.             $channelarray = array($channelarray);
  140.         }
  141.  
  142.         $channellist implode(','$channelarray);
  143.  
  144.         if ($reason !== null{
  145.             $this->send('PART '.$channellist.' :'.$reason$priority);
  146.         else {
  147.             $this->send('PART '.$channellist$priority);
  148.         }
  149.         return $this;
  150.     }
  151.  
  152.     /**
  153.      * Kicks one or more user from an IRC channel with an optional reason.
  154.      *
  155.      * @param string $channel 
  156.      * @param mixed $nicknamearray 
  157.      * @param string $reason 
  158.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  159.      * @return Net_SmartIRC 
  160.      * @api
  161.      */
  162.     public function kick($channel$nicknamearray$reason = null,
  163.         $priority = SMARTIRC_MEDIUM
  164.     {
  165.         if (!is_array($nicknamearray)) {
  166.             $nicknamearray = array($nicknamearray);
  167.         }
  168.  
  169.         $nicknamelist implode(','$nicknamearray);
  170.  
  171.         if ($reason !== null{
  172.             $this->send('KICK '.$channel.' '.$nicknamelist.' :'.$reason$priority);
  173.         else {
  174.             $this->send('KICK '.$channel.' '.$nicknamelist$priority);
  175.         }
  176.         return $this;
  177.     }
  178.  
  179.     /**
  180.      * gets a list of one ore more channels
  181.      *
  182.      * Requests a full channellist if $channelarray is not given.
  183.      * (use it with care, usually its a looooong list)
  184.      *
  185.      * @param mixed $channelarray 
  186.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  187.      * @return Net_SmartIRC 
  188.      * @api
  189.      */
  190.     public function getList($channelarray = null$priority = SMARTIRC_MEDIUM)
  191.     {
  192.         if ($channelarray !== null{
  193.             if (!is_array($channelarray)) {
  194.                 $channelarray = array($channelarray);
  195.             }
  196.  
  197.             $channellist implode(','$channelarray);
  198.             $this->send('LIST '.$channellist$priority);
  199.         else {
  200.             $this->send('LIST'$priority);
  201.         }
  202.         return $this;
  203.     }
  204.  
  205.     /**
  206.      * requests all nicknames of one or more channels
  207.      *
  208.      * The requested nickname list also includes op and voice state
  209.      *
  210.      * @param mixed $channelarray 
  211.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  212.      * @return Net_SmartIRC 
  213.      * @api
  214.      */
  215.     public function names($channelarray = null$priority = SMARTIRC_MEDIUM)
  216.     {
  217.         if ($channelarray !== null{
  218.             if (!is_array($channelarray)) {
  219.                 $channelarray = array($channelarray);
  220.             }
  221.  
  222.             $channellist implode(','$channelarray);
  223.             $this->send('NAMES '.$channellist$priority);
  224.         else {
  225.             $this->send('NAMES'$priority);
  226.         }
  227.         return $this;
  228.     }
  229.  
  230.     /**
  231.      * sets a new topic of a channel
  232.      *
  233.      * @param string $channel 
  234.      * @param string $newtopic 
  235.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  236.      * @return Net_SmartIRC 
  237.      * @api
  238.      */
  239.     public function setTopic($channel$newtopic$priority = SMARTIRC_MEDIUM)
  240.     {
  241.         $this->send('TOPIC '.$channel.' :'.$newtopic$priority);
  242.         return $this;
  243.     }
  244.  
  245.     /**
  246.      * gets the topic of a channel
  247.      *
  248.      * @param string $channel 
  249.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  250.      * @return Net_SmartIRC 
  251.      * @api
  252.      */
  253.     public function getTopic($channel$priority = SMARTIRC_MEDIUM)
  254.     {
  255.         $this->send('TOPIC '.$channel$priority);
  256.         return $this;
  257.     }
  258.  
  259.     /**
  260.      * sets or gets the mode of an user or channel
  261.      *
  262.      * Changes/requests the mode of the given target.
  263.      *
  264.      * @param string $target the target, can be an user (only yourself) or a channel
  265.      * @param string $newmode the new mode like +mt
  266.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  267.      * @return Net_SmartIRC 
  268.      * @api
  269.      */
  270.     public function mode($target$newmode = null$priority = SMARTIRC_MEDIUM)
  271.     {
  272.         if ($newmode !== null{
  273.             $this->send('MODE '.$target.' '.$newmode$priority);
  274.         else {
  275.             $this->send('MODE '.$target$priority);
  276.         }
  277.         return $this;
  278.     }
  279.  
  280.     /**
  281.      * founders an user in the given channel
  282.      *
  283.      * @param string $channel 
  284.      * @param string $nickname 
  285.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  286.      * @return Net_SmartIRC 
  287.      * @api
  288.      */
  289.     public function founder($channel$nickname$priority = SMARTIRC_MEDIUM)
  290.     {
  291.         return $this->mode($channel'+q '.$nickname$priority);
  292.     }
  293.  
  294.     /**
  295.      * defounders an user in the given channel
  296.      *
  297.      * @param string $channel 
  298.      * @param string $nickname 
  299.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  300.      * @return Net_SmartIRC 
  301.      * @api
  302.      */
  303.     public function defounder($channel$nickname$priority = SMARTIRC_MEDIUM)
  304.     {
  305.         return $this->mode($channel'-q '.$nickname$priority);
  306.     }
  307.  
  308.     /**
  309.      * admins an user in the given channel
  310.      *
  311.      * @param string $channel 
  312.      * @param string $nickname 
  313.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  314.      * @return Net_SmartIRC 
  315.      * @api
  316.      */
  317.     public function admin($channel$nickname$priority = SMARTIRC_MEDIUM)
  318.     {
  319.         return $this->mode($channel'+a '.$nickname$priority);
  320.     }
  321.  
  322.     /**
  323.      * deadmins an user in the given channel
  324.      *
  325.      * @param string $channel 
  326.      * @param string $nickname 
  327.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  328.      * @return Net_SmartIRC 
  329.      * @api
  330.      */
  331.     public function deadmin($channel$nickname$priority = SMARTIRC_MEDIUM)
  332.     {
  333.         return $this->mode($channel'-a '.$nickname$priority);
  334.     }
  335.  
  336.     /**
  337.      * ops an user in the given channel
  338.      *
  339.      * @param string $channel 
  340.      * @param string $nickname 
  341.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  342.      * @return Net_SmartIRC 
  343.      * @api
  344.      */
  345.     public function op($channel$nickname$priority = SMARTIRC_MEDIUM)
  346.     {
  347.         return $this->mode($channel'+o '.$nickname$priority);
  348.     }
  349.  
  350.     /**
  351.      * deops an user in the given channel
  352.      *
  353.      * @param string $channel 
  354.      * @param string $nickname 
  355.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  356.      * @return Net_SmartIRC 
  357.      * @api
  358.      */
  359.     public function deop($channel$nickname$priority = SMARTIRC_MEDIUM)
  360.     {
  361.         return $this->mode($channel'-o '.$nickname$priority);
  362.     }
  363.  
  364.     /**
  365.      * hops an user in the given channel
  366.      *
  367.      * @param string $channel 
  368.      * @param string $nickname 
  369.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  370.      * @return Net_SmartIRC 
  371.      * @api
  372.      */
  373.     public function hop($channel$nickname$priority = SMARTIRC_MEDIUM)
  374.     {
  375.         return $this->mode($channel'+h '.$nickname$priority);
  376.     }
  377.  
  378.     /**
  379.      * dehops an user in the given channel
  380.      *
  381.      * @param string $channel 
  382.      * @param string $nickname 
  383.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  384.      * @return Net_SmartIRC 
  385.      * @api
  386.      */
  387.     public function dehop($channel$nickname$priority = SMARTIRC_MEDIUM)
  388.     {
  389.         return $this->mode($channel'-h '.$nickname$priority);
  390.     }
  391.  
  392.     /**
  393.      * voice a user in the given channel
  394.      *
  395.      * @param string $channel 
  396.      * @param string $nickname 
  397.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  398.      * @return Net_SmartIRC 
  399.      * @api
  400.      */
  401.     public function voice($channel$nickname$priority = SMARTIRC_MEDIUM)
  402.     {
  403.         return $this->mode($channel'+v '.$nickname$priority);
  404.     }
  405.  
  406.     /**
  407.      * devoice a user in the given channel
  408.      *
  409.      * @param string $channel 
  410.      * @param string $nickname 
  411.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  412.      * @return Net_SmartIRC 
  413.      * @api
  414.      */
  415.     public function devoice($channel$nickname$priority = SMARTIRC_MEDIUM)
  416.     {
  417.         return $this->mode($channel'-v '.$nickname$priority);
  418.     }
  419.  
  420.     /**
  421.      * bans a hostmask for the given channel or requests the current banlist
  422.      *
  423.      * The banlist will be requested if no hostmask is specified
  424.      *
  425.      * @param string $channel 
  426.      * @param string $hostmask 
  427.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  428.      * @return Net_SmartIRC 
  429.      * @api
  430.      */
  431.     public function ban($channel$hostmask = null$priority = SMARTIRC_MEDIUM)
  432.     {
  433.         if ($hostmask !== null{
  434.             $this->mode($channel'+b '.$hostmask$priority);
  435.         else {
  436.             $this->mode($channel'b'$priority);
  437.         }
  438.         return $this;
  439.     }
  440.  
  441.     /**
  442.      * unbans a hostmask on the given channel
  443.      *
  444.      * @param string $channel 
  445.      * @param string $hostmask 
  446.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  447.      * @return Net_SmartIRC 
  448.      * @api
  449.      */
  450.     public function unban($channel$hostmask$priority = SMARTIRC_MEDIUM)
  451.     {
  452.         return $this->mode($channel'-b '.$hostmask$priority);
  453.     }
  454.  
  455.     /**
  456.      * invites a user to the specified channel
  457.      *
  458.      * @param string $nickname 
  459.      * @param string $channel 
  460.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  461.      * @return Net_SmartIRC 
  462.      * @api
  463.      */
  464.     public function invite($nickname$channel$priority = SMARTIRC_MEDIUM)
  465.     {
  466.         return $this->send('INVITE '.$nickname.' '.$channel$priority);
  467.     }
  468.  
  469.     /**
  470.      * changes the own nickname
  471.      *
  472.      * Trys to set a new nickname, nickcollisions are handled.
  473.      *
  474.      * @param string $newnick 
  475.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  476.      * @return Net_SmartIRC 
  477.      * @api
  478.      */
  479.     public function changeNick($newnick$priority = SMARTIRC_MEDIUM)
  480.     {
  481.         $this->_nick $newnick;
  482.         return $this->send('NICK '.$newnick$priority);
  483.     }
  484.  
  485.     /**
  486.      * requests a 'WHO' from the specified target
  487.      *
  488.      * @param string $target 
  489.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  490.      * @return Net_SmartIRC 
  491.      * @api
  492.      */
  493.     public function who($target$priority = SMARTIRC_MEDIUM)
  494.     {
  495.         return $this->send('WHO '.$target$priority);
  496.     }
  497.  
  498.     /**
  499.      * requests a 'WHOIS' from the specified target
  500.      *
  501.      * @param string $target 
  502.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  503.      * @return Net_SmartIRC 
  504.      * @api
  505.      */
  506.     public function whois($target$priority = SMARTIRC_MEDIUM)
  507.     {
  508.         return $this->send('WHOIS '.$target$priority);
  509.     }
  510.  
  511.     /**
  512.      * requests a 'WHOWAS' from the specified target
  513.      * (if he left the IRC network)
  514.      *
  515.      * @param string $target 
  516.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  517.      * @return Net_SmartIRC 
  518.      * @api
  519.      */
  520.     public function whowas($target$priority = SMARTIRC_MEDIUM)
  521.     {
  522.         return $this->send('WHOWAS '.$target$priority);
  523.     }
  524.  
  525.     /**
  526.      * sends QUIT to IRC server and disconnects
  527.      *
  528.      * @param string $quitmessage optional quitmessage
  529.      * @param integer $priority message priority, default is SMARTIRC_CRITICAL
  530.      * @return Net_SmartIRC 
  531.      * @api
  532.      */
  533.     public function quit($quitmessage = null$priority = SMARTIRC_CRITICAL)
  534.     {
  535.         if ($quitmessage !== null{
  536.             $this->send('QUIT :'.$quitmessage$priority);
  537.         else {
  538.             $this->send('QUIT'$priority);
  539.         }
  540.  
  541.         return $this->disconnect(true);
  542.     }
  543. }

Documentation generated on Thu, 25 Jul 2019 12:49:08 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.