BeBot - An Anarchy Online and Age Of Conan chat automaton

General => Feedback and Suggestions => Topic started by: kuznechik on February 27, 2007, 01:15:44 pm

Title: AFK module fixes/little tweak to Main.php
Post by: kuznechik on February 27, 2007, 01:15:44 pm
Set myself afk and found bot is spamming "Kuznechik is AFK" nonstop. After looking into code realised it didn't checked if bot_name written in lowercase with 1st letter being capital.
Fix:
Code: [Select]
--- AFK.php.orig        Wed Feb 21 21:43:50 2007
+++ AFK.php     Tue Feb 27 14:50:36 2007
@@ -80,7 +80,7 @@
        }

        function privgroup($name, $msg) {
-               if($name != $this -> bot -> botname) {
+               if($name != ucfirst(strtolower($this -> bot -> botname))) {
                        if(preg_match("/^" . $this -> bot -> commpre . "afk (.*)/i", $msg, $afkmsg)) {
                                $this -> gone($name, $afkmsg[1]);
                                $this -> bot -> send_pgroup($name . " is now AFK.");
@@ -98,7 +98,7 @@
        }

        function gmsg($name, $group, $msg) {
-               if($name != $this -> bot -> botname) {
+               if($name != ucfirst(strtolower($this -> bot -> botname))) {
                        if(preg_match("/^" . $this -> bot -> commpre . "afk (.*)/i", $msg, $afkmsg)) {
                                $this -> gone($name, $afkmsg[1]);
                                $this -> bot -> send_gc($name . " is now AFK.");

Alternate fix:
Code: [Select]
--- Main.php.orig       Wed Feb 21 21:25:12 2007
+++ Main.php    Tue Feb 27 14:58:25 2007
@@ -122,7 +122,7 @@
 global $db;
 global $bot;

-
+$bot_name = ucfirst(strtolower($bot_name));
 $db = new MySQL();
 $aoc = new AOChat("callback");
 $bot = new Bot($ao_username, $ao_password, $bot_name, $dimension, $bot_version, $bot_version_name, $other_bots, $aoc, $irc, $db, $commands, $command_prefix, $cron, $cron_delay, $tell_delay, $max_blobsize, $reconnect_time, $guildbot, $guild_name, $guild_id, $guild_relay_target, $log, $log_path);

I myself went with alternate fix due to more global fix of things.
Also due to pregmatch empty "!afk" will fail since you need a space after.
Fix for it:
Code: [Select]
--- AFK.php.orig        Wed Feb 21 21:43:50 2007
+++ AFK.php     Tue Feb 27 15:11:27 2007
@@ -73,16 +73,16 @@
        }

        function tell($name, $msg) {
-               if(preg_match("/^" . $this -> bot -> commpre . "afk (.*)/i", $msg, $afkmsg)) {
-                       $this -> gone($name, $afkmsg[1]);
+               if(preg_match("/^" . $this -> bot -> commpre . "afk( *)(.*)/i", $msg, $afkmsg)) {
+                       $this -> gone($name, $afkmsg[2]);
                        $this -> bot -> send_gc($name . " is now AFK.");
                }
        }

        function privgroup($name, $msg) {
                if($name != $this -> bot -> botname) {
-                       if(preg_match("/^" . $this -> bot -> commpre . "afk (.*)/i", $msg, $afkmsg)) {
-                               $this -> gone($name, $afkmsg[1]);
+                       if(preg_match("/^" . $this -> bot -> commpre . "afk( *)(.*)/i", $msg, $afkmsg)) {
+                               $this -> gone($name, $afkmsg[2]);
                                $this -> bot -> send_pgroup($name . " is now AFK.");
                        } else if($this -> acheck($name)) {
                                $this -> back($name);
@@ -99,8 +99,8 @@

        function gmsg($name, $group, $msg) {
                if($name != $this -> bot -> botname) {
-                       if(preg_match("/^" . $this -> bot -> commpre . "afk (.*)/i", $msg, $afkmsg)) {
-                               $this -> gone($name, $afkmsg[1]);
+                       if(preg_match("/^" . $this -> bot -> commpre . "afk( *)(.*)/i", $msg, $afkmsg)) {
+                               $this -> gone($name, $afkmsg[2]);
                                $this -> bot -> send_gc($name . " is now AFK.");
                        } else if($this -> acheck($name)) {
                                $this -> back($name);
Title: Re: AFK module fixes/little tweak to Main.php
Post by: Vhab on February 27, 2007, 04:03:57 pm
Code: [Select]
if($name != ucfirst(strtolower($this -> bot -> botname))) {
the strtolower is kinda pointless there since it's gonna be converted to ucfirst right after that.
better way to make sure both match:

Code: [Select]
if(strtolower($name) != strtolower($this -> bot -> botname)) {
Title: Re: AFK module fixes/little tweak to Main.php
Post by: kuznechik on February 27, 2007, 04:28:16 pm
Well, ingame names are in UCFirst() format... And I dunno why, but all bebot modules are covered with ucfirst(strtolower(..))

From php.net manual
Code: [Select]
Example 2367. ucfirst() example
<?php
$foo 
'hello world!';
$foo ucfirst($foo);            // Hello world!

$bar 'HELLO WORLD!';
$bar ucfirst($bar);            // HELLO WORLD!
$bar ucfirst(strtolower($bar)); // Hello world!
?>
Title: Re: AFK module fixes/little tweak to Main.php
Post by: Nytridr on May 26, 2007, 07:20:27 am
not sure if this was fixed at one time or not in the svn but it is broke again. 

Code: [Select]
[Rising Sun (AoF)] Metanyt: !afk test
[Rising Sun (AoF)] Rsbot: Metanyt is now AFK.
[Rising Sun (AoF)] Rsbot: Metanyt is AFK (test).
[Rising Sun (AoF)] Rsbot: Metanyt is AFK (test).
[Rising Sun (AoF)] Rsbot: Metanyt is AFK (test).
[Rising Sun (AoF)] Rsbot: Metanyt is AFK (test).
[Rising Sun (AoF)] Rsbot: Metanyt is AFK (test).
[Rising Sun (AoF)] Metanyt: oh wow
[Rising Sun (AoF)] Rsbot: Metanyt is AFK (test).
[Rising Sun (AoF)] Rsbot: Metanyt is back.

just figured someone can fix it again if they want for the snv release.
Title: Re: AFK module fixes/little tweak to Main.php
Post by: Alreadythere on May 27, 2007, 11:21:56 am
Fix applied in SVN.
SimplePortal 2.3.7 © 2008-2024, SimplePortal