Blog Nodeloc

记录一些NodeLoc发展中遇到的问题及解决方法

为了防止脚本签到,加了每天发帖或回帖才可以签到


目前签到使用的是Ziven的自动签到 ,但是在他的基础上改了不少东西。比如随机的签到奖励,签到的内容提示等。

Nodeloc近来发现有一些使用脚本进行自动签到的行为,我想这是不太可取的,于是仿照98堂做了发帖或回帖才可以签到。

修改方式很简单,在后台判断用户当天有没有发帖,然后前台显示,最后提交后台时,再进行校验。

前台修改

import { extend } from 'flarum/extend';
import IndexPage from 'flarum/forum/components/IndexPage';
import Button from 'flarum/components/Button';
import Alert from 'flarum/common/components/Alert';
import checkInSuccessModal from './components/checkInSuccessModal';
import checkInFailedModal from './components/checkInFailedModal';

app.initializers.add('ziven-checkin', () => {
  extend(IndexPage.prototype, 'sidebarItems', function(items) {
    if(app.session.user!==null && app.forum.attribute('allowCheckIn')===true){
      const routeName = app.current.get('routeName');

      const totalContinuousCheckIn = app.session.user.attribute("totalContinuousCheckIn");
      const canCheckin = app.session.user.attribute("canCheckin");
      const isPostToday = app.session.user.attribute("isPostToday");
      const canCheckinContinuous = app.session.user.attribute("canCheckinContinuous");
      const serverData = app.session.user.attribute("serverDate");
      const forumCheckinSuccessPromptType = app.forum.attribute("forumCheckinSuccessPromptType");
      let checkInCompatibleExtensions = app.session.user.attribute("checkInCompatibleExtensions");
      let lastCheckinTime = app.session.user.attribute("lastCheckinTime");
      let checkinButtonText;
      let itemName = "forum-checkin";

      if(routeName==="tag"){
        if(checkInCompatibleExtensions.indexOf("fof-follow-tags")!==-1){
            itemName = "forum-checkin-1";
        }
      }

      if(canCheckin===true&&isPostToday){
        checkinButtonText = app.translator.trans('ziven-checkin.forum.check-in');
        items.add(itemName, Button.component({
          icon: 'fas fa-calendar',
          className: 'Button CheckInButton--yellow',
          itemClassName: 'App-primaryControl',
          id:"checkInButton",
          onclick: () => {
            app.session.user.save({canCheckin:false,totalContinuousCheckIn:canCheckinContinuous===true?totalContinuousCheckIn+1:1}).then(() => {
              const forumCheckinSuccessPromptText = app.forum.attribute("forumCheckinSuccessPromptText");
              const forumCheckinSuccessPromptRewardText = app.forum.attribute("forumCheckinSuccessPromptRewardText");
              const canCheckinRecheck = app.session.user.attribute("canCheckin");

              if(forumCheckinSuccessPromptText!=="" || forumCheckinSuccessPromptRewardText!==""){
                if(forumCheckinSuccessPromptType===1){
                  if(canCheckinRecheck===false){
                    const forumCheckinRewarMoney = app.forum.attribute("forumCheckinRewarMoney");
                    const moneyExtensionExist = app.forum.attribute('antoinefr-money.moneyname')!==undefined;

                    let moneyName = "";
                    let rewardText = "";

                    if(forumCheckinSuccessPromptText!==""){
                      const checkInSuccessText = forumCheckinSuccessPromptText.replace('[days]', app.session.user.attribute("totalContinuousCheckIn"));
                      const successTextAlertKey = app.alerts.show(Alert, { type: 'success' }, checkInSuccessText);
                    }

                    if(moneyExtensionExist===true && forumCheckinSuccessPromptRewardText!==""){
                      moneyName = app.forum.attribute('antoinefr-money.moneyname') || '[money]';
                      rewardText = moneyName.replace('[money]', forumCheckinRewarMoney);

                      const checkInSuccessRewardText = forumCheckinSuccessPromptRewardText.replace('[reward]', rewardText);
                      const successRewardTextAlertKey = app.alerts.show(Alert, { type: 'success' }, checkInSuccessRewardText);
                    }
                  }else{
                    const failedTextAlertKey = app.alerts.show(Alert, { type: 'error' }, app.translator.trans('ziven-checkin.forum.check-in-failed')+" "+app.translator.trans('ziven-checkin.forum.try-again-later'));
                  }
                }else if(forumCheckinSuccessPromptType===2){
                  if(canCheckinRecheck===false){
                    app.modal.show(checkInSuccessModal);
                  }else{
                    app.modal.show(checkInFailedModal);
                  }
                }
              }
            });
          }
        }, checkinButtonText),50);

        const forumAutoCheckIn = app.forum.attribute("forumAutoCheckin");
        const forumAutoCheckInDelay = app.forum.attribute("forumAutoCheckinDelay");

        if(forumAutoCheckIn===1){
          setTimeout(function(){
            $("#checkInButton").click();
          },forumAutoCheckInDelay);
        }
      }else if(isPostToday){
        checkinButtonText = totalContinuousCheckIn<=1?app.translator.trans('ziven-checkin.forum.checked-in-day', {count: totalContinuousCheckIn}):app.translator.trans('ziven-checkin.forum.checked-in-days', {count: totalContinuousCheckIn});
        items.add(itemName, Button.component({
          icon: 'fas fa-calendar-check',
          className: 'Button CheckInButton--green',
          itemClassName: 'App-primaryControl',
          disabled: true
        }, checkinButtonText),50);
      }else{
        checkinButtonText = '发帖后签到';
        items.add(itemName, Button.component({
          icon: 'fas fa-calendar-check',
          className: 'Button CheckInButton--green',
          itemClassName: 'App-primaryControl',
          disabled: true
        }, checkinButtonText),50);
      }
    }
  });
});

