BeBot - An Anarchy Online and Age Of Conan chat automaton

Development => Module Requests => Topic started by: Heffalomp on January 27, 2008, 05:09:46 am

Title: Relay coloring on recieving end.
Post by: Heffalomp on January 27, 2008, 05:09:46 am
Not realy a module request tho but....
Me and the girlfriend patched together a relay module by disecting the orignal Relay_GUILD.php and patching it up again as a separate module to use in an alliance relay, where we now need to find a way to set colors on the recieving end instead of the transmitting side and hope someone can help us with that....

Annyhow, the code is attatched to this message and it's probably  messy as hell, but it works werry well for our now 10bot and growing relay network, and now we hope you lot can help us out on the coloring part as it's "fun" watching the rainbows as all the senders are sending their own defined colors to the rest of the alliance:)


Title: Re: Relay coloring on recieving end.
Post by: Alreadythere on January 27, 2008, 01:38:36 pm
Interesting idea.

To colorize on the receiving side you need to remove the color tags added on the sending side before relaying (or just remove those you don't want anymore), those are in one of the relay_to_xyz() functions. Just check where the color schemes are used.
On the receiving side you then need to check the sender against your color list and simply add the color tags you want before calling the send_output() function.
Title: Re: Relay coloring on recieving end.
Post by: Heffalomp on January 27, 2008, 08:26:40 pm
that would color the entire thing with the same color or would it then be possible to split the message in to different colors like when we assemble it before it is sent?
Title: Re: Relay coloring on recieving end.
Post by: Alreadythere on January 27, 2008, 08:40:52 pm
You will have to parse the incoming relayed chat if you want to color it differently depending on the parts, most likely something like checking for text between [] for the guild name and text between ] and : for the character name.
Something like preg_match("/^[(.+)] (.+): (.+)$/i", $msg, $info) would give you org string in $info[1], name of the sending character in $info[2] and the chat in info[3]. Not sure if [] and : need to be escaped in the regular expression...
You may have to check for <font color=""></font> tags in the incoming chat too...
Title: Re: Relay coloring on recieving end.
Post by: Temar on January 27, 2008, 08:47:54 pm
won't it be easier to set colour in bot that sends using ##".$this -> bot -> settings -> get(   )."## text ##end##
Title: Re: Relay coloring on recieving end.
Post by: Alreadythere on January 27, 2008, 08:51:09 pm
That's the easiest way, true.

Though as I understand it johskar wants a solution working on the receiving bot, I guess that's the only one he can control.
Title: Re: Relay coloring on recieving end.
Post by: Temar on January 27, 2008, 09:00:19 pm
well if he want to colour the bots on recieveing end then maybe a good way is prob set a colour too a botname then have it use that colour for relays from that bot
Title: Re: Relay coloring on recieving end.
Post by: Temar on January 27, 2008, 09:46:53 pm
i had a good idea!
At the moment im at work using my mobile
I finish in 2 hours then ill do it and post it for you
Title: Re: Relay coloring on recieving end.
Post by: Temar on January 28, 2008, 12:51:51 am
ok i havnt done what you want as im not sure exactly what you want
but i did notice a big problem with ur module
u repeat WAY TOO MUCH
i have changed it so it doesnt repeat code
and adding more bots too your code is very simple , you only have to edit 1 line ;D

module is about 1/3 the original size now :p
Title: Re: Relay coloring on recieving end.
Post by: Heffalomp on January 28, 2008, 05:08:08 am
well if he want to colour the bots on recieveing end then maybe a good way is prob set a colour too a botname then have it use that colour for relays from that bot
so for ONE relay wich contains over 10 bots we'd then have to set the color on each of those even tho it's intended that those are going to use the same color?
the relay module has 5 separate relays, on wich each can use ither a tell to ONE bot or a privgroup to talk to multiple bots
Title: Re: Relay coloring on recieving end.
Post by: Heffalomp on January 28, 2008, 05:09:56 am
ok i havnt done what you want as im not sure exactly what you want
but i did notice a big problem with ur module
u repeat WAY TOO MUCH
i have changed it so it doesnt repeat code
and adding more bots too your code is very simple , you only have to edit 1 line ;D

