Skip to content

Instantly share code, notes, and snippets.

@trepmal
Last active June 4, 2025 03:42
Show Gist options
  • Save trepmal/978ce01e1cd17c614876c508cae53eb8 to your computer and use it in GitHub Desktop.
Save trepmal/978ce01e1cd17c614876c508cae53eb8 to your computer and use it in GitHub Desktop.
<?php
$allowed_tokens = [
];
if ( ! in_array( $_POST['token'], $allowed_tokens, true ) ) {
die('forbidden');
}
$query = $_POST['text'];
if ( "help" == $query || empty( $query ) ) {
header("cache-control: no-store, no-cache, must-revalidate");
header("content-type: application/json");
$response = [
"response_type" => "in_channel",
"blocks" => [
[
"type" => "section",
"text" => [
"type" => "mrkdwn",
"text" => "[<style>|]your text\n".
"\nExample: `neon|glow big or glow home`".
"\nYields: :neon-g::neon-l::neon-o::neon-w::empty::neon-b::neon-i::neon-g::empty::neon-o::neon-r::empty::neon-g::neon-l::neon-o::neon-w::empty::neon-h::neon-o::neon-m::neon-e:\n".
"\nExample: `i hate mondays`".
"\nYields: :garfield_i::empty::garfield_h::garfield_a::garfield_t::garfield_e::empty::garfield_m::garfield_o::garfield_n::garfield_d::garfield_a::garfield_y::garfield_s:\n".
"\nDefault style is 'garfield'. Other options are: 'yellow', 'white', 'comic', 'intense', 'neon', 'flicker', 'caps', 'scrabble', 'janky', 'boop', 'boop2', 'boop3'\n".
"All support alphas, but number and punctuation support is mixed"
]
],
[
"type" => "context",
"elements" => [
[
"type" => "mrkdwn",
"text" => sprintf( '<%s|Source code>', 'https://gist.github.com/trepmal/978ce01e1cd17c614876c508cae53eb8' )
],
[
"type" => "plain_text",
"text" => ':heart: @trepmal'
]
]
],
]
];
die( json_encode( $response ) );
}
$query = strtolower( $query );
preg_match( "/^(?:([a-z0-9]*)\|)?(.*?)$/", $query, $matches );
$style = $matches[1];
$text = $matches[2];
$text = trim( str_replace( ' ', ' ', $text ) );
$text_length = strlen( $text );
if ( $text_length < 3 ) {
$flicker_modulo = 2;
} elseif ( $text_length < 15 ) {
$flicker_modulo = 3;
} else {
$flicker_modulo = 6;
}
if ( in_array( $style, [ 'boop', 'boop1', 'boop2', 'boop3' ] ) ) {
require 'boop.php';
$return_text = render_word( $text );
if ( $style == 'boop2' ) {
$return_text = str_replace('boop-1','boop-2', $return_text );
}
if ( $style == 'boop3' ) {
$return_text = str_replace('boop-1','boop-3', $return_text );
}
} else {
$letters = array_map( function( $i ) use ( $style, $flicker_modulo ) {
switch ( $style ) {
case 'boop':
if ( preg_match('/[a-z\?\!.-]/i', $i ) ) {
$i = str_replace(
[ '?', '#', '!', '@'],
[ 'question', 'hash', 'exclamation', 'at'],
$i
);
$i = ":alphabet-yellow-$i:";
}
break;
case 'yellow':
if ( preg_match('/[a-z0-9\?#\!@]/i', $i ) ) {
$i = str_replace(
[ '?', '#', '!', '@'],
[ 'question', 'hash', 'exclamation', 'at'],
$i
);
$i = ":alphabet-yellow-$i:";
}
break;
case 'white':
if ( preg_match('/[a-z0-9\?#\!@]/i', $i ) ) {
$i = str_replace(
[ '?', '#', '!', '@'],
[ 'question', 'hash', 'exclamation', 'at'],
$i
);
$i = ":alphabet-white-$i:";
}
break;
case 'comic':
if ( preg_match('/[a-z0-9]/i', $i ) ) {
$i = ":comicsans$i:";
}
break;
case 'neon':
if ( preg_match('/[a-z]/i', $i ) ) {
$i = ":neon-$i:";
}
break;
case 'intense':
if ( preg_match('/[a-z0-9]/i', $i ) ) {
$i = ":garfield_$i-intensifies:";
}
break;
case 'janky':
if ( preg_match('/[a-z0-9\?\!]/i', $i ) ) {
$i = str_replace(
[ '?', '!'],
[ 'question-mark', 'exclamation-mark' ],
$i
);
$i = ":janky-$i:";
}
break;
case 'flicker':
if ( preg_match('/[a-z]/i', $i ) ) {
$i = sprintf( ":neon-$i%s:", ( rand( 0, 100 ) % $flicker_modulo === 0 ? '-flicker' : '' ) );
}
break;
case 'caps':
if ( preg_match('/[a-z]/i', $i ) ) {
$i = ":letters-cap-$i:";
}
break;
case 'scrabble':
if ( preg_match('/[a-z]/i', $i ) ) {
$i = ":$i-scrabble:";
}
break;
case 'garfield':
default:
if ( preg_match('/[a-z0-9]/i', $i ) ) {
$i = ":garfield_$i:";
}
}
if ( ' ' === $i ) {
$i = ":empty:";
}
return $i;
}, str_split( $text, 1 ) );
$return_text = implode( $letters );
} // end if style
$response = [
"response_type" => "in_channel",
"blocks" => [
[
"type" => "section",
"text" => [
"type" => "mrkdwn",
"text" => $return_text
]
],
[
"type" => "context",
"elements" => [
[
"type" => "mrkdwn",
"text" => sprintf( '<%s|Source code>', 'https://gist.github.com/trepmal/978ce01e1cd17c614876c508cae53eb8' )
],
[
"type" => "plain_text",
"text" => ':heart: @trepmal'
]
]
],
]
];
header("cache-control: no-store, no-cache, must-revalidate");
header( 'Content-Type: application/json' );
die( json_encode( $response ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment