From 84edecd0f10facda3d3e864b1c481b557e9aaed4 Mon Sep 17 00:00:00 2001 From: gsd Date: Thu, 16 Feb 2023 19:11:06 +0300 Subject: [PATCH] admin info to ban --- src/main/java/app/entities/db/AdminInfo.java | 29 +++++++++++++++++++ src/main/java/app/entities/db/Ban.java | 1 + .../java/app/services/ProfileService.java | 5 ++++ .../app/services/db/PermitionService.java | 8 +++++ 4 files changed, 43 insertions(+) create mode 100644 src/main/java/app/entities/db/AdminInfo.java diff --git a/src/main/java/app/entities/db/AdminInfo.java b/src/main/java/app/entities/db/AdminInfo.java new file mode 100644 index 0000000..49673df --- /dev/null +++ b/src/main/java/app/entities/db/AdminInfo.java @@ -0,0 +1,29 @@ +package app.entities.db; + +import app.utils.SteamIDConverter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import lombok.Data; + +@Data +public class AdminInfo { + @JsonIgnore + int id; + int vk_id; + long discord_id; + String discord_name; + @JsonIgnore + String steam3; + String steam_url; + @JsonIgnore + int permition; + + public AdminInfo(Object[] obj) { + id = (int) obj[0]; + vk_id = (int) obj[1]; + discord_id = (long) obj[2]; + discord_name = (String) obj[3]; + steam3 = (String) obj[4]; + permition = (int) obj[5]; + steam_url = SteamIDConverter.getSteamID(steam3).community_url; + } +} diff --git a/src/main/java/app/entities/db/Ban.java b/src/main/java/app/entities/db/Ban.java index 8e36a0d..11c877d 100644 --- a/src/main/java/app/entities/db/Ban.java +++ b/src/main/java/app/entities/db/Ban.java @@ -24,6 +24,7 @@ public class Ban { boolean active; String unbanned_by_id; Timestamp unbanned_timestamp; + AdminInfo admin_info; public Ban(Object[] obj) { id = (int) obj[0]; diff --git a/src/main/java/app/services/ProfileService.java b/src/main/java/app/services/ProfileService.java index 9852b80..cf4e4f4 100644 --- a/src/main/java/app/services/ProfileService.java +++ b/src/main/java/app/services/ProfileService.java @@ -88,6 +88,11 @@ public class ProfileService { //if(requests.contains("ban")){ start_time = Instant.now().toEpochMilli(); profile.setBan(banService.getBan(steamID)); + if(profile.getBan() != null) { + profile.getBan().setAdmin_info( + permitionService.getAdminInfo(SteamIDConverter.getSteamID(profile.getBan().getBanned_by_id())) + ); + } end_time = Instant.now().toEpochMilli() - start_time; profile.getResponse_time().put("ban", Double.valueOf(end_time) / 1000); //} diff --git a/src/main/java/app/services/db/PermitionService.java b/src/main/java/app/services/db/PermitionService.java index 1a8dc13..444d89e 100644 --- a/src/main/java/app/services/db/PermitionService.java +++ b/src/main/java/app/services/db/PermitionService.java @@ -1,5 +1,6 @@ package app.services.db; +import app.entities.db.AdminInfo; import app.entities.db.Ban; import app.entities.db.Permition; import app.entities.other.SteamID; @@ -65,4 +66,11 @@ public class PermitionService { if (getPermition(steamID) == null) return true; return removePermition(steamID, "VIP"); } + + public AdminInfo getAdminInfo(SteamID steamID) { + List result = entityManager.createNativeQuery("SELECT id, vk_id, discord_id, discord_name, steam3, permition FROM bot_admins WHERE steam3 LIKE ?1") + .setParameter(1, steamID.steam3) + .getResultList(); + return result.stream().map(AdminInfo::new).findFirst().orElse(null); + } }