BeBot - An Anarchy Online and Age Of Conan chat automaton

Archive => Anarchy Online Archive => AO 0.6.x Custom/Unofficial modules => Topic started by: Jiheld on December 07, 2008, 02:50:04 pm

Title: Cron module
Post by: Jiheld on December 07, 2008, 02:50:04 pm
Hi,
I used the Cron module to send a msg in the guildchat every 20 mins.
But the text is in Yellow.
Is there a way to make this another color?

Quote
<?php
/*
* cron.php - Module template.
* Cron module - <module description>
* <Copyright notice for your module>
*
* BeBot - An Anarchy Online & Age of Conan Chat Automaton
* Copyright (C) 2004 Jonas Jax
* Copyright (C) 2005-2007 Thomas Juberg Stensås, ShadowRealm Creations and the BeBot development team.
*
* Developed by:
* - Alreadythere (RK2)
* - Blondengy (RK1)
* - Blueeagl3 (RK1)
* - Glarawyn (RK1)
* - Khalem (RK1)
* - Naturalistic (RK1)
* - Temar (RK1)
*
* See Credits file for all aknowledgements.
*
*  This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; version 2 of the License only.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software
*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
*  USA
*
* File last changed at $LastChangedDate: 2008-11-30 23:09:06 +0100 (Sun, 30 Nov 2008) $
* Revision: $Id: _ExampleModule.php 1833 2008-11-30 22:09:06Z alreadythere $
*/

/*
Add a "_" at the beginning of the file (_ClassName.php) if you do not want it to be loaded.
*/

$thisClass = new cron($bot);

/*
The Class itself...
*/
class cron extends BaseActiveModule
{

   function __construct (&$bot)
   {
      //Initialize the base module
      parent::__construct(&$bot, get_class($this));


      $this->register_event('cron', '20min');

   
   }


   /*
   Unified message handler
   $source: The originating player
   $msg: The actual message, including command prefix and all
   $type: The channel the message arrived from. This can be either "tell", "pgmsg" or "gc"
   */
   function command_handler($source, $msg, $origin)
   {
      //ALWAYS reset the error handler before parsing the commands to prevent stale errors from giving false reports
      $this->error->reset();
      
      //The default is to split the command to com, sub and args. If you want to split it some other way change the pattern for it
      //parse_com() returns an array where the pattern is the keys and the values are split out from $msg
      $com = $this->parse_com($msg, array('com', 'sub', 'args'));
      
      $command = $vars[0];

      switch($com['com'])
      {
         case 'command1':
            return($this -> somefunction($name, $com));
            break;
         case 'command2':
            return($this -> someotherfunction($name, $com));
         default:
            // Just a safety net to allow you to catch errors where a module has registered  a command, but fails to actually do anything about it
            $this -> error -> set("Broken plugin, recieved unhandled command: $command");
            return($this->error->message());
      }
   }
   
   /*
   This gets called on cron  if you previously registered the event 'cron, interval'
   $interval is the string name for the time delay between two cron jobs.
   */
   function cron($interval)
   {
$this -> bot -> send_gc( "New Raid, Join for the Epix!!! Sign up on the raid calendar on our site!!! Dont sit there!!! SIGN!!!");
   }
   
   
}
?>

playing AoC btw.

Thnx.

Jih.
Title: Re: Cron module
Post by: Alreadythere on December 07, 2008, 03:08:57 pm
Simply add a color tag around the output.

Like ##forestgreen##Output##end##, will give Output colored in forest green. Check !color for a list of all existing color tags.
Title: Re: Cron module
Post by: Jiheld on December 07, 2008, 06:11:13 pm
cool, got it.

Can you ad highlights with this also?

Title: Re: Cron module
Post by: Alreadythere on December 07, 2008, 06:16:36 pm
Sure, you can put as many tags inside as you want.

At least as long as you close the last one before starting the new one, AO got a limit for encapsulating font tags. Though around 5 definitly work.
Title: Re: Cron module
Post by: Jiheld on December 07, 2008, 06:47:26 pm
cool,

Hows the line going to look like?
got this now

