From 1ed8a3a50b3dcc32a39eed6a126a2759f8e598f2 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Mon, 9 Aug 2021 17:02:07 +0800 Subject: [PATCH] feat: base framework of tgbot --- .env | 2 ++ cmdRoute.php | 23 +++++++++++++++++ main.php | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ tgInterface.php | 60 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 154 insertions(+) create mode 100644 .env create mode 100644 cmdRoute.php create mode 100644 main.php create mode 100644 tgInterface.php diff --git a/.env b/.env new file mode 100644 index 0000000..9af583b --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +BOT_NAME={Bot Username} +BOT_TOKEN={Bot Api_token} diff --git a/cmdRoute.php b/cmdRoute.php new file mode 100644 index 0000000..d14ff1f --- /dev/null +++ b/cmdRoute.php @@ -0,0 +1,23 @@ + diff --git a/main.php b/main.php new file mode 100644 index 0000000..f880881 --- /dev/null +++ b/main.php @@ -0,0 +1,69 @@ + diff --git a/tgInterface.php b/tgInterface.php new file mode 100644 index 0000000..3641d40 --- /dev/null +++ b/tgInterface.php @@ -0,0 +1,60 @@ + $content) { + $url .= '&' . $param . '=' . urlencode($content); + } + return file_get_contents($url); +} + +function sendMessage($chatId, $params) { // 发送消息 + $params += array ( + 'method' => 'sendMessage', + 'chat_id' => $chatId + ); + return sendPayload($params); +} + +function sendDocument($chatId, $params) { // 发送文件 + $params += array ( + 'method' => 'sendDocument', + 'chat_id' => $chatId + ); + return sendPayload($params); +} + +function sendText($chatId, $msg) { // 发送纯文本 + return sendMessage($chatId, array( + 'text' => $msg + )); +} + +function sendAuto($chatId, $content) { // 自动判别发送类型 + if (isset($content['document'])) { // 以文件类型发送 + sendDocument($chatId, $content); + } else { + sendMessage($chatId, $content); + } +} + +function debugDump() { // 调试接口 + global $webhook; + global $isCallback, $isGroup; + global $messageId, $chatId, $userId; + global $messageText, $userName, $userAccount, $userLanguage; + $msg .= 'isCallback: ' . ($isCallback ? 'true' : 'false') . PHP_EOL; + $msg .= 'isGroup: ' . ($isGroup ? 'true' : 'false') . PHP_EOL; + $msg .= 'messageText: ' . $messageText . PHP_EOL; + $msg .= 'messageId: ' . $messageId . PHP_EOL; + $msg .= 'chatId: ' . $chatId . PHP_EOL; + $msg .= 'userId: ' . $userId . PHP_EOL; + $msg .= 'userName: ' . $userName . PHP_EOL; + $msg .= 'userAccount: ' . $userAccount . PHP_EOL; + $msg .= 'userLanguage: ' . $userLanguage . PHP_EOL; + sendText($chatId, $msg); + sendText($chatId, json_encode($webhook)); +} + +?>