后台修改

<?php

namespace Ziven\checkin\AddAttribute;

use Carbon\Carbon;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Events\Dispatcher;
use Flarum\Api\Serializer\UserSerializer;
use Flarum\User\User;

class AddUserCheckinAttributes
{
    protected $settings;
    protected $events;

    public function __construct(SettingsRepositoryInterface $settings, Dispatcher $events)
    {
        $this->settings = $settings;
        $this->events = $events;
    }

    public function __invoke(UserSerializer $serializer, User $user)
    {
        $last_checkin_time = $user->last_checkin_time;
        $attributes = [];
        $attributes['lastCheckinTime'] = $user->last_checkin_time;
        $attributes['lastCheckinMoney'] = $user->last_checkin_money;
        $attributes['totalContinuousCheckIn'] = $user->total_continuous_checkin_count;
        $attributes['checkInCompatibleExtensions'] = [];

        $extensions_enabled = json_decode($this->settings->get('extensions_enabled'));
        $compatibleCheckList = array("fof-follow-tags");

        foreach ($compatibleCheckList as $key => $value) {
            $fof_follow_tags = array_search($value, $extensions_enabled);

            if($fof_follow_tags!==false){
                array_push($attributes['checkInCompatibleExtensions'],$value);
            }
        }

        $timezone = intval($this->settings->get('ziven-forum-checkin.checkinTimeZone', 0));
        $time = time()+$timezone*60*60;

        $lastCheckinTimeTimestamp = $last_checkin_time===null?0:strtotime($last_checkin_time);
        $timedifference = (strtotime(date('Y-m-d', $time)." 23:59:59") - $lastCheckinTimeTimestamp)/3600;
        // 获取当前日期时间
        $now = Carbon::now();
        // 获取用户当天的帖子数量
        $postCount = $user->posts()
            ->where('created_at', '>=', $now->startOfDay()) // 当天开始时间
            ->count();
        $attributes['isPostToday'] = $postCount>0;
        $attributes['canCheckin'] = $last_checkin_time===null?true:$timedifference>=24;
        $attributes['canCheckinContinuous'] = $timedifference<48;
        return $attributes;
    }
}

后台提交时再次校验

        if(!$this->isPostToday($user)){
            return;
        }

当然不排除有MJJ会先自动回帖,再自动签到,但使用自动回帖是不被允许的,被抓到就要被切JJ了。


发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注