reasonableframework/helper/webhooktool.php

75 lines
2.7 KiB
PHP
Raw Normal View History

2019-05-04 06:53:21 +00:00
<?php
2019-05-04 06:57:48 +00:00
/**
* @file webhooktool.php
* @date 2019-05-04
* @author Go Namhyeon <gnh1201@gmail.com>
* @brief WebhookTools
* @trademark
2019-05-04 07:00:29 +00:00
* * `NateOn` is trademark of SK Communications Co Ltd., SK Planet Co Ltd., or other SK businesses.
2019-05-04 06:57:48 +00:00
* * `Discord' is trademark of Discord Inc. (Originally Hammer And Chisel)
* * `Slack` is trademark of Slack Technologies Inc.
*/
2019-05-25 07:18:25 +00:00
if(!check_function_exists("send_web_hook")) {
2019-05-20 08:19:05 +00:00
function send_web_hook($message, $networkid, $options=array()) {
$response = false;
2019-05-04 06:53:21 +00:00
2019-05-25 18:11:35 +00:00
$id = get_value_in_array("id", $options, "");
$username = get_value_in_array("username", $options, "ReasonableBot");
2019-05-25 18:12:08 +00:00
$message = str_replace("http:", "hxxp:", $message);
2019-05-25 11:37:03 +00:00
2019-05-20 08:19:05 +00:00
switch($networkid) {
case "nateon":
$request_url = sprintf("https://teamroom.nate.com/api/webhook/%s", $id);
if(loadHelper("webpagetool")) {
$response = get_web_page($request_url, "post", array(
"headers" => array(
"Content-Type" => "application/x-www-form-urlencoded",
),
"data" => array(
"content" => urlencode($message),
),
));
}
2019-05-04 06:53:21 +00:00
2019-05-25 18:11:35 +00:00
2019-05-20 08:19:05 +00:00
break;
2019-05-04 07:00:29 +00:00
2019-05-20 08:19:05 +00:00
case "discord":
$request_url = sprintf("https://discordapp.com/api/webhooks/%s", $id);
2019-05-25 07:18:25 +00:00
2019-05-20 08:19:05 +00:00
if(loadHelper("webpagetool")) {
$response = get_web_json($request_url, "jsondata", array(
"headers" => array(
"Content-Type" => "application/json",
),
"data" => array(
"content" => $message,
2019-05-25 07:18:25 +00:00
"username" => $username,
2019-05-20 08:19:05 +00:00
),
));
}
break;
2019-05-04 06:53:21 +00:00
2019-05-20 08:19:05 +00:00
case "slack":
$request_url = sprintf("https://hooks.slack.com/services/%s", $id);
if(loadHelper("webpagetool")) {
$response = get_web_json($request_url, "jsondata", array(
"headers" => array(
"Content-Type" => "application/json",
),
"data" => array(
"channel" => sprintf("#%s", get_value_in_array("channel", $options, "general")),
2019-05-25 07:18:25 +00:00
"username" => $username,
2019-05-20 08:19:05 +00:00
"text" => $message,
"icon_emoji" => sprintf(":%s:", get_value_in_array("emoji", $options, "ghost")),
),
));
}
break;
}
2019-05-04 07:00:29 +00:00
2019-05-20 08:19:05 +00:00
return $response;
}
2019-05-04 06:53:21 +00:00
}