Skip to content

Commit

Permalink
✨ 每天清理2个月前的聊天记录
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaomujin committed Nov 26, 2024
1 parent 1bcb639 commit 1fc8e4e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 150 deletions.
155 changes: 5 additions & 150 deletions src/main/java/com/kuroneko/cqbot/controller/TestController.java
Original file line number Diff line number Diff line change
@@ -1,47 +1,15 @@
package com.kuroneko.cqbot.controller;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.kuroneko.cqbot.constant.Constant;
import com.kuroneko.cqbot.constant.RedisKey;
import com.kuroneko.cqbot.enums.Regex;
import com.kuroneko.cqbot.event.BiliSubscribeEvent;
import com.kuroneko.cqbot.exception.BotException;
import com.kuroneko.cqbot.handler.ApplicationContextHandler;
import com.kuroneko.cqbot.service.AiService;
import com.kuroneko.cqbot.service.BiLiService;
import com.kuroneko.cqbot.service.BulletService;
import com.kuroneko.cqbot.service.TarKovMarketService;
import com.kuroneko.cqbot.utils.CacheUtil;
import com.kuroneko.cqbot.utils.HttpUtil;
import com.kuroneko.cqbot.utils.PuppeteerUtil;
import com.kuroneko.cqbot.entity.WordCloud;
import com.kuroneko.cqbot.service.*;
import com.kuroneko.cqbot.vo.BiliDynamicVo;
import com.kuroneko.cqbot.vo.TarKovMarketVo;
import com.mikuac.shiro.common.utils.CommonUtils;
import com.mikuac.shiro.common.utils.MsgUtils;
import com.mikuac.shiro.common.utils.OneBotMedia;
import com.mikuac.shiro.common.utils.RegexUtils;
import com.ruiyun.jvppeteer.core.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;

