mirror of
https://github.com/Shimeo98/DiscordWhitelisterSpigot.git
synced 2024-12-01 07:03:36 +01:00
help command & minor optimization
if a user with a valid role types !whitelist without a name after, the bot will respond with a help message
This commit is contained in:
parent
63c09e9c3f
commit
158c5b5a27
@ -3,7 +3,7 @@
|
||||
A simple spigot plugin which allows whitelisting through a discord text channel.
|
||||
|
||||
Features:
|
||||
- use '!whitelist MinecraftUsername' in a valid channel to whitelist people on your minecraft server
|
||||
- use '!whitelist <MinecraftUsername>' in a valid channel to whitelist people on your minecraft server
|
||||
- only select Discord roles can whitelist through the bot
|
||||
- bot only listens for messages in select text channels
|
||||
- logs whitelist attempts from valid roles in the console
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: DiscordWhitelister
|
||||
version: 1.0.0
|
||||
version: 1.0.1
|
||||
author: Joe Shimell
|
||||
main: uk.co.angrybee.joe.DiscordWhitelister
|
||||
description: Discord whitelister bot.
|
||||
|
@ -1,5 +1,6 @@
|
||||
package uk.co.angrybee.joe;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
@ -47,6 +48,14 @@ public class DiscordWhitelister extends JavaPlugin
|
||||
{
|
||||
getLogger().info("Initializing Discord client");
|
||||
serverDiscordClient = new ServerDiscordClient();
|
||||
|
||||
serverDiscordClient.allowedToUseRoles = new String[DiscordWhitelister.getWhitelisterBotConfig().getList("allowed-to-use-roles").size()];
|
||||
|
||||
for(int roles = 0; roles < serverDiscordClient.allowedToUseRoles.length; ++roles)
|
||||
{
|
||||
serverDiscordClient.allowedToUseRoles[roles] = DiscordWhitelister.getWhitelisterBotConfig().getList("allowed-to-use-roles").get(roles).toString();
|
||||
}
|
||||
|
||||
serverDiscordClient.InitializeClient(botToken);
|
||||
getLogger().info("Successfully initialized Discord client");
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ import java.util.Arrays;
|
||||
// handles Discord interaction
|
||||
public class ServerDiscordClient extends ListenerAdapter
|
||||
{
|
||||
public static String[] allowedToUseRoles;
|
||||
|
||||
public void InitializeClient(String clientToken)
|
||||
{
|
||||
try
|
||||
@ -63,13 +65,6 @@ public class ServerDiscordClient extends ListenerAdapter
|
||||
|
||||
boolean userHasPerms = false;
|
||||
|
||||
String[] allowedToUseRoles = new String[DiscordWhitelister.getWhitelisterBotConfig().getList("allowed-to-use-roles").size()];
|
||||
|
||||
for(int roles = 0; roles < allowedToUseRoles.length; ++roles)
|
||||
{
|
||||
allowedToUseRoles[roles] = DiscordWhitelister.getWhitelisterBotConfig().getList("allowed-to-use-roles").get(roles).toString();
|
||||
}
|
||||
|
||||
for(Role role : messageReceivedEvent.getGuild().getMember(messageReceivedEvent.getAuthor()).getRoles())
|
||||
{
|
||||
if(Arrays.stream(allowedToUseRoles).parallel().anyMatch(role.getName()::contains))
|
||||
@ -89,7 +84,9 @@ public class ServerDiscordClient extends ListenerAdapter
|
||||
|
||||
if(finalNameToWhitelist.isEmpty())
|
||||
{
|
||||
channel.sendMessage(author.getAsMention() + ", please enter a valid Minecraft username").queue();
|
||||
channel.sendMessage(author.getAsMention() + ", Whitelist command usage:" + System.lineSeparator() +
|
||||
"```!whitelist <MinecraftUsername>" + System.lineSeparator() +
|
||||
"If you encounter an issue, please report it here: https://github.com/JoeShimo/DiscordWhitelisterBot-Spigot/issues```").queue();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user