mirror of
https://github.com/hakasenyang/osu-tournament-php
synced 2026-08-22 03:03:07 +09:00
Add function and fix style
This commit is contained in:
+85
-13
@@ -26,49 +26,121 @@
|
||||
* @var [int]
|
||||
*/
|
||||
private $mode;
|
||||
/**
|
||||
* [$data_profile description]
|
||||
* [$data_userdata description]
|
||||
* @var [string]
|
||||
*/
|
||||
private $data_profile, $data_userdata;
|
||||
/**
|
||||
* Other data
|
||||
* In production.
|
||||
*/
|
||||
|
||||
public function __construct($mode)
|
||||
public function __construct()
|
||||
{
|
||||
switch($mode)
|
||||
$this->Parser = new Parser();
|
||||
}
|
||||
/**
|
||||
* [SelectMode osu! mode]
|
||||
* [$mode osu! mode
|
||||
* 0 = osu! standard (standard)
|
||||
* 1 = Taiko (taiko)
|
||||
* 2 = Catch The Beat (ctb)
|
||||
* 3 = osu!mania (mania)
|
||||
* ]
|
||||
* @var [int]
|
||||
*/
|
||||
public function SelectMode($mode)
|
||||
{
|
||||
switch(strtolower($mode))
|
||||
{
|
||||
case 0:
|
||||
case '0':
|
||||
case 'standard':
|
||||
$this->mode = 0;
|
||||
break;
|
||||
case 1:
|
||||
case '1':
|
||||
case 'taiko':
|
||||
$this->mode = 1;
|
||||
break;
|
||||
case 2:
|
||||
case '2':
|
||||
case 'ctb':
|
||||
$this->mode = 2;
|
||||
break;
|
||||
case 3:
|
||||
case '3':
|
||||
case 'mania':
|
||||
$this->mode = 3;
|
||||
break;
|
||||
default:
|
||||
throw new Exception('Error Mode');
|
||||
throw new \Exception($mode . ' is not supported.');
|
||||
break;
|
||||
}
|
||||
$this->Parser = new Parser();
|
||||
return $this->mode;
|
||||
}
|
||||
/**
|
||||
* [CheckUser Get osu! UserID]
|
||||
* @param [string] $osuid [osu! ID]
|
||||
*/
|
||||
public function CheckUser($osuid)
|
||||
{
|
||||
// Transfer osu! ID to Num
|
||||
$data = $this->Parser->WEBParsing('https://osu.ppy.sh/u/'.$osuid);
|
||||
$this->OsuID = $this->Parser->splits($data, 'var userId = ', ';');
|
||||
if(!isset($this->OsuID)) return 0;
|
||||
$this->data_profile = $this->Parser->WEBParsing('https://osu.ppy.sh/u/' . $osuid);
|
||||
$this->OsuID = $this->Parser->splits($this->data_profile, 'var userId = ', ';');
|
||||
if(empty($this->OsuID))
|
||||
return false;
|
||||
|
||||
$this->Occupation = $this->Parser->splits($this->data_profile, '<div title=\'Occupation\'><i class=\'icon-pencil\'></i><div>', '</div></div>');
|
||||
return $this->OsuID;
|
||||
}
|
||||
public function CheckOccupation()
|
||||
{
|
||||
/**
|
||||
* md5 = $OsuID|date('Ymd')|$mode
|
||||
* 20 string (substr)
|
||||
*/
|
||||
$occu = substr(md5($this->OsuID.'|' . date('Ymd') . '|' . $this->mode), 0, 20);
|
||||
if ($occu === $this->Occupation)
|
||||
return true;
|
||||
else
|
||||
return $occu;
|
||||
}
|
||||
private function GetUserData()
|
||||
{
|
||||
if(empty($this->OsuID))
|
||||
throw new \Exception('Please, CheckUser(OsuID) first!');
|
||||
if(empty($this->data_userdata))
|
||||
$this->data_userdata = $this->Parser->WEBParsing('https://osu.ppy.sh/pages/include/profile-general.php?u=' . $this->OsuID . '&m=' . $this->mode);
|
||||
}
|
||||
/**
|
||||
* [CheckPlayCount Get PlayCount]
|
||||
*/
|
||||
public function CheckPlayCount()
|
||||
{
|
||||
$data = $this->Parser->WEBParsing('https://osu.ppy.sh/pages/include/profile-general.php?u=' . $this->OsuID .'&m=' . $this->mode);
|
||||
$this->PlayCount = $this->Parser->splits($data, '<b>Play Count</b>: ', '</div>');
|
||||
$this->GetUserData();
|
||||
$this->PlayCount = $this->Parser->splits($this->data_userdata, '<b>Play Count</b>: ', '</div>');
|
||||
return $this->PlayCount;
|
||||
}
|
||||
public function CheckPerformance()
|
||||
{
|
||||
$this->GetUserData();
|
||||
if (strpos($this->data_userdata, 'This user has not played enough, or has not played recently.'))
|
||||
return false;
|
||||
$this->Performance = str_replace(',', NULL, $this->Parser->splits($this->data_userdata, 'Performance</a>: ', 'pp'));
|
||||
return $this->Performance;
|
||||
}
|
||||
public function CheckRank()
|
||||
{
|
||||
$this->GetUserData();
|
||||
if (strpos($this->data_userdata, 'This user has not played enough, or has not played recently.'))
|
||||
return false;
|
||||
$this->Rank = str_replace(',', NULL, $this->Parser->splits($this->data_userdata, 'pp (#', ')'));
|
||||
return $this->Rank;
|
||||
}
|
||||
public function ResetObject()
|
||||
{
|
||||
foreach ($this as $key => $value)
|
||||
unset($this->$key);
|
||||
|
||||
$this->__construct();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,20 @@
|
||||
<?php
|
||||
require_once 'include.php';
|
||||
$Check = new OsuTournament\Check('ctb');
|
||||
$Check = new OsuTournament\Check();
|
||||
$Check->SelectMode(0);
|
||||
|
||||
echo $Check->CheckUser('Angelsim');
|
||||
echo $Check->CheckUser('peppy');
|
||||
if ($Check->CheckOccupation() === true)
|
||||
echo '<br>You are applied!';
|
||||
else
|
||||
echo '<br>Please change occupation to ' . $Check->CheckOccupation();
|
||||
echo '<br>';
|
||||
echo $Check->CheckPlayCount();
|
||||
echo 'Performance : ' . $Check->CheckPerformance();
|
||||
echo '<br>';
|
||||
echo 'Ranking : ' . $Check->CheckRank();
|
||||
|
||||
$Check->ResetObject();
|
||||
|
||||
echo $Check->CheckUser('ExampleToNotUser');
|
||||
echo '<br>';
|
||||
echo 'Performance : ' . $Check->CheckPerformance();
|
||||
Reference in New Issue
Block a user