Quote
$this -> bot -> send_gc( "##highlight## ##purple## New Raid, Join for the Epix!!! Sign up on the raid calendar on our site!!! Dont sit there!!! SIGN!!!##end##");

But the highlight isnt working, did i mis something?

thnx alot

Jih.
Title: Re: Cron module
Post by: Alreadythere on December 07, 2008, 07:45:03 pm
Ah. Highlight is just a color like purple, FC doesn't support any other formatting ingame.

You can just mix as many colors as you want in the output.
Title: Re: Cron module
Post by: Jiheld on December 07, 2008, 08:06:35 pm
ahh oke, thanx alot for your help :D

Title: Re: Cron module
Post by: khayman on December 08, 2008, 06:30:26 pm
Actually FC supports some more formating using <font face=facename>BeBot</font>
Where the supported facenames are:
NORMAL,NORMAL_ITALIC,NORMAL_BOLD,SMALL,LARGE,LARGE_BOLD,HUGE,CHAT,HEADLINE,LARGE_SC,
3D_TEXT,3D_TEXT_BOLD,SCALED,3D_TEXT_SMALL,3D_TEXT_ARIAL,3D_TEXT_HYB,HYBORIANSMALL,
HYBORIANLARGE,FLYING_NUMBERS,FLYING_NUMBERS_ITALICS,FLYING_NUMBERS_SHIELDED,
FLYING_NUMBERS_SHIELDED_ITALICS,COMBAT_FEEDBACK

i.e. <font face=HYBORIANSMALL>BeBot</font>

Title: Re: Cron module
Post by: Blueeagle on December 11, 2008, 10:02:40 pm
Actually FC supports some more formating using <font face=facename>BeBot</font>
...
i.e. <font face=HYBORIANSMALL>BeBot</font>
There are differences in AoCML and AOML. Since the BeBot project supports both I think it unwise to use anything but the common ground.
Ofcourse it would be possible to make a translation table where those AoCML font entities actually meant something in both ML sets.
Title: Re: Cron module
Post by: Temar on December 11, 2008, 10:36:17 pm
yer we use tags so when the tag gets change , what it gets changed to can depend on the game
Title: Re: Cron module
Post by: xdave78 on February 14, 2009, 07:03:24 pm
Code: [Select]
  function cron($interval)
   {
$this -> bot -> send_gc("Events der Woche - <a href='chatcmd:///!script events'>Klick!</a>");
   }
   

..why does the Link NOT WORK? Its shown bun no klick allowed???
Title: Re: Cron module
Post by: Alreadythere on February 14, 2009, 07:22:23 pm
Because it's no chat command I guess.

Code: [Select]
function cron($interval)
   {
$this -> bot -> send_gc("Events der Woche - <a href='chatcmd:///tell <botname> <pre>script events'>Klick!</a>");
   }
Replace /tell <botname> with the command for whichever channel you want to use.
Title: Re: Cron module
Post by: xdave78 on February 14, 2009, 07:47:41 pm
It is a command ..and it works when I call it manually in the Guidchat with !script events.
When I call it by Cron it has also the rightformat (underlines and Orange) its just not clickable...
I dont want to TELL I want the Cron to post the output in GC.
(Its a ScriptModue command)
Title: Re: Cron module
Post by: Alreadythere on February 14, 2009, 08:58:14 pm
!script events might be a working bot command, but it's no legal format inside a chat command.

Try removing one of the three / inside, or put <a href='chatcmd:///gu <pre>script events'> inside, I think that should work.

Of course, you could check out the tools function chatcmd. 14_Tools.php is in the main/ folder.
Title: Re: Cron module
Post by: xdave78 on February 14, 2009, 10:28:33 pm
Didnt work  :-\  :'( I dont get it...
I tried everything possible with my small knowledge about coding .

When I let the bot ONLY write out the simple command "!events" (when I write it into chat it makes the right response) in the Guildchat its also not working...I think it doesnt listen to itself.

I dont think its got to do with the chatcmd:/// because in another tool where I also call one of these scripts out of a window it works.

