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

Commit

Permalink
🔀 Merge patch-2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
kj415j45 committed Aug 17, 2018
2 parents fce3347 + 6e85a46 commit 0a794a8
Show file tree
Hide file tree
Showing 22 changed files with 194 additions and 57 deletions.
1 change: 1 addition & 0 deletions SDK/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class API{
const clean_plugin_log = '/clean_plugin_log';
const _get_friend_list = '/_get_friend_list';
const _get_group_info = '/_get_group_info';
const _get_vip_info = '/_get_vip_info';
const __check_update = '/.check_update';
const __handle_quick_operation = '/.handle_quick_operation';
}
24 changes: 18 additions & 6 deletions SDK/CoolQ.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,12 @@ public function getVersionInfo(){
return $this->query($api, $param);
}

public function setRestart($clean_cache = false){
public function setRestart($clean_log = false, $clean_cache = false, $clean_event = false){
$api = API::set_restart;
$param = [
'clean_log' => $clean_log,
'clean_cache' => $clean_cache,
'clean_event'=> $clean_event,
];
return $this->query($api, $param);
}
Expand All @@ -336,16 +338,26 @@ public function cleanPluginLog(){
return $this->query($api, $param);
}

public function _getFriendList(){
public function _getFriendList($flat = false){
$api = API::_get_friend_list;
$param = [];
$param = [
'flat' => $flat,
];
return $this->query($api, $param);
}

public function _getGroupInfo($flat = false){
public function _getGroupInfo($group_id){
$api = API::_get_group_info;
$param = [
'flat' => $flat,
'group_id' => $group_id,
];
return $this->query($api, $param);
}

public function _get_vip_info($user_id){
$api = API::_get_vip_info;
$param = [
'user_id' => $user_id,
];
return $this->query($api, $param);
}
Expand Down Expand Up @@ -381,7 +393,7 @@ private function query($api, $param){
case 1:
return NULL;
default:
throw new \Exception("Query Failed", $result['retcode']);
throw new \Exception("Query Failed", $result->retcode);
}
}

Expand Down
4 changes: 2 additions & 2 deletions config.ini.example
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
API=127.0.0.1:5700
API="127.0.0.1:5700"
token=
prefix="!"
master=919815238
bot=2839098896
allowFriends=true
allowGroups=true
WelcomeMsg="感谢您添加 kjBot 为好友,发送 !help 查看帮助列表"
WelcomeMsg="感谢您添加 kjBot 为好友,发送 !help 查看帮助列表。用户协议:https://github.com/kjBot-Dev/TOS/blob/master/README.md"
;DEBUG=true
DebugListen=919815238
;Listen=
Expand Down
59 changes: 59 additions & 0 deletions module/AD/main.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

global $Queue, $Text, $CQ;
use kjBot\Frame\Message;
requireMaster();
set_time_limit(0);

$groupList = $CQ->getGroupList();
$whiteList = file_get_contents('https://raw.githubusercontent.com/kjBot-Dev/ADwhitelist/master/whitelist.json');
if(false === $whiteList)leave('打开白名单失败,终止');

$prefix=<<<EOT
广告:
----------
EOT;

$suffix=<<<EOT
----------
kjBot 正在接受广告推送请求,5元一次。屏蔽 1元/月。详情联系:[email protected]
EOT;

$Text = $prefix.$Text.$suffix;

$whiteList = json_decode($whiteList)->list;
$expireDay = [];
$success = 0;
$silence = 0;
$error = 0;
$now = new \DateTime();

foreach($whiteList as $group){
$expireDay[$group->group] = \DateTime::createFromFormat('Y-m-d H:i:s', $group->expire_day);
}

foreach($groupList as $group){
if(isset($expireDay[$group->group_id])){
if($now < $expireDay[$group->group_id])continue;
}
try{
$CQ->sendGroupMsg($group->group_id, $Text);
$success++;
}catch(\Exception $e){
if(-34 === $e->getCode()){
$silence++;
}else{
$error++;
}
$Queue[]= sendMaster("Query {$group->group_id} failed: ".$e->getCode());
}
if($error>5)leave('错误次数过多,终止');
sleep(10); //10秒延迟
}
$groupCount = count($groupList);
$whiteCount = $groupCount-$success-$error-$silence;
$Queue[]= sendMaster("目前共有 {$groupCount} 个群,有 {$whiteCount} 个群白名单生效中。\n已投放 {$success} 条广告,异常原因失败 {$error} 个,被 {$silence} 个群禁言中");

?>
21 changes: 19 additions & 2 deletions module/announce/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,28 @@
global $Queue, $Text, $CQ;
use kjBot\Frame\Message;
requireMaster();
set_time_limit(0);

$groupList = $CQ->getGroupList();
$success = 0;
$silence = 0;
$error = 0;

foreach($groupList as $group){
$Queue[]= new Message($Text, $group->group_id, true);
try{
$CQ->sendGroupMsg($group->group_id, $Text);
$success++;
}catch(\Exception $e){
if(-34 === $e->getCode()){
$silence++;
}else{
$error++;
}
$Queue[]= sendMaster("Query {$group->group_id} failed: ".$e->getCode());
}
if($error>5)leave('错误次数过多,终止');
sleep(10); //10秒延迟
}

$groupCount = count($groupList);
$Queue[]= sendMaster("目前共有 {$groupCount} 个群,成功 {$success} 个,异常原因失败 {$error} 个,被 {$silence} 个群禁言中");
?>
6 changes: 5 additions & 1 deletion module/credit/check.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
global $Queue, $Event;
use kjBot\SDK\CQCode;

$QQ = parseQQ(nextArg())??$Event['user_id'];
$QQ = nextArg();
if(!(preg_match('/\d+/', $QQ, $match) && $match[0] == $QQ)){
$QQ = parseQQ($QQ);
}
$QQ = $QQ??$Event['user_id'];
$Queue[]= sendBack(CQCode::At($QQ).' 的余额为 '.getData("credit/{$QQ}"));

?>
5 changes: 4 additions & 1 deletion module/credit/set.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

loadModule('credit.tools');

$QQ = parseQQ(nextArg());
$QQ = nextArg();
if(!(preg_match('/\d+/', $QQ, $match) && $match[0] == $QQ)){
$QQ = parseQQ($QQ);
}
$credit = (int)nextArg();
setCredit($QQ, $credit);

Expand Down
9 changes: 6 additions & 3 deletions module/credit/tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ function getCredit($QQ){
return (int)getData("credit/{$QQ}");
}

function setCredit($QQ, $credit){
function setCredit($QQ, $credit, $set = false){
if($set)setData('credit.history', "* {$QQ} {$credit}\n", true);
return setData("credit/{$QQ}", (int)$credit);
}

function addCredit($QQ, $income){
return setCredit($QQ, getCredit($QQ)+(int)$income);
setData('credit.history', "+ {$QQ} {$income}\n", true);
return setCredit($QQ, getCredit($QQ)+(int)$income, true);
}

function decCredit($QQ, $pay){
$balance = getCredit($QQ);
if($balance >= $pay){
return setCredit($QQ, (int)($balance-$pay));
setData('credit.history', "- {$QQ} {$pay}\n");
return setCredit($QQ, (int)($balance-$pay), true);
}else{
throw new \Exception('余额不足,还需要 '.($pay-$balance).' 个金币');
}
Expand Down
5 changes: 4 additions & 1 deletion module/credit/transfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
loadModule('credit.tools');
use kjBot\SDK\CQCode;

$QQ = parseQQ(nextArg());
$QQ = nextArg();
if(!(preg_match('/\d+/', $QQ, $match) && $match[0] == $QQ)){
$QQ = parseQQ($QQ);
}
$transfer = abs((int)nextArg());
transferCredit($Event['user_id'], $QQ, $transfer);

Expand Down
2 changes: 1 addition & 1 deletion module/osu/bp.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
$u = $user??$osuUser;
}else{
if($user == NULL){
throw new \Exception('未绑定 osu!,且未指定用户');
throw new \Exception("未绑定 osu!,请使用\n!osu.bind 用户名\n进行绑定");
}else{
$u = $user;
}
Expand Down
2 changes: 1 addition & 1 deletion module/osu/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
$osuid = $osuid??getOsuID($qq);

if($osuid == ''){
throw new \Exception('未绑定 osu!');
throw new \Exception("未绑定 osu!,请使用\n!osu.bind 用户名\n进行绑定");
}

$osuid = OsuUsernameEscape($osuid);
Expand Down
2 changes: 1 addition & 1 deletion module/osu/recent.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
$u = $user??$osuUser;
}else{
if($user == NULL){
throw new \Exception('未绑定 osu!,且未指定用户');
throw new \Exception("未绑定 osu!,请使用\n!osu.bind 用户名\n进行绑定");
}else{
$u = $user;
}
Expand Down
7 changes: 2 additions & 5 deletions module/pixiv/IID.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,21 @@
$pixiv = getIllustInfoByID($iID);
$img = getIllustImgstr($pixiv);
}
$tags = implode(' ', $pixiv->tags);

$tags = getIllustTagsFromPixivJSON($pixiv);
$msg=<<<EOT
画师ID:{$pixiv->userId}
标签:{$tags}
{$pixiv->illustTitle}
{$pixiv->illustComment}
EOT;

$msg.=sendImg($img);

if($pixiv->xRestrict === 1){
$Queue[]= sendPM($msg, false, true); //异步发送加快处理速度
}else{
$Queue[]= sendBack($msg, false, true);
}

}while($iID!==NULL);


Expand Down
5 changes: 4 additions & 1 deletion module/pixiv/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,18 @@
}

$pixiv = $result[$index++];
$tags = implode(' ', $pixiv->tags);
$pixiv = getIllustInfoByID($pixiv->illustId);
$tags = getIllustTagsFromPixivJSON($pixiv);
$img = getIllustImgstr($pixiv);

$msg=<<<EOT
该关键字共有 {$count[1]} 幅作品,这是第 {$page} 页第 {$index}
插画ID:{$pixiv->illustId}
画师ID:{$pixiv->userId}
标签:{$tags}
{$pixiv->illustTitle}
{$pixiv->illustComment}
EOT;

Expand Down
34 changes: 13 additions & 21 deletions module/pixiv/tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,10 @@
function getIllustImgstr($pixiv, $page = NULL){
global $pixivCookieHeader;

$img = $pixiv->url;
$img = str_replace('_master1200', '', $img); //消去尾缀
$img = str_replace('.jpg', '.png', $img); //优先尝试以 png 取得原图
if($page !== NULL){ //如果是在获取 manga ID
$img = str_replace('_p0.png', "_p{$page}.png", $img);
$img = str_replace('/img-master', '/img-original', $img);
$imgHeader['http']['header']=$pixivCookieHeader['http']['header'].'referer: https://www.pixiv.net/member_illust.php?mode=manga&illust_id='.$pixiv->illustId."\n";
}else{
$img = str_replace('/c/240x240/img-master', '/img-original', $img); //转换为原图路径
$imgHeader['http']['header']=$pixivCookieHeader['http']['header'].'referer: https://www.pixiv.net/member_illust.php?mode=medium&illust_id='.$pixiv->illustId."\n"; //伪造上级页面来源
}

$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));

if($imgStr === false){ //如果 png 没取到图
$img = str_replace('.png', '.jpg', $img);
$imgStr = file_get_contents($img, false, stream_context_create($imgHeader)); //改用 jpg 取图
if($imgStr === false){
leave('未知图片类型');
}
}

return $imgStr;
}

Expand All @@ -40,12 +22,22 @@ function getIllustInfoByID($iID){
$web = file_get_contents('https://www.pixiv.net/member_illust.php?mode=medium&illust_id='.$iID, false, stream_context_create($pixivCookieHeader));
if($web===false)leave('无法打开 Pixiv');

if(!preg_match('/"'.$iID.'":({[^}]*})/', $web, $result)){
if(!preg_match('/illust:\s?\{\s?'.$iID.':\s?({[\S\s]*}\})/', $web, $result)){
leave('没有这张插画');
}

$pixiv = json_decode($result[1]);
setData('test.txt', var_export($pixiv, true));
return $pixiv;
}

function getIllustTagsFromPixivJSON($pixiv){
$tags = $pixiv->tags->tags;
$tagString = '';
foreach($tags as $tag){
$tagString.= $tag->tag.' ';
}
return rtrim($tagString);
}

?>
1 change: 1 addition & 0 deletions module/recordStat/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
!recordStat.verify
EOT;

if(trim(getData('recordStat/'.$User_id))=='')
setData('recordStat/'.$User_id, 'read');
$Queue[]= sendPM($agreement); //仅在私聊中发送用户协议

Expand Down
19 changes: 18 additions & 1 deletion module/status/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,29 @@
$usedDiskPercent = sprintf('%.2f%%', $disk['used']/$disk['size']*100);

$msg=<<<EOT
[System]
Load: {$load['now']} {$load['5min']} {$load['15min']}
Mem: {$usedRam}/{$totalRam} ({$usedRamPercent})
Disk: {$usedDisk}/{$totalDisk} ({$usedDiskPercent})
Up: {$uptime['text']}
EOT;

$opcache = opcache_get_status(false);
if(is_array($opcache)){
$opcStatus = $opcache['opcache_statistics'];
$opcMemWasteRate = sprintf('%.2f%%', $opcache['memory_usage']['current_wasted_percentage']*100);
$opcHitRate = sprintf('%.2f%%', $opcStatus['opcache_hit_rate']);
$msg.=<<<EOT
[OPcache]
Mem Waste Rate: {$opcMemWasteRate}
Cached/Max: ({$opcStatus['num_cached_scripts']}){$opcStatus['num_cached_keys']}/{$opcStatus['max_cached_keys']}
Hits/Miss: {$opcStatus['hits']}/{$opcStatus['misses']} ({$opcHitRate})
Restart(OOM Hash): {$opcStatus['oom_restarts']} {$opcStatus['hash_restarts']}
EOT;
}

$Queue[]= sendBack($msg);

?>
?>
Loading

0 comments on commit 0a794a8

Please sign in to comment.