mirror of
				https://github.com/LamGC/ContentGrabbingJi.git
				synced 2025-11-04 02:26:57 +00:00 
			
		
		
		
	[Add] BotGlobal BotGlobal在初始化时将检查Redis连通性;
[Change] RandomRankingArtworksSender 支持外部设置groupId, 以使用群组配置; [Change] BotCommandProcess, BotAdminCommandProcess 适配RandomRankingArtworksSender更改;
This commit is contained in:
		@ -271,6 +271,7 @@ public class BotAdminCommandProcess {
 | 
			
		||||
 | 
			
		||||
        AutoSender sender = new RandomRankingArtworksSender(
 | 
			
		||||
                MessageSenderBuilder.getMessageSender(MessageSource.Group, id),
 | 
			
		||||
                id,
 | 
			
		||||
                rankingStart,
 | 
			
		||||
                rankingEnd,
 | 
			
		||||
                rankingMode, rankingContentType,
 | 
			
		||||
 | 
			
		||||
@ -14,8 +14,6 @@ import net.lamgc.cgj.pixiv.PixivDownload;
 | 
			
		||||
import net.lamgc.cgj.pixiv.PixivDownload.PageQuality;
 | 
			
		||||
import net.lamgc.cgj.pixiv.PixivSearchBuilder;
 | 
			
		||||
import net.lamgc.cgj.pixiv.PixivURL;
 | 
			
		||||
import net.lamgc.cgj.pixiv.PixivURL.RankingContentType;
 | 
			
		||||
import net.lamgc.cgj.pixiv.PixivURL.RankingMode;
 | 
			
		||||
import net.lamgc.utils.base.runner.Argument;
 | 
			
		||||
import net.lamgc.utils.base.runner.Command;
 | 
			
		||||
import org.slf4j.Logger;
 | 
			
		||||
@ -257,13 +255,34 @@ public class BotCommandProcess {
 | 
			
		||||
     * 随机获取一副作品
 | 
			
		||||
     */
 | 
			
		||||
    @Command(commandName = "random")
 | 
			
		||||
    public static String randomImage() {
 | 
			
		||||
    public static String randomImage(
 | 
			
		||||
            @Argument(name = "$fromGroup") long fromGroup,
 | 
			
		||||
            @Argument(force = false, name = "mode", defaultValue = "DAILY") String contentMode,
 | 
			
		||||
            @Argument(force = false, name = "type", defaultValue = "ILLUST") String contentType) {
 | 
			
		||||
        PixivURL.RankingMode mode;
 | 
			
		||||
        try {
 | 
			
		||||
            String rankingModeValue = contentMode.toUpperCase();
 | 
			
		||||
            mode = PixivURL.RankingMode.valueOf(rankingModeValue.startsWith("MODE_") ?
 | 
			
		||||
                    rankingModeValue : "MODE_" + rankingModeValue);
 | 
			
		||||
        } catch (IllegalArgumentException e) {
 | 
			
		||||
            log.warn("无效的RankingMode值: {}", contentMode);
 | 
			
		||||
            return "参数无效, 请查看帮助信息";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        PixivURL.RankingContentType type;
 | 
			
		||||
        try {
 | 
			
		||||
            String contentTypeValue = contentType.toUpperCase();
 | 
			
		||||
            type = PixivURL.RankingContentType.valueOf(
 | 
			
		||||
                    contentTypeValue.startsWith("TYPE_") ? contentTypeValue : "TYPE_" + contentTypeValue);
 | 
			
		||||
        } catch (IllegalArgumentException e) {
 | 
			
		||||
            log.warn("无效的RankingContentType值: {}", contentType);
 | 
			
		||||
            return "参数无效, 请查看帮助信息";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        BufferMessageEvent event = new BufferMessageEvent();
 | 
			
		||||
        RandomRankingArtworksSender artworksSender = 
 | 
			
		||||
            new RandomRankingArtworksSender(event, 1, 200, 
 | 
			
		||||
            RankingMode.MODE_MALE, 
 | 
			
		||||
            RankingContentType.TYPE_ALL, 
 | 
			
		||||
            PageQuality.ORIGINAL);
 | 
			
		||||
            new RandomRankingArtworksSender(event, fromGroup, 1, 200, mode, type,
 | 
			
		||||
                    PageQuality.ORIGINAL);
 | 
			
		||||
        artworksSender.send();
 | 
			
		||||
        return event.getBufferMessage();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -19,6 +19,7 @@ import java.util.Random;
 | 
			
		||||
public class RandomRankingArtworksSender extends AutoSender {
 | 
			
		||||
 | 
			
		||||
    private final Logger log;
 | 
			
		||||
    private final long groupId;
 | 
			
		||||
    private final int rankingStart;
 | 
			
		||||
    private final int rankingStop;
 | 
			
		||||
    private final PixivURL.RankingMode mode;
 | 
			
		||||
@ -35,8 +36,37 @@ public class RandomRankingArtworksSender extends AutoSender {
 | 
			
		||||
     * @param quality 图片质量, 详见{@link PixivDownload.PageQuality}
 | 
			
		||||
     * @throws IndexOutOfBoundsException 当 rankingStart > rankingStop时抛出
 | 
			
		||||
     */
 | 
			
		||||
    public RandomRankingArtworksSender(MessageSender messageSender, int rankingStart, int rankingStop, PixivURL.RankingMode mode, PixivURL.RankingContentType contentType, PixivDownload.PageQuality quality) {
 | 
			
		||||
    public RandomRankingArtworksSender(
 | 
			
		||||
            MessageSender messageSender,
 | 
			
		||||
            int rankingStart,
 | 
			
		||||
            int rankingStop,
 | 
			
		||||
            PixivURL.RankingMode mode,
 | 
			
		||||
            PixivURL.RankingContentType contentType,
 | 
			
		||||
            PixivDownload.PageQuality quality) {
 | 
			
		||||
        this(messageSender, 0, rankingStart, rankingStop, mode, contentType, quality);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 构造一个推荐作品发送器
 | 
			
		||||
     * @param messageSender 消息发送器
 | 
			
		||||
     * @param groupId 群组Id, 如果发送目标为群组, 则可设置群组Id, 以使用群组配置.
 | 
			
		||||
     * @param rankingStart 排行榜开始范围(从1开始, 名次),如传入0或负数则为默认值,默认为1
 | 
			
		||||
     * @param rankingStop 排名榜结束范围(包括该名次),如传入0或负数则为默认值,默认为150
 | 
			
		||||
     * @param mode 排行榜模式
 | 
			
		||||
     * @param contentType 排行榜内容类型
 | 
			
		||||
     * @param quality 图片质量, 详见{@link PixivDownload.PageQuality}
 | 
			
		||||
     * @throws IndexOutOfBoundsException 当 rankingStart > rankingStop时抛出
 | 
			
		||||
     */
 | 
			
		||||
    public RandomRankingArtworksSender(
 | 
			
		||||
            MessageSender messageSender,
 | 
			
		||||
            long groupId,
 | 
			
		||||
            int rankingStart,
 | 
			
		||||
            int rankingStop,
 | 
			
		||||
            PixivURL.RankingMode mode,
 | 
			
		||||
            PixivURL.RankingContentType contentType,
 | 
			
		||||
            PixivDownload.PageQuality quality) {
 | 
			
		||||
        super(messageSender);
 | 
			
		||||
        this.groupId = groupId;
 | 
			
		||||
        this.mode = mode;
 | 
			
		||||
        this.contentType = contentType;
 | 
			
		||||
        log = LoggerFactory.getLogger(this.toString());
 | 
			
		||||
@ -78,7 +108,7 @@ public class RandomRankingArtworksSender extends AutoSender {
 | 
			
		||||
            JsonObject rankingInfo = rankingList.get(0);
 | 
			
		||||
            int illustId = rankingInfo.get("illust_id").getAsInt();
 | 
			
		||||
            if(BotCommandProcess.isNoSafe(illustId,
 | 
			
		||||
                    SettingProperties.getProperties(SettingProperties.GLOBAL), false)) {
 | 
			
		||||
                    SettingProperties.getProperties(groupId), false)) {
 | 
			
		||||
                log.warn("作品为r18作品, 取消本次发送.");
 | 
			
		||||
                return;
 | 
			
		||||
            } else if(BotCommandProcess.isReported(illustId)) {
 | 
			
		||||
 | 
			
		||||
@ -8,7 +8,9 @@ import org.apache.http.HttpHost;
 | 
			
		||||
import org.apache.http.client.CookieStore;
 | 
			
		||||
import org.slf4j.Logger;
 | 
			
		||||
import org.slf4j.LoggerFactory;
 | 
			
		||||
import redis.clients.jedis.Jedis;
 | 
			
		||||
import redis.clients.jedis.JedisPool;
 | 
			
		||||
import redis.clients.jedis.exceptions.JedisConnectionException;
 | 
			
		||||
 | 
			
		||||
import java.io.File;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
@ -56,6 +58,12 @@ public final class BotGlobal {
 | 
			
		||||
        this.redisServer = new JedisPool(
 | 
			
		||||
                getRedisUri().getHost(),
 | 
			
		||||
                getRedisUri().getPort() == -1 ? 6379 : getRedisUri().getPort());
 | 
			
		||||
        try (Jedis jedis = this.redisServer.getResource()) {
 | 
			
		||||
            log.warn("Redis连接状态(Ping): {}", jedis.ping().equalsIgnoreCase("pong"));
 | 
			
		||||
        } catch(JedisConnectionException e) {
 | 
			
		||||
            log.warn("Redis连接失败, 将会影响到后续功能运行.", e);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        String dataStoreDirPath = System.getProperty("cgj.botDataDir");
 | 
			
		||||
        this.dataStoreDir = new File((!dataStoreDirPath.endsWith("/") || !dataStoreDirPath.endsWith("\\")) ?
 | 
			
		||||
                dataStoreDirPath + System.getProperty("file.separator") : dataStoreDirPath);
 | 
			
		||||
@ -95,13 +103,6 @@ public final class BotGlobal {
 | 
			
		||||
        return proxy;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public CookieStore getCookieStore() {
 | 
			
		||||
        if(pixivDownload == null) {
 | 
			
		||||
            throw new IllegalStateException("CookieStore needs to be set before PixivDownload can be obtained");
 | 
			
		||||
        }
 | 
			
		||||
        return cookieStore;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setCookieStore(CookieStore cookieStore) {
 | 
			
		||||
        if(this.cookieStore != null) {
 | 
			
		||||
            throw new IllegalStateException("CookieStore set");
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user