BeBot - An Anarchy Online and Age Of Conan chat automaton

Development => Coding and development discussion => Topic started by: Hyde on August 27, 2007, 02:53:43 am

Title: Coding a /tell relay question
Post by: Hyde on August 27, 2007, 02:53:43 am
On our old bot I had a plugin that would take message input from pre-determined people and echo that message on orgchat and guest chat without giving any reply back to the source.

We used this to display Infonet and Elitenet relays in orgchat. I did some other stuff to them as well to reformat them (so that elitenet and infonet messages looked virtually identical as well as to include a simple profanity filter).

It is key that the bot not ever send any reply back to these senders, even in the event of error. Otherwise you get chat loops.

What do I need to do to make sure I intercept the message and never respond to it if it comes from certain names?
Title: Re: Coding a /tell relay question
Post by: Alreadythere on August 27, 2007, 11:05:33 am
Try something like the code below, tells is used to catch all incoming tells that don't match a command. You need to check the sender, and if it's the right one relay it. If the function tells() returns true the handler for incoming tells won't send back any access denied or help lines.

Code: [Select]
<?php
$infonet 
= new InfoNet($bot);

$commands["tells"]["infonet"] = &$infonet;

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

        function 
InfoNet(&$bot)
        {
                
$this -> bot = &$bot;
        }

        function 
tells($name$msg)
        {
                if (
$name == "Infonet")
                {
                        
$this -> bot -> send_gc($msg);
                        return 
true;
                }
                return 
false;
        }
}
?>

Title: Re: Coding a /tell relay question
Post by: Hyde on December 03, 2007, 05:50:30 am
I finally got around to doing this. Attaching the initial (seems to be working) version.

Includes a primitive customizable profanity filter and will parse out infonet and elitenet formats to make them a less spammy on orgchat.

(edit: removed attachment, see new version in code quote a couple of posts down)
Title: Re: Coding a /tell relay question
Post by: Malosar on February 07, 2008, 11:00:22 pm
Hiya folks, been awhile :) I'm upgrading my bot since I still run it for my old guild though I don't play anymore. Starting it from scratch. Tried this announcer and it doesn't seem to do anything. I am still getting tells from infonet but the module never seems to react to it. Still am getting familiar with this bot and all the changes (used to 2.x) so is there anything I need to enable or some security setting I need to do?
Title: Re: Coding a /tell relay question
Post by: Hyde on February 10, 2009, 03:37:22 am
I'm trying to move my Relay bot to 0.6.2 and my Announcer module isn't working anymore. Posting the current version below. It seemed to "just work" on 0.4.x (well, except for Malo :/ ) but when I run it on my 0.6.2 bot it loads ... but none of the defined $announcers work.

Any chance 0.6.x changed how this module needs to work? I'm just not that knowledgeable about the lower level issues that might be involved.

When Elitenet sends the bot a message I get:
[2009-02-10 02:14:57]   [TELL]  [INC]   Elitenet: botcommand [Elitenet][Test Message][Me] This is a test message from Elitenet.
[2009-02-10 02:14:57]   [TELL]  [OUT]   -> Elitenet: I only listen to members of this bot.

When Doctorhyde sends the bot a message I get:
[2009-02-10 02:17:45]   [TELL]  [INC]   Doctorhyde: test, ignore
[2009-02-10 02:17:45]   [TELL]  [OUT]   -> Doctorhyde: /tell Aput !help

Both of those are configured as $announcers (see below). I don't remember ever needing to set up security settings for the Announcers. When I load the same module in my 0.4.1 bot it works and I checked "!security groups" to make sure I never did anything funky for it there.

Code sample below. Only changes were removing my bot's elitenet password (replace "botcommand" with yours) and removing the profanity from the filter (add your censored words to that array, you'll see where).

(sample removed, updated one later in thread, keeping the thread from being too huge)
Title: Re: Coding a /tell relay question
Post by: Alreadythere on February 10, 2009, 06:52:28 am
Your announcer class needs to extend BaseActiveModule. Then replacing $commands["tells"]["announcer"] = &$announcer; outside the bot definition with the following inside the constructor should do the trick:
Code: [Select]
parent::__construct(&$bot, get_class($this));
$this->register_event("tells");

You can remove the $this->bot = &$bot; line too, the parent constructor sets it.
Title: Re: Coding a /tell relay question
Post by: Hyde on February 10, 2009, 05:03:35 pm
Thanks.

After looking at the way the main modules for 0.6.2 are built I also changed:
        function Announcer(&$bot)
to:
        function __construct(&$bot)

(Not really sure that did anything)

However when I try to run the bot I get this error and bot cycles infinitely (note: I got this error even before I changed the line mentioned above):

Quote
Additional modules in directory custom/modules/commsbot

Fatal error: Class Announcer contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (BaseActiveModule::command_handler) in /home/bots/bebot/bebot-0.6.2/custom/modules/commsbot/Announcer.php on line 141

Since line 141 is the next to the last line of the script, and is where the class terminates, something is still wrong with how I've put it together.

Current version is below (and removed non-functional code above).

(edit: removed, will post a link to a full working version once I've finished it)
Title: Re: Coding a /tell relay question
Post by: Alreadythere on February 10, 2009, 06:10:08 pm
Oh right, you have to instance command_handler(). Simple function command_handler($name, $msg, $origin) {} should be enough.
Title: Re: Coding a /tell relay question
Post by: Hyde on February 10, 2009, 11:21:55 pm
That did it, thanks.

Going to clean up some code and modify a few things, then I'll post the "final" 0.6.x version on a thread in the other forum. Thanks again for all the help.
Title: Re: Coding a /tell relay question
Post by: Hyde on February 11, 2009, 07:39:33 am
Posted the new version. I cleaned it up enough I don't think it is a problem to have it in the unofficial modules forum:

bebot.link/0-6-x-customunofficial-modules/announcer-php

So this thread should be dead except as a reference. Thanks again for the help.
SimplePortal 2.3.7 © 2008-2024, SimplePortal