0

i want to send timed message likes @alertbot, my code like this. but at 20.30 the bot doesnt send any message.

date_default_timezone_set("mytimezone");
$time = date(H:i);
$date = date(d/m/Y);

$pesan = “/alert 20:30 27/04/2017 some texts”;
$chatid = 13245;

$texts = explode(“ “,$pesan,4);
$message = $texts[0];

switch ($message) {
    case ‘/alert’:
      $times = $texts[1];
      $dates = $texts[2];
      $text  = $texts[3];

    while ($times == $time && $dates == $date) {
       sendMessage($chatid,$text);  
       break;
// the bot will stop after sendMessage to chatid
    }
}

what's wrong with my script?

achmad311
  • 21
  • 6
  • date(H:i:s) will include seconds and will not match 20:30 – Sondre Apr 26 '17 at 06:47
  • oh thank you, but i've changed to date(H:i) the bot still doesnt send message at time. – achmad311 Apr 26 '17 at 06:57
  • I notice that your time is not a valid string. $times = "20:30"; should work better. Same goes for your date. – Sondre Apr 26 '17 at 07:15
  • And without knowing what sendMessage actually does I don't really see the point in having a while loop which you break after the first execution anyways, why not use a simple if? – Sondre Apr 26 '17 at 07:18
  • sorry miss on typing, actually date and time was from data array. – achmad311 Apr 26 '17 at 08:02
  • That was impossible to read, please edit your questions if you have updates to your code. – Sondre Apr 26 '17 at 08:08
  • How is your code called? Only when someone sends a message or via cron? If you are only aswering to messages the bot won't send any message by itself. You would instead have to use cron to run your script and store the requested alarms either as direct cronjobs (which i don't recommend) or in a database using a timestamp. – Tobias F. Apr 26 '17 at 08:24
  • yes, only when someone sends a message. oh thank you @TobiasF. i will try to use database using a timestamp, – achmad311 Apr 26 '17 at 08:32
  • cron is the solution for the timing, create e.g. a PHP-file which checks all of the entries with their timestamps and run it via cron in a regular interval. – Tobias F. Apr 26 '17 at 09:05
  • @achmad311 did it worked? – Tobias F. Apr 26 '17 at 13:56
  • @TobiasF. not yet, still trying. i'm new on this so may be it will take a more time. but i know what should i do, – achmad311 Apr 27 '17 at 01:50

0 Answers0