🔨 Add canManage to guild list
This commit is contained in:
parent
ccb0c6eee8
commit
606d223361
@ -1,4 +1,4 @@
|
|||||||
package net.Broken.Api.Data.Guild;
|
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) {
|
||||||
}
|
}
|
||||||
|
@ -16,46 +16,51 @@ import java.util.List;
|
|||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class GuildService {
|
public class GuildService {
|
||||||
public List<Guild> getMutualGuilds(UserEntity user){
|
public List<Guild> getMutualGuilds(UserEntity user) {
|
||||||
User discordUser = CacheTools.getJdaUser(user);
|
User discordUser = CacheTools.getJdaUser(user);
|
||||||
List<net.dv8tion.jda.api.entities.Guild> mutualGuilds = discordUser.getMutualGuilds();
|
List<net.dv8tion.jda.api.entities.Guild> mutualGuilds = discordUser.getMutualGuilds();
|
||||||
List<Guild> guildList = new ArrayList<>();
|
List<Guild> guildList = new ArrayList<>();
|
||||||
|
|
||||||
for (net.dv8tion.jda.api.entities.Guild guild : mutualGuilds){
|
for (net.dv8tion.jda.api.entities.Guild guild : mutualGuilds) {
|
||||||
guildList.add(new Guild(guild.getId(), guild.getName(), guild.getIconUrl()));
|
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;
|
return guildList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Channel> getVoiceChannel(String guildId, String userId){
|
public List<Channel> getVoiceChannel(String guildId, String userId) {
|
||||||
net.dv8tion.jda.api.entities.Guild guild = MainBot.jda.getGuildById(guildId);
|
net.dv8tion.jda.api.entities.Guild guild = MainBot.jda.getGuildById(guildId);
|
||||||
Member member = guild.getMemberById(userId);
|
Member member = guild.getMemberById(userId);
|
||||||
List<Channel> voiceChannels = new ArrayList<>();
|
List<Channel> voiceChannels = new ArrayList<>();
|
||||||
for(net.dv8tion.jda.api.entities.VoiceChannel voiceChannel : guild.getVoiceChannels()){
|
for (net.dv8tion.jda.api.entities.VoiceChannel voiceChannel : guild.getVoiceChannels()) {
|
||||||
if(member.hasPermission(voiceChannel, Permission.VIEW_CHANNEL)){
|
if (member.hasPermission(voiceChannel, Permission.VIEW_CHANNEL)) {
|
||||||
voiceChannels.add(new Channel(voiceChannel.getId(), voiceChannel.getName()));
|
voiceChannels.add(new Channel(voiceChannel.getId(), voiceChannel.getName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return voiceChannels;
|
return voiceChannels;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Channel> getTextChannel(String guildId, String userId){
|
public List<Channel> getTextChannel(String guildId, String userId) {
|
||||||
net.dv8tion.jda.api.entities.Guild guild = MainBot.jda.getGuildById(guildId);
|
net.dv8tion.jda.api.entities.Guild guild = MainBot.jda.getGuildById(guildId);
|
||||||
Member member = guild.getMemberById(userId);
|
Member member = guild.getMemberById(userId);
|
||||||
List<Channel> voiceChannels = new ArrayList<>();
|
List<Channel> voiceChannels = new ArrayList<>();
|
||||||
for(net.dv8tion.jda.api.entities.TextChannel textChannel : guild.getTextChannels()){
|
for (net.dv8tion.jda.api.entities.TextChannel textChannel : guild.getTextChannels()) {
|
||||||
if(member.hasPermission(textChannel, Permission.VIEW_CHANNEL)) {
|
if (member.hasPermission(textChannel, Permission.VIEW_CHANNEL)) {
|
||||||
voiceChannels.add(new Channel(textChannel.getId(), textChannel.getName()));
|
voiceChannels.add(new Channel(textChannel.getId(), textChannel.getName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return voiceChannels;
|
return voiceChannels;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Role> getRole(String guildId){
|
public List<Role> getRole(String guildId) {
|
||||||
net.dv8tion.jda.api.entities.Guild guild = MainBot.jda.getGuildById(guildId);
|
net.dv8tion.jda.api.entities.Guild guild = MainBot.jda.getGuildById(guildId);
|
||||||
List<Role> roles = new ArrayList<>();
|
List<Role> roles = new ArrayList<>();
|
||||||
for(net.dv8tion.jda.api.entities.Role role : guild.getRoles()){
|
for (net.dv8tion.jda.api.entities.Role role : guild.getRoles()) {
|
||||||
if(!role.isManaged()){
|
if (!role.isManaged()) {
|
||||||
roles.add(new Role(role.getId(), role.getName()));
|
roles.add(new Role(role.getId(), role.getName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user