Page 1 of 2

automated administrator messages?

Posted: Sun Dec 27, 2009 3:42 pm
by Mr.Victor
Could it be possible using the API to create different automated administrator messages sent out every 'x' minutes to every table?

Re: automated administrator messages?

Posted: Sun Dec 27, 2009 8:18 pm
by Kent Briggs
Mr.Victor wrote:Could it be possible using the API to create different automated administrator messages sent out every 'x' minutes to every table?
Yes, use the RingGamesMessage and the TournamentsMessage calls for that. You'll have to control the timing of that with your code, typically in some kind of loop or via a cron job.

Re: automated administrator messages?

Posted: Thu Dec 31, 2009 12:52 pm
by Mr.Victor
What is a cron job? This is pretty new to me.

Re: automated administrator messages?

Posted: Thu Dec 31, 2009 1:27 pm
by Kent Briggs
Mr.Victor wrote:What is a cron job? This is pretty new to me.
On Linux systems, it's a timer you can set (usually in the cPanel) to launch a program (including PHP scripts) at specific times or specific intervals. Windows has something similar with its Task Scheduler utility.

Re: automated administrator messages?

Posted: Thu Dec 31, 2009 4:52 pm
by Mr.Victor
What's the parameter that I put after Name= if I want to send to all tables and not just one specifically?

Re: automated administrator messages?

Posted: Thu Dec 31, 2009 5:13 pm
by Kent Briggs
Mr.Victor wrote:What's the parameter that I put after Name= if I want to send to all tables and not just one specifically?
There's no single broadcasting command so you'll need to get the list of games with RingGamesList and TournamentsList and then loop through those to send out your message.

Re: automated administrator messages?

Posted: Sat Jan 02, 2010 1:44 pm
by Mr.Victor
Ok I'm very new to php and mostly only use it for includes in my html but PM API has put me up to the challenge. I've written a script to send automated messages to ring games and tournaments and I'm sooooo close to getting it to work but it seems as soon as the code hits an active table something goes wrong. My code is probably not that great but like I said I'm a newb. Please let me know where I went wrong here. Results are below:

Code: Select all

<?php

  include "API.php";  // API $url and $pw values set here
  
  $message = 'This is a test message sent to all active tables.  Please ignore.';

      // Get list of all ring games and send message.

  $url = "http://75.127.91.178:8087/api";
  $params = "Password=" . $pw . "&Command=RingGamesList&Fields=Name,Status";
  $api = Poker_API($url,$params,true);
  
  if ($result == "Error") die("Error: " . $api["Error"]);
  
  $namestatus = $api["RingGames"];
  
  for ($i = 1; $i <= $namestatus; $i++)
  { 
		  $name = $api["Name" . $i];
          $status = $api["Status" . $i];
	 
	 if  ($status != 'Playing: 0') // Check to make sure ring game is not empty
	  
	  // Send message to all ring game tables that aren't empty.
       {
        $url = "http://75.127.91.178:8087/api";
        $params = "Password=" . $pw . "&Command=RingGamesMessage&Name=" . $name . "&Message=" . $message;
        $api = Poker_API($url,$params,true);
  
        if ($api[Result] == "Ok") echo "<font color='#00FF00'>Message Sent to " . $name . " Ring Game Table. </font><br />";
        else echo "<font color='#FF0000'>Error: " . $api[Error] . ".</font><br />";
	   }
	   
	 else
	    echo  "<font color='#FF0000'>" . $name . " table is empty.  No message sent. </font><br />";
  }
  
      // Get list of all tournaments and send message.

  $url = "http://75.127.91.178:8087/api";
  $params = "Password=" . $pw . "&Command=TournamentsList&Fields=Name,Status";
  $api = Poker_API($url,$params,true);
  
  if ($result == "Error") die("Error: " . $api["Error"]);
  
  $namestatus = $api["Tournaments"];
  
  for ($i = 1; $i <= $namestatus; $i++)
  { 
		  $name = $api["Name" . $i];
          $status = $api["Status" . $i];
	 
	 if  (strstr($status,"Playing: ")) // Check to make sure tournament is running
	  
	  // Send message to all tournaments that are running.
       {
        $url = "http://75.127.91.178:8087/api";
        $params = "Password=" . $pw . "&Command=TournamentsMessage&Name=" . $name . "&Message=" . $message;
        $api = Poker_API($url,$params,true);
  
        if ($api[Result] == "Ok") echo "<font color='#00FF00'>Message Sent to " . $name . " Tournament Table. </font><br />";
        else echo "<font color='#FF0000'>Error: " . $api[Error] . ".</font><br />";
	   }
	   
	 else
	    echo  "<font color='#FF0000'>" . $name . " is not running.  No message sent. </font><br />";
  }

