return ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'][$monthNum-1];
}
-// XXX: Consider renaming these to "is[First/Last]WeekOf[Month/Season]"
function isStartOfSeason($monthNum, $dayNum) {
return ($monthNum)%3 == 0 && isStartOfMonth($dayNum);
}
}
);
}
+
+function log_error($num, $str, $file, $line, $context = null) {
+ $message = $str . "\n" . $file . "(" . $line . ")";
+ getTelegram()->sendMessage([
+ 'chat_id' => array_flip(PARTICIPANT_IDS)['Cam'],
+ 'parse_mode' => 'Markdown',
+ 'text' => "I think there's a mistake in my programming. I can still run but something went wrong... Here's what I know:\n\n```\n" . $message . "\n```"
+ ]);
+}
+
+function log_exception(Throwable $e) {
+ $message = $e->getMessage() . "\n" . $e->getFile() . "(" . $e->getLine() . ")";
+ getTelegram()->sendMessage([
+ 'chat_id' => array_flip(PARTICIPANT_IDS)['Cam'],
+ 'parse_mode' => 'Markdown',
+ 'text' => "Oh man, I hurt myself trying to do something and had to stop... Here's what I know:\n\n```\n" . $message . "\n\n" . $e->getTraceAsString() . "\n```"
+ ]);
+ exit();
+}
+
+function check_for_fatal() {
+ $error = error_get_last();
+ if (in_array(
+ $error['type'],
+ [E_PARSE, E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR]
+ )) {
+ $message = $error['message'] . "\n" . $error['file'] . "(" . $error['line'] . ")";
+ getTelegram()->sendMessage([
+ 'chat_id' => array_flip(PARTICIPANT_IDS)['Cam'],
+ 'parse_mode' => 'Markdown',
+ 'text' => "Oh man, I hurt myself trying to do something and had to stop... Here's what I know:\n\n```\n" . $message . "\n\n" . $e->getTraceAsString() . "\n```"
+ ]);
+ exit();
+ }
+
+ if($error) {
+ $message = $error['message'] . "\n" . $error['file'] . "(" . $error['line'] . ")";
+ getTelegram()->sendMessage([
+ 'chat_id' => array_flip(PARTICIPANT_IDS)['Cam'],
+ 'parse_mode' => 'Markdown',
+ 'text' => "I think there's a mistake in my programming. I can still run but something went wrong... Here's what I know:\n\n```\n" . $message . "\n```"
+ ]);
+ }
+}
+
+if (SEND_ERRORS_TO_TELEGRAM) {
+ register_shutdown_function( "check_for_fatal" );
+ set_error_handler( "log_error" );
+ set_exception_handler( "log_exception" );
+ error_reporting( E_ALL );
+}