Skip to content
This repository has been archived by the owner on Nov 22, 2019. It is now read-only.

Patch 2.7 #149

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions module/about/main.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
global $Queue;
$Queue[]= sendBack(getData('about.txt'));
6 changes: 3 additions & 3 deletions module/credit/tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -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).' 个金币');
Expand Down
2 changes: 1 addition & 1 deletion module/crypto/hash.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));

?>
2 changes: 2 additions & 0 deletions module/help/about.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
loadModule('about');
14 changes: 1 addition & 13 deletions module/help/issue.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
<?php

global $Queue;
$msg=<<<EOT
报告一个问题
用法:
!issue
{标题}
[细节内容]

该命令有24小时冷却时间
EOT;

$Queue[]= sendBack($msg);
loadModule('issue');

?>
2 changes: 1 addition & 1 deletion module/help/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
!help.{命令}[.下一级命令]
获得特定命令的帮助
可用命令:
checkin credit issue osu pixiv recordStat roll search sleep time trans unsleep version voice
about checkin credit issue osu pixiv recordStat roll search sleep time trans unsleep version voice

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

机器人被拉进群之后也可以提示一下 使用 !about 了解什么是 kjBot 。

EOT;

$Queue[]= sendBack($msg);
Expand Down
1 change: 1 addition & 0 deletions module/help/pixiv/IID.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
!pixiv.IID {ID} [...ID]

该命令可以接受多个ID,使用空格分隔。
对于套图,可以使用 xxxxxxxx_yy 格式指定第 yy-1 张图
R18图片只会通过私聊发送,其他图片均直接返回。
EOT
);
Expand Down
4 changes: 2 additions & 2 deletions module/help/pixiv/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion module/help/trans.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
leave(<<<EOT
使用谷歌翻译
用法:
!voice {源语言} {目标语言}
!trans {源语言} {目标语言}
{
文本
}
Expand Down
46 changes: 8 additions & 38 deletions module/issue/main.php
Original file line number Diff line number Diff line change
@@ -1,42 +1,12 @@
<?php

global $Queue, $Text, $Event;
use Http\Adapter\Guzzle6\Client as GuzzleClient;
use Lcobucci\JWT\Builder;
use Lcobucci\JWT\Signer\Key;
use Lcobucci\JWT\Signer\Rsa\Sha256;

$builder = new Github\HttpClient\Builder(new GuzzleClient());

$length = strpos($Text, "\r");
if(false===$length)$length=strlen($Text);
$title = substr($Text, 0, $length);
$body = substr($Text, $length+2);

if($title == '')leave('请提供 issue 标题');

if(coolDown("issue/{$Event['user_id']}")<0)leave('冷却中');
coolDown("issue/{$Event['user_id']}", 60*60*24);

$github = new Github\Client($builder, 'machine-man-preview');
$jwt = (new Builder)
->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(<<<EOT
请前往 https://support.qq.com/products/47576 进行反馈。
最快回复时间为一天,最慢不会超过一周。
如果您的问题长时间无答复,请联系 [email protected]
EOT
);

?>
4 changes: 2 additions & 2 deletions module/osu/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) //插入用户名
Expand All @@ -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));
Expand Down
14 changes: 8 additions & 6 deletions module/pixiv/IID.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@

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);
$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('<br />', "\n", $pixiv->illustComment));
$msg=<<<EOT
插画ID:{$pixiv->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);
if($pixiv->xRestrict === 1){
$Queue[]= sendPM($msg, false, true); //异步发送加快处理速度
}else{
Expand All @@ -34,4 +36,4 @@
}while($iID!==NULL);


?>
?>
16 changes: 9 additions & 7 deletions module/pixiv/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -54,21 +57,20 @@
$pixiv = $result[$index++];
$pixiv = getIllustInfoByID($pixiv->illustId);
$tags = getIllustTagsFromPixivJSON($pixiv);
$img = getIllustImgstr($pixiv);
$pixiv->illustComment = strip_tags(str_replace('<br />', "\n", $pixiv->illustComment));

$msg=<<<EOT
该关键字共有 {$count[1]} 幅作品,这是第 {$page} 页第 {$index} 幅
插画ID:{$pixiv->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->regular}]
EOT;

$msg.=sendImg($img);

$Queue[]= sendBack($msg);

?>
?>
10 changes: 0 additions & 10 deletions module/pixiv/tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions module/search/anime.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
loadModule('whatanime');
12 changes: 12 additions & 0 deletions module/search/vndb.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

global $Queue;
$query='';
$mode = nextArg();
do{
$arg = nextArg();
$query.=urlencode($arg).'+';
}while($arg!==NULL);
$Queue[]= sendBack('https://vndb.org/'.$mode.'/all?q='.rtrim($query, '+'));

?>
43 changes: 43 additions & 0 deletions module/whatanime/main.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

loadModule('credit.tools');
global $Text, $Queue, $User_id;

$whatanimeBase = 'https://trace.moe/api';
$token = config('whatanime_token');
if(!preg_match('/url=(\S*)[,\]]/', $Text, $match))leave('解析图片失败');
$image = file_get_contents($match[1]);
$b64Image = base64_encode($image);

$opt = [
'http' => [
'method' => 'POST',
'header' => <<<EOT
Content-Type: application/json
EOT
,
'content' => "{\"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 = <<<EOT
{$R18}你搜索的图片来自 {$anime->title_native}({$anime->title_chinese}){$episode}
位于 {$minute}分{$second}秒
可信度 {$similarity}(低于85%表明搜索结果很可能不准确)

你的余额为 {$credit}
EOT;

$Queue[]= sendBack($msg);
1 change: 1 addition & 0 deletions public/noticeProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here, ref to the comment above :)

$Queue[]= sendMaster('Join group '.$Event['group_id'].' by '.$Event['operator_id']);
}
break;
case 'group_decrease':
Expand Down
2 changes: 1 addition & 1 deletion public/requestProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
}
Expand Down