?>
Results look like this:

LHE Level 1 table is empty. No message sent.
LHE Level 2 table is empty. No message sent.
LHE Level 3 table is empty. No message sent.
LHE Level 4 table is empty. No message sent.
LHE Level 5 table is empty. No message sent.
LHE Level 6 table is empty. No message sent.
NLHE Level 1 table is empty. No message sent.
NLHE Level 1 6max table is empty. No message sent.
NLHE Level 1 HU table is empty. No message sent.
NLHE Level 2 table is empty. No message sent.
NLHE Level 2 6max table is empty. No message sent.
NLHE Level 2 HU table is empty. No message sent.
NLHE Level 3 table is empty. No message sent.
NLHE Level 3 6max table is empty. No message sent.
NLHE Level 3 HU table is empty. No message sent.
NLHE Level 4 table is empty. No message sent.
NLHE Level 4 6max table is empty. No message sent.
NLHE Level 4 HU table is empty. No message sent.
NLHE Level 5 table is empty. No message sent.
NLHE Level 5 6max table is empty. No message sent.
NLHE Level 5 HU table is empty. No message sent.
NLHE Level 6 table is empty. No message sent.
NLHE Level 6 6max table is empty. No message sent.

Message Sent to NLHE Level 6 HU Ring Game Table.
Error: Ring game not found.
Error: Ring game not found.
Error: Ring game not found.
Error: Ring game not found.
Error: Ring game not found.
Error: Ring game not found.

**Furious Friday Turbo is not running. No message sent.
**Hump Day 10k Deepstack is not running. No message sent.
**Saturday Showdown is not running. No message sent.
**Sunday Service is not running. No message sent.
*Daily Lunchbreak Turbo is not running. No message sent.
*Daily Night Owl Tourney is not running. No message sent.
Level 1 SnG is not running. No message sent.
Level 1 SnG 6max is not running. No message sent.
Level 1 SnG 6max Turbo is not running. No message sent.
Level 1 SnG HU is not running. No message sent.

Message Sent to Level 1 SnG HU Turbo Tournament Table.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.
is not running. No message sent.

Re: automated administrator messages?

Posted: Sat Jan 02, 2010 1:58 pm
by Mr.Victor
also how could I send those results to a log?

Re: automated administrator messages?

Posted: Sat Jan 02, 2010 3:36 pm
by Kent Briggs
Mr.Victor wrote:Ok I'm very new to php and mostly only use it for includes in my html but PM API has put me up to the challenge. I've written a script to send automated messages to ring games and tournaments and I'm sooooo close to getting it to work but it seems as soon as the code hits an active table something goes wrong. My code is probably not that great but like I said I'm a newb. Please let me know where I went wrong here.
My guess is that you might have some URL unfriendly characters in your table names that need to be encoded. So instead of this:

Code: Select all

$params = "Password=" . $pw . "&Command=RingGamesMessage&Name=" . $name . "&Message=" . $message;
Do this instead:

Code: Select all

$params = "Password=" . $pw . "&Command=RingGamesMessage&Name=" .  urlencode($name) . "&Message=" . urlencode($message);
And do the same for the tournaments. See if that makes any difference.

Re: automated administrator messages?

Posted: Sat Jan 02, 2010 3:41 pm
by Kent Briggs
Mr.Victor wrote:also how could I send those results to a log?
Every API command supports an optional Log parameter that you can include. See the examples in the help file near the top of the API topic of the Technical Information section. There is also a standalone LogAddEvent function in the API. It's only parameter is "Log".