diff --git a/pom.xml b/pom.xml index e04e8dd..a7e3a45 100644 --- a/pom.xml +++ b/pom.xml @@ -172,7 +172,7 @@ net.dv8tion JDA - 4.2.0_177 + 4.2.0_184 com.github.cage diff --git a/src/main/java/com/fpghoti/biscuit/Main.java b/src/main/java/com/fpghoti/biscuit/Main.java index 0779db8..d124d57 100644 --- a/src/main/java/com/fpghoti/biscuit/Main.java +++ b/src/main/java/com/fpghoti/biscuit/Main.java @@ -8,6 +8,7 @@ import java.util.Scanner; import org.fusesource.jansi.AnsiConsole; import com.fpghoti.biscuit.biscuit.Biscuit; +import com.fpghoti.biscuit.captcha.BCage; import com.fpghoti.biscuit.commands.CommandManager; import com.fpghoti.biscuit.commands.client.AddCommand; import com.fpghoti.biscuit.commands.client.ChanIDCommand; @@ -55,6 +56,7 @@ import com.fpghoti.biscuit.listener.ReactionListener; import com.fpghoti.biscuit.listener.RoleListener; import com.fpghoti.biscuit.logging.BColor; import com.fpghoti.biscuit.logging.BiscuitLog; +import com.github.cage.Cage; import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager; import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager; import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers; @@ -85,6 +87,7 @@ public class Main { public static boolean ready = false; public static boolean isPlugin = false; public static boolean shutdownStarted = false; + private static Cage cage; private static AudioPlayerManager playerManager; @@ -106,6 +109,8 @@ public class Main { mainBiscuit = new Biscuit(null, null, log); startJDA(); + + cage = new BCage(); jda.addEventListener(new GuildListener()); jda.addEventListener(new MessageReceiveListener()); @@ -244,6 +249,10 @@ public class Main { public static JDA getJDA() { return jda; } + + public static Cage getCage() { + return cage; + } public static BiscuitLog getLogger() { return log; diff --git a/src/main/java/com/fpghoti/biscuit/audio/AudioResultHandler.java b/src/main/java/com/fpghoti/biscuit/audio/AudioResultHandler.java index ca14c39..255cbca 100644 --- a/src/main/java/com/fpghoti/biscuit/audio/AudioResultHandler.java +++ b/src/main/java/com/fpghoti/biscuit/audio/AudioResultHandler.java @@ -2,6 +2,7 @@ package com.fpghoti.biscuit.audio; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; +import com.fpghoti.biscuit.rest.MessageText; import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler; import com.sedmelluq.discord.lavaplayer.tools.FriendlyException; import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; @@ -60,16 +61,16 @@ public class AudioResultHandler implements AudioLoadResultHandler { biscuit.log("Exact match not found. Searching instead..."); Main.getPlayerManager().loadItemOrdered(biscuit.getGuild(),"ytsearch:" + searchPhrase, new AudioResultHandler(uid, channel, true, searchPhrase, first, false)); }else { - channel.sendMessage("Song match not found.").queue(); + MessageText.send(channel, "Song match not found."); } } @Override public void loadFailed(FriendlyException exception) { exception.printStackTrace(); - channel.sendMessage("An error was encountered while attempting to load audio.").queue(); + MessageText.send(channel, "An error was encountered while attempting to load audio."); } - - + + } diff --git a/src/main/java/com/fpghoti/biscuit/audio/AudioScheduler.java b/src/main/java/com/fpghoti/biscuit/audio/AudioScheduler.java index 0362aa1..eece3d6 100644 --- a/src/main/java/com/fpghoti/biscuit/audio/AudioScheduler.java +++ b/src/main/java/com/fpghoti/biscuit/audio/AudioScheduler.java @@ -6,6 +6,7 @@ import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.audio.queue.AudioQueue; import com.fpghoti.biscuit.audio.queue.QueuedTrack; import com.fpghoti.biscuit.biscuit.Biscuit; +import com.fpghoti.biscuit.rest.MessageText; import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; import com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter; import com.sedmelluq.discord.lavaplayer.tools.FriendlyException; @@ -56,7 +57,7 @@ public class AudioScheduler extends AudioEventAdapter { if(!qt.triedAlternative()) { qt.useAttempt(); TextChannel channel = qt.getCommandChannel(); - channel.sendMessage("The video selected cannot be played through the music player. An alternate track will be played if available.").queue(); + MessageText.send(channel, "The video selected cannot be played through the music player. An alternate track will be played if available."); title = title.toLowerCase().replace("vevo", "") + " lyrics"; Main.getPlayerManager().loadItemOrdered(biscuit.getGuild(),"ytsearch:" + title, new AudioResultHandler(qt.getUserId(), channel, true, title, true, !queue.isEmpty())); return; @@ -65,7 +66,7 @@ public class AudioScheduler extends AudioEventAdapter { case CLEANUP: log("A track stopped playing due to audio player cleanup."); if(qt != null && qt.getCommandChannel() != null) - qt.getCommandChannel().sendMessage("Track **" + track.getInfo().title + "** stopped playing due to audio player cleanup.").queue(); + MessageText.send(qt.getCommandChannel(), "Track **" + track.getInfo().title + "** stopped playing due to audio player cleanup."); break; case FINISHED: log("Finished playing track " + title + "."); @@ -103,7 +104,7 @@ public class AudioScheduler extends AudioEventAdapter { public void onTrackStuck(AudioPlayer player, AudioTrack track, long thresholdMs) { QueuedTrack qt = queue.getPreviousTrack(track); if(qt != null && qt.getCommandChannel() != null) { - qt.getCommandChannel().sendMessage("The current track has become stuck and will be skipped.").queue(); + MessageText.send(qt.getCommandChannel(), "The current track has become stuck and will be skipped."); } } diff --git a/src/main/java/com/fpghoti/biscuit/audio/queue/AudioQueue.java b/src/main/java/com/fpghoti/biscuit/audio/queue/AudioQueue.java index a21be4d..184254b 100644 --- a/src/main/java/com/fpghoti/biscuit/audio/queue/AudioQueue.java +++ b/src/main/java/com/fpghoti/biscuit/audio/queue/AudioQueue.java @@ -2,6 +2,7 @@ package com.fpghoti.biscuit.audio.queue; import java.util.ArrayList; +import com.fpghoti.biscuit.rest.MessageText; import com.sedmelluq.discord.lavaplayer.track.AudioTrack; import net.dv8tion.jda.api.entities.MessageEmbed; @@ -103,7 +104,7 @@ public class AudioQueue { if(track.getCommandChannel() != null) { TextChannel c = track.getCommandChannel(); MessageEmbed m = track.getEmbedMessage("Queued:"); - c.sendMessage(m).queue(); + MessageText.send(c, m); } } diff --git a/src/main/java/com/fpghoti/biscuit/biscuit/Biscuit.java b/src/main/java/com/fpghoti/biscuit/biscuit/Biscuit.java index 51bdf73..a230c32 100644 --- a/src/main/java/com/fpghoti/biscuit/biscuit/Biscuit.java +++ b/src/main/java/com/fpghoti/biscuit/biscuit/Biscuit.java @@ -10,17 +10,17 @@ import java.util.concurrent.CopyOnWriteArrayList; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.PluginCore; import com.fpghoti.biscuit.audio.AudioScheduler; -import com.fpghoti.biscuit.captcha.BCage; import com.fpghoti.biscuit.config.BiscuitConfig; import com.fpghoti.biscuit.config.BiscuitProperties; import com.fpghoti.biscuit.logging.BColor; import com.fpghoti.biscuit.logging.BiscuitLog; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.timer.BiscuitTimer; import com.fpghoti.biscuit.timer.task.ChatCountTimer; import com.fpghoti.biscuit.timer.task.DecrementTimer; import com.fpghoti.biscuit.timer.task.SoftMuteTimer; +import com.fpghoti.biscuit.user.CaptchaUser; import com.fpghoti.biscuit.user.PreUser; -import com.github.cage.Cage; import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; import net.dv8tion.jda.api.JDA; @@ -81,7 +81,7 @@ public class Biscuit { private Timer timer; private List timers; private File captchaDir; - private Cage cage; + //private Cage cage; private Guild guild; private HashMap inviteUses; private BiscuitConfig config; @@ -104,10 +104,10 @@ public class Biscuit { this.properties = new BiscuitProperties(this); this.rolequeue = new HashMap(); this.player = Main.getPlayerManager().createPlayer(); - + scheduler = new AudioScheduler(this); player.addListener(scheduler); - + timer = new Timer(); timers = new ArrayList(); if(!Main.isPlugin) { @@ -117,7 +117,6 @@ public class Biscuit { captchaDir = new File(PluginCore.plugin.getDataFolder(), "captcha"); captchaDir.mkdir(); } - cage = new BCage(); if(isMain) { wipeCaptchaDir(); } @@ -155,11 +154,11 @@ public class Biscuit { public AudioPlayer getAudioPlayer() { return player; } - + public AudioScheduler getAudioScheduler() { return scheduler; } - + public void log(String message) { if(properties == null) { logger.info(message); @@ -189,7 +188,7 @@ public class Biscuit { } public void say(TextChannel channel, String message) { - channel.sendMessage(message).queue(); + MessageText.send(channel, message); } public void loadTimers() { @@ -225,10 +224,6 @@ public class Biscuit { } } - public Cage getCage() { - return this.cage; - } - public ArrayList getCaptchaLogChannels() { ArrayList ch = new ArrayList(); for(TextChannel t : guild.getTextChannels()) { @@ -242,11 +237,29 @@ public class Biscuit { public void captchaLog(String msg) { if(properties.logCaptcha()) { for(TextChannel t : getCaptchaLogChannels()) { - t.sendMessage(msg).queue(); + MessageText.send(t, msg); } } } + public Role getDefaultRole() { + for(Role r : guild.getRoles()) { + if(r.getName().toLowerCase().contains(properties.getDefaultRole().toLowerCase())) { + return r; + } + } + return null; + } + + public Role getCaptchaRewardRole() { + for(Role r : guild.getRoles()) { + if(r.getName().toLowerCase().contains(properties.getCaptchaReward().toLowerCase())) { + return r; + } + } + return null; + } + private void loadPreUsers() { if(!properties.captchaEnabled()) { return; @@ -258,7 +271,7 @@ public class Biscuit { for(Role role : m.getRoles()){ if(role.getName().equalsIgnoreCase(properties.getDefaultRole())){ log(BColor.MAGENTA_BOLD + "Adding pre-join check for user " + u.getName() + " (" + u.getAsMention() + ")..."); - users.add(new PreUser(u,this)); + users.add(PreUser.getPreUser(CaptchaUser.getCaptchaUser(u), this)); } } } @@ -288,11 +301,21 @@ public class Biscuit { } public void addPreUser(PreUser user) { - users.add(user); + if(!users.contains(user)) { + users.add(user); + }else { + error("CAPTCHA ERROR: Tried to add PreUser when one already exists"); + } } public void removePreUser(PreUser user) { - users.remove(user); + ArrayList temp = new ArrayList(users); + for(PreUser u : temp) { + if(u.getUser().getId().equals(user.getUser().getId())) { + user.setDone(); + users.remove(u); + } + } } public CopyOnWriteArrayList getPreUsers(){ @@ -332,7 +355,7 @@ public class Biscuit { return dir; } } - + public HashMap getRoleQueue() { return rolequeue; } diff --git a/src/main/java/com/fpghoti/biscuit/captcha/Captcha.java b/src/main/java/com/fpghoti/biscuit/captcha/Captcha.java new file mode 100644 index 0000000..1dfc0c1 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/captcha/Captcha.java @@ -0,0 +1,239 @@ +package com.fpghoti.biscuit.captcha; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +import com.fpghoti.biscuit.Main; +import com.fpghoti.biscuit.PluginCore; +import com.fpghoti.biscuit.biscuit.Biscuit; +import com.fpghoti.biscuit.logging.BColor; +import com.fpghoti.biscuit.rest.MessageText; +import com.fpghoti.biscuit.user.CaptchaUser; +import com.fpghoti.biscuit.user.PreUser; +import com.github.cage.Cage; + +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.PrivateChannel; +import net.dv8tion.jda.api.entities.Role; +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent; + +public class Captcha { + + public static Captcha getUpdatedCaptcha(PrivateMessageReceivedEvent event) { + CaptchaUser c = CaptchaUser.getCaptchaUser(event.getAuthor()); + if(c.getCaptcha() == null) { + Captcha captcha = new Captcha(event); + c.setCaptcha(captcha); + return captcha; + }else { + Captcha captcha = c.getCaptcha(); + captcha.setEvent(event); + c.setCaptcha(captcha); + return captcha; + } + } + + private CaptchaUser user; + private PrivateMessageReceivedEvent event; + private PrivateChannel channel; + private User author; + private String token; + + private Captcha(PrivateMessageReceivedEvent event) { + this.user = CaptchaUser.getCaptchaUser(event.getAuthor()); + this.event = event; + this.channel = event.getChannel(); + this.author = event.getAuthor(); + this.token = null; + } + + public void setEvent(PrivateMessageReceivedEvent event) { + this.event = event; + } + + public User getAuthor() { + return author; + } + + public CaptchaUser getCaptchaUser() { + return user; + } + + public PrivateChannel getChannel() { + return channel; + } + + public String getToken() { + return this.token; + } + + public void genToken() { + Cage cage = Main.getCage(); + token = cage.getTokenGenerator().next(); + } + + public void handleResponse() { + if(user.isEmpty() && !user.inTestMode()) { + return; + } + + String response = leeway(event.getMessage().getContentDisplay()); + + if(token != null && !response.equalsIgnoreCase(token)) { + respond("Sorry! That's not quite right! Please try again."); + return; + } + + if(token == null) { + + log("Generating captcha challenge for user " + author.getName() + " " + author.getAsMention() + "..."); + + genToken(); + generateImage(); + File captcha = getImageFile(); + + respond("Respond with the exact text in this image."); + channel.sendFile(captcha).submit(); + + }else { + boolean disable = false; + if(user.inTestMode()) { + disable = true; + }else { + doCaptchaReward(); + } + respond("Well done, " + author.getAsMention() + "!"); + if(disable) { + user.disableTestMode(); + } + } + } + + public void generateImage() { + Cage cage = Main.getCage(); + OutputStream os; + + try { + if(!Main.isPlugin) { + //If Biscuit is running standalone output to this directory + os = new FileOutputStream("captcha/" + author.getId() + ".jpg", false); + }else { + //If Biscuit is running as a Spigot plugin output to this directory + File c = new File(PluginCore.plugin.getDataFolder(), "captcha/" + author.getId() + ".jpg"); + os = new FileOutputStream(c, false); + } + } catch (FileNotFoundException e) { + Main.getMainBiscuit().error("Cannot retrieve captcha image directory."); + e.printStackTrace(); + return; + } + + //Draw captcha image + try { + cage.draw(token, os); + } catch (IOException e) { + e.printStackTrace(); + return; + } finally { + try { + os.close(); + } catch (IOException e) { + e.printStackTrace(); + return; + } + } + } + + public File getImageFile() { + if(!Main.isPlugin) { + return new File("captcha/" + author.getId() + ".jpg"); + }else { + return new File(PluginCore.plugin.getDataFolder(), "captcha/" + author.getId() + ".jpg"); + } + } + + public void doCaptchaReward() { + for(PreUser p : user) { + //mark the PreUser as "done" + p.setDone(); + + Biscuit biscuit = p.getBiscuit(); + + if(biscuit == null) { + Main.getMainBiscuit().error("CAPTCHA ERROR: Null Biscuit"); + return; + } + + Guild g = biscuit.getGuild(); + + if(g == null) { + biscuit.error("CAPTCHA ERROR: Null Guild"); + return; + } + + Role newrole = biscuit.getCaptchaRewardRole(); + Role defaultrole = biscuit.getDefaultRole(); + + if(newrole == null) { + biscuit.error("Cannot find captcha reward role!"); + return; + } + + if(defaultrole == null) { + biscuit.error("Cannot find captcha default role!"); + return; + } + + Member member = g.getMemberById(author.getId()); + + g.addRoleToMember(member, newrole).complete(); + g.removeRoleFromMember(member, defaultrole).complete(); + p.remove(); + token = null; + + log(BColor.YELLOW_BOLD + author.getName() + " successfully completed a captcha challenge. Granting role."); + biscuit.captchaLog(" ``" + author.getName() +"`` " + author.getAsMention() + " successfully completed a captcha challenge. Granting role."); + } + } + + public void removeFiles() { + File captcha; + if(!Main.isPlugin) { + //Biscuit is running standalone. Remove file from this directory + captcha = new File("captcha/" + user.getUser().getId() + ".jpg"); + }else { + //Biscuit is running as Spigot plugin. Remove file from this directory + captcha = new File(PluginCore.plugin.getDataFolder(), "captcha/" + user.getUser().getId() + ".jpg"); + } + captcha.delete(); + } + + //More characters may be replaced/removed here based on + //How many/what type of errors users commonly make + private String leeway(String s) { + s = s.replace("0", "O"); + return s; + } + + private void log(String msg) { + String prefix = ""; + if(user.inTestMode()) { + prefix = "[TEST] "; + } + Main.getMainBiscuit().log(prefix + msg); + } + + private void respond(String msg) { + String prefix = ""; + if(user.inTestMode()) { + prefix = "[TEST] "; + } + MessageText.send(channel, prefix + msg); + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/commands/CommandManager.java b/src/main/java/com/fpghoti/biscuit/commands/CommandManager.java index d060bf5..9187d52 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/CommandManager.java +++ b/src/main/java/com/fpghoti/biscuit/commands/CommandManager.java @@ -9,6 +9,7 @@ import com.fpghoti.biscuit.commands.base.ClientCommand; import com.fpghoti.biscuit.commands.base.ConsoleCommand; import com.fpghoti.biscuit.commands.base.CustomCommand; import com.fpghoti.biscuit.commands.base.MusicClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.PermUtil; import com.fpghoti.biscuit.util.Util; @@ -119,7 +120,7 @@ public class CommandManager { public static void commandReply(GuildMessageReceivedEvent event, String msg) { if(event != null) { - event.getChannel().sendMessage(msg).queue(); + MessageText.send(event.getChannel(), msg); }else { Main.getLogger().info(msg); } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/AddCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/AddCommand.java index 115a74c..6d1510f 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/AddCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/AddCommand.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.ClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.Util; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; @@ -30,7 +31,7 @@ public class AddCommand extends ClientCommand{ if(end.equals(".0")) { sum = sum.replace(".0",""); } - event.getChannel().sendMessage(args[0] + " + " + args[1] + " is **" + sum + "**.").queue(); + MessageText.send(event.getChannel(), args[0] + " + " + args[1] + " is **" + sum + "**."); } } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/ChanIDCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/ChanIDCommand.java index a2896e5..0c501c2 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/ChanIDCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/ChanIDCommand.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.ClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; @@ -22,7 +23,7 @@ public class ChanIDCommand extends ClientCommand{ Biscuit b = Biscuit.getBiscuit(event.getGuild()); b.log(event.getAuthor().getName() + " issued a command: -chanid"); String id = event.getChannel().getId(); - event.getChannel().sendMessage(id).queue(); + MessageText.send(event.getChannel(), id); } } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/DivideCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/DivideCommand.java index bf05d25..ee21a19 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/DivideCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/DivideCommand.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.ClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.Util; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; @@ -31,7 +32,7 @@ public class DivideCommand extends ClientCommand{ if(end.equals(".0")) { divide = divide.replace(".0",""); } - event.getChannel().sendMessage(args[0] + " / " + args[1] + " is **" + divide + "**.").queue(); + MessageText.send(event.getChannel(), args[0] + " / " + args[1] + " is **" + divide + "**."); } } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/ForceSkipCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/ForceSkipCommand.java index 6be530d..be7b047 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/ForceSkipCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/ForceSkipCommand.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.MusicClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.PermUtil; import net.dv8tion.jda.api.entities.MessageEmbed; @@ -24,10 +25,10 @@ public class ForceSkipCommand extends MusicClientCommand{ Biscuit b = Biscuit.getBiscuit(event.getGuild()); b.log(event.getAuthor().getName() + " issued a command: -forceskip"); if(PermUtil.isMod(event.getMember())) { - event.getChannel().sendMessage("Force skipping current song.").queue(); + MessageText.send(event.getChannel(), "Force skipping current song."); if(b.getAudioScheduler().getQueue().getNext() != null ) { MessageEmbed next = b.getAudioScheduler().getQueue().getNext().getEmbedMessage("Now Playing:"); - event.getChannel().sendMessage(next).queue(); + MessageText.send(event.getChannel(), next); } b.getAudioScheduler().skip(); } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/GetConfigCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/GetConfigCommand.java index 8fefa22..0ceb6e4 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/GetConfigCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/GetConfigCommand.java @@ -1,15 +1,12 @@ package com.fpghoti.biscuit.commands.client; -import java.util.concurrent.TimeUnit; -import java.util.function.Consumer; - import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.ClientCommand; import com.fpghoti.biscuit.logging.BColor; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.PermUtil; -import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; public class GetConfigCommand extends ClientCommand{ @@ -31,14 +28,8 @@ public class GetConfigCommand extends ClientCommand{ event.getChannel().sendFile(b.getConfig().getFile(), "config-" + b.getProperties().getGuildCode() + ".properties").queue(); }else { b.log(BColor.MAGENTA_BOLD + event.getAuthor().getName() + " lacks permission to view the config!"); - event.getChannel().sendMessage(event.getAuthor().getAsMention() + " You do not have " - + "permission to view the config.").queue(new Consumer() - { - @Override - public void accept(Message msg){ - msg.delete().submitAfter(5, TimeUnit.SECONDS); - } - }); + MessageText.sendTimed(event.getChannel(), event.getAuthor().getAsMention() + " You do not have " + + "permission to view the config.", 5); } } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/GuildIDCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/GuildIDCommand.java index 082860f..d038014 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/GuildIDCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/GuildIDCommand.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.ClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.PermUtil; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; @@ -24,7 +25,7 @@ public class GuildIDCommand extends ClientCommand{ Biscuit b = Biscuit.getBiscuit(event.getGuild()); b.log(event.getAuthor().getName() + " issued a command: -guildid"); if(PermUtil.isMod(event.getMember())) { - event.getChannel().sendMessage(event.getGuild().getId()).queue(); + MessageText.send(event.getChannel(), event.getGuild().getId()); } } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/HelpCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/HelpCommand.java index af44956..1a68576 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/HelpCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/HelpCommand.java @@ -10,6 +10,7 @@ import com.fpghoti.biscuit.commands.CommandManager; import com.fpghoti.biscuit.commands.base.ClientCommand; import com.fpghoti.biscuit.commands.base.CustomCommand; import com.fpghoti.biscuit.commands.base.MusicClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.Util; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; @@ -35,7 +36,7 @@ public class HelpCommand extends ClientCommand { if(Util.isDigit(args[0])) { pg = Integer.parseInt(args[0]); }else { - event.getChannel().sendMessage("Usage: ``" + usage + "``").queue(); + MessageText.send(event.getChannel(), "Usage: ``" + usage + "``"); } } List commands = new ArrayList(); @@ -72,8 +73,8 @@ public class HelpCommand extends ClientCommand { pg = pageCount; } - event.getChannel().sendMessage("**Use " + Main.getMainBiscuit().getProperties().getCommandSignifier() + "help [Page #] to navigate the different pages.**").queue(); - event.getChannel().sendMessage("[" + Integer.toString(pg) + "/" + Integer.toString(pageCount) + "] **Bot Commands:**").queue(); + MessageText.send(event.getChannel(), "**Use " + Main.getMainBiscuit().getProperties().getCommandSignifier() + "help [Page #] to navigate the different pages.**"); + MessageText.send(event.getChannel(), "[" + Integer.toString(pg) + "/" + Integer.toString(pageCount) + "] **Bot Commands:**"); String msg = ""; for (int i = 0; i < 8; i++) { int index = (pg - 1) * 8 + i; @@ -88,8 +89,7 @@ public class HelpCommand extends ClientCommand { msg = msg + line; } } - event.getChannel().sendMessage(msg).queue(); - + MessageText.send(event.getChannel(), msg); } } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/LoopMusicCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/LoopMusicCommand.java index 92cdb9a..e929433 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/LoopMusicCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/LoopMusicCommand.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.MusicClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.PermUtil; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; @@ -24,10 +25,10 @@ public class LoopMusicCommand extends MusicClientCommand{ b.log(event.getAuthor().getName() + " issued a command: -loopmusic"); if(PermUtil.isMod(event.getMember())) { if(!b.getAudioScheduler().isLooping()) { - event.getChannel().sendMessage("Setting all music to loop.").queue(); + MessageText.send(event.getChannel(), "Setting all music to loop."); b.getAudioScheduler().setLooping(true); }else { - event.getChannel().sendMessage("Disabling music looping.").queue(); + MessageText.send(event.getChannel(), "Disabling music looping."); b.getAudioScheduler().setLooping(false); } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/MakeInviteCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/MakeInviteCommand.java index 6c037a8..486f2f7 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/MakeInviteCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/MakeInviteCommand.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.ClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.PermUtil; import com.fpghoti.biscuit.util.Util; @@ -39,7 +40,7 @@ public class MakeInviteCommand extends ClientCommand{ } } if(doubAge > 86400) { - event.getChannel().sendMessage("That length is longer than what Discord allows. Please try again. (Max 24 hours)").queue(); + MessageText.send(event.getChannel(), "That length is longer than what Discord allows. Please try again. (Max 24 hours)"); return; } final double db = doubAge; @@ -49,7 +50,7 @@ public class MakeInviteCommand extends ClientCommand{ if(db > 0) { exp = args[1] + " hour(s)"; } - event.getChannel().sendMessage("Created invite **" + i.getCode() + "** Expiration: **" + exp + "**.").queue(); + MessageText.send(event.getChannel(), "Created invite **" + i.getCode() + "** Expiration: **" + exp + "**."); }); } } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/MultiplyCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/MultiplyCommand.java index 04e87af..cbbebbc 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/MultiplyCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/MultiplyCommand.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.ClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.Util; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; @@ -31,7 +32,7 @@ public class MultiplyCommand extends ClientCommand{ if(end.equals(".0")) { prod = prod.replace(".0",""); } - event.getChannel().sendMessage(args[0] + " x " + args[1] + " is **" + prod + "**.").queue(); + MessageText.send(event.getChannel(), args[0] + " x " + args[1] + " is **" + prod + "**."); } } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/NotSpammerCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/NotSpammerCommand.java index 2d9a1e6..64892ad 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/NotSpammerCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/NotSpammerCommand.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.ClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.PermUtil; import net.dv8tion.jda.api.entities.Member; @@ -29,7 +30,7 @@ public class NotSpammerCommand extends ClientCommand{ String s = u.getAsMention(); if(event.getChannel().getName().equals("public-spam-test") || (PermUtil.isMod(event.getMember()))) { b.getMessageStore().removeSpammer(u); - event.getChannel().sendMessage(s+ " is no longer flagged as spam.").queue(); + MessageText.send(event.getChannel(), s + " is no longer flagged as spam."); } } } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/NowPlayingCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/NowPlayingCommand.java index 3b768a8..cf39c1b 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/NowPlayingCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/NowPlayingCommand.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.MusicClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; @@ -24,9 +25,9 @@ public class NowPlayingCommand extends MusicClientCommand{ b.log(event.getAuthor().getName() + " issued a command: -nowplaying"); if(b.getAudioScheduler().getQueue().getLastTrack() != null ) { MessageEmbed next = b.getAudioScheduler().getQueue().getLastTrack().getEmbedMessage("Now Playing:", true); - event.getChannel().sendMessage(next).queue(); + MessageText.send(event.getChannel(), next); }else { - event.getChannel().sendMessage("No song is currently playing.").queue(); + MessageText.send(event.getChannel(), "No song is currently playing."); } } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/PauseCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/PauseCommand.java index 0e73dd3..596b595 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/PauseCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/PauseCommand.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.MusicClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.PermUtil; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; @@ -25,9 +26,9 @@ public class PauseCommand extends MusicClientCommand{ if(PermUtil.isMod(event.getMember())) { if(!b.getAudioPlayer().isPaused()) { b.getAudioPlayer().setPaused(true); - event.getChannel().sendMessage("Paused the current track.").queue(); + MessageText.send(event.getChannel(), "Paused the current track."); }else { - event.getChannel().sendMessage("The music player is already paused.").queue(); + MessageText.send(event.getChannel(), "The music player is already paused."); } } } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/PingCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/PingCommand.java index 0c008e9..fa81f86 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/PingCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/PingCommand.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.ClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; @@ -21,7 +22,7 @@ public class PingCommand extends ClientCommand{ public void execute(String[] args, GuildMessageReceivedEvent event) { Biscuit b = Biscuit.getBiscuit(event.getGuild()); b.log(event.getAuthor().getName() + " issued a command: -ping"); - event.getChannel().sendMessage("Pong!").queue(); + MessageText.send(event.getChannel(), "Pong!"); } } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/PlayCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/PlayCommand.java index 2dad924..ae1a162 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/PlayCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/PlayCommand.java @@ -5,6 +5,7 @@ import com.fpghoti.biscuit.audio.AudioHandler; import com.fpghoti.biscuit.audio.AudioResultHandler; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.MusicClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager; import net.dv8tion.jda.api.entities.Guild; @@ -41,7 +42,7 @@ public class PlayCommand extends MusicClientCommand{ String vcname = ""; if(!event.getMember().getVoiceState().inVoiceChannel()) { - tchannel.sendMessage("You must be in a voice channel to do this!").queue(); + MessageText.send(tchannel, "You must be in a voice channel to do this!"); return; } vcname = event.getMember().getVoiceState().getChannel().getName(); @@ -55,14 +56,14 @@ public class PlayCommand extends MusicClientCommand{ } } if(found == false) { - tchannel.sendMessage("You are not in a channel that is authorized to use the music player.").queue(); + MessageText.send(tchannel, "You are not in a channel that is authorized to use the music player."); return; } } if(b.getAudioPlayer().getPlayingTrack() != null && guild.getAudioManager().isConnected() && !guild.getAudioManager().getConnectedChannel().getMembers().contains(event.getMember())) { - tchannel.sendMessage("Music is already playing in a voice channel. Connect to " - + "that channel, then queue your song.").queue(); + MessageText.send(tchannel, "Music is already playing in a voice channel. Connect to " + + "that channel, then queue your song."); return; } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/PlayFirstCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/PlayFirstCommand.java index 20eab6e..b361056 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/PlayFirstCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/PlayFirstCommand.java @@ -5,6 +5,7 @@ import com.fpghoti.biscuit.audio.AudioHandler; import com.fpghoti.biscuit.audio.AudioResultHandler; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.MusicClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.PermUtil; import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager; @@ -43,12 +44,12 @@ public class PlayFirstCommand extends MusicClientCommand{ String vcname = ""; if(!PermUtil.isMod(event.getMember())) { - tchannel.sendMessage("You do not have permission to do this!").queue(); + MessageText.send(tchannel, "You do not have permission to do this!"); return; } if(!event.getMember().getVoiceState().inVoiceChannel()) { - tchannel.sendMessage("You must be in a voice channel to do this!").queue(); + MessageText.send(tchannel, "You must be in a voice channel to do this!"); return; } vcname = event.getMember().getVoiceState().getChannel().getName(); @@ -62,14 +63,14 @@ public class PlayFirstCommand extends MusicClientCommand{ } } if(found == false) { - tchannel.sendMessage("You are not in a channel that is authorized to use the music player.").queue(); + MessageText.send(tchannel, "You are not in a channel that is authorized to use the music player."); return; } } if(b.getAudioPlayer().getPlayingTrack() != null && guild.getAudioManager().isConnected() && !guild.getAudioManager().getConnectedChannel().getMembers().contains(event.getMember())) { - tchannel.sendMessage("Music is already playing in a voice channel. Connect to " - + "that channel, then queue your song.").queue(); + MessageText.send(tchannel, "Music is already playing in a voice channel. Connect to " + + "that channel, then queue your song."); return; } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/PowerCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/PowerCommand.java index 167de84..21a9c10 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/PowerCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/PowerCommand.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.ClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.Util; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; @@ -31,7 +32,7 @@ public class PowerCommand extends ClientCommand{ if(end.equals(".0")) { pow = pow.replace(".0",""); } - event.getChannel().sendMessage(args[0] + "^" + args[1] + " is **" + pow + "**.").queue(); + MessageText.send(event.getChannel(), args[0] + "^" + args[1] + " is **" + pow + "**."); } } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/QueueCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/QueueCommand.java index e973025..d5a34e9 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/QueueCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/QueueCommand.java @@ -5,6 +5,7 @@ import com.fpghoti.biscuit.audio.queue.AudioQueue; import com.fpghoti.biscuit.audio.queue.QueuedTrack; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.MusicClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.Util; import com.sedmelluq.discord.lavaplayer.track.AudioTrack; @@ -32,7 +33,7 @@ public class QueueCommand extends MusicClientCommand{ if(Util.isDigit(args[0])) { pg = Integer.parseInt(args[0]); }else { - event.getChannel().sendMessage("Usage: ``" + usage + "``").queue(); + MessageText.send(event.getChannel(), "Usage: ``" + usage + "``"); } } @@ -45,15 +46,15 @@ public class QueueCommand extends MusicClientCommand{ if(queue.size() == 0) { if(biscuit.getAudioPlayer().getPlayingTrack() == null) { - event.getChannel().sendMessage("There is currently no song playing.").queue(); + MessageText.send(event.getChannel(), "There is currently no song playing."); }else { - event.getChannel().sendMessage("Nothing is queued to play after the current track.").queue(); + MessageText.send(event.getChannel(), "Nothing is queued to play after the current track."); } return; } - event.getChannel().sendMessage("**Use " + Main.getMainBiscuit().getProperties().getCommandSignifier() + "queue [Page #] to navigate the different pages.**").queue(); - event.getChannel().sendMessage("[" + Integer.toString(pg) + "/" + Integer.toString(pageCount) + "] ** Upcoming Music Tracks:**").queue(); + MessageText.send(event.getChannel(), "**Use " + Main.getMainBiscuit().getProperties().getCommandSignifier() + "queue [Page #] to navigate the different pages.**"); + MessageText.send(event.getChannel(), "[" + Integer.toString(pg) + "/" + Integer.toString(pageCount) + "] ** Upcoming Music Tracks:**"); String msg = ""; for (int i = 0; i < 8; i++) { int index = (pg - 1) * 8 + i; @@ -75,7 +76,7 @@ public class QueueCommand extends MusicClientCommand{ msg = msg + line; } } - event.getChannel().sendMessage(msg).queue(); + MessageText.send(event.getChannel(), msg); } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/RecentSpammersCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/RecentSpammersCommand.java index 0bbbbf3..ca6cdd2 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/RecentSpammersCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/RecentSpammersCommand.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.ClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; @@ -22,7 +23,7 @@ public class RecentSpammersCommand extends ClientCommand{ Biscuit b = Biscuit.getBiscuit(event.getGuild()); b.log(event.getAuthor().getName() + " issued a command: -recentspammers"); String msg = b.getMessageStore().getSpammerList(); - event.getChannel().sendMessage(msg).queue(); + MessageText.send(event.getChannel(), msg); } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/SaveConfigCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/SaveConfigCommand.java index 93a26b4..51b0955 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/SaveConfigCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/SaveConfigCommand.java @@ -1,16 +1,14 @@ package com.fpghoti.biscuit.commands.client; import java.util.List; -import java.util.concurrent.TimeUnit; -import java.util.function.Consumer; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.ClientCommand; import com.fpghoti.biscuit.logging.BColor; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.PermUtil; -import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.Message.Attachment; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; @@ -39,35 +37,17 @@ public class SaveConfigCommand extends ClientCommand{ b = Biscuit.loadGuild(event.getGuild()); } }else { - event.getChannel().sendMessage(event.getAuthor().getAsMention() + " Too many attachments added! " - + "Please only include the config file you want to save.").queue(new Consumer() - { - @Override - public void accept(Message msg){ - msg.delete().submitAfter(5, TimeUnit.SECONDS); - } - }); + MessageText.sendTimed(event.getChannel(), event.getAuthor().getAsMention() + " Too many attachments added! " + + "Please only include the config file you want to save.", 5); } }else { - event.getChannel().sendMessage(event.getAuthor().getAsMention() + " You need to send " - + "a file in order to save the config.").queue(new Consumer() - { - @Override - public void accept(Message msg){ - msg.delete().submitAfter(5, TimeUnit.SECONDS); - } - }); + MessageText.sendTimed(event.getChannel(), event.getAuthor().getAsMention() + " You need to send " + + "a file in order to save the config.", 5); } }else { b.log(BColor.MAGENTA_BOLD + event.getAuthor().getName() + " lacks permission to save the config!"); - event.getChannel().sendMessage(event.getAuthor().getAsMention() + " You do not have " - + "permission to save the config.").queue(new Consumer() - { - @Override - public void accept(Message msg){ - msg.delete().submitAfter(5, TimeUnit.SECONDS); - } - }); + MessageText.sendTimed(event.getChannel(), event.getAuthor().getAsMention() + " You do not have " + + "permission to save the config.", 5); } } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/SkipCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/SkipCommand.java index 04705f2..ec7c52f 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/SkipCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/SkipCommand.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.MusicClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; @@ -27,41 +28,41 @@ public class SkipCommand extends MusicClientCommand{ b.log(event.getAuthor().getName() + " issued a command: -skip"); if(b.getAudioPlayer().getPlayingTrack() == null) { - event.getChannel().sendMessage("There is not a song playing for you to skip!").queue(); + MessageText.send(event.getChannel(), "There is not a song playing for you to skip!"); return; } if(!event.getGuild().getAudioManager().getConnectedChannel().getMembers().contains(event.getMember())) { - event.getChannel().sendMessage("You need to be in the same voice channel in order to skip!").queue(); + MessageText.send(event.getChannel(), "You need to be in the same voice channel in order to skip!"); return; } if(b.getAudioScheduler().getVotes() >= (event.getGuild().getAudioManager().getConnectedChannel().getMembers().size() - 1) / 2) { - event.getChannel().sendMessage("Skip vote status: **[" + ( b.getAudioScheduler().getVotes() + 1) + "/" + MessageText.send(event.getChannel(), "Skip vote status: **[" + ( b.getAudioScheduler().getVotes() + 1) + "/" + (event.getGuild().getAudioManager().getConnectedChannel().getMembers().size() - 1) + "]**" - + "\nSkipping current track.").queue(); + + "\nSkipping current track."); if(b.getAudioScheduler().getQueue().getNext() != null ) { MessageEmbed next = b.getAudioScheduler().getQueue().getNext().getEmbedMessage("Now Playing:"); - event.getChannel().sendMessage(next).queue(); + MessageText.send(event.getChannel(), next); } b.getAudioScheduler().skip(); return; } if(b.getAudioScheduler().voteSkip(event.getAuthor().getId())) { - event.getChannel().sendMessage("You voted to skip the current track.").queue(); + MessageText.send(event.getChannel(), "You voted to skip the current track."); }else { - event.getChannel().sendMessage("You cannot vote to skip this track again." + MessageText.send(event.getChannel(), "You cannot vote to skip this track again." + "\nSkip vote status: **[" + b.getAudioScheduler().getVotes() + "/" - + (event.getGuild().getAudioManager().getConnectedChannel().getMembers().size() - 1) + "]**").queue(); + + (event.getGuild().getAudioManager().getConnectedChannel().getMembers().size() - 1) + "]**"); } if(b.getAudioScheduler().getVotes() >= (event.getGuild().getAudioManager().getConnectedChannel().getMembers().size() - 1) / 2) { - event.getChannel().sendMessage("Skip vote status: **[" + b.getAudioScheduler().getVotes() + "/" + MessageText.send(event.getChannel(), "Skip vote status: **[" + b.getAudioScheduler().getVotes() + "/" + event.getGuild().getAudioManager().getConnectedChannel().getMembers().size() + "]**" - + "\nSkipping current track.").queue(); + + "\nSkipping current track."); if(b.getAudioScheduler().getQueue().getNext() != null ) { MessageEmbed next = b.getAudioScheduler().getQueue().getNext().getEmbedMessage("Now Playing:"); - event.getChannel().sendMessage(next).queue(); + MessageText.send(event.getChannel(), next); } b.getAudioScheduler().skip(); } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/SoftMuteCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/SoftMuteCommand.java index ccd7b04..1711d63 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/SoftMuteCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/SoftMuteCommand.java @@ -1,15 +1,12 @@ package com.fpghoti.biscuit.commands.client; -import java.util.concurrent.TimeUnit; -import java.util.function.Consumer; - import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.ClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.PermUtil; import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; @@ -32,19 +29,13 @@ public class SoftMuteCommand extends ClientCommand{ User u = m.getUser(); String s = u.getAsMention(); if(b.getMessageStore().isSoftmuted(u)) { - event.getChannel().sendMessage(s+ " is already softmuted.").queue(new Consumer() - { - @Override - public void accept(Message msg){ - msg.delete().reason("Automatic bot message removal").submitAfter(3, TimeUnit.SECONDS); - } - }); + MessageText.sendTimed(event.getChannel(), s + " is already softmuted.", 3); return; } if(event.getChannel().getName().equals("public-softmute-test") || (PermUtil.isMod(event.getMember()))) { b.getMessageStore().addSoftmuted(u); u.openPrivateChannel().queue(); - event.getChannel().sendMessage(s+ " is now soft-muted. They will now be only able to send one message every two minutes.").queue(); + MessageText.send(event.getChannel(), s + " is now soft-muted. They will now be only able to send one message every two minutes."); } } } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/SquareRootCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/SquareRootCommand.java index 8c193af..d509942 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/SquareRootCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/SquareRootCommand.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.ClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.Util; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; @@ -30,7 +31,7 @@ public class SquareRootCommand extends ClientCommand{ if(end.equals(".0")) { root = root.replace(".0",""); } - event.getChannel().sendMessage("The sqaure root of " + args[0] + " is **" + root + "**.").queue(); + MessageText.send(event.getChannel(), "The sqaure root of " + args[0] + " is **" + root + "**."); } } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/SubtractCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/SubtractCommand.java index aaa51d2..6e04b6d 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/SubtractCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/SubtractCommand.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.ClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.Util; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; @@ -31,7 +32,7 @@ public class SubtractCommand extends ClientCommand{ if(end.equals(".0")) { sub = sub.replace(".0",""); } - event.getChannel().sendMessage(args[0] + " - " + args[1] + " is **" + sub + "**.").queue(); + MessageText.send(event.getChannel(), args[0] + " - " + args[1] + " is **" + sub + "**."); } } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/TogglePauseCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/TogglePauseCommand.java index f8ef395..a366a8d 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/TogglePauseCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/TogglePauseCommand.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.MusicClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.PermUtil; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; @@ -26,10 +27,10 @@ public class TogglePauseCommand extends MusicClientCommand{ if(PermUtil.isMod(event.getMember())) { if(b.getAudioPlayer().isPaused()) { b.getAudioPlayer().setPaused(false); - event.getChannel().sendMessage("Unpaused the current track.").queue(); + MessageText.send(event.getChannel(), "Unpaused the current track."); }else { b.getAudioPlayer().setPaused(true); - event.getChannel().sendMessage("Paused the current track.").queue(); + MessageText.send(event.getChannel(), "Paused the current track."); } } } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/ToggleRoleCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/ToggleRoleCommand.java index 16027f4..5eb8b37 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/ToggleRoleCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/ToggleRoleCommand.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.ClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.PermUtil; import net.dv8tion.jda.api.entities.Emote; @@ -37,7 +38,7 @@ public class ToggleRoleCommand extends ClientCommand{ } if(rolename.equals("")) { - event.getChannel().sendMessage("Sorry! This role either cannot be toggled or does not exist!").queue(); + MessageText.send(event.getChannel(), "Sorry! This role either cannot be toggled or does not exist!"); return; } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/UIDCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/UIDCommand.java index 9844baf..5b2c9ae 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/UIDCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/UIDCommand.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.ClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.PermUtil; import net.dv8tion.jda.api.entities.Member; @@ -27,7 +28,7 @@ public class UIDCommand extends ClientCommand{ for(Member m : event.getMessage().getMentionedMembers()){ User u = m.getUser(); if(PermUtil.isMod(event.getMember())) { - event.getChannel().sendMessage(u.getId()).queue(); + MessageText.send(event.getChannel(), u.getId()); } } } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/UnSoftMuteCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/UnSoftMuteCommand.java index bc1e8dc..2af0121 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/UnSoftMuteCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/UnSoftMuteCommand.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.ClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.PermUtil; import net.dv8tion.jda.api.entities.Member; @@ -29,7 +30,7 @@ public class UnSoftMuteCommand extends ClientCommand{ String s = u.getAsMention(); if(event.getChannel().getName().equals("public-softmute-test") || (PermUtil.isMod(event.getMember()))) { b.getMessageStore().removeSoftmuted(u); - event.getChannel().sendMessage(s+ " is no longer soft-muted.").queue(); + MessageText.send(event.getChannel(), s + " is no longer soft-muted."); } } } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/UnpauseCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/UnpauseCommand.java index 8bf8a53..d066a16 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/UnpauseCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/UnpauseCommand.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.ClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.PermUtil; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; @@ -25,9 +26,9 @@ public class UnpauseCommand extends ClientCommand{ if(PermUtil.isMod(event.getMember())) { if(b.getAudioPlayer().isPaused()) { b.getAudioPlayer().setPaused(false); - event.getChannel().sendMessage("Unpaused the current track.").queue(); + MessageText.send(event.getChannel(), "Unpaused the current track."); }else { - event.getChannel().sendMessage("The music player is not paused.").queue(); + MessageText.send(event.getChannel(), "The music player is not paused."); } } } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/WikiCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/WikiCommand.java index 9489968..c673a8e 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/WikiCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/WikiCommand.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.ClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.PermUtil; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; @@ -23,7 +24,7 @@ public class WikiCommand extends ClientCommand{ Biscuit b = Biscuit.getBiscuit(event.getGuild()); b.log(event.getAuthor().getName() + " issued a command: -wiki"); if(PermUtil.isMod(event.getMember())) { - event.getChannel().sendMessage("https://git.fpghoti.com/thmsdy/Biscuit/wiki").queue(); + MessageText.send(event.getChannel(), "https://git.fpghoti.com/thmsdy/Biscuit/wiki"); } } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/WipeQueueCommand.java b/src/main/java/com/fpghoti/biscuit/commands/client/WipeQueueCommand.java index b84b079..50c19b7 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/WipeQueueCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/client/WipeQueueCommand.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.commands.client; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.MusicClientCommand; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.PermUtil; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; @@ -25,7 +26,7 @@ public class WipeQueueCommand extends MusicClientCommand{ b.log(event.getAuthor().getName() + " issued a command: -wipequeue"); if(PermUtil.isMod(event.getMember())) { b.getAudioScheduler().wipeQueue(); - event.getChannel().sendMessage("Removed upcoming songs from the music queue.").queue(); + MessageText.send(event.getChannel(), "Removed upcoming songs from the music queue."); } } diff --git a/src/main/java/com/fpghoti/biscuit/commands/console/GuildSayCommand.java b/src/main/java/com/fpghoti/biscuit/commands/console/GuildSayCommand.java index f818a28..37e4ea0 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/console/GuildSayCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/console/GuildSayCommand.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.commands.console; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.ConsoleCommand; +import com.fpghoti.biscuit.rest.MessageText; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.TextChannel; @@ -41,7 +42,7 @@ public class GuildSayCommand extends ConsoleCommand{ for(TextChannel c : guild.getTextChannels()) { if(c.getName().equalsIgnoreCase(channel) || c.getName().equalsIgnoreCase("#" + channel)) { - c.sendMessage(message).queue(); + MessageText.send(c, message); } } diff --git a/src/main/java/com/fpghoti/biscuit/commands/console/SayCommand.java b/src/main/java/com/fpghoti/biscuit/commands/console/SayCommand.java index c825b5e..b73b7a9 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/console/SayCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/console/SayCommand.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.commands.console; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.ConsoleCommand; +import com.fpghoti.biscuit.rest.MessageText; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.TextChannel; @@ -37,7 +38,7 @@ public class SayCommand extends ConsoleCommand{ for(TextChannel c : guild.getTextChannels()) { if(c.getName().equalsIgnoreCase(target) || c.getName().equalsIgnoreCase("#" + target)) { - c.sendMessage(message).queue(); + MessageText.send(c, message); } } diff --git a/src/main/java/com/fpghoti/biscuit/config/BiscuitConfig.java b/src/main/java/com/fpghoti/biscuit/config/BiscuitConfig.java index d84cf90..acd6b50 100644 --- a/src/main/java/com/fpghoti/biscuit/config/BiscuitConfig.java +++ b/src/main/java/com/fpghoti/biscuit/config/BiscuitConfig.java @@ -15,6 +15,7 @@ import org.apache.commons.configuration2.PropertiesConfigurationLayout; import org.apache.commons.configuration2.ex.ConfigurationException; import com.fpghoti.biscuit.biscuit.Biscuit; +import com.fpghoti.biscuit.rest.MessageText; import com.jcabi.aspects.Async; import net.dv8tion.jda.api.entities.Guild; @@ -69,16 +70,16 @@ public class BiscuitConfig { } String name = guild.getId() + ".properties"; if(a.getSize() > 51200) { - c.sendMessage("**The file is too big!**").queue(); + MessageText.send(c, "**The file is too big!**"); return; } File config = new File(biscuit.getConfigDir(), name); a.downloadToFile(config).thenAccept(file -> { updateConfig(file, true, code); - c.sendMessage("**The config was successfully updated.**").queue(); + MessageText.send(c, "**The config was successfully updated.**"); }).exceptionally(t -> { biscuit.error("Could not accept config file."); - c.sendMessage("**An Exception occurred while trying to read the file.**").queue(); + MessageText.send(c, "**An Exception occurred while trying to read the file.**"); return null; }); diff --git a/src/main/java/com/fpghoti/biscuit/listener/DMListener.java b/src/main/java/com/fpghoti/biscuit/listener/DMListener.java index bc02cbe..474e881 100644 --- a/src/main/java/com/fpghoti/biscuit/listener/DMListener.java +++ b/src/main/java/com/fpghoti/biscuit/listener/DMListener.java @@ -1,196 +1,48 @@ package com.fpghoti.biscuit.listener; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.ArrayList; - import com.fpghoti.biscuit.Main; -import com.fpghoti.biscuit.PluginCore; -import com.fpghoti.biscuit.biscuit.Biscuit; +import com.fpghoti.biscuit.captcha.Captcha; import com.fpghoti.biscuit.logging.BColor; -import com.fpghoti.biscuit.user.PreUser; +import com.fpghoti.biscuit.user.CaptchaUser; import com.fpghoti.biscuit.util.PermUtil; -import com.github.cage.Cage; import net.dv8tion.jda.api.JDA; -import net.dv8tion.jda.api.entities.ChannelType; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.PrivateChannel; -import net.dv8tion.jda.api.entities.Role; -import net.dv8tion.jda.api.entities.User; -import net.dv8tion.jda.api.events.message.MessageReceivedEvent; +import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; public class DMListener extends ListenerAdapter{ - private static ArrayList testers = new ArrayList(); - @Override - public void onMessageReceived(MessageReceivedEvent event){ - //Biscuit biscuit = Biscuit.getBiscuit(event.getGuild()); - if (event.isFromType(ChannelType.PRIVATE) && !event.getAuthor().isBot()) { - String content = event.getMessage().getContentDisplay(); - User user = event.getAuthor(); - boolean isTest = false; - boolean found = false; - if(testers.size() > 0) { - for(User u : testers) { - if(user.getId().equals(u.getId())) { - isTest = true; - found = true; - } - } - } - if(content.equalsIgnoreCase("captcha pls") || content.equalsIgnoreCase("cpls")) { - JDA jda = Main.getJDA(); - for(Guild g : jda.getGuilds()) { - if(g.isMember(user)) { - Member m = g.getMember(user); - if(PermUtil.isAdmin(m)) { - isTest = true; - if(!found && !PreUser.hasTestUser(event.getAuthor())) { - PreUser.testusers.add(new PreUser(user, Main.getMainBiscuit(), true)); - testers.add(user); - } - } - } - } - } + public void onPrivateMessageReceived(PrivateMessageReceivedEvent event){ + if (!event.getAuthor().isBot()) { + + //Log DM content to console if(Main.getMainBiscuit().getProperties().logChat()) { Main.getMainBiscuit().log("[" + BColor.CYAN_BOLD + "DM" + BColor.RESET + "] " + BColor.YELLOW + "ID: " + BColor.RESET + event.getMessageId() + BColor.YELLOW + " Sender: " + BColor.RESET + event.getAuthor().getAsMention()); Main.getMainBiscuit().log(BColor.YELLOW + event.getAuthor().getName() + ": " + BColor.WHITE_BOLD + event.getMessage().getContentDisplay()); } - handleCaptcha(event, isTest); + + String content = event.getMessage().getContentDisplay(); + Captcha captcha = Captcha.getUpdatedCaptcha(event); + CaptchaUser capUser = captcha.getCaptchaUser(); + + //User is requesting a captcha test + if(content.equalsIgnoreCase("captcha pls") || content.equalsIgnoreCase("cpls")) { + JDA jda = Main.getJDA(); + for(Guild g : jda.getGuilds()) { + if(g.isMember(capUser.getUser())) { + Member m = g.getMember(capUser.getUser()); + if(PermUtil.isAdmin(m)) { + capUser.enableTestMode(); + } + } + } + } + captcha.handleResponse(); } } - private void handleCaptcha(MessageReceivedEvent event, boolean isTest) { - PreUser preu; - PrivateChannel channel = event.getPrivateChannel(); - User author = event.getAuthor(); - ArrayList preus = Biscuit.getPreUsers(event.getAuthor()); - if(!preus.isEmpty() || isTest) { - if(isTest) { - preu = PreUser.getTestUser(author); - }else { - preu = preus.get(0); - } - - - String response = leeway(event.getMessage().getContentDisplay()); - - if(preu.getToken() == null || !response.equalsIgnoreCase(preu.getToken())) { - String tlabel = ""; - if(isTest) { - tlabel = "[TEST] "; - } - if(preu.getToken() != null) { - channel.sendMessage(tlabel + "Sorry! That's not quite right! Please try again.").queue(); - } - Main.getMainBiscuit().log(tlabel + "Generating captcha challenge for user " + author.getName() + " " + author.getAsMention() + "..."); - - Cage cage = Main.getMainBiscuit().getCage(); - - preu.genToken(); - - OutputStream os; - try { - //os = new FileOutputStream("captcha/" + author.getId() + ".jpg", false); - if(!Main.isPlugin) { - os = new FileOutputStream("captcha/" + author.getId() + ".jpg", false); - }else { - File c = new File(PluginCore.plugin.getDataFolder(), "captcha/" + author.getId() + ".jpg"); - os = new FileOutputStream(c, false); - } - } catch (FileNotFoundException e) { - e.printStackTrace(); - return; - } - try { - cage.draw(preu.getToken() , os); - } catch (IOException e) { - e.printStackTrace(); - return; - } finally { - try { - os.close(); - } catch (IOException e) { - e.printStackTrace(); - return; - } - } - File captcha; - if(!Main.isPlugin) { - captcha = new File("captcha/" + author.getId() + ".jpg"); - }else { - captcha = new File(PluginCore.plugin.getDataFolder(), "captcha/" + author.getId() + ".jpg"); - } - channel.sendMessage(tlabel+ "Respond with the exact text in this image.").queue(); - channel.sendFile(captcha).queue(); - - }else { - String tlabel = ""; - if(isTest) { - tlabel = "[TEST] "; - } - - Main.getMainBiscuit().log(BColor.YELLOW_BOLD + tlabel + author.getName() + " successfully completed a captcha challenge. Granting role."); - - if(isTest) { - preu.setDone(); - Main.getMainBiscuit().captchaLog("" + tlabel + " ``" + author.getName() +"`` " + author.getAsMention() + " successfully completed a captcha challenge. Test complete."); - testers.remove(author); - preu.remove(); - }else { - for(PreUser p : preus) { - p.setDone(); - Role newrole = null; - Role defaultrole = null; - - Biscuit biscuit = p.getBiscuit(); - - biscuit.captchaLog("" + tlabel + " ``" + author.getName() +"`` " + author.getAsMention() + " successfully completed a captcha challenge. Granting role."); - - Guild g = biscuit.getGuild(); - for(Role r : g.getRoles()) { - if(r.getName().toLowerCase().contains(biscuit.getProperties().getCaptchaReward().toLowerCase())) { - newrole = r; - }else if(r.getName().toLowerCase().contains(biscuit.getProperties().getDefaultRole().toLowerCase())) { - defaultrole = r; - } - } - if(newrole == null) { - biscuit.error("Cannot find captcha reward role!"); - return; - } - - if(defaultrole == null) { - biscuit.error("Cannot find captcha default role!"); - return; - } - - Member member = g.getMemberById(author.getId()); - - g.addRoleToMember(member, newrole).complete(); - g.removeRoleFromMember(member, defaultrole).complete(); - p.remove(); - } - } - channel.sendMessage(tlabel + "Well done, " + author.getAsMention() + "!").complete(); - } - - } - } - - private String leeway(String s) { - s = s.replace("0", "O"); - return s; - } - - } diff --git a/src/main/java/com/fpghoti/biscuit/listener/JoinListener.java b/src/main/java/com/fpghoti/biscuit/listener/JoinListener.java index ef6e364..d0cab0c 100644 --- a/src/main/java/com/fpghoti/biscuit/listener/JoinListener.java +++ b/src/main/java/com/fpghoti/biscuit/listener/JoinListener.java @@ -4,6 +4,7 @@ import java.util.HashMap; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.logging.BColor; +import com.fpghoti.biscuit.user.CaptchaUser; import com.fpghoti.biscuit.user.PreUser; import com.jcabi.aspects.Async; @@ -43,7 +44,7 @@ public class JoinListener extends ListenerAdapter { if(biscuit.getProperties().captchaEnabled()) { biscuit.log(BColor.MAGENTA_BOLD + "Adding pre-join check for user " + user.getName() + " (" + user.getAsMention() + ")..."); - new PreUser(event.getMember().getUser(), biscuit); + PreUser.getPreUser(CaptchaUser.getCaptchaUser(user), biscuit); } event.getGuild().addRoleToMember(event.getMember(), role).queue(); diff --git a/src/main/java/com/fpghoti/biscuit/listener/MessageReceiveListener.java b/src/main/java/com/fpghoti/biscuit/listener/MessageReceiveListener.java index ff50e09..44655b3 100644 --- a/src/main/java/com/fpghoti/biscuit/listener/MessageReceiveListener.java +++ b/src/main/java/com/fpghoti/biscuit/listener/MessageReceiveListener.java @@ -1,20 +1,22 @@ package com.fpghoti.biscuit.listener; -import java.util.concurrent.TimeUnit; -import java.util.function.Consumer; - import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.biscuit.BiscuitMessageStore; import com.fpghoti.biscuit.logging.BColor; +import com.fpghoti.biscuit.rest.MessageText; import com.fpghoti.biscuit.util.ChatFilter; import com.fpghoti.biscuit.util.PermUtil; import com.fpghoti.biscuit.util.Util; -import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.Message.Attachment; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; public class MessageReceiveListener extends ListenerAdapter{ + + /**TODO create new user class + * for keeping track of spammers + * and softmutes. + */ @Override public void onGuildMessageReceived(GuildMessageReceivedEvent event){ @@ -75,13 +77,7 @@ public class MessageReceiveListener extends ListenerAdapter{ private boolean isNaughty(GuildMessageReceivedEvent event) { // TODO make staff filter configurable if(!event.getChannel().getName().toLowerCase().contains("staff") && ChatFilter.filter(event, false)){ - event.getChannel().sendMessage(event.getAuthor().getAsMention() + " This message contains words not appropriate for this channel.").queue(new Consumer() - { - @Override - public void accept(Message msg){ - msg.delete().submitAfter(3, TimeUnit.SECONDS); - } - }); + MessageText.sendTimed(event.getChannel(), event.getAuthor().getAsMention() + " This message contains words not appropriate for this channel.", 3); event.getMessage().delete().submit(); return true; } @@ -149,26 +145,14 @@ public class MessageReceiveListener extends ListenerAdapter{ store.addSpammer(event.getAuthor()); store.removeSpamWarned(event.getAuthor()); event.getMessage().delete().submit(); - event.getChannel().sendMessage("*Flagging " + mention + " as spam!*").queue(new Consumer() - { - @Override - public void accept(Message msg){ - msg.delete().reason("Automatic bot message removal").submitAfter(3, TimeUnit.SECONDS); - } - }); + MessageText.sendTimed(event.getChannel(), "*Flagging " + mention + " as spam!*", 3); biscuit.log(BColor.MAGENTA_BOLD + "User " + event.getAuthor().getName() + " has been flagged as spam!"); event.getMessage().delete().reason("Spam removal activated for " + mention).submit(); //User is spamming and has not been warned. Apply warning. }else if(!store.isSpammer(event.getAuthor()) && !store.isSpamWarned(event.getAuthor())){ store.removeMessageCount(event.getAuthor()); store.addSpamWarned(event.getAuthor()); - event.getChannel().sendMessage("**STOP spamming, " + mention + "! You have been warned!**").queue(new Consumer() - { - @Override - public void accept(Message msg){ - msg.delete().reason("Automatic bot message removal").submitAfter(3, TimeUnit.SECONDS); - } - }); + MessageText.sendTimed(event.getChannel(), "**STOP spamming, " + mention + "! You have been warned!**", 3); biscuit.log(BColor.MAGENTA_BOLD + "User " + event.getAuthor().getName() + " has been warned for spam!"); } } diff --git a/src/main/java/com/fpghoti/biscuit/rest/MessageText.java b/src/main/java/com/fpghoti/biscuit/rest/MessageText.java new file mode 100644 index 0000000..ad2bcf3 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/rest/MessageText.java @@ -0,0 +1,97 @@ +package com.fpghoti.biscuit.rest; + +import java.util.concurrent.TimeUnit; + +import com.fpghoti.biscuit.Main; +import com.fpghoti.biscuit.biscuit.Biscuit; + +import net.dv8tion.jda.api.entities.MessageEmbed; +import net.dv8tion.jda.api.entities.PrivateChannel; +import net.dv8tion.jda.api.entities.TextChannel; + +public class MessageText { + + /** Sends an async message. **/ + public static void send(TextChannel c, final String message) { + if(c == null) { + Main.getMainBiscuit().error("Message could not be sent to null channel: " + message); + return; + } + final Biscuit b = Biscuit.getBiscuit(c.getGuild()); + c.sendMessage(message).submit().whenComplete((msg, error) -> { + if(error != null) { + b.warn("Message did not send: " + message); + } + }); + } + + /** Sends an async private message. **/ + public static void send(PrivateChannel c, final String message) { + if(c == null) { + Main.getMainBiscuit().error("Private message could not be sent to null channel: " + message); + return; + } + c.sendMessage(message).submit().whenComplete((msg, error) -> { + if(error != null) { + Main.getMainBiscuit().warn("Private message did not send: " + message); + } + }); + } + + /** Sends an async message embed. **/ + public static void send(TextChannel c, final MessageEmbed message) { + if(c == null) { + Main.getMainBiscuit().error("Message embed could not be sent to null channel: " + message); + return; + } + final Biscuit b = Biscuit.getBiscuit(c.getGuild()); + c.sendMessage(message).submit().whenComplete((msg, error) -> { + if(error != null) { + b.warn("Message embed did not send: " + message); + } + }); + } + + /** Sends an async message that will be deleted after a specified number of seconds. **/ + public static void sendTimed(TextChannel c, final String message, final int seconds) { + if(c == null) { + Main.getMainBiscuit().error("Timed message could not be sent to null channel - Time: " + seconds + " Text: " + message); + return; + } + final Biscuit b = Biscuit.getBiscuit(c.getGuild()); + c.sendMessage(message).submit() + .whenComplete((msg, error) -> { + if(error != null) { + b.warn("Timed message did not send - Time: " + seconds + " Text: " + message); + } + }) + .thenCompose((msg) -> msg.delete().submitAfter(seconds, TimeUnit.SECONDS)) + .whenComplete((msg, error) -> { + if(error != null) { + b.warn("Timed message did not delete - Time: " + seconds + " Text: " + message); + } + }); + } + + /** Sends an async message embed that will be deleted after a specified number of seconds. **/ + public static void sendTimed(TextChannel c, final MessageEmbed message, final int seconds) { + if(c == null) { + Main.getMainBiscuit().error("Timed message embed could not be sent to null channel - Time: " + seconds + " Text: " + message); + return; + } + final Biscuit b = Biscuit.getBiscuit(c.getGuild()); + c.sendMessage(message).submit() + .whenComplete((msg, error) -> { + if(error != null) { + b.warn("Timed message embed did not send - Time: " + seconds + " Text: " + message); + } + }) + .thenCompose((msg) -> msg.delete().submitAfter(seconds, TimeUnit.SECONDS)) + .whenComplete((msg, error) -> { + if(error != null) { + b.warn("Timed message embed did not delete - Time: " + seconds + " Text: " + message); + } + }); + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/timer/task/StatusTimer.java b/src/main/java/com/fpghoti/biscuit/timer/task/StatusTimer.java deleted file mode 100644 index 87165ff..0000000 --- a/src/main/java/com/fpghoti/biscuit/timer/task/StatusTimer.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.fpghoti.biscuit.timer.task; - -import com.fpghoti.biscuit.Main; -import com.fpghoti.biscuit.biscuit.Biscuit; -import com.fpghoti.biscuit.timer.BiscuitTimer; -import com.fpghoti.biscuit.user.PreUser; - -public class StatusTimer extends BiscuitTimer{ - - public StatusTimer(Biscuit b){ - biscuit = b; - delay = (long) 0; - period = (long) 60*1000; - } - - public void run() { - if(Main.ready) { - for(PreUser p : biscuit.getPreUsers()) { - p.decrementTime(); - } - } - } - -} diff --git a/src/main/java/com/fpghoti/biscuit/user/CaptchaUser.java b/src/main/java/com/fpghoti/biscuit/user/CaptchaUser.java new file mode 100644 index 0000000..8b1039d --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/user/CaptchaUser.java @@ -0,0 +1,217 @@ +package com.fpghoti.biscuit.user; + +import java.util.ArrayList; +import java.util.Iterator; + +import com.fpghoti.biscuit.Main; +import com.fpghoti.biscuit.biscuit.Biscuit; +import com.fpghoti.biscuit.captcha.Captcha; + +import net.dv8tion.jda.api.JDA; +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent; + +public class CaptchaUser implements Iterable{ + + private static ArrayList captchaUsers = new ArrayList(); + + public static void wipeCaptchaUsers() { + captchaUsers = new ArrayList(); + } + + public static boolean contains(User u) { + for(CaptchaUser c : captchaUsers) { + if(c.equals(u)) { + return true; + } + } + return false; + } + + public static boolean contains(PreUser u) { + for(CaptchaUser c : captchaUsers) { + if(c.equals(u)) { + return true; + } + } + return false; + } + public static boolean contains(CaptchaUser u) { + for(CaptchaUser c : captchaUsers) { + if(c.equals(u)) { + return true; + } + } + return false; + } + + public static CaptchaUser getCaptchaUser(User u) { + if(contains(u)) { + for(CaptchaUser c : captchaUsers) { + if(c.equals(u)) { + return c; + } + } + }else { + CaptchaUser c = new CaptchaUser(u); + captchaUsers.add(c); + return c; + } + Main.getMainBiscuit().error("Could not get Captcha User."); + return null; + } + + public static void remove(CaptchaUser u) { + ArrayList cu = new ArrayList(captchaUsers); + for(CaptchaUser c : cu) { + if(c.equals(u)) { + captchaUsers.remove(c); + } + } + } + + private User user; + private boolean testMode; + private Captcha captcha; + private ArrayList preUsers; + + private CaptchaUser(User user) { + this.user = user; + this.testMode = false; + this.captcha = null; + this.preUsers = new ArrayList(); + } + + @Override + public Iterator iterator() { + return new ArrayList(preUsers).iterator(); + } + + public User getUser() { + return user; + } + + public Captcha getCaptcha(PrivateMessageReceivedEvent event) { + captcha = Captcha.getUpdatedCaptcha(event); + return captcha; + } + + public void setCaptcha(Captcha c) { + captcha = c; + } + + public boolean equals(User u) { + return user.getId().equals(u.getId()); + } + + public boolean equals(PreUser u) { + return user.getId().equals(u.getUser().getId()); + } + + public boolean equals(CaptchaUser u) { + return user.getId().equals(u.getUser().getId()); + } + + public boolean contains(Guild g) { + if(g == null) { + return false; + } + for(PreUser u : preUsers) { + if(u.getBiscuit().getGuild().getId().equals(g.getId())) { + return true; + } + } + return false; + } + + public boolean contains(Biscuit b) { + return contains(b.getGuild()); + } + + public boolean isEmpty() { + return preUsers.isEmpty(); + } + + public boolean inTestMode() { + return testMode; + } + + public void enableTestMode() { + testMode = true; + } + + public void disableTestMode() { + testMode = false; + } + + public boolean shareGuild() { + JDA jda = Main.getJDA(); + for(Guild g : jda.getGuilds()) { + if(g.isMember(user)){ + return true; + } + } + return false; + } + + public ArrayList getSharedGuilds(){ + ArrayList guilds = new ArrayList(); + JDA jda = Main.getJDA(); + for(Guild g : jda.getGuilds()) { + if(g.isMember(user)){ + guilds.add(g); + } + } + return guilds; + } + + public void add(PreUser u) { + if(u.getBiscuit() == null || u.getBiscuit().getGuild() == null) { + return; + } + if(contains(u.getBiscuit())) { + return; + } + preUsers.add(u); + } + + public void remove(PreUser u) { + ArrayList ps = new ArrayList(preUsers); + for(PreUser p : ps) { + if(p.equals(u)) { + preUsers.remove(p); + } + } + } + + public PreUser get(Guild g) { + if(g == null) { + return null; + } + for(PreUser u : preUsers) { + if(u.getBiscuit().getGuild().getId().equals(g.getId())) { + return u; + } + } + return null; + } + + public PreUser get(Biscuit b) { + return get(b.getGuild()); + } + + // public PreUser getTestUser() { + // if(testUser == null) { + // PreUser preu = PreUser.makeTestUser(this); + // testUser = preu; + // } + // return testUser; + // } + + + public Captcha getCaptcha() { + return captcha; + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/user/PreUser.java b/src/main/java/com/fpghoti/biscuit/user/PreUser.java index 7a547bc..599613a 100644 --- a/src/main/java/com/fpghoti/biscuit/user/PreUser.java +++ b/src/main/java/com/fpghoti/biscuit/user/PreUser.java @@ -1,52 +1,42 @@ package com.fpghoti.biscuit.user; -import java.io.File; -import java.util.ArrayList; -import java.util.concurrent.CopyOnWriteArrayList; - import com.fpghoti.biscuit.Main; -import com.fpghoti.biscuit.PluginCore; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.util.PermUtil; -import com.github.cage.Cage; -import net.dv8tion.jda.api.JDA; -import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.User; public class PreUser { - - public static CopyOnWriteArrayList testusers = new CopyOnWriteArrayList(); - - public static PreUser getTestUser(User u) { - for(PreUser pu : testusers) { - if(pu.getUser().getId().equals(u.getId())) { - return pu; - } + + public static PreUser getPreUser(CaptchaUser capUser, Biscuit biscuit) { + if(capUser == null) { + Main.getMainBiscuit().error("Cannot get PreUser (Invalid Captcha User)."); + return null; } - return null; - } - - public static boolean hasTestUser(User u) { - return getTestUser(u) != null; + if(biscuit == null) { + Main.getMainBiscuit().error("Cannot get PreUser (Invalid Biscuit Instance)."); + return null; + } + if(capUser.contains(biscuit)) { + return capUser.get(biscuit); + } + PreUser preu = new PreUser(capUser, biscuit, false); + capUser.add(preu); + return preu; } + private CaptchaUser capUser; private User user; - private String token; private int timeLeft; private boolean done; private boolean test; private Biscuit biscuit; - public PreUser(User user, Biscuit biscuit) { - this(user, biscuit, false); - } - - public PreUser(User user, Biscuit biscuit, boolean test) { + private PreUser(CaptchaUser capUser, Biscuit biscuit, boolean test) { this.test = test; - this.user = user; - this.token = null; + this.capUser = capUser; + this.user = capUser.getUser(); this.biscuit = biscuit; this.done = false; this.timeLeft = biscuit.getProperties().noCaptchaKickTime() + 1; @@ -62,14 +52,13 @@ public class PreUser { public User getUser() { return this.user; } - - public String getToken() { - return this.token; + + public boolean isTestUser() { + return test; } - - public void genToken() { - Cage cage = biscuit.getCage(); - token = cage.getTokenGenerator().next(); + + public CaptchaUser getCaptchaUser() { + return this.capUser; } public void setDone() { @@ -81,7 +70,7 @@ public class PreUser { } public void decrementTime() { - if(!shareGuild()) { + if(!capUser.shareGuild()) { remove(); return; } @@ -108,52 +97,50 @@ public class PreUser { msg = msg + " " + invite; } final String fmsg = msg; - user.openPrivateChannel().flatMap(channel -> channel.sendMessage(fmsg)).complete(); + user.openPrivateChannel().flatMap(channel -> channel.sendMessage(fmsg)).submit().whenComplete((message, error) -> { + if (error != null) { + biscuit.log("Unable to private message user " + user.getName() +"."); + } + kick(); + }); + }else { + kick(); } - biscuit.getGuild().kick(user.getId()).submit(); } - - remove(); } } } } - public boolean shareGuild() { - JDA jda = biscuit.getJDA(); - for(Guild g : jda.getGuilds()) { - if(g.isMember(user)){ - return true; - } - } - return false; + public void kick() { + remove(); + biscuit.getGuild().kick(user.getId()).submit(); + } + + public boolean equals(User u) { + return user.getId().equals(u.getId()); } - public ArrayList getGuilds(){ - ArrayList guilds = new ArrayList(); - JDA jda = biscuit.getJDA(); - for(Guild g : jda.getGuilds()) { - if(g.isMember(user)){ - guilds.add(g); - } - } - return guilds; + public boolean equals(PreUser u) { + return user.getId().equals(u.getUser().getId()); + } + + public boolean equals(CaptchaUser u) { + return user.getId().equals(u.getUser().getId()); } public void remove() { setDone(); biscuit.log("Removing captcha data for user " + user.getName() + " " + user.getAsMention()); - File captcha; - if(!Main.isPlugin) { - captcha = new File("captcha/" + user.getId() + ".jpg"); - }else { - captcha = new File(PluginCore.plugin.getDataFolder(), "captcha/" + user.getId() + ".jpg"); + if(capUser.getCaptcha() != null) { + capUser.getCaptcha().removeFiles(); } - token = null; - captcha.delete(); biscuit.removePreUser(this); - testusers.remove(this); + if(biscuit.preUserExists(user)) { + biscuit.error("CAPTCHA ERROR: PreUser exists after removal"); + } + capUser.remove(this); } }