cvs: pearbot /modules botcmds.php

[email protected] ("Mirco 'meebey' Bauer") Fri, 25 Jul 2003 16:58:07 -0000
Newsgroups php.pear.bot
Message-ID <cvsmeebey1059152287@cvsserver>
--meebey1059152287
Content-Type: text/plain

meebey		Fri Jul 25 12:58:07 2003 EDT

  Added files:                 
    /pearbot/modules	botcmds.php 
  Log:
  - first import.
  
  
--meebey1059152287
Content-Type: text/plain
Content-Disposition: attachment; filename="meebey-20030725125807.txt"


Index: pearbot/modules/botcmds.php
+++ pearbot/modules/botcmds.php
<?php
/**
 * $Id: botcmds.php,v 1.1 2003/07/25 16:58:06 meebey Exp $
 * $Revision: 1.1 $
 * $Author: meebey $
 * $Date: 2003/07/25 16:58:06 $
 *
 * Copyright (c) 2003 Nicolas CHAILLAN <[email protected]>
*/
 
class Net_SmartIRC_module_botcmds
{
    var $name = 'botcmds';
    var $description = '!* commands';
    var $author = 'Nicolas CHAILLAN <[email protected]>';
    var $license = 'LGPL';
    
    var $actionids = array();
    
    function module_init(&$irc)
    {
        $this->actionids[] = $irc->registerActionhandler(SMARTIRC_TYPE_QUERY|SMARTIRC_TYPE_NOTICE, '^!op', $this, 'give_op');
        $this->actionids[] = $irc->registerActionhandler(SMARTIRC_TYPE_QUERY|SMARTIRC_TYPE_NOTICE, '^!deop', $this, 'give_deop');
        $this->actionids[] = $irc->registerActionhandler(SMARTIRC_TYPE_QUERY|SMARTIRC_TYPE_NOTICE, '^!voice', $this, 'give_voice');
        $this->actionids[] = $irc->registerActionhandler(SMARTIRC_TYPE_QUERY|SMARTIRC_TYPE_NOTICE, '^!devoice', $this, 'give_devoice');
        $this->actionids[] = $irc->registerActionhandler(SMARTIRC_TYPE_QUERY|SMARTIRC_TYPE_NOTICE, '^!topic', $this, 'topic');
        $this->actionids[] = $irc->registerActionhandler(SMARTIRC_TYPE_QUERY|SMARTIRC_TYPE_NOTICE, '^!kick', $this, 'kick');
        $this->actionids[] = $irc->registerActionhandler(SMARTIRC_TYPE_QUERY|SMARTIRC_TYPE_NOTICE, '^!invite', $this, 'invite');
    }
    
    function module_exit(&$irc)
    {
        foreach ($this->actionids as $value) {
            $irc->unregisterActionid($value);
        }
    }

    /* !op nick1 nick2... */
    function give_op(&$irc, &$data)
    {
        global $bot;
        
        if ($bot->isAuthorized($irc, $data)) {
            $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, 'Sorry '.$data->nick.', I am not fool, I dont know you, you will not op anyone.'); 
            return;
        }
        
        if (!$irc->isOpped($data->channel)) {
            return;
        }
        
