1- package net .javadiscord .javabot .systems .help .commands . subcommands ;
1+ package net .javadiscord .javabot .systems .help .commands ;
22
33import com .dynxsty .dih4jda .interactions .commands .SlashCommand ;
44import net .dv8tion .jda .api .EmbedBuilder ;
2222 * Handler for the /help ping sub-command that allows users to occasionally ping
2323 * helpers.
2424 */
25- public class HelpPingCommand extends SlashCommand .Subcommand {
25+ public class HelpPingSubcommand extends SlashCommand .Subcommand {
2626 private static final String WRONG_CHANNEL_MSG = "This command can only be used in **reserved help channels**." ;
2727 private static final long CACHE_CLEANUP_DELAY = 60L ;
2828
@@ -31,7 +31,7 @@ public class HelpPingCommand extends SlashCommand.Subcommand {
3131 /**
3232 * Constructor that initializes and handles the cooldown map.
3333 */
34- public HelpPingCommand () {
34+ public HelpPingSubcommand () {
3535 setSubcommandData (new SubcommandData ("ping" , "Notify those with the help-ping role that your question is urgent." ));
3636 lastPingTimes = new ConcurrentHashMap <>();
3737 Bot .getAsyncPool ().scheduleWithFixedDelay (this ::cleanTimeoutCache , CACHE_CLEANUP_DELAY , CACHE_CLEANUP_DELAY , TimeUnit .SECONDS );
@@ -87,33 +87,35 @@ public void execute(@NotNull SlashCommandInteractionEvent event) {
8787 /**
8888 * Determines if a user is forbidden from sending a help-ping command due
8989 * to their status in the server.
90+ *
9091 * @param reservation The channel reservation for the channel they're
9192 * trying to send the command in.
92- * @param member The member.
93- * @param config The guild config.
93+ * @param member The member.
94+ * @param config The guild config.
9495 * @return True if the user is forbidden from sending the command.
9596 */
9697 private boolean isHelpPingForbiddenForMember (@ NotNull ChannelReservation reservation , @ NotNull Member member , @ NotNull GuildConfig config ) {
9798 Set <Role > allowedRoles = Set .of (config .getModerationConfig ().getStaffRole (), config .getHelpConfig ().getHelperRole ());
9899 return !(
99100 reservation .getUserId () == member .getUser ().getIdLong () ||
100- member .getRoles ().stream ().anyMatch (allowedRoles ::contains ) ||
101- member .isOwner ()
101+ member .getRoles ().stream ().anyMatch (allowedRoles ::contains ) ||
102+ member .isOwner ()
102103 );
103104 }
104105
105106 /**
106107 * Determines if the user's timeout has elapsed (or doesn't exist), which
107108 * implies that it's fine for the user to send the command.
109+ *
108110 * @param memberId The members' id.
109- * @param config The guild config.
111+ * @param config The guild config.
110112 * @return True if the user's timeout has elapsed or doesn't exist, or
111113 * false if the user should NOT send the command because of their timeout.
112114 */
113115 private boolean isHelpPingTimeoutElapsed (long memberId , GuildConfig config ) {
114- Long lastPing = lastPingTimes .get (memberId ). first ( );
116+ Pair < Long , Guild > lastPing = lastPingTimes .get (memberId );
115117 return lastPing == null ||
116- lastPing + config .getHelpConfig ().getHelpPingTimeoutSeconds () * 1000L < System .currentTimeMillis ();
118+ lastPing . first () + config .getHelpConfig ().getHelpPingTimeoutSeconds () * 1000L < System .currentTimeMillis ();
117119 }
118120
119121 /**
0 commit comments