Browse Source

refactor: new CFOP pic model

dev
Dnomd343 3 years ago
parent
commit
3e2c1a1ca8
  1. 83
      models/cfopPic.php

83
models/cfopPic.php

@ -1,11 +1,8 @@
<?php <?php
class cfopPicEntry { class cfopPicEntry { // 获取CFOP公式图片
private function getCfopMsg() { private function sendMenu() { // 发送菜单
return array( $buttons = array(
'text' => 'CFOP魔方公式合集',
'reply_markup' => json_encode(array(
'inline_keyboard' => array(
array([ array([
'text' => '网页下载', 'text' => '网页下载',
'url' => 'https://res.dnomd343.top/Share/cfop/' 'url' => 'https://res.dnomd343.top/Share/cfop/'
@ -28,64 +25,50 @@ class cfopPicEntry {
'callback_data' => '/cfop yx' 'callback_data' => '/cfop yx'
) )
) )
)
))
); );
tgApi::sendMessage(array(
'text' => 'CFOP魔方公式合集',
'reply_markup' => json_encode(array(
'inline_keyboard' => $buttons
))
));
} }
private function getPicId($type) { // 返回图片文件ID private function sendCfopPic($type) { // 发送图片
global $env; global $env;
switch ($type) { if ($type === 'gan') {
case 'gan': $picId = $env['CFOP_GAN'];
return $env['CFOP_GAN']; } else if ($type === 'mfg') {
case 'mfg': $picId = $env['CFOP_MFG'];
return $env['CFOP_MFG']; } else if ($type === 'yx') {
case 'yx': $picId = $env['CFOP_YX'];
return $env['CFOP_YX']; } else if ($type === '' || $type === 'help') {
} $this->sendMenu();
}
private function getPic($type) { // 获取图片
switch ($type) {
case 'gan':
case 'mfg':
case 'yx':
return array(
'document' => $this->getPicId($type)
);
case '':
return $this->getCfopMsg();
default:
return array(
'text' => '未知公式'
);
}
}
private function sendCfopPic($params) { // 发送图片或信息
if ($params['document']) {
tgApi::sendDocument($params);
} else { } else {
tgApi::sendMessage($params); tgApi::sendText('未知公式');
}
if (isset($picId)) {
tgApi::sendDocument(array(
'document' => $picId
));
} }
} }
public function query($rawParam) { // CFOP图片查询入口 public function query($rawParam) { // CFOP图片查询入口
$this->sendCfopPic($this->getPic($rawParam)); $this->sendCfopPic($rawParam);
} }
public function callback($rawParam) { // CFOP图片回调入口 public function callback($rawParam) { // CFOP图片回调入口
if ($rawParam === 'all') { if ($rawParam !== 'all') {
global $tgEnv; $this->sendCfopPic($rawParam);
tgApi::deleteMessage(array( // 删除源消息
'message_id' => $tgEnv['messageId']
));
$this->sendCfopPic($this->getPic('gan'));
$this->sendCfopPic($this->getPic('mfg'));
$this->sendCfopPic($this->getPic('yx'));
return; return;
} }
$this->sendCfopPic($this->getPic($rawParam)); $this->sendCfopPic('gan');
$this->sendCfopPic('mfg');
$this->sendCfopPic('yx');
tgApi::deleteMessage(array( // 删除源消息
'message_id' => $GLOBALS['tgEnv']['messageId']
));
} }
} }

Loading…
Cancel
Save