BiliHelper-personal/plugin/LoveClub/LoveClub.php
2023-08-22 10:44:36 +08:00

125 lines
3.8 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php declare(strict_types=1);
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2023 ~ 2024
*
* _____ _ _ _ _ _ _____ _ _____ _____ _____
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & l、
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、 。
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ /   \、゙ ~ヽ *
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \  じしf_, )
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
*/
use Bhp\Api\LinkGroup\ApiLoveClub;
use Bhp\Log\Log;
use Bhp\Plugin\BasePlugin;
use Bhp\Plugin\Plugin;
use Bhp\TimeLock\TimeLock;
use Bhp\Util\Exceptions\NoLoginException;
class LoveClub extends BasePlugin
{
/**
* 插件信息
* @var array|string[]
*/
public ?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');
}
/**
* 执行
* @return void
* @throws NoLoginException
*/
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);
}
/**
* 获取友爱社列表
* @return array
* @throws NoLoginException
*/
protected function getGroupList(): array
{
$response = ApiLoveClub::myGroups();
//
switch ($response['code']) {
case -101:
throw new NoLoginException($response['message']);
case 0:
//
if (empty($response['data']['list'])) {
Log::notice('友爱社: 没有需要签到的应援团哦~');
return [];
}
//
return $response['data']['list'];
default:
Log::warning("友爱社: 获取应援团失败 {$response['code']} -> {$response['message']}");
return [];
}
}
/**
* 签到
* @param array $group
* @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;
}
}