@RestController
@RequiredArgsConstructor
Expand All @@ -51,6 +19,7 @@ public class TestController {
private final RestTemplate restTemplate;
private final AiService aiService;
private final TarKovMarketService tarKovMarketService;
private final WordCloudService wordCloudService;

@RequestMapping(value = "/testBiLi")
public BiliDynamicVo.BiliDynamicCard testBiLi() {
Expand All @@ -60,123 +29,9 @@ public BiliDynamicVo.BiliDynamicCard testBiLi() {

@RequestMapping(value = "/testRedis")
public Collection<String> testRedis() {
// redisUtil.add(RedisKey.BILI_SUB+":123456",123123);
// redisUtil.add(RedisKey.BILI_SUB+":123456",1234);
// redisUtil.add(RedisKey.BILI_SUB+":12345",1234);
// redisUtil.remove(RedisKey.BILI_SUB + ":12345", 1234);
// Collection<String> allKeys = redisUtil.getAllKeys(RedisKey.BILI_SUB);
LocalDateTime localDateTime = LocalDateTime.now().minusDays(10);
wordCloudService.lambdaUpdate().lt(WordCloud::getTime, localDateTime).remove();
return Collections.emptyList();
}

@RequestMapping(value = "/testListener")
public Collection<String> testListener() {
// redisUtil.add(RedisKey.BILI_SUB+":123456",123123);
// redisUtil.add(RedisKey.BILI_SUB+":123456",1234);
// redisUtil.add(RedisKey.BILI_SUB+":12345",1234);
// redisUtil.remove(RedisKey.BILI_SUB + ":12345", 1234);
// Collection<String> allKeys = redisUtil.getAllKeys(RedisKey.BILI_SUB);
// ApplicationContextHandler.publishEvent(new BiliSubscribeEvent(new BiliDynamicVo.BiliDynamicCard()));
return Collections.emptyList();
}

@RequestMapping(value = "/testBullet")
public Integer testBullet() {
// Page page = PuppeteerUtil.getNewPage("https://escapefromtarkov.fandom.com/wiki/Ballistics", "domcontentloaded", 120000, 1650, 12000);
//
// ElementHandle b = page.$("div._2O--J403t2VqCuF8XJAZLK");
// if (b != null) {
// try {
// b.click();
// } catch (InterruptedException | ExecutionException e) {
// throw new RuntimeException(e);
// }
// }
//
// String fun = """
// ()=>{
// let list = document.querySelectorAll(".sortable.stickyheader tr");
// let data_list = [];
// let caliber = "";
// for (let i = 0; i < list.length; i++) {
// let line_data = list[i];
// if(!line_data) continue;
// let td_list = line_data.querySelectorAll("td");
// if(!td_list) continue;
// let td_data_list = [];
// for (let j = 0; j < td_list.length; j++) {
// let td_line_data = td_list[j];
// if(j == 0 && td_list.length == 16){
// caliber = td_line_data.innerText;
// } else if(j == 0 && td_list.length == 15){
// td_data_list.push(caliber);
// }
// if (j === (td_list.length - 15)) {
// td_data_list.push(td_line_data.querySelector("a").innerText);
// let b = [];
// let b_list = td_line_data.querySelectorAll("b");
// if (b_list) {
// for (let k = 0; k < b_list.length; k++) {
// b.push(b_list[k].innerText);
// }
// td_data_list.push(b);
// }
// } else {
// td_data_list.push(td_line_data.innerText);
// }
// }
// data_list.push(td_data_list);
// }
// return data_list;
// }
// """;
// try {
// JSHandle jsHandle = page.waitFor(fun);
// ArrayList<Object> jsonValue = CastUtils.cast(jsHandle.jsonValue());
//
//
// } catch (InterruptedException e) {
// throw new RuntimeException(e);
// }
return 1;
}

@RequestMapping(value = "/testBili")
public String testBili() {
// Page newPage = PuppeteerUtil.getNewPage("http://127.0.0.1:8081/Life/智爷", 500, 800);
// PuppeteerUtil.screenshot(newPage, "/opt/bot_img/life/1.png");
// Page page = PuppeteerUtil.getNewPage("http://localhost:8081/baRank", 880, 500);
// String imgPath = Constant.BASE_IMG_PATH + "ba/ba.png";
// PuppeteerUtil.screenshot(page, imgPath, "#app");
// return aiService.getWuGuoKai(1, "吃了什么");
// HttpClient client = HttpClient.newHttpClient();
// URI uri = URI.create("https://www.bilibili.com/opus/887167886324400164");
// String scheme = uri.getScheme();
// HttpRequest request = HttpRequest.newBuilder().uri(uri).build();
// String urlBid;
// try {
// HttpResponse<String> send = client.send(request, HttpResponse.BodyHandlers.ofString());
// urlBid = send.headers().firstValue("location").orElse("");
// } catch (IOException | InterruptedException e) {
// throw new BotException(e.getMessage());
// } finally {
// client.close();
// }
// uri = URI.create(STR."\{scheme}:\{urlBid}");
// long l = System.currentTimeMillis();
// String redirect = HttpUtil.getRedirect("https://www.bilibili.com/opus/887167886324400164");
// System.out.println(System.currentTimeMillis() - l);
// List<TarKovMarketVo> btc = tarKovMarketService.search("btc");
PuppeteerUtil.getBrowser();
return """
你想查什么呢?
发送:跳蚤+(需要查询的物品关键字名称 多个关键字用空格分开)
如下:
跳蚤 显卡
跳蚤 btc
""" + "\n123\n";
// Optional<Matcher> match = RegexUtils.matcher(Regex.TKF_MARKET_SEARCH, "跳蚤123");
// return match.map(matcher -> matcher.group("text").trim()).orElse("null");
}


}
13 changes: 13 additions & 0 deletions src/main/java/com/kuroneko/cqbot/timer/BotTask.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package com.kuroneko.cqbot.timer;

import com.kuroneko.cqbot.entity.WordCloud;
import com.kuroneko.cqbot.service.BotTaskService;
import com.kuroneko.cqbot.service.TarKovMarketService;
import com.kuroneko.cqbot.service.WordCloudService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Slf4j
@RequiredArgsConstructor
Expand All @@ -18,6 +22,7 @@ public class BotTask {

private final BotTaskService botTaskService;
private final TarKovMarketService tarKovMarketService;
private final WordCloudService wordCloudService;

@Scheduled(cron = "0 0/10 * * * ? ")
public void refreshThreeDog() {
Expand Down Expand Up @@ -62,5 +67,13 @@ public void refreshBiliSubscribe() {
log.info("刷新哔哩订阅 结束");
}

@Scheduled(cron = "0 0 4 * * ? ")
public void cleanWordCloud() {
log.info("清理聊天日志 开始");
LocalDateTime localDateTime = LocalDateTime.now().minusMonths(2);
wordCloudService.lambdaUpdate().lt(WordCloud::getTime, localDateTime).remove();
log.info("清理聊天日志 结束");
}


}

0 comments on commit 1fc8e4e

Please sign in to comment.