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:
JoeShimo 2019-08-25 14:18:29 +01:00
parent 63c09e9c3f
commit 158c5b5a27
4 changed files with 16 additions and 10 deletions

View File

@ -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

View File

@ -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.

View File

@ -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");
}

View File

@ -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
{