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

Commit

Permalink
Merge pull request #93 from kj415j45/patch-2.6
Browse files Browse the repository at this point in the history
Patch 2.6
  • Loading branch information
kj415j45 authored Aug 9, 2018
2 parents afbba71 + 59da32f commit fce3347
Show file tree
Hide file tree
Showing 26 changed files with 576 additions and 166 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"knplabs/github-api": "^2.9",
"lcobucci/jwt": "^3.2",
"linfo/linfo": "^4.0",
"meyfa/php-svg": "^0.9.0",
"nelexa/zip": "^3.1",
"php-http/guzzle6-adapter": "^1.1",
"statickidz/php-google-translate-free": "^1.0"
Expand Down
47 changes: 46 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion module/help/osu.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$msg=<<<EOT
osu! 系列命令
用法:
!osu.{bind|bp|listen|me|recent|setMode} [参数列表]
!osu.{bind|bp|listen|profile|recent|setMode} [参数列表]
具体用法请查看下一级 help
EOT;
Expand Down
2 changes: 1 addition & 1 deletion module/help/osu/me.php → module/help/osu/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$msg=<<<EOT
展示你的 osu! 个人资料
用法:
!osu.me [...]
!osu.profile [...]
参数列表:
-user "用 户 名" 查看别人的资料
Expand Down
2 changes: 1 addition & 1 deletion module/help/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
$msg=<<<EOT
搜索
用法:
!search{.pixiv|.baidu|.google}
!search.{pixiv|baidu|google}
返回指定的搜索引擎链接
Expand Down
2 changes: 1 addition & 1 deletion module/issue/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
]);

$Queue[]= sendBack('Issue 创建成功!'.$result['html_url']);
$Queue[]= sendMaster($Event['user_id'].' 创建了新 issue '.$result['html_url'])
$Queue[]= sendMaster($Event['user_id'].' 创建了新 issue '.$result['html_url']."\n".var_export($Event, true));

?>
Binary file modified module/osu/Exo2-Italic.ttf
Binary file not shown.
5 changes: 2 additions & 3 deletions module/osu/bind.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php

loadModule('osu.tools');
global $Queue, $Event, $Command, $osu_api_key;
use kjBot\SDK\CQCode;
loadModule('osu.tools');

$length = strpos($Event['message'], "\r");
if(false===$length)$length=strlen($Event['message']);
$username = substr($Event['message'], strpos($Event['message'], nextArg()), $length-strlen($Command[0]));

$userRealname = json_decode(get_user($osu_api_key, $username))[0]->username;
$userRealname = get_user($osu_api_key, $username)['username'];

setOsuID($Event['user_id'], $userRealname);

Expand Down
17 changes: 13 additions & 4 deletions module/osu/bp.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

global $Event, $Queue, $osu_api_key;
global $Event, $Queue, $osu_api_key, $User_id;
loadModule('osu.tools');

$qq = $User_id;

do{
$arg = nextArg();
if(preg_match('/-(\d{1,3})/', $arg, $result)){
Expand All @@ -11,7 +13,14 @@
}
switch($arg){
case '-user':
$user = nextArg();
$temp = nextArg();
if(parseQQ($temp)!==NULL){
$qq = parseQQ($temp);
$user = getOsuID($qq);
if($user=='')leave('指定的用户未绑定 osu!');
}else{
$user = $temp;
}
break;
case '-std':
$mode = OsuMode::std;
Expand All @@ -30,7 +39,7 @@
}
}while($arg !== NULL);

$osuUser = getOsuID($Event['user_id']);
$osuUser = getOsuID($qq);
if($osuUser !== ''){
$u = $user??$osuUser;
}else{
Expand All @@ -40,7 +49,7 @@
$u = $user;
}
}
$osuMode = rtrim(getData("osu/mode/{$Event['user_id']}"));
$osuMode = rtrim(getData("osu/mode/{$qq}"));
$m = $mode??$osuMode;

$bp = get_user_best($osu_api_key, $u, $x, $m);
Expand Down
147 changes: 1 addition & 146 deletions module/osu/me.php
Original file line number Diff line number Diff line change
@@ -1,147 +1,2 @@
<?php

global $Event, $Queue;
loadModule('osu.tools');
use Intervention\Image\ImageManagerStatic as Image;

Image::configure(array('driver' => 'imagick'));

$withMeText = false;

do{
$arg = nextArg();
switch($arg){
case '-withMe':
$withMeText = true;
break;
case '-osu':
case '-std':
$mode = 'osu';
break;
case '-taiko':
$mode = 'taiko';
break;
case '-ctb':
case '-fruit':
case '-fruits':
$mode = 'fruits';
break;
case '-mania':
$mode = 'mania';
break;
case '-user':
$osuid = nextArg();
break;
default:

}
}while($arg !== NULL);

$osuid = $osuid??getOsuID($Event['user_id']);

if($osuid == ''){
throw new \Exception('未绑定 osu!');
}

$osuid = OsuUsernameEscape($osuid);

$web = file_get_contents('https://osu.ppy.sh/users/'.$osuid.'/'.$mode);

$target = '<script id="json-user" type="application/json">';

$start = strpos($web, $target);
if($start === false)leave('指定的用户不存在');

$end = strpos(substr($web, $start), '</script>');

$userJson = substr($web, $start+strlen($target), $end-strlen($target));

$user = json_decode($userJson);