module is about 1/3 the original size now :p
Yes it's a dirty code, but it was working well ;P (except for the coloring)

Thank you for the shrinking code, but with your version I get this error:
Code: [Select]
Parse error: syntax error, unexpected T_FOREACH in /<removedpath>/Alliance_Relay.php on line 70
Title: Re: Relay coloring on recieving end.
Post by: Temar on January 28, 2008, 08:18:16 am
Yer was untested, i had some probs connecting to my server,
anyway i removed the few typos and tested it loads
Title: Re: Relay coloring on recieving end.
Post by: Heffalomp on January 28, 2008, 05:59:03 pm
The way I/We want it is that it colors the messages it recieve from each channel separately, instead of when it sends it, cause then each guild can choose what color they want on their separate relays, but have the same color on every guild in the same relay, this so that we don't spam in all of the colors in the rainbow when we are chatting, like we do now, cause some has set colors and some have not.

Your module works after fix btw, ty :)
Title: Re: Relay coloring on recieving end.
Post by: Heffalomp on February 18, 2008, 08:15:02 pm
This is what we ended up with in the end :)
(well.. haven't cleaned out stuff that's commented out due to not being in use annymore yet tho ::))
Title: Re: Relay coloring on recieving end.
Post by: Glarawyn on February 18, 2008, 11:08:36 pm
The send_output function does not have support for removing color tags, but if I recall correctly the send_tell function does. Check Bot.php to be sure...

This won't remove color tags that were added before you passed your output string to send_tell, it just prevents send_tell from adding color tags. If you want to remove all color tags you would have to remove them from your string before sending the string to send_tell...
Title: Re: Relay coloring on recieving end.
Post by: Heffalomp on February 19, 2008, 02:10:46 am
it did recolor the stuff from those who was running the old version with coloring on sending side just fine atleast.... only bug it has is the coloring goes out on irc too, but we don't use irc so that's not an issue, but will probably get fixed... as for now, we are happy with the way it work :)
Title: Re: Relay coloring on recieving end.
Post by: Heffalomp on October 20, 2008, 07:50:56 pm
dang! found some problems in the coloring stuff....
relay a single word that's in the coloring lists
like.... clan, omni, aqua or blue for instance it outputs
Code: [Select]
Testbot: [Test] Testchar: ##hrelayone_messageend##the end## part comes in the color I just relayed the name of.

