mirror of
https://github.com/TheDeus-Group/TFM-4.3-Reloaded.git
synced 2024-12-22 22:14:57 +00:00
Add uptime discord command and add penis exception (closes #10)
This commit is contained in:
parent
c2b7cc9e19
commit
ae97ecacd1
3 changed files with 60 additions and 5 deletions
|
@ -1,9 +1,6 @@
|
|||
package me.StevenLawson.TotalFreedomMod.discord.command;
|
||||
|
||||
import me.StevenLawson.TotalFreedomMod.discord.commands.AdminConsoleCommand;
|
||||
import me.StevenLawson.TotalFreedomMod.discord.commands.HelpCommand;
|
||||
import me.StevenLawson.TotalFreedomMod.discord.commands.ListCommand;
|
||||
import me.StevenLawson.TotalFreedomMod.discord.commands.TPSCommand;
|
||||
import me.StevenLawson.TotalFreedomMod.discord.commands.*;
|
||||
import org.javacord.api.entity.channel.TextChannel;
|
||||
import org.javacord.api.entity.message.MessageBuilder;
|
||||
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||
|
@ -20,11 +17,11 @@ public class DiscordCommandManager {
|
|||
public List<ExecutableDiscordCommand> commands = new ArrayList<>();
|
||||
|
||||
public void init() {
|
||||
|
||||
// Server Commands
|
||||
commands.add(new ListCommand("list", "Gives a list of online players.", "Server Commands", Collections.singletonList("l"), false));
|
||||
commands.add(new TPSCommand("tps", "Lag information regarding the server.", "Server Commands", false));
|
||||
commands.add(new AdminConsoleCommand("adminconsole", "Execute admin commands from discord.", "Server Commands", Collections.singletonList("ac"),true));
|
||||
commands.add(new UptimeCommand("uptime", "Returns the uptime of the VPS.", "Server Commands", false));
|
||||
|
||||
// Help
|
||||
commands.add(new HelpCommand("help", "Displays the help command", "Help", false));
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
package me.StevenLawson.TotalFreedomMod.discord.commands;
|
||||
|
||||
import me.StevenLawson.TotalFreedomMod.discord.command.ExecutableDiscordCommand;
|
||||
import me.StevenLawson.TotalFreedomMod.exception.PenisException;
|
||||
import org.javacord.api.entity.message.MessageBuilder;
|
||||
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||
import org.javacord.api.entity.user.User;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class UptimeCommand extends ExecutableDiscordCommand {
|
||||
public UptimeCommand(String command, String description, String category, boolean isAdmin) {
|
||||
super(command, description, category, isAdmin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageBuilder execute(User user, List<String> args) {
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
try {
|
||||
builder.setTitle("VPS Uptime Information")
|
||||
.setDescription(getSystemUptime());
|
||||
} catch (Exception e) {
|
||||
builder.setTitle("Command error")
|
||||
.setColor(Color.RED)
|
||||
.setDescription("Something went wrong");
|
||||
}
|
||||
return new MessageBuilder().addEmbed(builder);
|
||||
}
|
||||
|
||||
private String getSystemUptime() throws Exception {
|
||||
Process uptimeProc = Runtime.getRuntime().exec("uptime");
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(uptimeProc.getInputStream()));
|
||||
String line = in.readLine();
|
||||
if (line != null) {
|
||||
return line;
|
||||
} else {
|
||||
throw new PenisException();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package me.StevenLawson.TotalFreedomMod.exception;
|
||||
|
||||
public class PenisException extends Exception {
|
||||
public PenisException() {
|
||||
|
||||
}
|
||||
|
||||
public PenisException(String name) {
|
||||
super(name);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue