Skip to content

Instantly share code, notes, and snippets.

@lewayotte
Created April 12, 2019 16:43
Show Gist options
  • Save lewayotte/13858396bbcbfb6ab20bff9e4fd91e21 to your computer and use it in GitHub Desktop.
Save lewayotte/13858396bbcbfb6ab20bff9e4fd91e21 to your computer and use it in GitHub Desktop.
Let Britney Spears tell people when they're getting Toxic in Slack... /toxic #
<?php
if ( empty( $_POST['command'] ) || $_POST['command'] != '/toxic' ) {
return false;
}
$command = $_POST['command'];
if ( empty( $_POST['text'] ) ) {
return false;
}
$toxic_value = intval( $_POST['text'] );
if ( empty( $_POST['token'] ) ) {
return false;
}
$token = $_POST['token'];
$toxic_emoji = ':toxic-waste:';
if ( $toxic_value < 0 ) {
$toxic_value = 0;
} else if ( $toxic_value > 11 ) {
$toxic_value = 10;
}
for ( $i = 0; $i <= 10; $i ++ ) {
if ( $i == $toxic_value ) {
$toxic_array[] = $toxic_emoji;
} else if ( $i == 0 ) {
$toxic_array[] = '0';
} else if ( $i == 5 ) {
$toxic_array[] = '5';
} else if ( $i == 10 ) {
$toxic_array[] = '10';
} else {
$toxic_array[] = '- -';
}
}
if ( 11 == $toxic_value ) {
$toxic_array[] = $toxic_emoji;
}
$message = '[ ' . join( ' ', $toxic_array ) . ' ]';
if ( $toxic_value >= 7 ) {
$message .= "\nDon't you know that you're toxic?";
}
send_to_slack( $message );
function send_to_slack( $message ) {
$ch = curl_init( 'WEBHOOK_URL' );
$header = array(
'Content-type: application/json'
);
$data = json_encode([
'text' => $message,
]);
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'POST' );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $header );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
$result = curl_exec( $ch );
curl_close( $ch);
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment