22
33import net .dv8tion .jda .api .entities .Member ;
44import net .dv8tion .jda .api .entities .Message ;
5+ import net .dv8tion .jda .api .entities .User ;
56import net .dv8tion .jda .api .entities .channel .middleman .MessageChannel ;
67import net .dv8tion .jda .api .entities .channel .unions .MessageChannelUnion ;
78import net .dv8tion .jda .api .interactions .commands .OptionType ;
@@ -98,7 +99,7 @@ public TrickCommand(MangoBot plugin) {
9899 var gid = g .getIdLong ();
99100 var trick = getTrick (valueOption .getAsString (), gid );
100101 if (trick != null ) {
101- useTrick (trick , null , e .getChannel (), gid , Arguments .of ());
102+ useTrick (trick , e . getUser (), null , e .getChannel (), gid , Arguments .of ());
102103 e .reply ("Executed Trick!" ).setEphemeral (true ).queue ();
103104 return ;
104105 }
@@ -190,12 +191,15 @@ public void onModal(DiscordModalInteractionEvent event) {
190191 var guild = DEvent .getGuild ();
191192 var user = DEvent .getUser ();
192193 if (guild == null ) {
193- DEvent .deferReply (true ).setContent ("""
194+ DEvent .deferReply (true ).setContent (
195+ """
194196 Cannot Add Trick. Only works in guilds.
195- """ ).queue ();
197+ """
198+ ).queue ();
196199 } else {
197200 var modalID = DEvent .getModalId ();
198- if (modalID .equals ("trickcreation" )) {
201+ if (modalID .startsWith ("trickcreation" )) {
202+ var isSilent = modalID .startsWith ("trickcreation1" );
199203 var trickID = DEvent .getInteraction ().getValue ("trickid" );
200204 var content = DEvent .getInteraction ().getValue ("content" );
201205 if (trickID != null && content != null ) {
@@ -207,6 +211,7 @@ public void onModal(DiscordModalInteractionEvent event) {
207211 newTrick .setOwnerID (user .getIdLong ());
208212 newTrick .setType (TrickType .NORMAL );
209213 newTrick .setContent (content .getAsString ());
214+ newTrick .setSuppress (isSilent );
210215 save (newTrick );
211216 TRICKS .put (new TrickKey (trickID .getAsString (), guild .getIdLong ()), newTrick );
212217 DEvent .reply ("Created new trick '%s'!" .formatted (trickID .getAsString ())).queue ();
@@ -450,7 +455,7 @@ public CommandResult execute(Message message, Arguments args) {
450455 }
451456
452457 var trick = getTrick (trickID , guildID );
453- useTrick (trick , message , message .getChannel (), guildID , args );
458+ useTrick (trick , message . getAuthor (), message , message .getChannel (), guildID , args );
454459 } else if (type == TrickCMDType .LIST ) {
455460 int length ;
456461
@@ -545,7 +550,7 @@ public CommandResult execute(Message message, Arguments args) {
545550 return CommandResult .PASS ;
546551 }
547552
548- private void useTrick (Trick trick , @ Nullable Message message , MessageChannel channel , long guildID , Arguments args ) {
553+ private void useTrick (Trick trick , User requester , @ Nullable Message message , MessageChannel channel , long guildID , Arguments args ) {
549554 MessageSettings dMessage = plugin .getMessageSettings ();
550555 var type = trick .getType ();
551556 var replyTarget = message == null ? null : (message .getMessageReference () == null ? null : message .getMessageReference ().getMessage ());
@@ -558,7 +563,7 @@ private void useTrick(Trick trick, @Nullable Message message, MessageChannel cha
558563 if (type == TrickType .NORMAL ) {
559564 dMessage .withButton (
560565 dMessage .apply (channel .sendMessage (trick .getContent ()))
561- .setSuppressEmbeds (trick .isSuppressed ()), MangoBot .ACTION_REGISTRY .get (TrashButtonAction .class ).createForUser (message . getAuthor () )
566+ .setSuppressEmbeds (trick .isSuppressed ()), MangoBot .ACTION_REGISTRY .get (TrashButtonAction .class ).createForUser (requester )
562567 ).setAllowedMentions (
563568 Arrays .stream (Message .MentionType .values ())
564569 .filter (t -> {
@@ -574,7 +579,7 @@ private void useTrick(Trick trick, @Nullable Message message, MessageChannel cha
574579 if (exists (trick .getAliasTarget (), guildID )) {
575580 var alias = getTrick (trick .getAliasTarget (), guildID );
576581 trick .use ();
577- useTrick (alias , message , channel , guildID , args );
582+ useTrick (alias , requester , message , channel , guildID , args );
578583 }
579584 // Cannot use Scripts with slash commands
580585 } else if (type == TrickType .SCRIPT && message != null ) {
0 commit comments