BeBot - An Anarchy Online and Age Of Conan chat automaton

Archive => Anarchy Online Archive => BeBot 0.2 support => Topic started by: Zarkingu on June 02, 2005, 02:37:25 pm

Title: Trouble with modified module
Post by: Zarkingu on June 02, 2005, 02:37:25 pm
I've been modifying some of the modules to limit who got access to the different commands. I got 3 different groups at the moment (Superadmin, Admin, Raidleader).

All of a sudden my loot module decided to kick everyone that do not have access to the commands from privategroup. I've been checking the module over and over again, but can't find whats wrong.
Here is what it looks like


<?
/*
* Loot Module for BE Bot <http://bebot.fieses.net>
* Module coded by Craized <http://www.craized.net>

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

$loot = new Rolls($bot);


$commands["tell"]["rem"] = &$loot;
$commands["tell"]["add"] = &$loot;
$commands["pgmsg"]["loot"] = &$loot;
$commands["pgmsg"]["add"] = &$loot;
$commands["pgmsg"]["rem"] = &$loot;
$commands["pgmsg"]["result"] = &$loot;
$commands["pgmsg"]["mode"] = &$loot;
$commands["pgmsg"]["list"] = &$loot;
$commands["pgmsg"]["clear"] = &$loot;

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

    /*
    Constructor:
    Hands over a referance to the "Bot" class.
    */
    function Rolls (&$bot) {
        $this -> bot = &$bot;
        $this -> mode = "multi";
        if(!$this -> bot -> highlight_color) {
            $this -> highlight = "<font color=#CB11C9>";
            } else {

            $this -> highlight = "<font color=" . $this -> bot -> highlight_color . ">";
        }
    }

    /*
    This gets called on a tell with the command
    */
    function tell($name, $msg) {
        $highlight = $this -> highlight;
        if(preg_match("/^" . $this -> bot -> commpre . "rem ([0-9]+)/i", $msg, $info)) {
            unset($this -> loot[$info[1]][$name]);
            $this -> bot -> send_pgroup($highlight . $name . "</font> removed from rolls in slot$highlight #" . $info[1]);
            $this -> bot -> send_tell($name, $highlight . $name . " </font>removed from rolls in slot$highlight #" . $info[1]);
        }
        if(preg_match("/^" . $this -> bot -> commpre . "add ([0-9]+)/i", $msg, $info)) {
            $this -> add($name, $info[1]);
            $this -> bot -> send_tell($name, $this -> addmsg);
        }
    }

    /*
    This gets called on a msg in the privgroup with the command
    */
    function pgmsg($name, $msg) {
    if ( ($this -> bot -> admin -> in_group($name, "superadmin")) or ($this -> bot -> admin -> in_group($name, "admin")) or ($this -> bot -> admin -> in_group($name, "raidleader")) ) {
        $highlight = $this -> highlight;
        if(preg_match("/^" . $this -> bot -> commpre . "loot (.*)/i", $msg, $info)) {
            $this -> loot($info[1], $name);
        }
        }

        if(preg_match("/^" . $this -> bot -> commpre . "add ([0-9]+)/i", $msg, $info)) {
            $this -> add($name, $info[1]);
        }
        if ( ($this -> bot -> admin -> in_group($name, "superadmin")) or ($this -> bot -> admin -> in_group($name, "admin")) or  ($this -> bot -> raidleader -> in_group($name, "raidleader")) ) {
        if(preg_match("/^" . $this -> bot -> commpre . "list/i", $msg)) {
            $this -> rlist();
        }
        }

   if ( ($this -> bot -> admin -> in_group($name, "superadmin")) or ($this -> bot -> admin -> in_group($name, "admin")) or ($this -> bot -> admin -> in_group($name, "raidleader")) ) {
        if(preg_match("/^" . $this -> bot -> commpre . "mode ?(.*)/i", $msg, $info)) {
            if(!$info[1]) {
                $this -> bot -> send_pgroup("Loot mode currently set to$highlight " . $this -> mode . "</font>.");
            }
            if(!$this -> lead || $this -> bot -> commands[pgmsg][leader] -> raidleader == $name || $this -> bot -> admin -> in_group($name, "raidleader") || $this -> bot -> admin -> in_group($name, "admin")) {
                if(!$this -> lead) {
                    if($info[1] == single) {
                        $this -> mode = "single";
                        $this -> bot -> send_pgroup("Roll mode changed to$highlight single loot</font>.");
                    } else if($info[1] == multi) {
                        $this -> mode = "multi";
                        $this -> bot -> send_pgroup("Roll mode changed to$highlight multiple loot</font>.");
                    }
                    } else {
                    $this -> bot -> send_pgroup("You cannot change the loot mode while rolling is in progress.");
                }
            }
        }
        }

        if(preg_match("/^" . $this -> bot -> commpre . "rem ([0-9]+)/i", $msg, $info)) {
            unset($this -> loot[$info[1]][$name]);
            $this -> bot -> send_pgroup($highlight . $name . "</font> removed from rolls in slot$highlight #" . $info[1]);
        }

        if ( ($this -> bot -> admin -> in_group($name, "superadmin")) or ($this -> bot -> admin -> in_group($name, "admin")) or ($this -> bot -> admin -> in_group($name, "raidleader")) ) {
        if(preg_match("/^" . $this -> bot -> commpre . "result/i", $msg)) {
            if($this -> lead == $name || !$this -> lead || $this -> bot -> commands[pgmsg][leader] -> raidleader == $name || $this -> bot -> admin -> in_group($name, "raidleader") || $this -> bot -> admin -> in_group($name, "admin")) {
                $this -> roll($name);
            }
        }
        }

        if ( ($this -> bot -> admin -> in_group($name, "superadmin")) or ($this -> bot -> admin -> in_group($name, "admin")) or ($this -> bot -> admin -> in_group($name, "raidleader")) ) {
        if(preg_match("/^" . $this -> bot -> commpre . "clear/i", $msg)) {
            if($this -> lead == $name || !$this -> lead || $this -> bot -> commands[pgmsg][leader] -> raidleader == $name || $this -> bot -> admin -> in_group($name, "raidleader") || $this -> bot -> admin -> in_group($name, "admin")) {
                unset($this -> loot);
                unset($this -> lead);
                $this -> bot -> send_pgroup($highlight . $name . "</font><font color=#FF0000> cancelled the loot rolls in progress");
            }
        }
        }

      else
         {
      // Error message if a non admin tries to use loot commands.
      $this -> bot -> send_pgroup("</font><font color=#DB9C15>You must be an admin to do this</font>");
      }

    }

    function add($name, $slot) {
        $highlight = $this -> highlight;
        unset($present);
        if($this -> loot[$slot]) {
            if($this -> mode == 'single') {
                $slots = array_keys($this -> loot);
                foreach($slots as $key=>$sslot) {
                    $list = array_keys($this -> loot[$sslot]);
                    foreach($list as $playerslot=>$player) {
                        if($player == $name) {
                            unset($this -> loot[$sslot][$player]);
                            $present = true;
                        }
                    }
                }
                if($present == true) {
                    $this -> addmsg = $highlight . "$name</font> changed to slot$highlight #$slot</font>";
                    } else {
                    $this -> addmsg = $highlight . "$name</font> assigned to slot$highlight #$slot</font>";
                }
                $this -> loot[$slot][$name] = true;
                } else {
                $this -> loot[$slot][$name] = true;
                $this -> addmsg = $highlight . "$name</font> assiged to slot$highlight #$slot</font>";
            }
            } else {
            $this -> addmsg = "There is currently no roll in slot $slot";
        }
        $this -> bot -> send_pgroup($this -> addmsg);
    }

    function loot($msg, $name) {
        $highlight = $this -> highlight;
        if($this -> lead == $name || !$this -> lead) {
            $this -> lead = $name;
            $count = count($this -> loot)+1;
            $this -> loot[$count][item] = $msg;
            $this -> bot -> send_pgroup($highlight . $msg . "</font> being rolled in slot$highlight #" . $count);
        }
    }

    function roll($name){
        $highlight = $this -> highlight;
        $num = 1;
        if($this -> bot -> commands[pgmsg][leader] -> raidleader == $name || $this -> bot -> admin -> in_group($name, "raidleader") || $this -> bot -> admin -> in_group($name, "admin") || $this -> lead == $name || !$this -> lead) {
            foreach($this -> loot as $slot) {
                unset($winner);
                $users = array();
                $item = $slot[item];
                unset($slot[item]);
                $list = $slot;
                $users = array_keys($slot);
                $rolling = $users;
                $count = count($slot)-1;
                for($i = 1; $i <= 10000; $i++) {
                    $list[$users[rand(0, $count)]] += 1;
                }
                natsort($list);
                foreach($list as $name => $points) {
                    $winner = $name;
                }
                if(!$winner) {
                    $winner = Nobody;
                }
                $this -> bot -> send_pgroup($highlight . $winner . " </font>won the roll for$highlight " . $item . " </font>in slot$highlight #" . $num . "!");
                unset($this -> loot[$num]);
                unset($this -> lead);
                $num++;
            }
        }
    }

    function rlist() {
        $highlight = $this -> highlight;
        $num = 0;
        foreach($this -> loot as $slot) {
            unset($msg);
            $num++;
            $msg .= "Rolling on item$highlight $slot[item]</font> in slot$highlight #$num</font>:";
            if(count($slot) == 1) {
                $msg .= $highlight . " Nobody included";
                } else {
                $list = array_keys($slot);
                foreach($list as $key=>$player) {
                    if($player != "item") {
                        $msg .= "$highlight [$player]</font>";
                    }
                }
            }
            $this -> bot -> send_pgroup($msg);
        }
    }
}
?>


I'm not all that good in PHP, so might be something obvious I'm missing. So please bare with me :)
Title: Trouble with modified module
Post by: Zacix on June 02, 2005, 02:51:58 pm
There's no need to check if the user is in "superadmin" group, that is automatically checked every time you do the admin->in_group(...). Also, I use || instead of 'or'...but don't really know what's allowed in PHP.
Title: Trouble with modified module
Post by: Derroylo on June 02, 2005, 03:02:15 pm
Well i changed the loot module too cuz it spames me to much when you have 50ppls on a raid and doing !add $ in the bot. When you are interested you can test my loot system :)

Download (http://www.nne-clan.clanintern.de/bebot/loot.zip)
Title: Trouble with modified module
Post by: Zarkingu on June 02, 2005, 03:25:46 pm
Seems like I found the problem.
Changed

($this -> bot -> raidleader -> in_group($name, "raidleader"))

to

($this -> bot -> admin -> in_group($name, "raidleader"))

I know that some programing languages use || instead of or. Or seems to work fins in PHP tho, atleast not getting any errors :D
SimplePortal 2.3.7 © 2008-2024, SimplePortal