Browse Source

refactor: interface of cfop pic and whois query

master
Dnomd343 3 years ago
parent
commit
e3bcbaefd0
  1. 4
      cmdRoute.php
  2. 73
      models/cfopPic.php
  3. 13
      models/whoisQuery.php
  4. 12
      tgInterface.php

4
cmdRoute.php

@ -31,10 +31,10 @@ function route($cmd, $rawParam) { // 命令请求路由
$entry = new ntpCheckEntry; $entry = new ntpCheckEntry;
break; break;
case 'cfop': case 'cfop':
cfopPic($rawParam); $entry = new cfopPicEntry;
break; break;
case 'whois': case 'whois':
whoisQuery($rawParam); $entry = new whoisQueryEntry;
break; break;
} }
if ($entry) { if ($entry) {

73
models/cfopPic.php

@ -1,23 +1,19 @@
<?php <?php
class cfopPic { class cfopPicEntry {
private function picList() { private function getCfopMsg() {
return array( return array(
'text' => 'CFOP魔方公式合集', 'text' => 'CFOP魔方公式合集',
'reply_markup' => json_encode(array( 'reply_markup' => json_encode(array(
'inline_keyboard' => array( 'inline_keyboard' => array(
array( array([
array(
'text' => '网页下载', 'text' => '网页下载',
'url' => 'https://res.dnomd343.top/Share/cfop/' 'url' => 'https://res.dnomd343.top/Share/cfop/'
) ]),
), array([
array(
array(
'text' => '获取全部', 'text' => '获取全部',
'callback_data' => '/cfop all' 'callback_data' => '/cfop all'
) ]),
),
array( array(
array( array(
'text' => 'GAN', 'text' => 'GAN',
@ -37,58 +33,59 @@ class cfopPic {
); );
} }
private function sendPic($type) { // 返回图片文件ID private function getPicId($type) { // 返回图片文件ID
switch ($type) { switch ($type) {
case 'gan': case 'gan':
$fileId = 'BQACAgUAAxkBAAIBtGEOLnr4Q6D4Z_80bgfXq5xsZMeWAAKtAwACWy55VOU-SGKqc7aMIAQ'; return 'BQACAgUAAxkBAAIBtGEOLnr4Q6D4Z_80bgfXq5xsZMeWAAKtAwACWy55VOU-SGKqc7aMIAQ';
break;
case 'mfg': case 'mfg':
$fileId = 'BQACAgUAAxkBAAIB3WEOVHKeYrrGhFo-GffB0W-tQRKlAALQAwACWy55VGny8ArGMkfoIAQ'; return 'BQACAgUAAxkBAAIB3WEOVHKeYrrGhFo-GffB0W-tQRKlAALQAwACWy55VGny8ArGMkfoIAQ';
break;
case 'yx': case 'yx':
$fileId = 'BQACAgUAAxkBAAIB32EOVISFQbgmir2abj6QkgqaSX1WAALRAwACWy55VMEuU9lCYTYWIAQ'; return 'BQACAgUAAxkBAAIB32EOVISFQbgmir2abj6QkgqaSX1WAALRAwACWy55VMEuU9lCYTYWIAQ';
break;
} }
return array(
'document' => $fileId
);
} }
public function getPic($type) { private function getPic($type) { // 获取图片
switch ($type) { switch ($type) {
case 'gan': case 'gan':
case 'mfg': case 'mfg':
case 'yx': case 'yx':
return $this->sendPic($type); return array(
'document' => $this->getPicId($type)
);
case '': case '':
return $this->picList(); return $this->getCfopMsg();
default: default:
return array( return array(
'text' => '未知公式' 'text' => '未知公式'
); );
} }
} }
}
function cfopPic($rawParam) { // 发送CFOP图片入口 private function sendCfopPic($params) { // 发送图片或信息
global $chatId; if ($params['document']) {
sendAuto($chatId, (new cfopPic)->getPic($rawParam)); tgApi::sendDocument($params);
} } else {
tgApi::sendMessage($params);
}
}
public function query($rawParam) { // CFOP图片查询入口
$this->sendCfopPic($this->getPic($rawParam));
}
function cfopPicCallback($rawParam) { // 发送CFOP图片回调入口 public function callback($rawParam) { // CFOP图片回调入口
global $chatId, $messageId;
if ($rawParam === 'all') { if ($rawParam === 'all') {
sendAuto($chatId, (new cfopPic)->getPic('gan')); global $tgEnv;
sendAuto($chatId, (new cfopPic)->getPic('mfg')); tgApi::deleteMessage(array( // 删除源消息
sendAuto($chatId, (new cfopPic)->getPic('yx')); 'message_id' => $tgEnv['messageId']
sendPayload(array( // 删除源消息
'method' => 'deleteMessage',
'chat_id' => $chatId,
'message_id' => $messageId
)); ));
$this->sendCfopPic($this->getPic('gan'));
$this->sendCfopPic($this->getPic('mfg'));
$this->sendCfopPic($this->getPic('yx'));
return; return;
} }
sendAuto($chatId, (new cfopPic)->getPic($rawParam)); $this->sendCfopPic($this->getPic($rawParam));
}
} }
?> ?>

13
models/whoisQuery.php

@ -1,7 +1,7 @@
<?php <?php
class whoisQuery { class whoisQueryEntry {
public function query($domain) { public function getWhois($domain) {
$temp = explode('.', $domain); $temp = explode('.', $domain);
$tld = $temp[count($temp) - 1]; $tld = $temp[count($temp) - 1];
$servers = array( $servers = array(
@ -162,15 +162,14 @@ class whoisQuery {
} }
return $output; return $output;
} }
}
function whoisQuery($rawParam) { public function query($rawParam) {
global $chatId; $content = $this->getWhois($rawParam);
$content = (new whoisQuery)->query($rawParam); tgApi::sendMessage(array(
sendMessage($chatId, array(
'text' => $content, 'text' => $content,
'disable_web_page_preview' => 'true' // 不显示页面预览 'disable_web_page_preview' => 'true' // 不显示页面预览
)); ));
}
} }
?> ?>

12
tgInterface.php

@ -7,6 +7,18 @@ class tgApi {
), $chatId); ), $chatId);
} }
function sendDocument($params, $chatId = 0) { // 发送文件
if ($chatId === 0) { // 未指定chatId
global $tgEnv;
$chatId = $tgEnv['chatId'];
}
$params += array (
'method' => 'sendDocument',
'chat_id' => $chatId
);
return tgApi::sendPayload($params);
}
public function sendMessage($params, $chatId = 0) { // 发送消息 public function sendMessage($params, $chatId = 0) { // 发送消息
if ($chatId === 0) { // 未指定chatId if ($chatId === 0) { // 未指定chatId
global $tgEnv; global $tgEnv;

Loading…
Cancel
Save