[feat] Manga

This commit is contained in:
Lkeme 2022-06-04 21:41:19 +08:00
parent 844d460c7e
commit a011f8f456
6 changed files with 281 additions and 5 deletions

139
plugin/Manga/Manga.php Normal file
View File

@ -0,0 +1,139 @@
<?php declare(strict_types=1);
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2022 ~ 2023
*
* _____ _ _ _ _ _ _____ _ _____ _____ _____
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & l、
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ /   \、゙ ~ *
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \  じしf_, )
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
*/
use Bhp\Api\Manga\ApiManga;
use Bhp\Log\Log;
use Bhp\Plugin\BasePlugin;
use Bhp\Plugin\Plugin;
use Bhp\TimeLock\TimeLock;
class Manga extends BasePlugin
{
/**
* 插件信息
* @var array|string[]
*/
protected ?array $info = [
'hook' => __CLASS__, // hook
'name' => 'Manga', // 插件名称
'version' => '0.0.1', // 插件版本
'desc' => '漫画签到/分享', // 插件描述
'author' => 'Lkeme',// 作者
'priority' => 1101, // 插件优先级
'cycle' => '24(小时)', // 运行周期
];
/**
* @param Plugin $plugin
*/
public function __construct(Plugin &$plugin)
{
//
TimeLock::initTimeLock();
// $this::class
$plugin->register($this, 'execute');
}
/**
* @use 执行
* @return void
*/
public function execute(): void
{
if (TimeLock::getTimes() > time() || !getEnable('manga')) return;
//
if ($this->shareTask() && $this->signInTask()) {
TimeLock::setTimes(TimeLock::timing(10));
} else {
TimeLock::setTimes(3600);
}
}
/**
* @use 签到任务
* @return bool
*/
protected function signInTask(): bool
{
// {"code":0,"msg":"","data":{}}
// {"code":"invalid_argument","msg":"clockin clockin is duplicate","meta":{"argument":"clockin"}}
$response = ApiManga::ClockIn();
//
switch ($response['code']) {
case 0:
Log::notice('漫画: 签到成功');
break;
case 'invalid_argument':
Log::notice('漫画: 今日已经签到过了哦~');
break;
default:
Log::warning("漫画: 签到失败 {$response['code']} -> {$response['msg']}");
return false;
}
$this->signInInfo();
return true;
}
/**
* @use 分享任务
* @return bool
*/
protected function shareTask(): bool
{
// {"code":0,"msg":"","data":{"point":5}}
// {"code":1,"msg":"","data":{"point":0}}
$response = ApiManga::ShareComic();
//
switch ($response['code']) {
case 0:
if ($response['msg'] == '今日已分享') {
Log::notice('漫画: 今日已经分享过了哦~');
} else {
Log::notice("漫画: 分享成功,经验值+{$response['data']['point']}");
}
break;
default:
Log::warning("漫画: 分享失败 {$response['code']} -> {$response['msg']}");
return false;
}
return true;
if ($response['code']) {
Log::warning("漫画: 分享失败或者重复分享 {$response['code']} -> {$response['msg']}");
} else {
}
return true;
}
/**
* @use 签到信息
* @return void
*/
protected function signInInfo(): void
{
$response = ApiManga::GetClockInInfo();
if ($response['code']) {
Log::warning("漫画: 获取签到信息失败 {$response['code']} -> {$response['msg']}");
} else {
Log::notice("漫画: 已连续签到 {$response['data']['day_count']} 天,继续加油哦~");
}
}
}

View File

@ -1,8 +1,5 @@
<?php declare(strict_types=1);
use Bhp\Plugin\Plugin;
use Bhp\TimeLock\TimeLock;
/**
* Website: https://mudew.com/
* Author: Lkeme
@ -18,7 +15,11 @@ use Bhp\TimeLock\TimeLock;
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
*/
class PluginTemplate
use Bhp\Plugin\BasePlugin;
use Bhp\Plugin\Plugin;
use Bhp\TimeLock\TimeLock;
class PluginTemplate extends BasePlugin
{
/**
* 插件信息
@ -61,6 +62,5 @@ class PluginTemplate
}
}

View File

@ -37,6 +37,10 @@ add_coin = true
add_coin_mode = random
add_coin_num = 5
; 漫画助手(每日签到、分享)
[manga]
enable = false
#######################
# 通知设置 #
#######################

View File

@ -0,0 +1,65 @@
<?php declare(strict_types=1);
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2022 ~ 2023
*
* _____ _ _ _ _ _ _____ _ _____ _____ _____
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & l、
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ /   \、゙ ~ *
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \  じしf_, )
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
*/
namespace Bhp\Api\Manga;
use Bhp\Request\Request;
use Bhp\Sign\Sign;
class ApiManga
{
/**
* @use 签到
* @return array
*/
public static function ClockIn(): array
{
$url = 'https://manga.bilibili.com/twirp/activity.v1.Activity/ClockIn';
$payload = [];
// {"code":0,"msg":"","data":{}}
// {"code":"invalid_argument","msg":"clockin clockin is duplicate","meta":{"argument":"clockin"}}
return Request::postJson(true, 'app', $url, Sign::common($payload));
}
/**
* @use 分享
* @return array
*/
public static function ShareComic(): array
{
$url = 'https://manga.bilibili.com/twirp/activity.v1.Activity/ShareComic';
$payload = [];
// {"code":0,"msg":"","data":{"point":5}}
// {"code":1,"msg":"","data":{"point":0}}
// {"code":0, "msg":"今日已分享"}
return Request::postJson(true, 'app', $url, Sign::common($payload));
}
/**
* @use 签到信息
* @return array
*/
public static function GetClockInInfo(): array
{
$url = 'https://manga.bilibili.com/twirp/activity.v1.Activity/GetClockInInfo';
$payload = [];
return Request::postJson(true, 'app', $url, Sign::common($payload));
}
}

View File

@ -0,0 +1,34 @@
<?php declare(strict_types=1);
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2022 ~ 2023
*
* _____ _ _ _ _ _ _____ _ _____ _____ _____
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & l、
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ /   \、゙ ~ *
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \  じしf_, )
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
*/
namespace Bhp\Util\Exceptions;
use Exception;
use Throwable;
class SingletonException extends Exception
{
/**
* @param string $message
* @param int $code
* @param Throwable|null $previous
*/
public function __construct(string $message = "", int $code = 0, ?Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}

View File

@ -0,0 +1,34 @@
<?php declare(strict_types=1);
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2022 ~ 2023
*
* _____ _ _ _ _ _ _____ _ _____ _____ _____
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & l、
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ /   \、゙ ~ *
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \  じしf_, )
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
*/
namespace Bhp\Util\Exceptions;
use Exception;
use Throwable;
class SingletonException extends Exception
{
/**
* @param string $message
* @param int $code
* @param Throwable|null $previous
*/
public function __construct(string $message = "", int $code = 0, ?Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}