From ea68d2d18ea736916e1e9ff59d9c98b5e8a9a748 Mon Sep 17 00:00:00 2001 From: MoeLoli Date: Wed, 17 Jul 2019 16:51:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AE=89=E5=85=A8=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=EF=BC=8C=E6=9B=B4=E6=8D=A2=E6=8E=A5=E5=8F=A3=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E5=9C=B0=E5=9D=80=EF=BC=88=E6=84=9F=E8=B0=A2=20Ridicu?= =?UTF-8?q?lous=20=E7=9A=84=E5=BB=BA=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Action.php | 38 ++++++++++++++++++++++++++------------ Plugin.php | 4 ++-- lib/Const.php | 2 +- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/Action.php b/Action.php index 6838c5f..c9d706b 100755 --- a/Action.php +++ b/Action.php @@ -40,18 +40,32 @@ public function RouteBan () { * @access public */ public function setWebhook () { - if (!$this->is_https()) { - exit (json_encode (array ('code' => -1, 'msg' => '原地爆炸,螺旋升天'))); - } - $newurl = (($GLOBALS['options']->rewrite) ? $GLOBALS['options']->siteUrl : $GLOBALS['options']->siteUrl . 'index.php/') . 'action/CommentEdit?do=CallBack'; - $ret = json_decode (Bootstrap::fetch ('https://api.telegram.org/bot' . $_POST['token'] . '/setWebhook', [ - 'url' => $newurl - ], 'POST'), true); + if ($this->_cfg->mode == 1) { + $addUrl = (($GLOBALS['options']->rewrite) ? $GLOBALS['options']->siteUrl : $GLOBALS['options']->siteUrl . 'index.php/') . 'action/CommentEdit?do=' . $GLOBALS['route']['Add']; + $delUrl = (($GLOBALS['options']->rewrite) ? $GLOBALS['options']->siteUrl : $GLOBALS['options']->siteUrl . 'index.php/') . 'action/CommentEdit?do=' . $GLOBALS['route']['Del']; + $markUrl = (($GLOBALS['options']->rewrite) ? $GLOBALS['options']->siteUrl : $GLOBALS['options']->siteUrl . 'index.php/') . 'action/CommentEdit?do=' . $GLOBALS['route']['Mark']; - if ($ret['ok'] == true) { + $text = <<< EOF +评论添加: {$addUrl} +评论删除: {$delUrl} +评论标记: {$markUrl} +EOF; + $GLOBALS['telegramModel']->sendMessage($this->_cfg->MasterID, $text); exit (json_encode (array ('code' => 0))); } else { - exit (json_encode (array ('code' => -1, 'msg' => $ret['description']))); + if (!$this->is_https()) { + exit (json_encode (array ('code' => -1, 'msg' => '原地爆炸,螺旋升天'))); + } + $newurl = (($GLOBALS['options']->rewrite) ? $GLOBALS['options']->siteUrl : $GLOBALS['options']->siteUrl . 'index.php/') . 'action/CommentEdit?do=CallBack'; + $ret = json_decode (Bootstrap::fetch ('https://api.telegram.org/bot' . $_POST['token'] . '/setWebhook', [ + 'url' => $newurl + ], 'POST'), true); + + if ($ret['ok'] == true) { + exit (json_encode (array ('code' => 0))); + } else { + exit (json_encode (array ('code' => -1, 'msg' => $ret['description']))); + } } } @@ -158,7 +172,7 @@ public function CallBack () { public function CommentAdd ($data = NULL) { if (empty($data)) { - exit (json_encode (array ('code' => -1, 'msg' => '原地爆炸,螺旋升天'))); + exit (json_encode (array ('code' => -1, 'msg' => '原地爆炸,螺旋升天 (A)'))); } if ($this->_cfg->mode == 0) { $cid = $data['cid']; @@ -239,7 +253,7 @@ public function CommentAdd ($data = NULL) { public function CommentDel ($data = NULL) { if (empty($data)) { - exit (json_encode (array ('code' => -1, 'msg' => '原地爆炸,螺旋升天'))); + exit (json_encode (array ('code' => -1, 'msg' => '原地爆炸,螺旋升天 (D)'))); } if ($this->_cfg->mode == 0) { $coid = $data['coid']; @@ -265,7 +279,7 @@ public function CommentDel ($data = NULL) { public function CommentMark ($data = NULL) { if (empty($data)) { - exit (json_encode (array ('code' => -1, 'msg' => '原地爆炸,螺旋升天'))); + exit (json_encode (array ('code' => -1, 'msg' => '原地爆炸,螺旋升天 (M)'))); } if ($this->_cfg->mode == 0) { $coid = $data['coid']; diff --git a/Plugin.php b/Plugin.php index b8752da..c805c5e 100755 --- a/Plugin.php +++ b/Plugin.php @@ -6,7 +6,7 @@ * * @package Comment2Telegram * @author Sora Jin - * @version 1.3.0 + * @version 1.3.1 * @link https://jcl.moe */ class Comment2Telegram_Plugin implements Typecho_Plugin_Interface { @@ -73,7 +73,7 @@ public static function config (Typecho_Widget_Helper_Form $form) { $form->addInput($Token->addRule('required', _t('您必须填写一个正确的Token'))); $MasterID = new Typecho_Widget_Helper_Form_Element_Text('MasterID', NULL, NULL, _t('MasterID'), _t('Telergam Master ID')); $form->addInput($MasterID->addRule('required', _t('您必须填写一个正确的 Telegram ID'))); - echo ''; + echo ''; } /** diff --git a/lib/Const.php b/lib/Const.php index 5b0d44e..4a88261 100755 --- a/lib/Const.php +++ b/lib/Const.php @@ -1,6 +1,6 @@