77import net .discordjug .javabot .systems .staff_commands .forms .model .FormData ;
88import net .dv8tion .jda .api .EmbedBuilder ;
99import net .dv8tion .jda .api .entities .Guild ;
10+ import net .dv8tion .jda .api .entities .channel .concrete .TextChannel ;
1011import net .dv8tion .jda .api .events .interaction .command .CommandAutoCompleteInteractionEvent ;
1112import net .dv8tion .jda .api .events .interaction .command .SlashCommandInteractionEvent ;
1213import net .dv8tion .jda .api .interactions .AutoCompleteQuery ;
1314import net .dv8tion .jda .api .interactions .commands .OptionMapping ;
1415import net .dv8tion .jda .api .interactions .commands .OptionType ;
1516import net .dv8tion .jda .api .interactions .commands .build .OptionData ;
1617import net .dv8tion .jda .api .interactions .commands .build .SubcommandData ;
17- import net .dv8tion .jda .api .utils .messages .MessageCreateBuilder ;
18- import net .dv8tion .jda .api .utils .messages .MessageCreateData ;
18+ import net .dv8tion .jda .api .utils .TimeFormat ;
1919import xyz .dynxsty .dih4jda .interactions .AutoCompletable ;
2020
2121/**
2222 * The `/form details` command. Displays information about the specified form.
2323 * The information is sent as a non-ephemeral embed in the same channel this
2424 * command is executed in.
25- *
25+ *
2626 * @see FormData
2727 */
2828public class DetailsFormSubcommand extends FormSubcommand implements AutoCompletable {
@@ -56,9 +56,7 @@ public void execute(SlashCommandInteractionEvent event) {
5656 EmbedBuilder embedBuilder = createFormDetailsEmbed (form , event .getGuild ());
5757 embedBuilder .setAuthor (event .getMember ().getEffectiveName (), null , event .getMember ().getEffectiveAvatarUrl ());
5858
59- MessageCreateData builder = new MessageCreateBuilder ().addEmbeds (embedBuilder .build ()).build ();
60-
61- event .getHook ().sendMessage (builder ).queue ();
59+ event .getHook ().sendMessageEmbeds (embedBuilder .build ()).queue ();
6260 }
6361
6462 @ Override
@@ -75,22 +73,37 @@ private EmbedBuilder createFormDetailsEmbed(FormData form, Guild guild) {
7573 builder .addField ("Created at" , String .format ("<t:%s>" , id / 1000L ), true );
7674
7775 builder .addField ("Expires at" ,
78- form .hasExpirationTime () ? String . format ("<t:%s>" , form .expiration ().toEpochMilli () / 1000L )
76+ form .hasExpirationTime () ? TimeFormat . DATE_TIME_LONG . format (form .expiration ().toEpochMilli ())
7977 : "`Never`" ,
8078 true );
8179
8280 addCodeblockField (builder , "State" , form .closed () ? "Closed" : form .hasExpired () ? "Expired" : "Open" , false );
8381
84- builder .addField ("Attached in" ,
85- form .isAttached () ? "<#" + form .getMessageChannel ().get () + ">" : "*Not attached*" , true );
86- builder .addField ("Attached to" ,
87- form .isAttached ()
88- ? String .format ("[Link](https://discord.com/channels/%s/%s/%s)" , guild .getId (),
89- form .getMessageChannel ().get (), form .getMessageId ().get ())
90- : "*Not attached*" ,
91- true );
82+ String channelMention ;
83+ String messageLink ;
84+ if (form .isAttached ()) {
85+ long channelId = form .getMessageChannel ().get ();
86+ TextChannel channel = guild .getTextChannelById (channelId );
87+ channelMention = channel != null ? channel .getAsMention () : "`" + channelId + "`" ;
88+ messageLink = String .format ("[Link](https://discord.com/channels/%s/%s/%s)" , guild .getId (),
89+ form .getMessageChannel ().get (), form .getMessageId ().get ());
90+ } else {
91+ channelMention = "*Not attached*" ;
92+ messageLink = "*Not attached*" ;
93+ }
94+
95+ String submissionsChannelMention ;
96+ TextChannel submissionsChannel = guild .getTextChannelById (form .submitChannel ());
97+ if (submissionsChannel != null ) {
98+ submissionsChannelMention = submissionsChannel .getAsMention ();
99+ } else {
100+ submissionsChannelMention = "`" + form .submitChannel ();
101+ }
102+
103+ builder .addField ("Attached in" , channelMention , true );
104+ builder .addField ("Attached to" , messageLink , true );
92105
93- builder .addField ("Submissions channel" , "<#" + form . submitChannel () + ">" , true );
106+ builder .addField ("Submissions channel" , submissionsChannelMention , true );
94107 builder .addField ("Is one-time" , form .onetime () ? ":white_check_mark:" : ":x:" , true );
95108 addCodeblockField (builder , "Submission message" ,
96109 form .submitMessage () == null ? "Default" : form .submitMessage (), true );
0 commit comments