Skip to content

Instantly share code, notes, and snippets.

@aaronpk
Created August 26, 2015 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronpk/9277c4465fa6b2864875 to your computer and use it in GitHub Desktop.
Save aaronpk/9277c4465fa6b2864875 to your computer and use it in GitHub Desktop.
<?php
$msg = $_POST['msg'];
$nick = $_POST['nick'];
$user = $_POST['user'];
$icon = $_POST['icon'];
if(!preg_match('/^\[/', $nick)) {
$msg = preg_replace(array('/\x03\d{1,2}/','/\x03/'), '', $msg);
$msg = preg_replace(
array('/(^|\s)(\/[^ ]+)/i','/\[\[([^\]]+)\]\]/'),
array('$1http://indiewebcamp.com$2','[[http://indiewebcamp.com/$1]]'), $msg);
$msg = str_replace('http://indiewebcamp.com/me', '/me', $msg);
$msg = str_replace('http://indiewebcamp.com/nick', '/nick', $msg);
// Convert mentions of slack usernames "[aaronpk]" to slack format "@aaronpk"
$msg = preg_replace('/\[([^@\ ]]+)\]/', '@$1', $msg);
// Except [mention] and [bridgy]
$msg = preg_replace('/^@(mention|bridgy)/', '[$1]', $msg);
$payload = array(
'text' => $msg,
'username' => $nick,
'icon_url' => $icon
);
$ch = curl_init($slack_hook_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('payload'=>json_encode($payload))));
$response = curl_exec($ch);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment