From f543ac1e75a60ebc6f71e8277b33d30481a3ebb2 Mon Sep 17 00:00:00 2001 From: Lkeme <19500576+lkeme@users.noreply.github.com> Date: Sat, 4 Jun 2022 22:16:32 +0800 Subject: [PATCH] [feat] LoveClub --- plugin/Login/Login.php | 2 +- plugin/LoveClub/LoveClub.php | 117 ++++++++++++++++++++++++++++++ plugin/MainSite/MainSite.php | 2 +- profile/example/config/user.ini | 6 +- src/Api/LinkGroup/ApiLoveClub.php | 52 +++++++++++++ 5 files changed, 176 insertions(+), 3 deletions(-) create mode 100644 plugin/LoveClub/LoveClub.php create mode 100644 src/Api/LinkGroup/ApiLoveClub.php diff --git a/plugin/Login/Login.php b/plugin/Login/Login.php index 745cfb6..c22e7e0 100644 --- a/plugin/Login/Login.php +++ b/plugin/Login/Login.php @@ -41,7 +41,7 @@ class Login extends BasePlugin 'desc' => '登录模块', // 插件描述 'author' => 'Lkeme',// 作者 'priority' => 1001, // 插件优先级 - 'cycle' => '24(小时)', // 运行周期 + 'cycle' => '2(小时)', // 运行周期 ]; /** diff --git a/plugin/LoveClub/LoveClub.php b/plugin/LoveClub/LoveClub.php new file mode 100644 index 0000000..b22aa8e --- /dev/null +++ b/plugin/LoveClub/LoveClub.php @@ -0,0 +1,117 @@ + __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; + } + +} + \ No newline at end of file diff --git a/plugin/MainSite/MainSite.php b/plugin/MainSite/MainSite.php index abae6d3..fde43fb 100644 --- a/plugin/MainSite/MainSite.php +++ b/plugin/MainSite/MainSite.php @@ -38,7 +38,7 @@ class MainSite extends BasePlugin 'desc' => '主站任务(观看|分享|投币)', // 插件描述 'author' => 'Lkeme',// 作者 'priority' => 1100, // 插件优先级 - 'cycle' => '1(小时)', // 运行周期 + 'cycle' => '24(小时)', // 运行周期 ]; /** diff --git a/profile/example/config/user.ini b/profile/example/config/user.ini index 15b59db..c6a1399 100644 --- a/profile/example/config/user.ini +++ b/profile/example/config/user.ini @@ -39,7 +39,11 @@ add_coin_num = 5 ; 漫画助手(每日签到、分享) [manga] -enable = false +enable = true + +; 友爱社签到 +[love_club] +enable = true ####################### # 通知设置 # diff --git a/src/Api/LinkGroup/ApiLoveClub.php b/src/Api/LinkGroup/ApiLoveClub.php new file mode 100644 index 0000000..56fe20a --- /dev/null +++ b/src/Api/LinkGroup/ApiLoveClub.php @@ -0,0 +1,52 @@ + $group_id, + 'owner_id' => $owner_id, + ]; + return Request::getJson(true, 'app', $url, Sign::common($payload)); + } + + +} \ No newline at end of file