涩图模块:新增每日统计

This commit is contained in:
Yutousama 2022-04-20 21:17:49 +08:00
parent 15b0e14edd
commit 4f3fea8615
2 changed files with 92 additions and 4 deletions

View File

@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class QQBotApplication {
public static final String version="QQBot v.1.2.19";
public static final String version="QQBot v.1.2.20";
public static void main(String[] args) {
System.out.println("version = " + version);
SpringApplication.run(QQBotApplication.class, args);

View File

@ -1,18 +1,23 @@
package com.yutou.qqbot.models.setu;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.interfaces.DownloadInterface;
import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.utlis.HttpTools;
import com.yutou.qqbot.utlis.Log;
import com.yutou.qqbot.utlis.RedisTools;
import com.yutou.qqbot.utlis.StringUtils;
import net.mamoe.mirai.event.events.MessageEvent;
import net.mamoe.mirai.message.data.At;
import net.mamoe.mirai.message.data.MessageChainBuilder;
import redis.clients.jedis.Jedis;
import java.io.File;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -32,6 +37,76 @@ public class GetSeTu extends Model {
return "随机二次元图";
}
@Override
public void onTime(Long qq, String time) {
super.onTime(qq, time);
if ("00:00:00".equals(time)) {
del();
} else if ("23:59:00".equals(time)) {
send();
}
}
private void del() {
Jedis redis = RedisTools.getRedis();
redis.select(RedisTools.QQBOT_USER);
Set<String> keys = redis.keys("Setu_*");
for (String key : keys) {
redis.del(key);
}
redis.close();
}
private void send() {
Jedis redis = RedisTools.getRedis();
redis.select(RedisTools.QQBOT_USER);
Set<String> keys = redis.keys("Setu_*");
redis.close();
for (String key : keys) {
String ret = RedisTools.get(key);
MessageChainBuilder builder = null;
if (!StringUtils.isEmpty(ret)) {
JSONArray array = JSONArray.parseArray(key);
builder = new MessageChainBuilder();
builder.append("各位老色胚们晚上好,现在公布本群涩图数据!");
builder.append("本群今日共查询:");
builder.append(String.valueOf(array.size()));
builder.append("次!\n");
builder.append("接下来公布大伙的XP系统");
builder.append("\n");
Map<Long, List<String>> map = new HashMap<>();
for (Object o : array) {
JSONObject item = (JSONObject) o;
List<String> tags = map.getOrDefault(item.getLong("user"), new ArrayList<>());
tags.add(item.getString("key"));
map.put(item.getLong("user"), tags);
}
Long maxQQ = -1L;
int max = -1;
for (Long qq : map.keySet()) {
List<String> list = map.get(qq);
if (list.size() > max) {
max = list.size();
maxQQ = qq;
}
builder.append(new At(qq))
.append(":\n");
for (String tag : list) {
builder.append(tag).append("\n");
}
}
builder.append("那么今日最色批的就是:");
builder.append(new At(maxQQ));
builder.append("\n");
builder.append("如果炸群了请找他(\n");
builder.append("明天见~");
}
if (builder != null) {
QQBotManager.getInstance().sendMessage(Long.parseLong(ret.replace("Setu_", "")), builder);
}
}
}
@Override
public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
super.onMessage(qq, event, isGroup);
@ -60,6 +135,19 @@ public class GetSeTu extends Model {
}
}
}
JSONObject data = new JSONObject();
data.put("user", event.getSource().getFromId());
data.put("group", qq);
data.put("key", key);
String redis = RedisTools.get("Setu_" + qq);
JSONArray array = new JSONArray();
if (!StringUtils.isEmpty(redis)) {
array = JSONArray.parseArray(redis);
}
array.add(data);
RedisTools.set("Setu_" + qq, array.toString());
}
}
@ -73,12 +161,12 @@ public class GetSeTu extends Model {
String[] keys = key.split(" ");
StringBuilder keyBuilder = new StringBuilder();
for (String _key : keys) {
keyBuilder.append(URLEncoder.encode(_key,StandardCharsets.UTF_8)).append("&tag=");
keyBuilder.append(URLEncoder.encode(_key, StandardCharsets.UTF_8)).append("&tag=");
}
key = keyBuilder.toString();
key = key.substring(0, key.length() - 5);
}else{
key=URLEncoder.encode(key,StandardCharsets.UTF_8);
} else {
key = URLEncoder.encode(key, StandardCharsets.UTF_8);
}
if (r18) {
url = "https://api.lolicon.app/setu/v2?" + model + "=" + key + "&r18=1&size=regular";