L* R*
HOME FORUM DOWNLOADS
Content
  Links
     Browse SVN
     SVN Commit log
     Documentation (Wiki)
  Developers
     Taskmanager
User
Welcome, Guest. Please login or register.
Did you miss your activation email?
September 07, 2008, 10:55:49 PM

Login with username, password and session length
Search



Advanced search
Support GoPHP5.org
BeBot - An Anarchy Online/Age Of Conan chat automaton > Forum > Development > Feedback and Suggestions > Topic: AFK module fixes/little tweak to Main.php
Pages: [1]   Go Down
« previous next »
Print
Author Topic: AFK module fixes/little tweak to Main.php  (Read 427 times)
0 Members and 1 Guest are viewing this topic.
kuznechik
BeBot Contributor
Rookie
*******
Offline Offline

Gender: Male
Posts: 60



AFK module fixes/little tweak to Main.php
« on: February 27, 2007, 07:15:44 AM »

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:
--- 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:
--- 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:
--- 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);
Logged

Kuznechik, proud bot admin of Disciples of Omni-Tek, Rimor.
Vhab
BeBot Contributor
Experienced
*******
Offline Offline

Posts: 155


WWW
Re: AFK module fixes/little tweak to Main.php
« Reply #1 on: February 27, 2007, 10:03:57 AM »

Code:
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:
if(strtolower($name) != strtolower($this -> bot -> botname)) {
Logged
kuznechik
BeBot Contributor
Rookie
*******
Offline Offline

Gender: Male
Posts: 60



Re: AFK module fixes/little tweak to Main.php
« Reply #2 on: February 27, 2007, 10:28:16 AM »

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:
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, 10:32:07 AM by kuznechik » Logged

Kuznechik, proud bot admin of Disciples of Omni-Tek, Rimor.
Nytridr
Experienced
****
Offline Offline

Posts: 241


WWW
Re: AFK module fixes/little tweak to Main.php
« Reply #3 on: May 26, 2007, 12:20:27 AM »

not sure if this was fixed at one time or not in the svn but it is broke again. 

Code:
[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.
Logged
Alreadythere
BeBot Maintainer
Administrator
Grandmaster
********
Offline Offline

Posts: 1023


Re: AFK module fixes/little tweak to Main.php
« Reply #4 on: May 27, 2007, 04:21:56 AM »

Fix applied in SVN.
Logged
Pages: [1]   Go Up
Print
BeBot - An Anarchy Online/Age Of Conan chat automaton > Forum > Development > Feedback and Suggestions > Topic: AFK module fixes/little tweak to Main.php
« previous next »
 
Jump to:  

Recent
Help with online info in ...
by Barlyman
[Today at 07:56:24 PM]

BeBot v0.5.3 released (de...
by Temar
[Today at 07:51:18 PM]

Security
by Alreadythere
[September 06, 2008, 10:02:42 AM]

Probs with relay from gue...
by Temar
[September 06, 2008, 09:03:06 AM]

Raid spam in guild chat
by Temar
[September 06, 2008, 09:01:18 AM]

Org Relaying
by Nytridr
[September 06, 2008, 01:34:35 AM]

Link 2 Guilds via 2 Bots?
by Temar
[September 05, 2008, 04:22:40 PM]

SVN download
by clashbot
[September 05, 2008, 05:12:59 AM]

TWC
by Temar
[September 05, 2008, 12:27:23 AM]

How to find the guild ID?...
by Irinir
[September 03, 2008, 02:58:54 PM]
Stats
Members
Total Members: 965
Latest: morisey
Stats
Total Posts: 10414
Total Topics: 1413
Online Today: 18
Online Ever: 168
(July 01, 2007, 09:30:02 PM)
Users Online
Users: 5
Guests: 20
Total: 25
egrath
blackspell
paranoiak
Zeephonz
Barlyman

Powered by SMF 1.1.5 | SMF © 2006-2008, Simple Machines LLC
TinyPortal v0.9.8 © Bloc | NewDef design by Bloc
Page created in 0.477 seconds with 28 queries. (Pretty URLs adds 0.031s, 4q)
Loading...