Here's the function:
Code: [Select]
/*
This gets called on commands in the external privgroup
*/
function extpgmsg($pgroup, $name, $msg)
{
foreach($this -> relays as $relaynum => $relayname)
{
$fsyntax = $this -> bot -> settings -> get('HRelay'.$relaynum, 'farSyntax');
//if (preg_match("/^" . $this -> bot -> commpre . "agcr /im", $msg) &&
if (preg_match("/^" .  $fsyntax . "agcr /im", $msg) &&
$this -> bot -> settings -> get('HRelay'.$relaynum, 'Status') &&
strtolower($this -> bot -> settings -> get('HRelay'.$relaynum, 'Relay')) == strtolower($pgroup))

/*
if (preg_match("/^" . $this -> bot -> commpre . "agcr /im", $msg) &&
$this -> bot -> settings -> get('HRelay'.$relaynum, 'Status'))
*/
{
$parts = explode(' ', $msg);
unset($parts[0]);
$txt = implode(' ', $parts);
            /* Hyde: parse out the Channel, Name and Message text, colorize it using the hrelayone colors */
if (preg_match("/\[<font color=#[ABCDEFabcdef0-9]{6}>([^\]]*)<\/font>\] <font color=#[ABCDEFabcdef0-9]{6}>([^\ ]*):<\/font> <font color=#[ABCDEFabcdef0-9]{6}>(.*)<\/font>$/", $txt, $matches) ||
{
$txtirc = "[" . $matches[1] . "]" . $matches[2] . ": " . $matches[3];
$txt_channel = ("##hrelay".$relayname."_channel##" . $matches[1] . "##end##");
$txt_name = ("##hrelay".$relayname."_name##" . $matches[2] . "##end##");
$txt_message = ("##hrelay".$relayname."_message##" . $matches[3] . "##end##");
$txt = "[" . $txt_channel . "] " . $txt_name . ": " . $txt_message;
}
if ($this -> bot -> settings -> get('HRelay'.$relaynum, 'Inc') == "Both" || $this -> bot -> settings -> get('HRelay'.$relaynum, 'Inc') == "Guildchat")
{
$this -> bot -> send_gc($txt);
}

if ($this -> bot -> settings -> get('HRelay'.$relaynum, 'Inc') == "Both" || $this -> bot -> settings -> get('HRelay'.$relaynum, 'Inc') == "Privgroup")
{
$this -> bot -> send_pgroup($txt);
}

if ($this -> bot -> settings -> get('HRelay'.$relaynum, 'Irc') == TRUE)
{
$this -> relay_to_irc2($txtirc);
}
}
}
}
Title: Re: Relay coloring on recieving end.
Post by: Glarawyn on October 20, 2008, 09:30:29 pm
I got tired of the whole mess and customized the module to strip all incoming color tags, parse out the relay guild name and character name, apply some proper color tags, then output to guild chat. All incoming messages get set to default bot colors, but orgs found this better than colors being all over the place.
Title: Re: Relay coloring on recieving end.
Post by: Heffalomp on October 20, 2008, 09:34:46 pm
true, tho, what it's trying to do is 1st strip colors from incomming messages(cause some basts are slow on updating from the module we made1st that colors when you send.) and then add colors on the recieving end.
annyone know a simple way to do that?
what we use now feel kinda chubby way to do it :)
Title: Re: Relay coloring on recieving end.
Post by: Glarawyn on October 20, 2008, 11:14:48 pm
Problem is BeBot replaces it's internal color tags with HTML color tags before sending the message, so if you're looking for ##COLOR## and ##END##, it won't work.

Here's the function I came up with for getting rid of HTML font tags. This gets rid of all HTML font tags, not just colors. Use with caution if you use it outside of BeBot. ;)

Code: (php) [Select]
    /*
    Removes HTML font tags from a string.
    */
    function strip_font_tags($string)
    { // Start function strip_font_tags()
        // Getting rid of </font> is simple.
        $string = str_ireplace("</font>", "", $string);
        // Getting rid of opening font tags is not quite as simple.
        $pattern = "/<font.*?>/i";
        $replacement = "";
        $string = preg_replace($pattern, $replacement, $string);
        return $string;
    } // End function strip_font_tags()
Title: Re: Relay coloring on recieving end.
Post by: Glarawyn on October 20, 2008, 11:16:07 pm
And for reference, here's me recoloring relayed chat messages:

Code: (php) [Select]
    /*
    Apply the local bot's coloring to an incoming gcr message.
    */
    function recolor($string)
    { // Start function recolor()
        if (preg_match("/^\[(.+)\] (.+): (.+)$/i", $string, $parts))
        {
            $string = "##relay_channel##[".$parts[1]."]##end## ##relay_name##".$parts[2]."##end##: ##relay_message##".$parts[3]."##end##";
        }
        else if (preg_match("/^\[(.+)\] (.+)$/i", $string, $parts))
        {
            $string = "##relay_channel##[".$parts[1]."]##end## ##logon_organization##".$parts[2]."##end##";
        }

        return $string;
    } // End function recolor()

Title: Re: Relay coloring on recieving end.
Post by: Heffalomp on October 21, 2008, 01:35:49 am
it looks for <font></font> tags to nerf colors, just not sure why it screws up when you type singleword where that word is one of the "colors" like clan/aqua/orange and so on

gonna see if we can put them functions you posted there to work tomorrow :)
SimplePortal 2.3.7 © 2008-2025, SimplePortal