11package net .javadiscord .javabot .systems .commands ;
22
3+ import lombok .extern .slf4j .Slf4j ;
34import net .dv8tion .jda .api .EmbedBuilder ;
45import net .dv8tion .jda .api .JDA ;
56import net .dv8tion .jda .api .entities .MessageEmbed ;
1112import net .javadiscord .javabot .command .interfaces .SlashCommand ;
1213import net .javadiscord .javabot .data .config .guild .SlashCommandConfig ;
1314
15+ import java .io .BufferedReader ;
16+ import java .io .IOException ;
17+ import java .io .InputStreamReader ;
1418import java .time .Instant ;
1519
1620/**
1721 * Command that provides some basic info about the bot.
1822 */
23+ @ Slf4j
1924public class BotInfoCommand implements SlashCommand {
2025 @ Override
2126 public ReplyCallbackAction handleSlashCommandInteraction (SlashCommandInteractionEvent event ) {
@@ -31,12 +36,34 @@ 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```" , getOperatingSystem ( )), 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 getOperatingSystem () {
49+ String os = System .getProperty ("os.name" );
50+ if (os .equals ("Linux" )) {
51+ try {
52+ String [] cmd = {"/bin/sh" , "-c" , "cat /etc/*-release" };
53+ Process p = Runtime .getRuntime ().exec (cmd );
54+ BufferedReader bri = new BufferedReader (new InputStreamReader (p .getInputStream ()));
55+
56+ String line = "" ;
57+ while ((line = bri .readLine ()) != null ) {
58+ if (line .startsWith ("PRETTY_NAME" )) {
59+ return line .split ("\" " )[1 ];
60+ }
61+ }
62+ } catch (IOException e ) {
63+ log .error ("Error while getting Linux Distribution." );
64+ }
65+
66+ }
67+ return os ;
68+ }
4269}
0 commit comments