Skip to content

Commit

Permalink
Release 1.13.16 (#528)
Browse files Browse the repository at this point in the history
  • Loading branch information
rainbowdashlabs authored May 30, 2023
2 parents a7af708 + c8cfb4e commit cfa9660
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = "de.chojo"
version = "1.13.15"
version = "1.13.16"

repositories {
maven("https://eldonexus.de/repository/maven-public")
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
database:
networks:
- repbot
image: postgres:15.2
image: postgres:15.3
expose:
- 5432
volumes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
import de.chojo.jdautil.wrapper.EventContext;
import de.chojo.repbot.dao.access.Gdpr;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.slf4j.Logger;

import static org.slf4j.LoggerFactory.getLogger;

public class Delete implements SlashHandler {
private final Gdpr gdpr;
private static final Logger log = getLogger(Delete.class);

public Delete(Gdpr gdpr) {
this.gdpr = gdpr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
import de.chojo.jdautil.wrapper.EventContext;
import de.chojo.repbot.service.GdprService;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.slf4j.Logger;

import static org.slf4j.LoggerFactory.getLogger;

public class Guild implements SlashHandler {
private static final Logger log = getLogger(Guild.class);
private final GdprService service;

public Guild(GdprService service) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static GdprUser build(Gdpr gdpr, Row rs, ShardManager shardManager) throw
}

public boolean queueDeletion() {
log.info("User {} requested deletion of their data", userId());
return builder()
.query("""
INSERT INTO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.User;
import org.slf4j.Logger;

import static org.slf4j.LoggerFactory.getLogger;

public class Gdpr extends QueryFactory implements MemberHolder {
private final RepUser repUser;
private static final Logger log = getLogger(Gdpr.class);

public Gdpr(RepUser repUser) {
super(repUser);
Expand All @@ -22,6 +26,7 @@ public Member member() {
}

public void queueDeletion() {
log.info("User {} is scheduled for deletion on guild {}", userId(), guildId());
builder()
.query("""
INSERT INTO
Expand All @@ -38,6 +43,7 @@ ON CONFLICT(guild_id, user_id)
}

public void dequeueDeletion() {
log.info("User {} deletion on guild {} canceled", userId(), guildId());
builder()
.query("""
DELETE FROM
Expand Down
27 changes: 18 additions & 9 deletions src/main/java/de/chojo/repbot/service/GdprService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import de.chojo.repbot.dao.access.Gdpr;
import de.chojo.repbot.dao.access.gdpr.RemovalTask;
import de.chojo.repbot.dao.access.guild.RepGuild;
import de.chojo.repbot.dao.provider.Guilds;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.ISnowflake;
import net.dv8tion.jda.api.sharding.ShardManager;
import org.slf4j.Logger;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;
Expand Down Expand Up @@ -60,17 +60,26 @@ public void run() {

public CompletableFuture<Integer> cleanupGuildUsers(Guild guild) {
return CompletableFuture.supplyAsync(() -> {
var savedIds = guilds.guild(guild).userIds();
var memberIds = guild.loadMembers().get()
.stream()
.map(ISnowflake::getIdLong).toList();
var collect = savedIds.stream().filter(id -> !memberIds.contains(id)).toList();
for (var id : collect) RemovalTask.anonymExecute(gdpr, guild.getIdLong(), id);
return collect.size();
log.info("Guild prune was started on {}", guild.getId());
var pruned = 0;
var users = guilds.guild(guild).userIds();
log.info("Checking {} users", users.size());
for (var user : users) {
try {
guild.retrieveMemberById(user).complete();
} catch (RuntimeException e) {
log.info("Removing user {} data during guild prune", user);
RemovalTask.anonymExecute(gdpr, guild.getIdLong(), user);
pruned++;
}
}
log.info("Prune on guild {} finished. Removed {} users", guild.getId(), pruned);
return pruned;
}, executorService);
}

public void cleanupGuildUser(Guild guild, Long user) {
log.info("User data of {} was pruned on guild {}.", user, guild.getIdLong());
CompletableFuture.runAsync(() -> RemovalTask.anonymExecute(gdpr, guild.getIdLong(), user), executorService);
}

Expand Down

0 comments on commit cfa9660

Please sign in to comment.