Sorry for my english..I´m from Germany ;) and that thing would really really be a useful function for my guildmates.
Title: Re: Cron module
Post by: Alreadythere on February 14, 2009, 11:25:52 pm
Oh right, I forgot - command links only work inside blobs.

So pack the chat command line inside a blob (make_blob() in the tools module will do that quite nicely) and it should work.

Of course, you could simply direcly execute the command by calling $this->command_handler("", "scripts events", "gc") if the cron job is running in the scripts module. That way you'll have the same effect as someone clicking on the link.
Title: Re: Cron module
Post by: xdave78 on February 15, 2009, 12:25:55 am
Oh the last thing seems quiet what I´m looking for....you now..some Guildmates ar LAAZYYY...

Can I just replace the send_gc with your string???

(remember I´m beginner - and not English native speaker :p )

Thanks so much for your suppport here.

EDIT:

Code: [Select]
[cron] Broken Plugin, received unhandeled command

what do you mean with "if the cron job is running in the scripts module"?
Do I have to rewrite sth in the command_handler? I´m gettig crazy with that task :p

so now i try
Code: [Select]
function cron($interval)
   {
   $inside="##blob_title##Events der Woche##end##\n\n";
   $inside.= implode("", file("./txt/events.txt"));
   return "Events der Woche: " . $this -> bot -> core("tools") -> make_blob("zum Ansehen hier klicken", $inside);
//$this->command_handler("", "gevent", "gc");
   }

..that does...nothing...

I probably forgot sth..no clue.

Title: Re: Cron module
Post by: xdave78 on February 16, 2009, 02:22:11 pm
no one any idea??? :(
Title: Re: Cron module
Post by: Alreadythere on February 16, 2009, 05:43:07 pm
You should put the cron() function inside the scripts module. Otherwise you can't reach the scripts command handler in an easy way.
Title: Re: Cron module
Post by: xdave78 on February 16, 2009, 06:58:40 pm
OMG...I dont know if I could get tis done as such a noob.

@Alreadythere:
Can I leave the con Module as it is and just take out the function()?
Code: [Select]
function cron($interval)
   {
$this -> bot -> send_gc("Events der Woche - <a href='chatcmd:///tell <botname> <pre>script events'>Klick!</a>");
   }
(Leave the registration and the build of the cron in cron.php)
And then put the function() into the scripts.php to call cron?!

Like sth... (this is the mak function of the scripts.php)
Code: [Select]
    function make_script($script)
    {
        if(false !== ($handle = @fopen("scripts/".$script.".txt", "r")))
        {
            $content = fread($handle, filesize("scripts/".$script.".txt"));
            fclose($handle);

            $content = "<font color=CCInfoHeadline> :::: Script Name [".$script."] ::::</font>\n\n".$content;
            return "Script :: " . $this -> bot -> core("tools") -> make_blob("click to view", $content);
        }

        return "Specified script not found! - " . $this -> make_list();
    }
}

and then put in at the End
Code: [Select]
function cron($interval) 
 {
$this -> bot -> send_gc($content);
   }


..or do I have to mesh up the whole cron.php content wirth the scripts.php????

Sorry there a massive errors in it for sure...but my last c++ program is 13years ago...


@all:
Perhaps so could do it for me ...I´d even pay for a module whith which I could call a script (txt) by using cron. The thing is, that it would be best that way because the "Events.txt" (script content) changes every week. PN me if interested. No clue how many work that is, for so used to coding perhaps 30Mins or an Hour?!
Title: Re: Cron module
Post by: Alreadythere on February 16, 2009, 07:23:20 pm
You need to register cron in the constructor of the scripts module (replace 30min with whatever time you want):
Code: [Select]
$this->register_event("cron","30min");
Then try the following cron function in the script module:
Code: [Select]
function cron($delay)
{
$this->bot->send_gc($this->make_script("events"));
}

And simply remove the cron module completely unless you want it to spam something else.
Title: Re: Cron module
Post by: xdave78 on February 16, 2009, 08:33:05 pm
YESSSS.....

I got it!!!!

Thank you so much Alreadythere.
SimplePortal 2.3.7 © 2008-2024, SimplePortal