Archive > 0.4.x Custom/Unofficial Modules

Updated Topic.php

(1/3) > >>

Hyde:
I know that !topic has been a bit odd in the past with various versions of BeBot. I grabbed all the ones I found and "fixed" the one that seems to be least messy for my purposes.

Again not claiming authorship, just modified some pieces to make it work with BeBot 4.1 and made a change so that its less spammy when people join the bot.


--- Code: ---<?
/*
* Topic Module for BE Bot <http://bebot.fieses.net>
* Module coded by Craized <http://www.craized.net>
... Modifications 2007-08-18 by Doctorhyde@RK2
  * Topic is now sent to you in a /tell when you join, not spammed in the
    channel. If you say "!topic" in the channel it will display normally.
  * Updated to use the 'Colors.inc' file (note: symlink or copy 'Colors.inc'
    from your "modules" to "custom/modules" if you're putting this script
    in "custom/modules").
  * Updated to use the "security -> check_access()" function instead of the
    "admin -> in_group()" function.
*/

/*
Add a "_" at the beginning of the file (_Topic.php) if you do not want it to be loaded.
*/

include_once("Colors.inc");

$topic = new Topic($bot);

$commands['pgmsg']['topic'] = &$topic;
$commands["pgjoin"][] = &$topic;

/*
The Class itself...
*/
class Topic {
    var $bot;

    /*
    Constructor:
    Hands over a referance to the "Bot" class.
    */
    function Topic (&$bot) {
        $this -> bot = &$bot;
        $this -> name = '';
    }
    /*
    This gets called on a tell with the command
    */
    function pgmsg($name, $msg) {
        if (preg_match('/^'.$this -> bot -> commpre.'topic$/i', $msg)) $c = $this -> show_topic();
        else if (preg_match('/^'.$this -> bot -> commpre.'topic clear$/i', $msg)) $c = $this -> clear($name);
        else if (preg_match('/^'.$this -> bot -> commpre.'topic (.+)/i', $msg, $info)) $c = $this -> set($name, $info['1']);
        $this -> bot -> send_pgroup($c);
    }
   
    function pgjoin($name) {
        $c = $this -> show_topic();
        $this -> bot -> send_tell($name, $c, 1);
    }
   
    function show_topic() {
        $c = (isset($this -> topic) ? 'Topic: '.Highlight($this -> topic).' [By '.Highlight($this -> name).'] ' : '').'('.Highlight(count($this -> bot -> commands['pgmsg']['online'] -> pgroup)).'/'.Highlight($this -> bot -> commands['pgmsg']['maxplayers'] -> maxplayers).' | Leader: '.Highlight((isset($this -> bot -> commands['pgmsg']['leader'] -> raidleader) ? $this -> bot -> commands['pgmsg']['leader'] -> raidleader : 'None')).'| Lock: '.Highlight(($this -> bot -> commands['pgmsg']['invite'] -> lock)).' | Invites: '.Highlight($this -> bot -> commands['pgmsg']['faction'] -> faction).')';
        return $c;
    }
   
    function set($name, $msg) {
        if($this -> bot -> commands['pgmsg']['leader'] -> raidleader == $name || $this -> bot -> security -> check_access($name, 'admin')) {
            $this -> topic = $msg;
            $this -> name = $name;
            $c = 'Topic has been set to '.Highlight($this -> topic).' by '.Highlight($name).'.';
        } else $c = 'You do not have permission to change the topic.';
        return $c;
    }
   
    function clear($name) {
        if($this -> bot -> commands['pgmsg']['leader'] -> raidleader == $name || $this -> bot -> security -> check_access($name, 'admin')) {
            unset($this -> topic);
            $this -> name = '';
            $c = 'Topic has been cleared by '.Highlight($name).'.';
        } else $c = 'You do not have permission to change the topic.';
        return $c;
    }


?>



--- End code ---

Diablo:
Im getting error on the function show topic is something missing on the end of that line?

Temar:
yes it seems to have been cut off
the 1st line in the function ends like this

--- Code: ---Highlight((isset($$

--- End code ---

Fxrluv:
im a php noob so how should that line end?

Hyde:
Sorry for that, was a bad paste. I've redone it ... let me know if its still b0rken.

Navigation

[0] Message Index

[#] Next page

Go to full version