Skip to content
This repository was archived by the owner on Jul 29, 2021. It is now read-only.

Commit 44fcd31

Browse files
Fixed a potentially fatal bug; Build 4
- Added "breakApart" variable to the illegal characters cleaning for configure command. Done to prevent a potentially fatal bug when adding more than one role to the configuration if tagging the role. - No longer using Instant to grab tiem, but using system time in ms precision.
1 parent 383130a commit 44fcd31

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

Project-Lynx/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>Project-Lynx</groupId>
44
<artifactId>Project-Lynx</artifactId>
5-
<version>0.2a</version>
5+
<version>Pre-Release 0.2.0a Build 4</version>
66
<name>Project Lynx</name>
77
<description>JDA-based moderation bot</description>
88
<properties>

Project-Lynx/src/main/java/commands/utilities/Configure.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,19 @@ public boolean action(MessageChannel chn, String msg, Object misc) {
178178
brokenString = breakApart;
179179
breakApart = "";
180180
}
181-
182-
// Check if they're tagged Roles or straight up long IDs
183-
System.out.println("DEBUG - BREAK APART [Configure.java] " + breakApart);
184-
System.out.println("DEBUG - BROKEN STRING [Configure.java] " + brokenString);
185181

182+
// Clean the strings
186183
String[] illegal_chars = new String[] {"<", ">", "@", "&", "!", " "};
187184

188185
for(String ill_char: illegal_chars) {
189186
brokenString = brokenString.replaceAll(ill_char, "");
187+
breakApart = breakApart.replaceAll(ill_char, "");
190188
}
191189

190+
// Check if they're tagged Roles or straight up long IDs
191+
System.out.println("DEBUG - BREAK APART [Configure.java] " + breakApart);
192+
System.out.println("DEBUG - BROKEN STRING [Configure.java] " + brokenString);
193+
192194
try {
193195
decipheredRole = new Long(brokenString);
194196
} catch (NumberFormatException e) {

Project-Lynx/src/main/java/handlers/MessageHandler.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package handlers;
22

33
import java.io.File;
4-
import java.time.Instant;
54
import java.util.HashMap;
65
import java.util.function.Consumer;
76

@@ -36,7 +35,7 @@ public void onEvent(GenericEvent event) {
3635

3736
User author = ((MessageReceivedEvent) event).getAuthor();
3837
Guild g = null;
39-
int delayTimer = 1;
38+
long delayTimer = 150; // 50 ms
4039
String prefix; //Server's prefix... if it's even a server.
4140

4241
try {
@@ -80,9 +79,9 @@ public void onEvent(GenericEvent event) {
8079

8180
// Check if user is trying to spam the command.
8281
if(!(limitCheck.get(((MessageReceivedEvent) event).getAuthor()) == null)) {
83-
long currentInstant = Instant.now().getEpochSecond();
82+
long currentMs = System.currentTimeMillis();
8483

85-
if(currentInstant-delayTimer <= limitCheck.get(((MessageReceivedEvent) event).getAuthor())) {
84+
if(currentMs-delayTimer <= limitCheck.get(((MessageReceivedEvent) event).getAuthor())) {
8685
System.out.println("WARNING [MessageHandler.java] " + author + " has breached the delay timer!");
8786
return;
8887
}
@@ -95,13 +94,19 @@ public void onEvent(GenericEvent event) {
9594

9695
//System.out.println("DEBUG [MessageHandler.java]: " + cmd.getName());
9796
//System.out.println("DEBUG [MessageHandler.java]: (ChannelType) " + c);
98-
99-
if(c.equals(ChannelType.PRIVATE))
100-
cmd.action(((MessageReceivedEvent) event).getAuthor().openPrivateChannel().complete(), fullMsg, event); //Just pass the entire thing to prevent NullPointers, each command will handle them appropriately
101-
else if(c.equals(ChannelType.TEXT))
102-
cmd.action(((MessageReceivedEvent) event).getChannel(), fullMsg, event);
10397

104-
limitCheck.put(((MessageReceivedEvent) event).getAuthor(), Instant.now().getEpochSecond());
98+
new Thread() {
99+
public void run() {
100+
101+
if(c.equals(ChannelType.PRIVATE))
102+
cmd.action(((MessageReceivedEvent) event).getAuthor().openPrivateChannel().complete(), fullMsg, event); //Just pass the entire thing to prevent NullPointers, each command will handle them appropriately
103+
else if(c.equals(ChannelType.TEXT))
104+
cmd.action(((MessageReceivedEvent) event).getChannel(), fullMsg, event);
105+
106+
}
107+
}.run();
108+
109+
limitCheck.put(((MessageReceivedEvent) event).getAuthor(), System.currentTimeMillis());
105110

106111
}
107112

Project-Lynx/src/main/java/init/InitData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ public class InitData {
7878
/*
7979
* Use this to define the version
8080
*/
81-
public static String version = "Pre-Release v0.2.0a Build 3 - The Rewrite Update";
81+
public static String version = "Pre-Release v0.2.0a Build 4 - The Rewrite Update";
8282

8383
}

0 commit comments

Comments
 (0)