Created
November 21, 2022 16:22
-
-
Save georgestephanis/ade72ae58e75066b69c63a7ab5cc8507 to your computer and use it in GitHub Desktop.
don't forget to add in the bearer token on line 23
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function set_myself_afk() { | |
$tz = date('I') ? 'EST' : 'EDT'; | |
$expiration = strtotime( "+1 Weekday 9am {$tz}" ); | |
$weekday = array( | |
'status_text' => 'AFK for the evening.', | |
'status_emoji' => ':family:', | |
'status_expiration' => $expiration, | |
); | |
$weekend = array( | |
'status_text' => 'AFK for the weekend.', | |
'status_emoji' => ':weekend-2:', | |
'status_expiration' => $expiration, | |
); | |
$opts = array( | |
'http' => array( | |
'method' => 'POST', | |
'header' => array( | |
'Authorization: Bearer TOKEN_GOES_HERE', | |
'Content-Type: application/json', | |
), | |
'content' => json_encode( | |
array( | |
'profile' => ( 5 <= (int) date( 'w' ) ) ? $weekend : $weekday, | |
) | |
), | |
), | |
); | |
$contents = file_get_contents( | |
'https://slack.com/api/users.profile.set', | |
false, | |
stream_context_create( $opts ) | |
); | |
return $contents; | |
} | |
set_myself_afk(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The crontab entry I use to fire this at 3:30pm on Weekdays for me is --