From 52d90434b37294528d4119723d278d936150ddab Mon Sep 17 00:00:00 2001 From: gsd Date: Sat, 11 Mar 2023 23:18:30 +0300 Subject: [PATCH] =?UTF-8?q?=D1=83=20=D0=BF=D0=B5=D0=BB=D1=8C=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D1=8F=20=D0=BE=D1=85=D1=83=D0=B5=D0=BD=D0=BD=D1=8B=D0=B5?= =?UTF-8?q?=20=D0=B8=D0=B4=D0=B5=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/bot/DiscordBanController.java | 30 +++++++++++++++++++ src/main/java/app/services/db/BanService.java | 6 ++++ 2 files changed, 36 insertions(+) create mode 100644 src/main/java/app/controllers/bot/DiscordBanController.java diff --git a/src/main/java/app/controllers/bot/DiscordBanController.java b/src/main/java/app/controllers/bot/DiscordBanController.java new file mode 100644 index 0000000..bc11a1f --- /dev/null +++ b/src/main/java/app/controllers/bot/DiscordBanController.java @@ -0,0 +1,30 @@ +package app.controllers.bot; + +import app.annotations.enums.AuthMethod; +import app.annotations.interfaces.CheckWebAccess; +import app.services.db.BanService; +import jakarta.servlet.http.HttpServletRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("api/bot/discord") +public class DiscordBanController { + BanService banService; + + @Autowired + public DiscordBanController(BanService banService) { + this.banService = banService; + } + + @GetMapping("/banlist") + @CheckWebAccess(auth_method = AuthMethod.SECRET_KEY) + public ResponseEntity getDiscordIDsBanList( + HttpServletRequest request) { + return new ResponseEntity(banService.getUsersDiscordWithBanOnServers(), HttpStatus.OK); + } +} diff --git a/src/main/java/app/services/db/BanService.java b/src/main/java/app/services/db/BanService.java index 03c3f8d..17c7aa4 100644 --- a/src/main/java/app/services/db/BanService.java +++ b/src/main/java/app/services/db/BanService.java @@ -88,4 +88,10 @@ public class BanService { serverService.kickPlayer(user, "banned"); return getBan(user.getSteamids()).getId(); } + + public List getUsersDiscordWithBanOnServers() { + return entityManager.createNativeQuery("SELECT `discord_id` FROM `light_bans` INNER JOIN `steam2discord` ON `light_bans`.`active` = ?1 AND `light_bans`.`steam_id` COLLATE utf8mb4_unicode_ci LIKE `steam2discord`.`steam_id`") + .setParameter(1,1) + .getResultList(); + } }