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

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

Author Topic: Announcer.php  (Read 8173 times)

0 Members and 1 Guest are viewing this topic.

Offline Hyde

  • BeBot Apprentice
  • ***
  • Posts: 92
  • Karma: +0/-0
Announcer.php
« on: February 11, 2009, 07:32:21 am »
Purpose: intercepts tells from trusted sources and routes them to your orgchat.

Updated this for 0.6.2 and made a ton of improvements tonight. It will be mostly plug-n-play for Clan on RK2 (almost as useful for Neutral/Omni since it has Neutnet and Elitenet filters ... but someone else will have to add Omninet, etc). It will still be useful for any AO orgs (since it will still announce any source, just won't have the pretty formatting for new sources). Not sure of its usefulness to AoC.

Any bot that it has a filter for will be reformatted so that colors and formats are similar (so that Infonet looks like Neutnet looks like Elitenet). There is also an optional very basic profanity filter.

I put detailed notes and instructions in the comments of the script. See the changelog if you want details on what has changed.

NOTE: right now it -only- sends to orgchat. However I made a note at the end where you might add code to forward to a privgroup or another bot. For instance to use 1 bot to receive all of the announcements and then forward them to multiple orgs (if, for instance, you want to receive notifications from a specific bot that doesn't have a way to register your low level bots and its admin is notoriously hard to get to do anything).

Background information about this module can be found here:
http://bebot.link/coding-and-development-discussion/coding-a-tell-relay-question/

Code: [Select]
<?php
/* Announcer.php

   Purpose:
   Announcer module, similar to relaying but with a different mechanism.

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

   Authors: Doctorhyde@RK2, Alreadythere@RK2

   This module will relay /tells verbatim (sort of) from other users
   without needing a command. It does this via a "whitelist" 
   of allowed senders. 

   ... for Infonet, Elitenet and Neutnet messages it will parse the 
       message into a neutral format (people complain less about the
       relays if they don't all look wildly different)

   ... NOTE: This module does not install any new commands nor does
       it have any bot !help text. It completely intercepts any
       messages from those toons designated as "$announcers". 

   ... There are some editable variables, they are marked with 
       "EDITABLE:" ... these include:

* Edit "$announcers" array to add more relay server bots. 
  Any bot you want to Announce needs to be listed here. 
  Any name listed here will NOT be able to send your bot
  commands. 

* $profanity, if FALSE, will filter out whatever words you
  specify in $profanityfilter. If $profanity is TRUE it 
  will not filter based on that line.

* If you receive Elitenet messages you need to edit 
  $elitenetcommand below to be the bot
  password you set with Elitenet's "!registerbot".

   ... If you want to add AND reformat a new relay service then 
       look at the PARSER: cases and make one for your relay.
       However this isn't completely necessary since anything
       that doesn't match a PARSER: will be spit out verbatim
       (except that we strip out the <font> tags).

   CHANGELOG: 
2009-02-10_2
* Enhanced Infonet parsing, should cover all types
   (BLESS you neutnet/elitenet coders for having a 
    single message format for your bots)
* Added comments and fixed old comment formatting
* Soft-coded the output colors (manage via "!color")
2009-02-10_1
* Updated to BeBot 0.6.2 with help from Alreadythere
* Re-added Elitenet, look for "$elitenetcommand" and edit accordingly
2008-12-14_1
* Added Neutnet relay
* Optimized font deletions and message reformatting
2007-12-13_1 ... initial version
*/

$announcer = new Announcer($bot);

/* The Class itself... */
class Announcer extends BaseActiveModule
{
        var 
$bot;
/* Constructor:Hands over a referance to the "Bot" class. */
        
function Announcer(&$bot) {
parent::__construct(&$botget_class($this));
$this->register_event("tells");
/* Colors */
                
$this -> bot -> core("colors") -> define_scheme("Announcer""botname""bluesilver");
                
$this -> bot -> core("colors") -> define_scheme("Announcer""sender""bluegray");
                
$this -> bot -> core("colors") -> define_scheme("Announcer""type""brightgreen");
                
$this -> bot -> core("colors") -> define_scheme("Announcer""text""lightyellow");
        }
        
/* Unified message handler */
function command_handler($name$msg$origin) {}

/* Main body of the module */
        
function tells($name$relay_message) {
/* EDITABLE: add more announcer bots */
$announcers = array(
"Infonet","Infonet1","Infonet2","Infonet3","Infonet4","Infonet5","Infonet6","Infonet7","Infonet8","Infonet9","Infonet10","Infonet11","Infonet12","Infonet13","Infonet14",
"Neutnet","Neutnet1","Neutnet2","Neutnet3","Neutnet4","Neutnet5","Neutnet6","Neutnet7","Neutnet8","Neutnet9","Neutnet0","Elitenet",
"Elitenet1","Elitenet2","Elitenet3","Elitenet4","Elitenet5","Elitenet6","Elitenet7","Elitenet8","Elitenet9"
);
/* EDITABLE: Do you want to filter profanity out? FALSE here = strip profanity, TRUE here = don't bother */
$profanity FALSE;
/* EDITABLE: What words do you consider profane? Add them to the array */
$profanityfilter = array("profanitytest","add","curse","words","like","this");
/* EDITABLE: If you use Elitenet (RK2) and you registered via !registerbot, then
             you had to choose a command password. Change $elitenetcommand 
             to match */
$elitenetcommand "botcommand";

/* No editable -Variables- below BUT if you are adding a new
   relay and want to intercept formatting you do need to play
   with those chunks below */
if (in_array($name,$announcers))
                {
/* 
Strip font colors 
*/
$font_pattern '/\<([\/]*)font([^\>]*)\>/';
$relay_message preg_replace($font_pattern,'',$relay_message);

/* NOTE: If you want to add a new relay, then use the following 
         parsing examples to help you figure out how to parse it. 
         NOT necessary though, if unparsed text is found it is 
         just stripped of <font> tags and spit out as-is. Make sure
         you add new parsers with elseif commands */

/* PARSER: Elitenet ... message matches are ElitenetID, Type, Sender, Text
   Examples: (/tell elitenet !testbot {yourbotname}):
elitenetommand [<font color=#ffff00>Elitenet</font>][<font color=#ffff00>Test Message</font>][<font color=#ffff00>Me</font>] Test message.
*/
                if (preg_match("/^$elitenetcommand \[([^\]]*)\]\[([^\]]*)\ Message\]\[([^\]]*)\]\ (.*)/"$relay_message$matches)) {
$relay_ElitenetID  = $matches[1];
$relay_Type  = $matches[2];
$relay_Sender  = $matches[3];
$relay_Text  = $matches[4];
/* PARSER: Infonet raid messages ... matches are Type, Sender, Message
  Examples:
<font color=#ff0000>[Tara]: Cameloot report that there is a Tarasque raid going on... (Timer: 21 Minutes /tell Cameloot Invite)
<font color=#8CB5FF>[Pande]: Phatznet says that... There is a Pandemonium raid starting... (Timer: 20 Minutes /tell Phatznet Invite)
<font color=#8CB5FF>[APF]: Radialix says... There is a Sector 42 raid starting... (Raid Req: 210+ and (Entry key) Timer: 15 Minutes /tell Sector42 !Invite)
*/
                
} elseif (preg_match("/^\[([^\]]*)\]:\ ([^\ ]*)\ (report that|says that\.\.\.|says\.\.\.) [tT]here is a (.*) raid [^\(]*\(.*Timer:\ ([^\ ]*)\ Minutes\ \/tell\ ([^\ ]*)/"$relay_message$matches)) {
$relay_Type  = $matches[1];
$relay_Sender  = $matches[2];
$relay_Text  = $matches[4];
/* This PARSER is special, the others don't have this */
$relay_Timer  = $matches[5];
$relay_Bot  = $matches[6];
$relay_Bot_invite   = "invite";
if (preg_match("/^(Sector42)$/i"$relay_Bot$matches)) {
$relay_Bot_invite "!invite";
}
$relay_Text .= " raid in $relay_Timer"min"
$relay_Text .= " [<a href=\"text://<a href='chatcmd:///tell $relay_Bot $relay_Bot_invite'>/tell $relay_Bot $relay_Bot_invite</a>\">/tell $relay_Bot $relay_Bot_invite</a>]"
/* PARSER: Infonet WAR message ... matches are Type, Sender, Text (Offense/Defensive will be added to Type)
  Examples:
<font color=#ff0000>[War]: Ruudvanniste report that there is a base under attack... (Offensive, tl7 /tell Clanside1 !Invite/Invite/!join/Join)
<font color=#ff0000>[War]: Lathinaa report that there is a base under attack... (Defensive, tl7 /tell Clanside1 !Invite/Invite/!join/Join)
*/
                
} elseif (preg_match("/^\[([^\]]*)\]:\ ([^\ ]*)\ report that there is a base under attack\.\.\. [^\(]*\(([^,]*),\ tl([1-7])\ \/tell\ ([^\ ]*)/"$relay_message$matches)) {
$relay_Type  = $matches[1];
$relay_Sender  = $matches[2];
$relay_Text  = $matches[3];
/* This PARSER is special, the others don't have this */
$relay_Titlelevel  = $matches[4];
$relay_Bot  = $matches[5];
$relay_Bot_invite   = "invite";
if (preg_match("/^(Sector42)$/i"$relay_Bot$matches)) {
$relay_Bot_invite "!invite";
}
$relay_Text "TL$relay_Titlelevel $relay_Text"
$relay_Text .= " [<a href=\"text://<a href='chatcmd:///tell $relay_Bot $relay_Bot_invite'>/tell $relay_Bot $relay_Bot_invite</a>\">/tell $relay_Bot $relay_Bot_invite</a>]"


/* PARSER: Infonet ADMIN message ... matches are Sender, Text
  Examples:
<font color=#8CB5FF>Grind42 says... WAR TL7 offensive, come kill some Omners guys... PVP is fun dont be lazy pst if u cant get into bot /tell clanside1 invite
<font color=#8CB5FF>Bombadoc says... It's now 35mins before raidlock and omnis gathering fast at 100%. Don't let them take control of box!! Join our force and lelt's stole Harios cookies :D   /t... [<a href="text://<div align=center><font color=#ffffff>Full Infonet Message by Bombadoc</font><br><br><font color=#8CB5FF>It's now 35mins before raidlock and omnis gathering fast at 100%. Don't let them take control of box!! Join our force and lelt's stole Harios cookies :D   /tell cameloot invite</font></div>">Full message</a>]
*/
                } elseif (preg_match("/^([^\ ]*)\ says\.\.\.\ (.*)/"$relay_message$matches)) {
$relay_Sender  = $matches[1];
$relay_Text  = $matches[2];
$relay_Type  = "Admin";
/* PARSER: Neutnet messages ... matches are Type, Text, Sender
  Examples:
<font color=#FF7718><font color=#FF7718>[<font color=#FFFF00>Wts</font>] wts <a href="itemref://270392/270392/200">Enhanced Dustbrigade Flexible Boots</a> loot rights got warp [<font color=#FFFF00>Havendoc</font>]</font></font>
<font color=#FF7718><font color=#FF7718>[<font color=#FFFF00>Pvp</font>] testing, sry for spam :] [<font color=#FFFF00>Zacix</font>]</font></font>
*/
                } elseif (preg_match("/^\[([^\]]*)\]\ (.*)\[([^\]]*)\]$/"$relay_message$matches)) {
$relay_Type  = $matches[1];
$relay_Text  = $matches[2];
$relay_Sender  = $matches[3];
                }
/* Edit these chunks to change the output of the bot: */
/* FORMAT: All PARSED messages have at least a Sender and Text */
if ($relay_Sender && $relay_Text) {
$relay_message "##Announcer_sender##" $relay_Sender ":##end## ##Announcer_text##" $relay_Text "##end##";
/* FORMAT: Some PARSED messages have a Type */
if ($relay_Type) { $relay_message "[##Announcer_type##" $relay_Type "##end##] " $relay_message; }

/* hook in our profanity filter */
if (! $profanity) {
                foreach ($profanityfilter as $curse_word) {
                        if (stristr(trim($relay_message)," ".$curse_word)) {
                                $length strlen($curse_word);
                                for ($i 1$i <= $length$i++) {
                                        $stars .= "*";
                                }
                                $relay_message eregi_replace($curse_word,$stars,trim($relay_message));
                                $stars "";
                        }
                }

}
/* Spit out the message
   some announcers don't have a relay_Type ... 
   this will just dump the default message minus its original <font>s*/

$relay_message "##Announcer_botname##" $name " relay:##end## ##Announcer_text##" $relay_message "##end##";
                        
$this -> bot -> send_gc($relay_message);

/* 
if I decide to hook in a way to /tell additional people the message, it will go here ...
for instance you could add send_tell code to !gcr to other bots here
*/


/* done */
                        
return true;
                }
                return 
false;
        }
}
?>

« Last Edit: February 11, 2009, 08:03:51 am by Hyde »
Doctorhyde/Jexyll/Goraud@RK2

Offline Hyde

  • BeBot Apprentice
  • ***
  • Posts: 92
  • Karma: +0/-0
Re: Announcer.php
« Reply #1 on: February 11, 2009, 07:46:34 pm »
The first part of the goodness of this script is that ALL of your orgmates can get these announcements without needing to subscribe (saving the announcerbot some /tell traffic AND allowing your lowbs to get messages from those bots that have level limits).

But ... in case you're wondering why I even bothered with the parsing of the known relays ... every messaging bot has its own output format. I find people "get" the Announcer concept -and- consider it far less intrusive if the formatting of the messages is consistent.

Don't get hung up on how bad this looks color wise, it looks alot better contrast-wise on the dark background of an AO chat window.

Some output examples:

... Original message (in a tell):
Infonet Raid message:
[Infonet8]: [Tara]: Cameloot report that there is a Tarasque raid going on... (Timer: 40 Minutes /tell Cameloot Invite)
Neutnet:
[Neutnet3]: [Nodrop] WTS Dreadloch Endurance Booster - Enforcer Special [Shaikorth]
Elitenet
[Elitenet:] botcommand [Elitenet][Test Message][Me] This is a test message from Elitenet.
[Doctorhyde:] This is an unknown format message and so is spit out verbatim.


.... Message to orgchat:
Infonet Raid message:
[Athen Paladins] Commsbot: Infonet relay: [Tara] Cameloot: Tarasque raid in 40min [/tell Cameloot invite]
Neutnet:
[Athen Paladins] Commsbot: Neutnet3 relay: [Nodrop] Shaikorth: WTS [Dreadloch Endurance Booster - Enforcer Special]
Elitenet
[Athen Paladins] Commsbot: Elitenet relay: [Test] Me: This is a test message from Elitenet.
[Athen Paladins] Commsbot: Doctorhyde relay: This is an unknown format message and so is spit out verbatim.


Yes, if a Parsed Announcer changes their format it will break the parsing (fun with regex) but as shown by the last example above even an unknown format will still display fairly regularly.
« Last Edit: February 11, 2009, 07:48:17 pm by Hyde »
Doctorhyde/Jexyll/Goraud@RK2

Offline lordamadeus

  • BeBot User
  • **
  • Posts: 45
  • Karma: +0/-0
Re: Announcer.php
« Reply #2 on: September 14, 2010, 06:14:54 am »
is there anything im missing, i copied it so my org can recieve neutnet messages, but its getting an error on line 65, some kind of missing var or something??

Offline Hyde

  • BeBot Apprentice
  • ***
  • Posts: 92
  • Karma: +0/-0
Re: Announcer.php
« Reply #3 on: September 14, 2010, 04:41:03 pm »
I won't be able to help, I stopped playing AO about 2 months after posting this (1.5 years ago). I know I got it running as well as a few others, but no clue what if anything has changed in the mean time.
Doctorhyde/Jexyll/Goraud@RK2

 

* Recent Posts
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 ]


Bebot and Rasberry by bitnykk
[November 29, 2023, 11:04:14 pm ]

* Who's Online
  • Dot Guests: 80
  • 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