forked from ChomeNS/chomens-bot-java
actually use less dependencies/.,,.,.
This commit is contained in:
parent
b65a4063c9
commit
43061c850b
7 changed files with 57 additions and 32 deletions
|
@ -7,11 +7,6 @@
|
|||
<version>rolling</version>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.github.ricksbrown</groupId>
|
||||
<artifactId>cowsay</artifactId>
|
||||
<version>1.1.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
|
|
19
pom.xml
19
pom.xml
|
@ -58,7 +58,6 @@
|
|||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.26</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -67,12 +66,6 @@
|
|||
<version>3.23.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.12.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.ricksbrown</groupId>
|
||||
<artifactId>cowsay</artifactId>
|
||||
|
@ -80,12 +73,6 @@
|
|||
<classifier>lib</classifier>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.ricksbrown</groupId>
|
||||
<artifactId>cowjar-extra</artifactId>
|
||||
<version>1.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
|
@ -125,12 +112,6 @@
|
|||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.github.ricksbrown</groupId>
|
||||
<artifactId>cowsay</artifactId>
|
||||
<version>1.1.0</version>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<!-- Build an executable JAR -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
|
|
@ -10,9 +10,9 @@ import com.github.steveice10.packetlib.packet.Packet;
|
|||
import com.github.steveice10.packetlib.tcp.TcpClientSession;
|
||||
import land.chipmunk.chayapak.chomens_bot.plugins.*;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ComponentUtilities;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.RandomStringUtilities;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -125,7 +125,7 @@ public class Bot {
|
|||
|
||||
final String _username = options.username();
|
||||
|
||||
if (_username == null) username = RandomStringUtils.randomAlphanumeric(8);
|
||||
if (_username == null) username = RandomStringUtilities.generate(8);
|
||||
else username = _username;
|
||||
|
||||
Session session = new TcpClientSession(host, port, new MinecraftProtocol(username), null);
|
||||
|
|
|
@ -18,7 +18,7 @@ public class CowsayCommand implements Command {
|
|||
|
||||
public List<String> usage() {
|
||||
final List<String> usages = new ArrayList<>();
|
||||
usages.add("<cow> <{message}>");
|
||||
usages.add("<{message}>");
|
||||
|
||||
return usages;
|
||||
}
|
||||
|
@ -35,11 +35,9 @@ public class CowsayCommand implements Command {
|
|||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
final String cow = args[0];
|
||||
final String message = String.join(" ", Arrays.copyOfRange(args, 1, args.length));
|
||||
final String message = String.join(" ", args);
|
||||
|
||||
final CowExecutor cowExecutor = new CowExecutor();
|
||||
cowExecutor.setCowfile(cow);
|
||||
cowExecutor.setMessage(message);
|
||||
|
||||
final String result = cowExecutor.execute();
|
||||
|
|
|
@ -4,13 +4,13 @@ import land.chipmunk.chayapak.chomens_bot.Bot;
|
|||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.commands.*;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ExceptionUtilities;
|
||||
import lombok.Getter;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
@ -146,7 +146,7 @@ public class CommandHandlerPlugin {
|
|||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
final String stackTrace = ExceptionUtils.getStackTrace(e);
|
||||
final String stackTrace = ExceptionUtilities.getStacktrace(e);
|
||||
if (inGame) {
|
||||
if (bot.options().useChat() || !bot.options().useCore()) return Component.text(e.toString()).color(NamedTextColor.RED);
|
||||
return Component
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.util;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
public class ExceptionUtilities {
|
||||
// totallynotskidded™ from apache's common utils thingy
|
||||
public static String getStacktrace (Throwable throwable) {
|
||||
final StringWriter sw = new StringWriter();
|
||||
final PrintWriter pw = new PrintWriter(sw, true);
|
||||
|
||||
throwable.printStackTrace(pw);
|
||||
|
||||
return sw.getBuffer().toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.util;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
|
||||
// https://stackoverflow.com/questions/41107/how-to-generate-a-random-alpha-numeric-string
|
||||
// but modified
|
||||
public class RandomStringUtilities {
|
||||
private static String nextString() {
|
||||
// fard
|
||||
for (int i = 0; i < buf.length; i++)
|
||||
buf[i] = symbols[random.nextInt(symbols.length)];
|
||||
return new String(buf);
|
||||
}
|
||||
|
||||
private static final String upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
private static final String lower = upper.toLowerCase();
|
||||
|
||||
private static final String digits = "0123456789";
|
||||
|
||||
private static final String alphanum = upper + lower + digits;
|
||||
|
||||
private static final char[] symbols = alphanum.toCharArray();
|
||||
|
||||
private static char[] buf = null;
|
||||
|
||||
private static final SecureRandom random = new SecureRandom();
|
||||
|
||||
// TODO: mabe support stuff than alpha-numeric
|
||||
public static String generate (int length) {
|
||||
buf = new char[length];
|
||||
|
||||
return nextString();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue