mirror of
https://github.com/Shimeo98/DiscordWhitelisterSpigot.git
synced 2025-01-25 09:32:12 +01:00
Support for using ids for Discord roles instead of the role name
Helps when trying to add Role with emojis and special characters
This commit is contained in:
parent
5b815d7cc3
commit
ba9b761b6d
@ -22,29 +22,70 @@ public class AuthorPermissions {
|
||||
return userHasLimitedAdd;
|
||||
}
|
||||
|
||||
public boolean isUserCanUseCommand() {
|
||||
public boolean isUserCanUseCommand()
|
||||
{
|
||||
return userCanAdd || userCanAddRemove || userHasLimitedAdd;
|
||||
}
|
||||
|
||||
public AuthorPermissions(MessageReceivedEvent event) {
|
||||
for (Role role : event.getGuild().getMember(event.getAuthor()).getRoles()) {
|
||||
if (Arrays.stream(DiscordClient.allowedToAddRemoveRoles).parallel().anyMatch(role.getName()::equalsIgnoreCase)) {
|
||||
userCanAddRemove = true;
|
||||
break;
|
||||
public AuthorPermissions(MessageReceivedEvent event)
|
||||
{
|
||||
for (Role role : event.getGuild().getMember(event.getAuthor()).getRoles())
|
||||
{
|
||||
if(!DiscordWhitelister.useIdForRoles)
|
||||
{
|
||||
if (Arrays.stream(DiscordClient.allowedToAddRemoveRoles).parallel().anyMatch(role.getName()::equalsIgnoreCase))
|
||||
{
|
||||
userCanAddRemove = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Arrays.stream(DiscordClient.allowedToAddRemoveRoles).parallel().anyMatch(role.getId()::equalsIgnoreCase))
|
||||
{
|
||||
userCanAddRemove = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Role role : event.getGuild().getMember(event.getAuthor()).getRoles()) {
|
||||
if (Arrays.stream(DiscordClient.allowedToAddRoles).parallel().anyMatch(role.getName()::equalsIgnoreCase)) {
|
||||
userCanAdd = true;
|
||||
break;
|
||||
for (Role role : event.getGuild().getMember(event.getAuthor()).getRoles())
|
||||
{
|
||||
if (!DiscordWhitelister.useIdForRoles)
|
||||
{
|
||||
if (Arrays.stream(DiscordClient.allowedToAddRoles).parallel().anyMatch(role.getName()::equalsIgnoreCase))
|
||||
{
|
||||
userCanAdd = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Arrays.stream(DiscordClient.allowedToAddRoles).parallel().anyMatch(role.getId()::equalsIgnoreCase))
|
||||
{
|
||||
userCanAdd = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Role role : event.getGuild().getMember(event.getAuthor()).getRoles()) {
|
||||
if (Arrays.stream(DiscordClient.allowedToAddLimitedRoles).parallel().anyMatch(role.getName()::equalsIgnoreCase)) {
|
||||
userHasLimitedAdd = true;
|
||||
break;
|
||||
for (Role role : event.getGuild().getMember(event.getAuthor()).getRoles())
|
||||
{
|
||||
if(!DiscordWhitelister.useIdForRoles)
|
||||
{
|
||||
if (Arrays.stream(DiscordClient.allowedToAddLimitedRoles).parallel().anyMatch(role.getName()::equalsIgnoreCase))
|
||||
{
|
||||
userHasLimitedAdd = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Arrays.stream(DiscordClient.allowedToAddLimitedRoles).parallel().anyMatch(role.getId()::equalsIgnoreCase))
|
||||
{
|
||||
userHasLimitedAdd = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,8 @@ public class DiscordClient extends ListenerAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
private static void AssignVars() {
|
||||
private static void AssignVars()
|
||||
{
|
||||
// assign vars here instead of every time a message is received, as they do not change
|
||||
targetTextChannels = new String[DiscordWhitelister.getWhitelisterBotConfig().getList("target-text-channels").size()];
|
||||
for (int i = 0; i < targetTextChannels.length; ++i) {
|
||||
@ -86,7 +87,8 @@ public class DiscordClient extends ListenerAdapter {
|
||||
whitelistedRoleName = DiscordWhitelister.getWhitelisterBotConfig().getString("whitelisted-role");
|
||||
}
|
||||
|
||||
private static void BuildStrings() {
|
||||
private static void BuildStrings()
|
||||
{
|
||||
// build here instead of every time a message is received, as they do not change
|
||||
EmbedBuilder embedBuilderBotInfo = new EmbedBuilder();
|
||||
embedBuilderBotInfo.setTitle("Discord Whitelister Bot for Spigot");
|
||||
@ -128,14 +130,18 @@ public class DiscordClient extends ListenerAdapter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(MessageReceivedEvent messageReceivedEvent) {
|
||||
if (messageReceivedEvent.isFromType(ChannelType.TEXT)) {
|
||||
public void onMessageReceived(MessageReceivedEvent messageReceivedEvent)
|
||||
{
|
||||
if (messageReceivedEvent.isFromType(ChannelType.TEXT))
|
||||
{
|
||||
// Check if message should be handled
|
||||
if (!Arrays.asList(targetTextChannels).contains(messageReceivedEvent.getTextChannel().getId())) {
|
||||
if (!Arrays.asList(targetTextChannels).contains(messageReceivedEvent.getTextChannel().getId()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (messageReceivedEvent.getAuthor().isBot()) {
|
||||
if (messageReceivedEvent.getAuthor().isBot())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@ -817,7 +823,8 @@ public class DiscordClient extends ListenerAdapter {
|
||||
}
|
||||
|
||||
// if the name is not on the list
|
||||
if (DiscordWhitelister.getRemovedList().get(finalNameToRemove) == null) {
|
||||
if (DiscordWhitelister.getRemovedList().get(finalNameToRemove) == null)
|
||||
{
|
||||
DiscordWhitelister.getRemovedList().set(finalNameToRemove, author.getId());
|
||||
DiscordWhitelister.getRemovedList().save(DiscordWhitelister.getRemovedListFile().getPath());
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ public class DiscordWhitelister extends JavaPlugin
|
||||
|
||||
public static boolean useEasyWhitelist = false;
|
||||
public static boolean useCustomMessages = false;
|
||||
public static boolean useIdForRoles = false;
|
||||
|
||||
private boolean botEnabled;
|
||||
|
||||
@ -78,6 +79,9 @@ public class DiscordWhitelister extends JavaPlugin
|
||||
{
|
||||
getLogger().info("Initializing Discord client...");
|
||||
|
||||
if(getWhitelisterBotConfig().getBoolean("use-id-for-roles"))
|
||||
useIdForRoles = true;
|
||||
|
||||
// set add & remove roles
|
||||
DiscordClient.allowedToAddRemoveRoles = new String[getWhitelisterBotConfig().getList("add-remove-roles").size()];
|
||||
for(int roles = 0; roles < DiscordClient.allowedToAddRemoveRoles.length; ++roles)
|
||||
@ -496,6 +500,16 @@ public class DiscordWhitelister extends JavaPlugin
|
||||
}
|
||||
}
|
||||
|
||||
if(getWhitelisterBotConfig().get("use-id-for-roles") == null)
|
||||
{
|
||||
getWhitelisterBotConfig().set("use-id-for-roles", false);
|
||||
|
||||
if(!configCreated)
|
||||
{
|
||||
getPlugin().getLogger().warning("Entry 'use-id-for-roles' was not found, adding it to the config...");
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
getWhitelisterBotConfig().save((whitelisterBotConfigFile.getPath()));
|
||||
|
Loading…
Reference in New Issue
Block a user