From b2f93cba988e0733ae75deddf77162e46ca05128 Mon Sep 17 00:00:00 2001 From: kj415j45 Date: Sat, 18 Aug 2018 12:16:42 +0900 Subject: [PATCH 01/14] :memo: Add illustComment --- module/pixiv/IID.php | 1 + module/pixiv/search.php | 1 + 2 files changed, 2 insertions(+) diff --git a/module/pixiv/IID.php b/module/pixiv/IID.php index 1a6d3ee..511d8c6 100644 --- a/module/pixiv/IID.php +++ b/module/pixiv/IID.php @@ -17,6 +17,7 @@ $img = getIllustImgstr($pixiv); } $tags = getIllustTagsFromPixivJSON($pixiv); + $pixiv->illustComment = str_replace('
', "\n", $pixiv->illustComment); $msg=<<userId} 标签:{$tags} diff --git a/module/pixiv/search.php b/module/pixiv/search.php index e63fc40..1bb07b6 100644 --- a/module/pixiv/search.php +++ b/module/pixiv/search.php @@ -55,6 +55,7 @@ $pixiv = getIllustInfoByID($pixiv->illustId); $tags = getIllustTagsFromPixivJSON($pixiv); $img = getIllustImgstr($pixiv); +$pixiv->illustComment = str_replace('
', "\n", $pixiv->illustComment); $msg=<< Date: Sat, 18 Aug 2018 12:17:41 +0900 Subject: [PATCH 02/14] :bug: Better text --- public/noticeProcessor.php | 1 + public/requestProcessor.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/public/noticeProcessor.php b/public/noticeProcessor.php index 36f3872..b771c97 100644 --- a/public/noticeProcessor.php +++ b/public/noticeProcessor.php @@ -9,6 +9,7 @@ $Queue[]= sendBack(CQCode::At($Event['user_id']).' 欢迎加入本群,请阅读群公告!'); }else{ $Queue[]= sendBack('kjBot 已入驻本群,发送 '.config('prefix', '!').'help 查看帮助'."\nkjBot 用户协议:https://github.com/kjBot-Dev/TOS/blob/master/README.md"); + $Queue[]= sendMaster('Join group '.$Event['group_id'].' by '.$Event['operator_id']); } break; case 'group_decrease': diff --git a/public/requestProcessor.php b/public/requestProcessor.php index 8e55482..ee1e369 100644 --- a/public/requestProcessor.php +++ b/public/requestProcessor.php @@ -13,7 +13,7 @@ break; case 'invite': $CQ->setGroupAddRequest($Event['flag'], $Event['sub_type'], config('allowGroups')); - $Queue[]= sendMaster('Join Group '.$Event['group_id'].' by '.$Event['user_id']); //通知master + $Queue[]= sendMaster('Being invited to group '.$Event['group_id'].' by '.$Event['user_id']); //通知master break; default: } From 61b6b7b1f6e1029f8aae9b3174a803855145320d Mon Sep 17 00:00:00 2001 From: kj415j45 Date: Sat, 18 Aug 2018 22:01:02 +0900 Subject: [PATCH 03/14] :sparkles: Improve pixiv --- module/help/pixiv/IID.php | 1 + module/help/pixiv/search.php | 4 ++-- module/pixiv/IID.php | 14 ++++++++------ module/pixiv/search.php | 15 ++++++++------- module/pixiv/tools.php | 10 ---------- 5 files changed, 19 insertions(+), 25 deletions(-) diff --git a/module/help/pixiv/IID.php b/module/help/pixiv/IID.php index 39a707d..128e730 100644 --- a/module/help/pixiv/IID.php +++ b/module/help/pixiv/IID.php @@ -6,6 +6,7 @@ !pixiv.IID {ID} [...ID] 该命令可以接受多个ID,使用空格分隔。 +对于套图,可以使用 xxxxxxxx_yy 格式指定第 yy-1 张图 R18图片只会通过私聊发送,其他图片均直接返回。 EOT ); diff --git a/module/help/pixiv/search.php b/module/help/pixiv/search.php index 68920c2..e191840 100644 --- a/module/help/pixiv/search.php +++ b/module/help/pixiv/search.php @@ -7,13 +7,13 @@ !pixiv.search [参数] {关键字} 可用参数: - +-like xxxxx xxxxx为喜欢的人数,可能的值为 (1|2|5) x 10^(2|3|4)。 -mode {safe|r18} 指定搜索类型,群聊时该参数不生效 -page x x 为页码数 - x x 为当前页码中第几张图,超出范围时该参数不生效 搜索时会提示你关键字的结果数与相关信息。 -一页最多有40张图,将会从中随机返回一张。 +一页最多有40张图,未指定时将会从第一页中随机返回一张。 EOT; $Queue[]= sendBack($msg); diff --git a/module/pixiv/IID.php b/module/pixiv/IID.php index 511d8c6..e8bd230 100644 --- a/module/pixiv/IID.php +++ b/module/pixiv/IID.php @@ -10,23 +10,25 @@ if(preg_match('/(\d+)_(\d+)/', $iID, $result)){ //如果给出的是 manga ID 格式 $pixiv = getIllustInfoByID($result[1]); - $img = getIllustImgstr($pixiv, $result[2]); - }else{ $pixiv = getIllustInfoByID($iID); - $img = getIllustImgstr($pixiv); } $tags = getIllustTagsFromPixivJSON($pixiv); - $pixiv->illustComment = str_replace('
', "\n", $pixiv->illustComment); + $imgURL = isset($result[2])?str_replace('_p0', "_p{$result[2]}", $pixiv->urls->original):$pixiv->urls->original; + $pCount = $result[2]+1; + if($pCount>$pixiv->pageCount)leave('P数超出范围'); + $pixiv->illustComment = strip_tags(str_replace('
', "\n", $pixiv->illustComment)); $msg=<<illustId} 当前是 {$pCount}/{$pixiv->pageCount} P 画师ID:{$pixiv->userId} 标签:{$tags} +收藏:{$pixiv->bookmarkCount} 喜欢:{$pixiv->likeCount} 浏览:{$pixiv->viewCount} {$pixiv->illustTitle} {$pixiv->illustComment} - +[CQ:image,file={$imgURL}] EOT; - $msg.=sendImg($img); + setData('test.txt', var_export($pixiv, true)); if($pixiv->xRestrict === 1){ $Queue[]= sendPM($msg, false, true); //异步发送加快处理速度 }else{ diff --git a/module/pixiv/search.php b/module/pixiv/search.php index 1bb07b6..06135f4 100644 --- a/module/pixiv/search.php +++ b/module/pixiv/search.php @@ -19,8 +19,11 @@ case '-mode': $mode = nextArg(); break; + case '-like': + $word.= nextArg().urlencode('users入り '); + break; default: - $word.= $arg??''; + $word.= $arg?urlencode($arg.' '):''; } }while($arg !== NULL); @@ -54,22 +57,20 @@ $pixiv = $result[$index++]; $pixiv = getIllustInfoByID($pixiv->illustId); $tags = getIllustTagsFromPixivJSON($pixiv); -$img = getIllustImgstr($pixiv); -$pixiv->illustComment = str_replace('
', "\n", $pixiv->illustComment); +$pixiv->illustComment = strip_tags(str_replace('
', "\n", $pixiv->illustComment)); $msg=<<illustId} +插画ID:{$pixiv->illustId} 共 {$pixiv->pageCount} P 画师ID:{$pixiv->userId} 标签:{$tags} +收藏:{$pixiv->bookmarkCount} 喜欢:{$pixiv->likeCount} 浏览:{$pixiv->viewCount} {$pixiv->illustTitle} {$pixiv->illustComment} - +[CQ:image,file={$pixiv->urls->original}] EOT; -$msg.=sendImg($img); - $Queue[]= sendBack($msg); ?> \ No newline at end of file diff --git a/module/pixiv/tools.php b/module/pixiv/tools.php index 14f3eea..a75798b 100644 --- a/module/pixiv/tools.php +++ b/module/pixiv/tools.php @@ -7,16 +7,6 @@ ] ]; -function getIllustImgstr($pixiv, $page = NULL){ - global $pixivCookieHeader; - - $img = $pixiv->urls->original; - $imgHeader['http']['header']=$pixivCookieHeader['http']['header'].'referer: https://www.pixiv.net/member_illust.php?mode=medium&illust_id='.$pixiv->illustId."\n"; //伪造上级页面来源 - $imgStr = file_get_contents($img, false, stream_context_create($imgHeader)); - - return $imgStr; -} - function getIllustInfoByID($iID){ global $pixivCookieHeader; $web = file_get_contents('https://www.pixiv.net/member_illust.php?mode=medium&illust_id='.$iID, false, stream_context_create($pixivCookieHeader)); From fa572b1867b35bd2dbb092eb92c701613c256e0a Mon Sep 17 00:00:00 2001 From: kj415j45 Date: Tue, 21 Aug 2018 11:07:52 +0900 Subject: [PATCH 04/14] :art: Avoid original image being eaten --- module/pixiv/search.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/pixiv/search.php b/module/pixiv/search.php index 06135f4..9bfe145 100644 --- a/module/pixiv/search.php +++ b/module/pixiv/search.php @@ -68,9 +68,9 @@ {$pixiv->illustTitle} {$pixiv->illustComment} -[CQ:image,file={$pixiv->urls->original}] +[CQ:image,file={$pixiv->urls->regular}] EOT; $Queue[]= sendBack($msg); -?> \ No newline at end of file +?> From 3313695bf45e231647e6a4132beb4dcf580b4ed9 Mon Sep 17 00:00:00 2001 From: kj415j45 Date: Tue, 21 Aug 2018 11:10:52 +0900 Subject: [PATCH 05/14] :memo: Add about info --- module/about/main.php | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 module/about/main.php diff --git a/module/about/main.php b/module/about/main.php new file mode 100644 index 0000000..7a9358e --- /dev/null +++ b/module/about/main.php @@ -0,0 +1,3 @@ + Date: Tue, 21 Aug 2018 11:11:12 +0900 Subject: [PATCH 06/14] :memo: Update help --- module/help/about.php | 2 ++ module/help/main.php | 2 +- module/help/trans.php | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 module/help/about.php diff --git a/module/help/about.php b/module/help/about.php new file mode 100644 index 0000000..f6490c3 --- /dev/null +++ b/module/help/about.php @@ -0,0 +1,2 @@ + Date: Tue, 28 Aug 2018 00:41:54 +0900 Subject: [PATCH 07/14] :bug: F*cking noob logic --- module/crypto/hash.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/crypto/hash.php b/module/crypto/hash.php index dd3de88..4e0f114 100644 --- a/module/crypto/hash.php +++ b/module/crypto/hash.php @@ -7,7 +7,7 @@ if(!in_array($algo, hash_hmac_algos()))leave('不支持的散列类型'); -if($key !== NULL)$Queue[]= sendBack(hash($algo, $Text)); +if($key === NULL)$Queue[]= sendBack(hash($algo, $Text)); else $Queue[]= sendBack(hash_hmac($algo, $Text, $key)); ?> From 6af13b0107521f6178eb6e08411bec7a7ff245a2 Mon Sep 17 00:00:00 2001 From: kj415j45 Date: Wed, 5 Sep 2018 03:37:36 +0900 Subject: [PATCH 08/14] :sparkles: Add vndb --- module/search/vndb.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 module/search/vndb.php diff --git a/module/search/vndb.php b/module/search/vndb.php new file mode 100644 index 0000000..c4ef792 --- /dev/null +++ b/module/search/vndb.php @@ -0,0 +1,12 @@ + From 1354fafe0cb241ca1f5f335209233049246e62d3 Mon Sep 17 00:00:00 2001 From: kj415j45 Date: Wed, 5 Sep 2018 03:43:09 +0900 Subject: [PATCH 09/14] :sparkles: Add whatanime --- module/search/anime.php | 2 ++ module/whatanime/main.php | 44 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 module/search/anime.php create mode 100644 module/whatanime/main.php diff --git a/module/search/anime.php b/module/search/anime.php new file mode 100644 index 0000000..be897f1 --- /dev/null +++ b/module/search/anime.php @@ -0,0 +1,2 @@ + [ + 'method' => 'POST', + 'header' => << 'image='.$b64Image, + ] +]; + +decCredit($User_id, 5); +$resultJson = file_get_contents($whatanimeBase.'/search?token='.$token, false, stream_context_create($opt)); + +if(false === $resultJson){addCredit($User_id, 5);leave('过热中,请稍后重试');} +$anime = json_decode($resultJson)->docs[0]; +$minute = floor($anime->at/60); +$second = $anime->at%60; +$episode = is_numeric($anime->episode)?"第 {$anime->episode} 集":$anime->episode; +$R18 = $anime->is_adult?"R18 警告\n\n":''; +$similarity = sprintf('%.2f%%', $anime->similarity*100); + +$credit = getCredit($User_id); +$msg = <<title_native}({$anime->title_chinese}){$episode} +位于 {$minute}分{$second}秒 +可信度 {$similarity}(低于85%表明搜索结果很可能不准确) + +你的余额为 {$credit} +EOT; + +$Queue[]= sendBack($msg); \ No newline at end of file From e78b7bd2b91310dfe6c5a2bc8232533a63301b1c Mon Sep 17 00:00:00 2001 From: kj415j45 Date: Fri, 7 Dec 2018 23:03:25 +0800 Subject: [PATCH 10/14] :lipstick: Apply upstream change Ref: ppy/osu-web#3937 This PR changes user profile background resolution: 2000x700 -> 2800x620 this fix is for the new one, but compatible with the old one --- module/osu/profile.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/osu/profile.php b/module/osu/profile.php index a8a3e0b..b497947 100644 --- a/module/osu/profile.php +++ b/module/osu/profile.php @@ -107,7 +107,7 @@ ]; //开始绘图 $img = Image::make($user->cover_url); -$img->resize(1000, 350) +$img->fit(1000, 350) ->insert(Image::canvas(1000, 350)->fill([0, 0, 0, 0.5])) //背景暗化50% ->insert($avatar->resize(110, 110), 'top-left', 40, 220) //插入头像 ->text($user->username, 170, 256, imageFont($exo2_italic, 24, $white, 'left', 'top')) //插入用户名 @@ -131,7 +131,7 @@ $yIndex = 120; foreach($stat as $key => $value){ $img->text($key, 690, $yIndex, $stats_key); - $img->text($value, 930, $yIndex, imageFont($exo2_bold, 16, $white, 'right')); + $img->text($value, 930, $yIndex+2, imageFont($exo2_bold, 16, $white, 'right')); $yIndex+=20; } $img->text(sprintf('%.2f', $statics->pp), 690, 280, imageFont($exo2_bold, 40, $white)); From 6a4c7e641922a1874d8dcd0b70e7a477077c1d04 Mon Sep 17 00:00:00 2001 From: kj415j45 Date: Fri, 7 Dec 2018 23:07:38 +0800 Subject: [PATCH 11/14] :twisted_rightwards_arrows: Apply upstream change whatanime.ga -> trace.moe API updates --- module/whatanime/main.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/module/whatanime/main.php b/module/whatanime/main.php index 5e82289..c2e3737 100644 --- a/module/whatanime/main.php +++ b/module/whatanime/main.php @@ -3,7 +3,7 @@ loadModule('credit.tools'); global $Text, $Queue, $User_id; -$whatanimeBase = 'https://whatanime.ga/api'; +$whatanimeBase = 'https://trace.moe/api'; $token = config('whatanime_token'); if(!preg_match('/url=(\S*)[,\]]/', $Text, $match))leave('解析图片失败'); $image = file_get_contents($match[1]); @@ -13,11 +13,10 @@ 'http' => [ 'method' => 'POST', 'header' => << 'image='.$b64Image, + 'content' => "{\"image\": \"${b64Image}\"}", ] ]; From 1336e5095f7ba8d1b69bb4a3d61071e97ed95c5a Mon Sep 17 00:00:00 2001 From: kj415j45 Date: Fri, 7 Dec 2018 23:10:39 +0800 Subject: [PATCH 12/14] :memo: Fix bugs in log --- module/credit/tools.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module/credit/tools.php b/module/credit/tools.php index ae2ae72..1ac7c7a 100644 --- a/module/credit/tools.php +++ b/module/credit/tools.php @@ -5,19 +5,19 @@ function getCredit($QQ){ } function setCredit($QQ, $credit, $set = false){ - if($set)setData('credit.history', "* {$QQ} {$credit}\n", true); + if(!$set)setData('credit.history', date('Y-m-d/H:i:s')." * {$QQ} {$credit}\n", true); return setData("credit/{$QQ}", (int)$credit); } function addCredit($QQ, $income){ - setData('credit.history', "+ {$QQ} {$income}\n", true); + setData('credit.history', date('Y-m-d/H:i:s')." + {$QQ} {$income}\n", true); return setCredit($QQ, getCredit($QQ)+(int)$income, true); } function decCredit($QQ, $pay){ $balance = getCredit($QQ); if($balance >= $pay){ - setData('credit.history', "- {$QQ} {$pay}\n"); + setData('credit.history', date('Y-m-d/H:i:s')." - {$QQ} {$pay}\n"); return setCredit($QQ, (int)($balance-$pay), true); }else{ throw new \Exception('余额不足,还需要 '.($pay-$balance).' 个金币'); From ae0e019f5ff6240e7e1ab7fa64c1a67db5571a8c Mon Sep 17 00:00:00 2001 From: kj415j45 Date: Fri, 7 Dec 2018 23:27:05 +0800 Subject: [PATCH 13/14] :fire: Clean test code --- module/pixiv/IID.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/module/pixiv/IID.php b/module/pixiv/IID.php index e8bd230..a045f4e 100644 --- a/module/pixiv/IID.php +++ b/module/pixiv/IID.php @@ -28,7 +28,6 @@ {$pixiv->illustComment} [CQ:image,file={$imgURL}] EOT; - setData('test.txt', var_export($pixiv, true)); if($pixiv->xRestrict === 1){ $Queue[]= sendPM($msg, false, true); //异步发送加快处理速度 }else{ @@ -37,4 +36,4 @@ }while($iID!==NULL); -?> \ No newline at end of file +?> From 1a46e1e9322f9166f8c3d89010d4cf687ceccaa0 Mon Sep 17 00:00:00 2001 From: kj415j45 Date: Sun, 9 Dec 2018 21:38:14 +0800 Subject: [PATCH 14/14] :fire: Github Issues died --- module/help/issue.php | 14 +------------ module/issue/main.php | 46 ++++++++----------------------------------- 2 files changed, 9 insertions(+), 51 deletions(-) diff --git a/module/help/issue.php b/module/help/issue.php index 198a01c..4d0684b 100644 --- a/module/help/issue.php +++ b/module/help/issue.php @@ -1,16 +1,4 @@ diff --git a/module/issue/main.php b/module/issue/main.php index 388bc69..e7c83c9 100644 --- a/module/issue/main.php +++ b/module/issue/main.php @@ -1,42 +1,12 @@ setIssuer(config('Github_Integration_ID')) - ->setIssuedAt(time()) - ->setExpiration(time() + 60) - ->sign(new Sha256(), new Key(getData('kjBot-Github.pem'))) - ->getToken(); - -$github->authenticate($jwt, null, Github\Client::AUTH_JWT); -$token = $github->api('apps')->createInstallationToken(config('Github_Installation_ID')); -$github->authenticate($token['token'], null, Github\Client::AUTH_HTTP_TOKEN); - -$result = $github->api('issue')->create('kj415j45', 'kjBot', [ - 'title' => $title, - 'body' => '>创建者:'.$Event['user_id']."\n\n".$body, - 'assignees' => ['kj415j45'], -]); - -$Queue[]= sendBack('Issue 创建成功!'.$result['html_url']); -$Queue[]= sendMaster($Event['user_id'].' 创建了新 issue '.$result['html_url']."\n".var_export($Event, true)); +global $Queue; + +$Queue[]= sendBack(<< \ No newline at end of file