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(); + } }