Archive > BeBot Hyborian modules

Simple Tells in Guild Chat as Cron tasks

(1/2) > >>

Organizer:
I'm a total noob on this, I know some simple PHP and essential stuff but coding anything from scratch is unfortunately not me. My issues now is that I would like our guild bot to spam some text strings at certain intervals.

For instance if we have some important news that we would like to give more focus than using the !news or guild announcement system for: e.g. that we would like the bot to send out a tell every 3 hours e.g. saying "quick reminder everyone; we're building the Guild city on next Tuesday, be there at 21:00 CET". Optimally it should of course also allow chat link codes in this text.

While I'm willing to set and change these texts in the PHP myself all manually, I can't even work our how a cron tasks get started/programmed. So maybe someone can help me out with the basic of doing something manual :)

If in the Module form I guess some more commands would be required:

// add a new timed chat message to the list
!cron add <interval> <message>

// list of messages with a Delete or Pause/Resume link option, also shows their ID
!cron list

// deletes a certain message ID, same as clicking the Delete link in the list
!cron del <id>

// places a messages on hold, same as clicking Pause link in the list
!cron pause <id>

// resumes a messages on hold, same as clicking Resume link in the list
!cron resume <id>

// changes text or interval of a message
!cron change interval <id> <new interval>
!cron change message <id> <new message>

So if someone wants to take on this module or not I don't know, but maybe someone can help me with a manually edited cron module for now?

What I tried to create myself is simple manually updated one ->


--- Code: ---<?

$cron_messages = new cron_messages($bot);

class cron_messages Extends BaseActiveModule
{
var $bot;

function __construct (&$bot)
{
parent::__construct(&$bot, get_class($this));
$this -> register_event('cron', '2min');
}


function cron()
{
$this -> bot -> send_gc( "just a test ");
}

}
?>
--- End code ---

This gives me the error:

Fatal error: Class cron_messages contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (BaseActiveModule::command_handler) in G:\arabia_source_files\bebot052r13\custom\modules\crons.php on line 23




Vrykolas:
you're on track with what you have, however for a class that extends BaseActiveModule (one that can recieve commands) you have to write a function called command_handler (even if there's nothing in it)

You may find some more useful bits and pieces here.

Organizer:
Thanks got it to work by as you said just adding the command_handler without any information inside, so this is good enough for now at least... :)

Organizer:
One issue someone might be able to hint on... if I reset the bot I presume this script just resets and start spamming out, is there a way to sort of not start directly, easily set a delay before first run?

Vrykolas:
try:

--- Code: ---function cron()
{
if(!isset($delay_until))
static $delay_until = time() + 300;

if($delay_until <= $time())
$this -> bot -> send_gc( "just a test ");
}

--- End code ---

for a 5 min delay (just off the top of my head & not tested)

Navigation

[0] Message Index

[#] Next page

Go to full version