Skip to content

Commit 052741f

Browse files
committed
Added linux distro to /botinfo
1 parent b985f9b commit 052741f

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/main/java/net/javadiscord/javabot/systems/commands/BotInfoCommand.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.javadiscord.javabot.systems.commands;
22

3+
import lombok.extern.slf4j.Slf4j;
34
import net.dv8tion.jda.api.EmbedBuilder;
45
import net.dv8tion.jda.api.JDA;
56
import net.dv8tion.jda.api.entities.MessageEmbed;
@@ -11,11 +12,15 @@
1112
import net.javadiscord.javabot.command.interfaces.SlashCommand;
1213
import net.javadiscord.javabot.data.config.guild.SlashCommandConfig;
1314

15+
import java.io.BufferedReader;
16+
import java.io.IOException;
17+
import java.io.InputStreamReader;
1418
import java.time.Instant;
1519

1620
/**
1721
* Command that provides some basic info about the bot.
1822
*/
23+
@Slf4j
1924
public class BotInfoCommand implements SlashCommand {
2025
@Override
2126
public ReplyCallbackAction handleSlashCommandInteraction(SlashCommandInteractionEvent event) {
@@ -31,12 +36,36 @@ private MessageEmbed buildBotInfoEmbed(JDA jda, SlashCommandConfig config) {
3136
.setThumbnail(bot.getEffectiveAvatarUrl())
3237
.setAuthor(bot.getAsTag(), null, bot.getEffectiveAvatarUrl())
3338
.setTitle("Info")
34-
.addField("OS", String.format("```%s```", System.getProperty("os.name")), true)
39+
.addField("OS", String.format("```%s```", getOs()), true)
3540
.addField("Library", "```JDA```", true)
3641
.addField("JDK", String.format("```%s```", System.getProperty("java.version")), true)
3742
.addField("Gateway Ping", String.format("```%sms```", jda.getGatewayPing()), true)
3843
.addField("Uptime", String.format("```%s```", new UptimeCommand().getUptime()), true)
3944
.setTimestamp(Instant.now())
4045
.build();
4146
}
47+
48+
private String getOs() {
49+
String os = System.getProperty("os.name");
50+
if(os.equals("Linux")) {
51+
try {
52+
String[] cmd = {"/bin/sh", "-c", "cat /etc/*-release" };
53+
54+
Process p = Runtime.getRuntime().exec(cmd);
55+
BufferedReader bri = new BufferedReader(new InputStreamReader(
56+
p.getInputStream()));
57+
58+
String line = "";
59+
while ((line = bri.readLine()) != null) {
60+
if (line.startsWith("PRETTY_NAME")) {
61+
return line.split("\"")[1];
62+
}
63+
}
64+
} catch (IOException e) {
65+
log.error("Error while getting Linux Distribution.");
66+
}
67+
68+
}
69+
return os;
70+
}
4271
}

0 commit comments

Comments
 (0)