        if (($messageex_count = count($data->messageex)) > 1) {
            for ($i = 1; $i < $messageex_count; $i++) {
                $this->op($irc, $data, $data->messageex[$i]);
            }
        } else {
            $this->op($irc, $data, $data->nick);
        }
    }

    /* !deop nick1 nick2... */
    function give_deop(&$irc, &$data)
    {
        global $bot;
        
        if ($bot->isAuthorized($irc, $data)) {
            $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, 'Sorry '.$data->nick.', I am not fool, I dont know you, you will not deop anyone.'); 
            return;
        }
        
        if (!$irc->isOpped($data->channel)) {
            return;
        }
        
        if (($messageex_count = count($data->messageex)) > 1) {
            for ($i = 1; $i < $messageex_count; $i++) {
                $this->deop($irc, $data, $data->messageex[$i]);
            }
        } else {
            $this->deop($irc, $data, $data->nick);
        }
    }
    
    /* !voice nick1 nick2... */
    function give_voice(&$irc, &$data)
    {
        global $bot;
        
        if ($bot->isAuthorized($irc, $data) !== false) {
            $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, 'Sorry '.$data->nick.', I am not fool, I dont know you, you will not voice anyone.');
            return;
        }
        
        if (!$irc->isOpped($data->channel)) {
            return;
        }
        
        if (($messageex_count = count($data->messageex)) > 1) {
            for ($i = 1; $i < $messageex_count; $i++) {
                $this->voice($irc, $data, $data->messageex[$i]);
            }
        } else {
            $this->voice($irc, $data, $data->nick);
        }
        return;
    }
    
    /* !devoice nick1 nick2... */
    function give_devoice(&$irc, &$data)
    {
        global $bot;
        
        if ($bot->isAuthorized($irc, $data) !== false) {
            $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, 'Sorry '.$data->nick.', I am not fool, I dont know you, you will not devoice anyone.'); 
            return;
        }
        
        if (!$irc->isOpped($data->channel)) {
            return;
        }
        
        if (($messageex_count = count($data->messageex)) > 1) {
            for ($i = 1; $i < $messageex_count; $i++) {
                $this->devoice($irc, $data, $data->messageex[$i]);
            }
        } else {
            $this->devoice($irc, $data, $data->nick);
        }
    }
    
    /* !topic [new_topic] */
    function topic(&$irc, &$data)
    {
        global $bot;
        
        $new_topic = '';
        if ($bot->isAuthorized($irc, $data) !== false) {
            $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, 'Sorry '.$data->nick.', I am not fool, I dont know you, you will not change the topic.'); 
            return;
        }
        
        if (!$irc->isOpped($data->channel)) {
            return;
        }
        
        if (($messageex_count = count($data->messageex)) < 1) {
            return;
        } else if ($messageex_count == 1) {
            $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, 'Topic is: '.$irc->channel[strtolower($data->channel)]->topic);
            return;
        } else {
            for ($i = 1; $i < $messageex_count; $i++) {
                    $new_topic .= $data->messageex[$i].' ';
            }
        }
        
        if (!empty($new_topic)) {
            $irc->setTopic($data->channel, $new_topic);
        }
    }
    
    /* !kick nick reason */
    function kick(&$irc, &$data)
    {
        global $bot;
        
        $reason = '';
        if ($bot->isAuthorized($irc, $data) !== false) {
            $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, 'Sorry '.$data->nick.', I am not fool, I dont know you, you will not kick anyone.'); 
            return;
        }
        
        if (!$irc->isOpped($data->channel)) {
            return;
        }
        
        if (($messageex_count = count($data->messageex)) <= 2) {
            return;
        } else if ($messageex_count >= 3) {
            for ($i = 2; $i < $messageex_count; $i++) {
                $reason .= $data->messageex[$i].' ';
            }
        }
        
        $who = $data->messageex[1];
        
        if (!$irc->isJoined($data->channel, $who)) {
            $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, 'Hey, '.$who.' is not on this channel.'); 
            return;
        }
        
        if ($irc->isMe($who)) {
            $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, 'Hey, I am not fool, I will not kick myself!'); 
            return;
        }
        
        if (empty($reason)) {
            $reason = 'No reason given';
        }
        
        $irc->kick($data->channel, $who, $reason);
    }
    
    /* !invite nick */
    function invite(&$irc, &$data)
    {
        global $bot;
        
        if ($bot->isAuthorized($irc, $data) !== false) {
            $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, 'Sorry '.$data->nick.', I am not fool, I dont know you, you will not invite anyone.'); 
            return;
        }
        
        if (!$irc->isOpped($data->channel)) {
            return;
        }
        
        if (($messageex_count = count($data->messageex)) != 2) {
            return;
        } else {
            $who = $data->messageex[1];
            if ($irc->isJoined($data->channel, $who)) {
                return;
            }
            
            if ($irc->isMe($who)) {
                $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, 'Hey, I am not fool, I will not invite myself!'); 
                return;
            }
            
            $irc->invite($who, $data->channel);
        }
    }
    
    /* basic functions */
    function op(&$irc, &$data, $nick) 
    {
        if ($irc->isMe($nick)) {
            $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, 'Hey, I am not fool, I will not op myself!'); 
            return;
        }
        
        if (!$irc->isJoined($data->channel, $nick)) {
            return;
        }
        
        if (!$irc->isOpped($data->channel, $nick)) {
            $irc->op($data->channel, $nick);
        }
    }
    
    function deop(&$irc, &$data, $nick) 
    {
        if ($irc->isMe($nick)) {
            $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, 'Hey, I am not fool, I will not deop myself!'); 
            return;
        }
        
        if (!$irc->isJoined($data->channel, $nick)) {
            return;
        }
        
        if ($irc->isOpped($data->channel, $nick)) {
            $irc->deop($data->channel, $nick);
        }
    }

    function voice(&$irc, &$data, $nick) 
    {
        if ($irc->isMe($nick)) {
            $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, 'Hey, I am not fool, I will not voice myself!'); 
            return;
        }
        
        if (!$irc->isJoined($data->channel, $nick)) {
            return;
        }
        
        if (!$irc->isVoiced($data->channel, $nick)) {
            $irc->voice($data->channel, $nick);
        }
    }
    
    function devoice(&$irc, &$data, $nick) 
    {
        if ($irc->isMe($nick)) {
            $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, 'Hey, I am not fool, I will not devoice myself!'); 
            return;
        }
        
        if (!$irc->isJoined($data->channel, $nick)) {
            return;
        }
        
        if ($irc->isVoiced($data->channel, $nick)) {
            $irc->devoice($data->channel, $nick);
        }
    }
}
?>
--meebey1059152287--