[feat] LoveClub

This commit is contained in:
Lkeme 2022-06-04 22:16:32 +08:00
parent a011f8f456
commit f543ac1e75
5 changed files with 176 additions and 3 deletions

View File

@ -41,7 +41,7 @@ class Login extends BasePlugin
'desc' => '登录模块', // 插件描述
'author' => 'Lkeme',// 作者
'priority' => 1001, // 插件优先级
'cycle' => '24(小时)', // 运行周期
'cycle' => '2(小时)', // 运行周期
];
/**

View File

@ -0,0 +1,117 @@
<?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\LinkGroup\ApiLoveClub;
use Bhp\Log\Log;
use Bhp\Plugin\BasePlugin;
use Bhp\Plugin\Plugin;
use Bhp\TimeLock\TimeLock;
class LoveClub extends BasePlugin
{
/**
* 插件信息
* @var array|string[]
*/
protected ?array $info = [
'hook' => __CLASS__, // hook
'name' => 'LoveClub', // 插件名称
'version' => '0.0.1', // 插件版本
'desc' => '友爱社签到', // 插件描述
'author' => 'Lkeme',// 作者
'priority' => 1102, // 插件优先级
'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('love_club')) return;
//
$groups = $this->getGroupList();
foreach ($groups as $group) {
$this->signInGroup($group);
}
//
TimeLock::setTimes(TimeLock::timing(10));
// TimeLock::setTimes(mt_rand(8, 12) * 60 * 60);
}
/**
* @use 获取友爱社列表
* @return array
*/
protected function getGroupList(): array
{
$response = ApiLoveClub::myGroups();
//
if ($response['code']) {
Log::warning("友爱社: 获取应援团失败 {$response['code']} -> {$response['message']}");
return [];
}
//
if (empty($response['data']['list'])) {
Log::notice('友爱社: 没有需要签到的应援团哦~');
return [];
}
//
return $response['data']['list'];
}
/**
* @use 签到
* @param array $groupInfo
* @return bool
*/
protected function signInGroup(array $group): bool
{
// {"code": 710001, "msg": "应援失败>_<", "message": "应援失败>_<", "ttl": "1", "data": {"add_num": 0, "status": 0}}
$response = ApiLoveClub::signIn($group['group_id'], $group['owner_uid']);
//
if ($response['code']) {
if ($response['code'] == '710001') {
Log::notice("友爱社: {$group['group_name']} 签到失败, 亲密度已达上限了哦~");
} else {
Log::warning("友爱社: {$group['group_name']} 签到失败, {$response['code']} -> {$response['message']}");
}
return false;
}
//
if ($response['data']['status']) {
Log::notice("友爱社: {$group['group_name']} 签到失败, 今日已经签到过了哦~");
} else {
Log::notice("友爱社: {$group['group_name']} 签到成功, 亲密度+{$response['data']['add_num']}");
}
return true;
}
}

View File

@ -38,7 +38,7 @@ class MainSite extends BasePlugin
'desc' => '主站任务(观看|分享|投币)', // 插件描述
'author' => 'Lkeme',// 作者
'priority' => 1100, // 插件优先级
'cycle' => '1(小时)', // 运行周期
'cycle' => '24(小时)', // 运行周期
];
/**

View File

@ -39,7 +39,11 @@ add_coin_num = 5
; 漫画助手(每日签到、分享)
[manga]
enable = false
enable = true
; 友爱社签到
[love_club]
enable = true
#######################
# 通知设置 #

View File

@ -0,0 +1,52 @@
<?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\LinkGroup;
use Bhp\Request\Request;
use Bhp\Sign\Sign;
class ApiLoveClub
{
/**
* @use 获取我的友爱社列表
* @return array
*/
public static function myGroups(): array
{
$url = 'https://api.vc.bilibili.com/link_group/v1/member/my_groups';
$payload = [];
return Request::getJson(true, 'app', $url, Sign::common($payload));
}
/**
* @param string $group_id 应援团id
* @param string $owner_id 爱豆ID
* @return array
*/
public static function signIn(string $group_id, string $owner_id): array
{
$url = 'https://api.vc.bilibili.com/link_setting/v1/link_setting/sign_in';
$payload = [
'group_id' => $group_id,
'owner_id' => $owner_id,
];
return Request::getJson(true, 'app', $url, Sign::common($payload));
}
}