//初始化绘图环境
$here = __DIR__.'/';
$exo2 = $here.'Exo2-Regular.ttf';
$exo2_italic = $here.'Exo2-Italic.ttf';
$exo2_bold = $here.'Exo2-Bold.ttf';
$yahei = $here.'Yahei.ttf';
$white = '#ffffff';
$mode = $mode??$user->playmode;
$badges = $user->badges;
$badge = $badges[rand(0, count($badges)-1)];
$flag = file_exists($here."flags/{$user->country->code}.png")?($here."flags/{$user->country->code}.png"):($here.'flags/__.png');
$stats_key = imageFont($yahei, 12, $white);
$statics = $user->statistics;
try{
$avatar = Image::make('https://a.ppy.sh/'.$user->id);
}catch(\Exception $e){
$avatar = Image::make($here.'avatar-guest.png');
}
$playtime = [
'hours' => sprintf('%d', $statics->play_time/3600),
'minutes' => sprintf('%d', ($statics->play_time%3600)/60),
'seconds' => sprintf('%d', $statics->play_time%60),
];
$stat = [
'Ranked 谱面总分' => number_format($statics->ranked_score),
'准确率' => sprintf('%.2f%%', $statics->hit_accuracy),
'游戏次数' => number_format($statics->play_count),
'总分' => number_format($statics->total_score),
'总命中次数' => number_format($statics->total_hits),
'最大连击' => number_format($statics->maximum_combo),
'回放被观看次数' => number_format($statics->replays_watched_by_others),
];
$grade = [
'XH' => $statics->grade_counts->ssh,
'X' => $statics->grade_counts->ss,
'SH' => $statics->grade_counts->sh,
'S' => $statics->grade_counts->s,
'A' => $statics->grade_counts->a,
];
//开始绘图
$img = Image::make($user->cover_url);
$img->resize(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')) //插入用户名
->text($user->title, 170, 285, imageFont($exo2_italic, 15, $white, 'left', 'top')) //插入title
;
if($badge!=NULL)$img->insert(Image::make($badge->image_url), 'top-left', 40, 168); //插入狗牌
if($user->is_supporter){
$img->insert(Image::make($here.'heart.png')->resize(28, 28), 'top-left', 170, 223) //插入支持者标志
->insert(Image::make($here."modes/{$mode}.png")->resize(28, 28), 'top-left', 210, 223) //插入模式标志
;
}else{
$img->insert(Image::make($here."modes/{$mode}.png")->resize(28, 28), 'top-left', 170, 223); //插入模式标志
}
$img->insert(Image::make($flag)->resize(30, 20), 'top-left', 170, 310) //插入国旗
->insert(Image::canvas(280, 323)->fill([0, 0, 0, 0.3]), 'top-left', 670, 27) //绘制右侧暗化
->text('游戏时间', 690, 50, $stats_key)
->text("{$playtime['hours']}小时 {$playtime['minutes']}分钟 {$playtime['seconds']}", 690, 72, imageFont($yahei, 18, '#ffcc22'))
->insert(Image::make($here.'levelbadge.png')->resize(50, 50), 'top-left', 880, 30)
->text($statics->level->current, 905, 45, imageFont($exo2_bold, 18, $white, 'center', 'middle'))
;
$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'));
$yIndex+=20;
}
$img->text(sprintf('%.2f', $statics->pp), 690, 280, imageFont($exo2_bold, 40, $white));
$img->text('PP', 740, 300, imageFont($exo2_bold, 20, $white));
$img->text('#'.number_format($statics->rank->global), 930, 280, imageFont($exo2_bold, 20, $white, 'right'));
$img->text($user->country->code.' '.'#'.number_format($statics->rank->country), 930, 300, imageFont($exo2_bold, 20, $white, 'right'));
$xIndex = 675;
foreach($grade as $key => $value){
$img->insert(Image::make($here."{$key}.png")->resize(50, 50), 'top-left', $xIndex, 300);
$img->text($value, $xIndex+20, 350, imageFont($exo2_bold, 16, $white, 'center', 'buttom'));
$xIndex+=55;
}
$img->save('../storage/cache/'.$Event['message_id']);

$msg = sendImg(getCache($Event['message_id']));
if($withMeText)$msg.="\n".preg_replace('/\n+/', "\n", str_replace('<br />', "\n", htmlspecialchars_decode(strip_tags($user->page->html, '<br>'))));

$Queue[]= sendBack($msg);


?>
loadModule('osu.profile');
Binary file added module/osu/mp/blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions module/osu/mp/head-to-head.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions module/osu/mp/jump.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

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

$limit = nextArg()??5;
$data = getData("osu/mp/{$User_id}");
if($data === false)leave('没有正在监听的mp');
sscanf(trim(getData("osu/mp/{$User_id}")), '%d %d', $matchID, $lastEventID);

$latestEventID = json_decode(file_get_contents("https://osu.ppy.sh/community/matches/{$matchID}/history?limit=1"))->latest_event_id;

$historyJson = file_get_contents("https://osu.ppy.sh/community/matches/{$matchID}/history?before={$latestEventID}&limit={$limit}");
$history = json_decode($historyJson);
$events = $history->events;
$users = getEventUsers($history->users);

decCredit($User_id, count($events));

$count = 0;
foreach($events as $event){
$Queue[]= sendBack(parseEvent($event, $users));
$count++;
if($event->detail->type == 'other' && $event->game->end_time == NULL){addCredit($User_id, count($events)-$count+1);break;}
setData("osu/mp/{$User_id}", "{$matchID} {$event->id}");
if($event->detail->type == 'match-disbanded'){
unlink("../storage/data/osu/mp/{$User_id}");
}
}

$Queue[]= sendBack('你的余额为 '.getCredit($User_id));

?>
Binary file added module/osu/mp/none.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added module/osu/mp/red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit fce3347

Please sign in to comment.