From 606d2233613cb3a5e06c061021a59fed5c6a925f Mon Sep 17 00:00:00 2001 From: SebClem Date: Sat, 11 Jun 2022 19:06:04 +0200 Subject: [PATCH] :hammer: Add canManage to guild list --- .../java/net/Broken/Api/Data/Guild/Guild.java | 2 +- .../net/Broken/Api/Services/GuildService.java | 29 +++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/Broken/Api/Data/Guild/Guild.java b/src/main/java/net/Broken/Api/Data/Guild/Guild.java index c5c880d..5f33ea5 100644 --- a/src/main/java/net/Broken/Api/Data/Guild/Guild.java +++ b/src/main/java/net/Broken/Api/Data/Guild/Guild.java @@ -1,4 +1,4 @@ package net.Broken.Api.Data.Guild; -public record Guild(String id, String name, String iconUrl) { +public record Guild(String id, String name, String iconUrl, boolean canManage) { } diff --git a/src/main/java/net/Broken/Api/Services/GuildService.java b/src/main/java/net/Broken/Api/Services/GuildService.java index 372a807..71dd64a 100644 --- a/src/main/java/net/Broken/Api/Services/GuildService.java +++ b/src/main/java/net/Broken/Api/Services/GuildService.java @@ -16,46 +16,51 @@ import java.util.List; @Service public class GuildService { - public List getMutualGuilds(UserEntity user){ + public List getMutualGuilds(UserEntity user) { User discordUser = CacheTools.getJdaUser(user); List mutualGuilds = discordUser.getMutualGuilds(); List guildList = new ArrayList<>(); - for (net.dv8tion.jda.api.entities.Guild guild : mutualGuilds){ - guildList.add(new Guild(guild.getId(), guild.getName(), guild.getIconUrl())); + for (net.dv8tion.jda.api.entities.Guild guild : mutualGuilds) { + boolean canManage = guild.getMember(discordUser).hasPermission( + Permission.MANAGE_SERVER, + Permission.MANAGE_PERMISSIONS, + Permission.MANAGE_CHANNEL + ); + guildList.add(new Guild(guild.getId(), guild.getName(), guild.getIconUrl(), canManage)); } return guildList; } - public List getVoiceChannel(String guildId, String userId){ + public List getVoiceChannel(String guildId, String userId) { net.dv8tion.jda.api.entities.Guild guild = MainBot.jda.getGuildById(guildId); Member member = guild.getMemberById(userId); List voiceChannels = new ArrayList<>(); - for(net.dv8tion.jda.api.entities.VoiceChannel voiceChannel : guild.getVoiceChannels()){ - if(member.hasPermission(voiceChannel, Permission.VIEW_CHANNEL)){ + for (net.dv8tion.jda.api.entities.VoiceChannel voiceChannel : guild.getVoiceChannels()) { + if (member.hasPermission(voiceChannel, Permission.VIEW_CHANNEL)) { voiceChannels.add(new Channel(voiceChannel.getId(), voiceChannel.getName())); } } return voiceChannels; } - public List getTextChannel(String guildId, String userId){ + public List getTextChannel(String guildId, String userId) { net.dv8tion.jda.api.entities.Guild guild = MainBot.jda.getGuildById(guildId); Member member = guild.getMemberById(userId); List voiceChannels = new ArrayList<>(); - for(net.dv8tion.jda.api.entities.TextChannel textChannel : guild.getTextChannels()){ - if(member.hasPermission(textChannel, Permission.VIEW_CHANNEL)) { + for (net.dv8tion.jda.api.entities.TextChannel textChannel : guild.getTextChannels()) { + if (member.hasPermission(textChannel, Permission.VIEW_CHANNEL)) { voiceChannels.add(new Channel(textChannel.getId(), textChannel.getName())); } } return voiceChannels; } - public List getRole(String guildId){ + public List getRole(String guildId) { net.dv8tion.jda.api.entities.Guild guild = MainBot.jda.getGuildById(guildId); List roles = new ArrayList<>(); - for(net.dv8tion.jda.api.entities.Role role : guild.getRoles()){ - if(!role.isManaged()){ + for (net.dv8tion.jda.api.entities.Role role : guild.getRoles()) { + if (!role.isManaged()) { roles.add(new Role(role.getId(), role.getName())); } }