🔨 Add textchannel and voicechannel endpoint

This commit is contained in:
SebClem 2022-06-10 16:55:31 +02:00
parent 47fa3ae2bf
commit 3f5225bef1
Signed by: sebclem
GPG Key ID: 5A4308F6A359EA50
5 changed files with 43 additions and 5 deletions

View File

@ -2,15 +2,14 @@ package net.Broken.Api.Controllers;
import net.Broken.Api.Data.Guild;
import net.Broken.Api.Data.InviteLink;
import net.Broken.Api.Data.Channel;
import net.Broken.Api.Security.Data.JwtPrincipal;
import net.Broken.Api.Services.GuildService;
import net.Broken.MainBot;
import net.dv8tion.jda.api.Permission;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -36,4 +35,17 @@ public class GuildController {
String link = MainBot.jda.getInviteUrl(Permission.ADMINISTRATOR);
return new InviteLink(link);
}
@GetMapping("/{guildId}/voiceChannels")
@PreAuthorize("isInGuild(#guildId)")
public List<Channel> getVoiceChannels(@PathVariable String guildId){
return guildService.getVoiceChannel(String.valueOf(guildId));
}
@GetMapping("/{guildId}/textChannels")
@PreAuthorize("isInGuild(#guildId)")
public List<Channel> getTextChannels(@PathVariable String guildId){
return guildService.getTextChannel(String.valueOf(guildId));
}
}

View File

@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.security.SecurityRequirements;
import net.Broken.Api.Security.Data.JwtPrincipal;
import net.Broken.DB.Entity.UserEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;

View File

@ -0,0 +1,4 @@
package net.Broken.Api.Data;
public record Channel(String id, String name) {
}

View File

@ -1,7 +1,9 @@
package net.Broken.Api.Services;
import net.Broken.Api.Data.Guild;
import net.Broken.Api.Data.Channel;
import net.Broken.DB.Entity.UserEntity;
import net.Broken.MainBot;
import net.Broken.Tools.CacheTools;
import net.dv8tion.jda.api.entities.User;
import org.springframework.stereotype.Service;
@ -22,4 +24,23 @@ public class GuildService {
return guildList;
}
public List<Channel> getVoiceChannel(String guildId){
net.dv8tion.jda.api.entities.Guild guild = MainBot.jda.getGuildById(guildId);
List<Channel> voiceChannels = new ArrayList<>();
for(net.dv8tion.jda.api.entities.VoiceChannel voiceChannel : guild.getVoiceChannels()){
voiceChannels.add(new Channel(voiceChannel.getId(), voiceChannel.getName()));
}
return voiceChannels;
}
public List<Channel> getTextChannel(String guildId){
net.dv8tion.jda.api.entities.Guild guild = MainBot.jda.getGuildById(guildId);
List<Channel> voiceChannels = new ArrayList<>();
for(net.dv8tion.jda.api.entities.TextChannel textChannel : guild.getTextChannels()){
voiceChannels.add(new Channel(textChannel.getId(), textChannel.getName()));
}
return voiceChannels;
}
}

View File

@ -2,7 +2,7 @@
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<!--<PatternLayout pattern="[%d{HH:mm:ss.SSS}][%-5level][%-30.30c{1.}]: %msg%n" />-->
<PatternLayout>
<PatternLayout disableAnsi="false">
<Pattern>[%d{HH:mm:ss.SSS}]%highlight{[%-5level]}{FATAL=red blink, ERROR=red, WARN=bright yellow ,
INFO=blue, DEBUG=bright black, TRACE=cyan}[%-30.30c{1.}]: %highlight{%msg%n}{FATAL=red blink,
ERROR=red, WARN=bright yellow , INFO=blue, DEBUG=bright black, TRACE=cyan}