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,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