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: irccommands.php,v 1.1.2.1 2003/10/10 20:20:58 meebey Exp $
  4.  * $Revision: 1.1.2.1 $
  5.  * $Author: meebey $
  6.  * $Date: 2003/10/10 20:20:58 $
  7.  *
  8.  * Copyright (c) 2002-2003 Mirco "MEEBEY" Bauer <mail@meebey.net> <http://www.meebey.net>
  9.  * 
  10.  * Full LGPL License: <http://www.meebey.net/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. {
  28.     /**
  29.      * sends a new message
  30.      *
  31.      * Sends a message to a channel or user.
  32.      *
  33.      * @see DOCUMENTATION
  34.      * @param integer $type specifies the type, like QUERY/ACTION or CTCP see 'Message Types'
  35.      * @param string $destination can be a user or channel
  36.      * @param string $message the message
  37.      * @return boolean 
  38.      * @access public
  39.      */
  40.     function message($type$destination$message$priority = SMARTIRC_MEDIUM)
  41.     {
  42.         switch ($type{
  43.             case SMARTIRC_TYPE_CHANNEL:
  44.             case SMARTIRC_TYPE_QUERY:
  45.                 $this->_send('PRIVMSG '.$destination.' :'.$message$priority);
  46.             break;
  47.             case SMARTIRC_TYPE_ACTION:
  48.                 $this->_send('PRIVMSG '.$destination.' :'.chr(1).'ACTION '.$message.chr(1)$priority);
  49.             break;
  50.             case SMARTIRC_TYPE_NOTICE:
  51.                 $this->_send('NOTICE '.$destination.' :'.$message$priority);
  52.             break;
  53.             case SMARTIRC_TYPE_CTCP// backwards compatibilty
  54.             case SMARTIRC_TYPE_CTCP_REPLY:
  55.                 $this->_send('NOTICE '.$destination.' :'.chr(1).$message.chr(1)$priority);
  56.             break;
  57.             case SMARTIRC_TYPE_CTCP_REQUEST:
  58.                 $this->_send('PRIVMSG '.$destination.' :'.chr(1).$message.chr(1)$priority);
  59.             break;
  60.             default:
  61.                 return false;
  62.         }
  63.             
  64.         return true;
  65.     }
  66.     
  67.     /**
  68.      * returns an object reference to the specified channel
  69.      *
  70.      * If the channel does not exist (because not joint) false will be returned.
  71.      *
  72.      * @param string $channelname 
  73.      * @return object reference to the channel object
  74.      * @access public
  75.      */
  76.     function &channel($channelname)
  77.     {
  78.         if (isset($this->_channels[strtolower($channelname)])) {
  79.             return $this->_channels[strtolower($channelname)];
  80.         else {
  81.             return false;
  82.         }
  83.     }
  84.     
  85.     // <IRC methods>
  86.     /**
  87.      * Joins one or more IRC channels with an optional key.
  88.      *
  89.      * @param mixed $channelarray 
  90.      * @param string $key 
  91.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  92.      * @return void 
  93.      * @access public
  94.      */
  95.     function join($channelarray$key = null$priority = SMARTIRC_MEDIUM)
  96.     {
  97.         if (!is_array($channelarray)) {
  98.             $channelarray = array($channelarray);
  99.         }
  100.         
  101.         $channellist implode(','$channelarray);
  102.         
  103.         if ($key !== null{
  104.             $this->_send('JOIN '.$channellist.' '.$key$priority);
  105.         else {
  106.             $this->_send('JOIN '.$channellist$priority);
  107.         }
  108.     }
  109.     
  110.     /**
  111.      * parts from one or more IRC channels with an optional reason
  112.      *
  113.      * @param mixed $channelarray 
  114.      * @param string $reason 
  115.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  116.      * @return void 
  117.      * @access public
  118.      */
  119.     function part($channelarray$reason = null$priority = SMARTIRC_MEDIUM)
  120.     {
  121.         if (!is_array($channelarray)) {
  122.             $channelarray = array($channelarray);
  123.         }
  124.         
  125.         $channellist implode(','$channelarray);
  126.         
  127.         if ($reason !== null{
  128.             $this->_send('PART '.$channellist.' :'.$reason$priority);
  129.         else {
  130.             $this->_send('PART '.$channellist$priority);
  131.         }
  132.     }
  133.     
  134.     /**
  135.      * Kicks one or more user from an IRC channel with an optional reason.
  136.      *
  137.      * @param string $channel 
  138.      * @param mixed $nicknamearray 
  139.      * @param string $reason 
  140.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  141.      * @return void 
  142.      * @access public
  143.      */
  144.     function kick($channel$nicknamearray$reason = null$priority = SMARTIRC_MEDIUM)
  145.     {
  146.         if (!is_array($nicknamearray)) {
  147.             $nicknamearray = array($nicknamearray);
  148.         }
  149.         
  150.         $nicknamelist implode(','$nicknamearray);
  151.         
  152.         if ($reason !== null{
  153.             $this->_send('KICK '.$channel.' '.$nicknamelist.' :'.$reason$priority);
  154.         else {
  155.             $this->_send('KICK '.$channel.' '.$nicknamelist$priority);
  156.         }
  157.     }
  158.     
  159.     /**
  160.      * gets a list of one ore more channels
  161.      *
  162.      * Requests a full channellist if $channelarray is not given.
  163.      * (use it with care, usualy its a looooong list)
  164.      *
  165.      * @param mixed $channelarray 
  166.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  167.      * @return void 
  168.      * @access public
  169.      */
  170.     function getList($channelarray = null$priority = SMARTIRC_MEDIUM)
  171.     {
  172.         if ($channelarray !== null{
  173.             if (!is_array($channelarray)) {
  174.                 $channelarray = array($channelarray);
  175.             }
  176.             
  177.             $channellist implode(','$channelarray);
  178.             $this->_send('LIST '.$channellist$priority);
  179.         else {
  180.             $this->_send('LIST'$priority);
  181.         }
  182.     }
  183.  
  184.     /**
  185.      * requests all nicknames of one or more channels
  186.      *
  187.      * The requested nickname list also includes op and voice state
  188.      *
  189.      * @param mixed $channelarray 
  190.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  191.      * @return void 
  192.      * @access public
  193.      */
  194.     function names($channelarray = null$priority = SMARTIRC_MEDIUM)
  195.     {
  196.         if ($channelarray !== null{
  197.             if (!is_array($channelarray)) {
  198.                 $channelarray = array($channelarray);
  199.             }
  200.             
  201.             $channellist implode(','$channelarray);
  202.             $this->_send('NAMES '.$channellist$priority);
  203.         else {
  204.             $this->_send('NAMES'$priority);
  205.         }
  206.     }
  207.     
  208.     /**
  209.      * sets a new topic of a channel
  210.      *
  211.      * @param string $channel 
  212.      * @param string $newtopic 
  213.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  214.      * @return void 
  215.      * @access public
  216.      */
  217.     function setTopic($channel$newtopic$priority = SMARTIRC_MEDIUM)
  218.     {
  219.         $this->_send('TOPIC '.$channel.' :'.$newtopic$priority);
  220.     }
  221.     
  222.     /**
  223.      * gets the topic of a channel
  224.      *
  225.      * @param string $channel 
  226.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  227.      * @return void 
  228.      * @access public
  229.      */
  230.     function getTopic($channel$priority = SMARTIRC_MEDIUM)
  231.     {
  232.         $this->_send('TOPIC '.$channel$priority);
  233.     }
  234.     
  235.     /**
  236.      * sets or gets the mode of an user or channel
  237.      *
  238.      * Changes/requests the mode of the given target.
  239.      *
  240.      * @param string $target the target, can be an user (only yourself) or a channel
  241.      * @param string $newmode the new mode like +mt
  242.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  243.      * @return void 
  244.      * @access public
  245.      */
  246.     function mode($target$newmode = null$priority = SMARTIRC_MEDIUM)
  247.     {
  248.         if ($newmode !== null{
  249.             $this->_send('MODE '.$target.' '.$newmode$priority);
  250.         else {
  251.             $this->_send('MODE '.$target$priority);
  252.         }
  253.     }
  254.     
  255.     /**
  256.      * ops an user in the given channel
  257.      *
  258.      * @param string $channel 
  259.      * @param string $nickname 
  260.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  261.      * @return void 
  262.      * @access public
  263.      */
  264.     function op($channel$nickname$priority = SMARTIRC_MEDIUM)
  265.     {
  266.         $this->mode($channel'+o '.$nickname$priority);
  267.     }
  268.     
  269.     /**
  270.      * deops an user in the given channel
  271.      *
  272.      * @param string $channel 
  273.      * @param string $nickname 
  274.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  275.      * @return void 
  276.      * @access public
  277.      */
  278.     function deop($channel$nickname$priority = SMARTIRC_MEDIUM)
  279.     {
  280.         $this->mode($channel'-o '.$nickname$priority);
  281.     }
  282.     
  283.     /**
  284.      * voice a user in the given channel
  285.      *
  286.      * @param string $channel 
  287.      * @param string $nickname 
  288.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  289.      * @return void 
  290.      * @access public
  291.      */
  292.     function voice($channel$nickname$priority = SMARTIRC_MEDIUM)
  293.     {
  294.         $this->mode($channel'+v '.$nickname$priority);
  295.     }
  296.     
  297.     /**
  298.      * devoice a user in the given channel
  299.      *
  300.      * @param string $channel 
  301.      * @param string $nickname 
  302.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  303.      * @return void 
  304.      * @access public
  305.      */
  306.     function devoice($channel$nickname$priority = SMARTIRC_MEDIUM)
  307.     {
  308.         $this->mode($channel'-v '.$nickname$priority);
  309.     }
  310.     
  311.     /**
  312.      * bans a hostmask for the given channel or requests the current banlist
  313.      *
  314.      * The banlist will be requested if no hostmask is specified
  315.      *
  316.      * @param string $channel 
  317.      * @param string $hostmask 
  318.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  319.      * @return void 
  320.      * @access public
  321.      */
  322.     function ban($channel$hostmask = null$priority = SMARTIRC_MEDIUM)
  323.     {
  324.         if ($hostmask !== null{
  325.             $this->mode($channel'+b '.$hostmask$priority);
  326.         else {
  327.             $this->mode($channel'b'$priority);
  328.         }
  329.     }
  330.     
  331.     /**
  332.      * unbans a hostmask on the given channel
  333.      *
  334.      * @param string $channel 
  335.      * @param string $hostmask 
  336.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  337.      * @return void 
  338.      * @access public
  339.      */
  340.     function unban($channel$hostmask$priority = SMARTIRC_MEDIUM)
  341.     {
  342.         $this->mode($channel'-b '.$hostmask$priority);
  343.     }
  344.     
  345.     /**
  346.      * invites a user to the specified channel
  347.      *
  348.      * @param string $nickname 
  349.      * @param string $channel 
  350.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  351.      * @return void 
  352.      * @access public
  353.      */
  354.     function invite($nickname$channel$priority = SMARTIRC_MEDIUM)
  355.     {
  356.         $this->_send('INVITE '.$nickname.' '.$channel$priority);
  357.     }
  358.     
  359.     /**
  360.      * changes the own nickname
  361.      *
  362.      * Trys to set a new nickname, nickcollisions are handled.
  363.      *
  364.      * @param string $newnick 
  365.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  366.      * @return void 
  367.      * @access public
  368.      */
  369.     function changeNick($newnick$priority = SMARTIRC_MEDIUM)
  370.     {
  371.         $this->_send('NICK '.$newnick$priority);
  372.         $this->_nick $newnick;
  373.     }
  374.     
  375.     /**
  376.      * requests a 'WHO' from the specified target
  377.      *
  378.      * @param string $target 
  379.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  380.      * @return void 
  381.      * @access public
  382.      */
  383.     function who($target$priority = SMARTIRC_MEDIUM)
  384.     {
  385.         $this->_send('WHO '.$target$priority);
  386.     }
  387.     
  388.     /**
  389.      * requests a 'WHOIS' from the specified target
  390.      *
  391.      * @param string $target 
  392.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  393.      * @return void 
  394.      * @access public
  395.      */
  396.     function whois($target$priority = SMARTIRC_MEDIUM)
  397.     {
  398.         $this->_send('WHOIS '.$target$priority);
  399.     }
  400.     
  401.     /**
  402.      * requests a 'WHOWAS' from the specified target
  403.      * (if he left the IRC network)
  404.      *
  405.      * @param string $target 
  406.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  407.      * @return void 
  408.      * @access public
  409.      */
  410.     function whowas($target$priority = SMARTIRC_MEDIUM)
  411.     {
  412.         $this->_send('WHOWAS '.$target$priority);
  413.     }
  414.     
  415.     /**
  416.      * sends QUIT to IRC server and disconnects
  417.      *
  418.      * @param string $quitmessage optional quitmessage
  419.      * @param integer $priority message priority, default is SMARTIRC_MEDIUM
  420.      * @return void 
  421.      * @access public
  422.      */
  423.     function quit($quitmessage = null$priority = SMARTIRC_MEDIUM)
  424.     {
  425.         if ($quitmessage !== null{
  426.             $this->_send('QUIT :'.$quitmessage$priority);
  427.         else {
  428.             $this->_send('QUIT'$priority);
  429.         }
  430.     }
  431. }
  432. ?>

Documentation generated on Mon, 11 Mar 2019 14:19:45 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.