mirror of
https://github.com/Shimeo98/DiscordWhitelisterSpigot.git
synced 2024-11-28 13:45:18 +01:00
Made !whitelist add/remove commands required to be at start of message.
Made the name be the text up to the first space following the command (everything else is ignored). This allows writing something like "@user please do !whitelist add <username>" without triggering the bot. Fixed error that occurred when users leave guild which did not use the plugin to add to the whitelist. Fixed version not displaying correctly (was still showing 1.2.0). Made GitHub link in /dwabout command green.
This commit is contained in:
parent
4d16d2f292
commit
2636cb47f8
@ -1,14 +1,14 @@
|
||||
name: DiscordWhitelister
|
||||
version: 1.3.0
|
||||
version: 1.3.1
|
||||
author: Joe Shimell
|
||||
main: uk.co.angrybee.joe.DiscordWhitelister
|
||||
description: Discord whitelister bot.
|
||||
commands:
|
||||
discordwhitelister:
|
||||
description: See VersionInfo and Discord status
|
||||
description: See info about this plugin
|
||||
usage: /<command>
|
||||
aliases: [dw]
|
||||
discordwhitelisterabout:
|
||||
description: See VersionInfo and Discord status
|
||||
description: See plugin version and Discord connection status
|
||||
usage: /<command>
|
||||
aliases: [dwabout]
|
@ -10,11 +10,11 @@ import uk.co.angrybee.joe.VersionInfo;
|
||||
|
||||
public class CommandAbout implements CommandExecutor {
|
||||
|
||||
// /dw
|
||||
// /dwabout
|
||||
// about command
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
sender.sendMessage("[DW] DiscordWhiteLister by JoeShimell\nhttps://github.com/JoeShimell/DiscordWhitelisterSpigot");
|
||||
sender.sendMessage("[DW] DiscordWhiteLister by JoeShimell\n" + ChatColor.GREEN + "https://github.com/JoeShimell/DiscordWhitelisterSpigot");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ public class DiscordClient extends ListenerAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
if (messageContents.toLowerCase().contains("!whitelist add")) {
|
||||
if (messageContents.toLowerCase().startsWith("!whitelist add")) {
|
||||
// add command
|
||||
|
||||
// permissions
|
||||
@ -197,11 +197,10 @@ public class DiscordClient extends ListenerAdapter {
|
||||
}
|
||||
|
||||
if (authorPermissions.isUserCanAddRemove() || authorPermissions.isUserCanAdd() || limitedWhitelistEnabled && authorPermissions.isUserHasLimitedAdd()) {
|
||||
String nameToWhitelist = messageContents.toLowerCase();
|
||||
nameToWhitelist = nameToWhitelist.substring(nameToWhitelist.indexOf("!whitelist add") + 14); // get everything after !whitelist add
|
||||
nameToWhitelist = nameToWhitelist.replaceAll(" ", "");
|
||||
messageContents = messageContents.toLowerCase();
|
||||
String messageContentsAfterCommand = messageContents.substring("!whitelist add".length() + 1); // get everything after !whitelist add[space]
|
||||
final String finalNameToAdd = messageContentsAfterCommand.replaceAll(" .*", ""); // The name is everything up to the first space
|
||||
|
||||
final String finalNameToAdd = nameToWhitelist;
|
||||
final char[] finalNameToWhitelistChar = finalNameToAdd.toCharArray();
|
||||
|
||||
int timesWhitelisted = 0;
|
||||
@ -438,13 +437,11 @@ public class DiscordClient extends ListenerAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
if (messageContents.toLowerCase().contains("!whitelist remove")) {
|
||||
if (messageContents.toLowerCase().startsWith("!whitelist remove")) {
|
||||
if (authorPermissions.isUserCanAddRemove()) {
|
||||
String nameToRemove = messageContents.toLowerCase();
|
||||
nameToRemove = nameToRemove.substring(nameToRemove.indexOf("!whitelist remove") + 17); // get everything after !whitelist remove
|
||||
nameToRemove = nameToRemove.replaceAll(" ", "");
|
||||
|
||||
final String finalNameToRemove = nameToRemove;
|
||||
messageContents = messageContents.toLowerCase();
|
||||
String messageContentsAfterCommand = messageContents.substring("!whitelist remove".length() + 1); // get everything after !whitelist add[space]
|
||||
final String finalNameToRemove = messageContentsAfterCommand.replaceAll(" .*", ""); // The name is everything up to the first space
|
||||
|
||||
if (finalNameToRemove.isEmpty()) {
|
||||
channel.sendMessage(removeCommandInfo).queue();
|
||||
@ -596,7 +593,6 @@ public class DiscordClient extends ListenerAdapter {
|
||||
embedBuilderFailure.setColor(new Color(231, 76, 60));
|
||||
embedBuilderFailure.addField("Insufficient Permissions", (author.getAsMention() + ", you do not have permission to use this command."), false);
|
||||
channel.sendMessage(embedBuilderFailure.build()).queue();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -604,24 +600,31 @@ public class DiscordClient extends ListenerAdapter {
|
||||
@Override
|
||||
public void onGuildMemberLeave(@Nonnull GuildMemberLeaveEvent event) {
|
||||
String discordUserToRemove = event.getMember().getId();
|
||||
DiscordWhitelister.getPlugin().getLogger().info(discordUserToRemove + " left. Removing his whitelisted entries.");
|
||||
DiscordWhitelister.getPlugin().getLogger().info(discordUserToRemove + " left. Removing their whitelisted entries...");
|
||||
List<?> ls = DiscordWhitelister.getRegisteredUsers(discordUserToRemove);
|
||||
for (Object minecraftNameToRemove: ls) {
|
||||
DiscordWhitelister.getPlugin().getLogger().info(minecraftNameToRemove.toString() + " left. Removing his whitelisted entries.");
|
||||
if (DiscordWhitelister.useEasyWhitelist) {
|
||||
executeServerCommand("easywl remove " + minecraftNameToRemove.toString());
|
||||
} else {
|
||||
executeServerCommand("whitelist remove " + minecraftNameToRemove.toString());
|
||||
|
||||
if(ls != null) {
|
||||
|
||||
for (Object minecraftNameToRemove : ls) {
|
||||
DiscordWhitelister.getPlugin().getLogger().info(minecraftNameToRemove.toString() + " left. Removing their whitelisted entries.");
|
||||
if (DiscordWhitelister.useEasyWhitelist) {
|
||||
executeServerCommand("easywl remove " + minecraftNameToRemove.toString());
|
||||
} else {
|
||||
executeServerCommand("whitelist remove " + minecraftNameToRemove.toString());
|
||||
}
|
||||
}
|
||||
try {
|
||||
DiscordWhitelister.resetRegisteredUsers(discordUserToRemove);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
DiscordWhitelister.getPlugin().getLogger().info(discordUserToRemove + " left. Successfully removed their whitelisted entries.");
|
||||
|
||||
}
|
||||
try {
|
||||
DiscordWhitelister.resetRegisteredUsers(discordUserToRemove);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
else {
|
||||
DiscordWhitelister.getPlugin().getLogger().warning(discordUserToRemove + " left. Could not removed their whitelisted entries as they did not whitelist through this plugin.");
|
||||
}
|
||||
DiscordWhitelister.getPlugin().getLogger().info(discordUserToRemove + " left. Successfully removed his whitelisted entries.");
|
||||
return;
|
||||
}
|
||||
|
||||
private boolean checkWhitelistJSON(File whitelistFile, String minecraftUsername) {
|
||||
|
@ -9,5 +9,5 @@ public class VersionInfo {
|
||||
return "v." + getVersion();
|
||||
}
|
||||
|
||||
private static String version = "1.2.0";
|
||||
private static String version = "1.3.1";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user