collapse collapse
* User Info
 
 
Welcome, Guest. Please login or register.
* Search

* Board Stats
  • stats Total Members: 989
  • stats Total Posts: 18366
  • stats Total Topics: 2501
  • stats Total Categories: 7
  • stats Total Boards: 35
  • stats Most Online: 1144

Author Topic: AFK module fixes/little tweak to Main.php  (Read 6019 times)

0 Members and 3 Guests are viewing this topic.

Offline kuznechik

  • Contributor
  • *******
  • Posts: 60
  • Karma: +0/-0
AFK module fixes/little tweak to Main.php
« 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);
Kuznechik, proud bot admin of Disciples of Omni-Tek, Rimor.

Offline Vhab

  • Contributor
  • *******
  • Posts: 180
  • Karma: +0/-0
    • VhaBot Forum
Re: AFK module fixes/little tweak to Main.php
« Reply #1 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)) {

Offline kuznechik

  • Contributor
  • *******
  • Posts: 60
  • Karma: +0/-0
Re: AFK module fixes/little tweak to Main.php
« Reply #2 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!
?>
« Last Edit: February 27, 2007, 04:32:07 pm by kuznechik »
Kuznechik, proud bot admin of Disciples of Omni-Tek, Rimor.

Offline Nytridr

  • BeBot Expert
  • ****
  • Posts: 262
  • Karma: +0/-0
    • Rising Sun
Re: AFK module fixes/little tweak to Main.php
« Reply #3 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.
Co-Prez of Rising Sun RK1 (1st & only org I will ever belong to)

Offline Alreadythere

  • BeBot Maintainer
  • BeBot Hero
  • ******
  • Posts: 1288
  • Karma: +0/-0
Re: AFK module fixes/little tweak to Main.php
« Reply #4 on: May 27, 2007, 11:21:56 am »
Fix applied in SVN.

 

* Recent Posts
Com bot module by bitnykk
[November 25, 2024, 05:36:11 pm ]


0.8.x updates for AO by bitnykk
[June 23, 2024, 03:19:47 pm ]


0.8.x updates for AoC by bitnykk
[June 23, 2024, 03:19:44 pm ]


[AoC] special char for items module by bitnykk
[February 09, 2024, 09:41:18 pm ]


BeBot still alive & kicking ! by bitnykk
[December 17, 2023, 12:58:44 am ]

* Who's Online
  • Dot Guests: 110
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.
* Forum Staff
bitnykk admin bitnykk
Administrator
Khalem admin Khalem
Administrator
WeZoN gmod WeZoN
Global Moderator
SimplePortal 2.3.7 © 2008-2024, SimplePortal