Compare commits
	
		
			3 commits
		
	
	
		
			
				28ba2699a3
			
			...
			
				3a76e62ba9
			
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
							 | 
						
							
							
								
							
							
	
	
	3a76e62ba9 | 
						
						
							||
| 
							 | 
						
							
							
								
							
							
	
	
	28ca47394b | 
						
						
							||
| 
							 | 
						
							
							
								
							
							
	
	
	02fdfdd532 | 
						
						
							
					 4 changed files with 59 additions and 3 deletions
				
			
		
							
								
								
									
										6
									
								
								.idea/misc.xml
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										6
									
								
								.idea/misc.xml
									
										
									
										generated
									
									
									
								
							| 
						 | 
				
			
			@ -1,4 +1,10 @@
 | 
			
		|||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<project version="4">
 | 
			
		||||
  <component name="EntryPointsManager">
 | 
			
		||||
    <list size="1">
 | 
			
		||||
      <item index="0" class="java.lang.String" itemvalue="com.freya02.botcommands.api.application.slash.annotations.JDASlashCommand" />
 | 
			
		||||
    </list>
 | 
			
		||||
  </component>
 | 
			
		||||
  <component name="ExternalStorageConfigurationManager" enabled="true" />
 | 
			
		||||
  <component name="MavenProjectsManager">
 | 
			
		||||
    <option name="originalFiles">
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,9 +23,9 @@ public class Timeout extends ApplicationCommand {
 | 
			
		|||
            subcommand = "set",
 | 
			
		||||
            description = "Times out a member"
 | 
			
		||||
    )
 | 
			
		||||
    public void mute(GuildSlashEvent event,
 | 
			
		||||
    public void timeout(GuildSlashEvent event,
 | 
			
		||||
                     @AppOption(name = "member") Member member,
 | 
			
		||||
                     @AppOption(name = "duration", description = "ex: 2h5m, must be between 1h and 7d") String duration) {
 | 
			
		||||
                     @AppOption(name = "duration", description = "ex: 2h5m, must be between 1m and 7d") String duration) {
 | 
			
		||||
        Duration timeoutDuration = DurationUtils.parseDuration(duration);
 | 
			
		||||
        member.timeoutFor(timeoutDuration).queue();
 | 
			
		||||
        event.replyFormat("Timed out %s for %s", member.getAsMention(), duration).queue();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										48
									
								
								src/main/java/net/hypr/doki/commands/utils/Poll.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								src/main/java/net/hypr/doki/commands/utils/Poll.java
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,48 @@
 | 
			
		|||
package net.hypr.doki.commands.utils;
 | 
			
		||||
 | 
			
		||||
import com.freya02.botcommands.api.annotations.BotPermissions;
 | 
			
		||||
import com.freya02.botcommands.api.annotations.CommandMarker;
 | 
			
		||||
import com.freya02.botcommands.api.annotations.Optional;
 | 
			
		||||
import com.freya02.botcommands.api.annotations.UserPermissions;
 | 
			
		||||
import com.freya02.botcommands.api.application.ApplicationCommand;
 | 
			
		||||
import com.freya02.botcommands.api.application.annotations.AppOption;
 | 
			
		||||
import com.freya02.botcommands.api.application.slash.GuildSlashEvent;
 | 
			
		||||
import com.freya02.botcommands.api.application.slash.annotations.JDASlashCommand;
 | 
			
		||||
import net.dv8tion.jda.api.Permission;
 | 
			
		||||
import net.dv8tion.jda.api.utils.messages.MessagePollBuilder;
 | 
			
		||||
import net.dv8tion.jda.api.utils.messages.MessagePollData;
 | 
			
		||||
import net.hypr.doki.utils.DurationUtils;
 | 
			
		||||
 | 
			
		||||
import java.time.Duration;
 | 
			
		||||
import java.util.Objects;
 | 
			
		||||
 | 
			
		||||
@CommandMarker
 | 
			
		||||
@BotPermissions(Permission.MESSAGE_SEND_POLLS)
 | 
			
		||||
@UserPermissions(Permission.MESSAGE_SEND_POLLS)
 | 
			
		||||
public class Poll extends ApplicationCommand {
 | 
			
		||||
    @JDASlashCommand(
 | 
			
		||||
            name = "poll",
 | 
			
		||||
            description = "Creates a poll"
 | 
			
		||||
    )
 | 
			
		||||
    public void poll(GuildSlashEvent event,
 | 
			
		||||
                     @AppOption(name = "title") String pollTitle,
 | 
			
		||||
                     @AppOption(name = "duration", description = "ex: 2h5m, must be between 1h and 7d") String duration,
 | 
			
		||||
                     @AppOption(name = "options", description = "Comma-seperated poll options") String options,
 | 
			
		||||
                     @Optional @AppOption(name = "multiple-choice", description = "Allow multiple choices? (defaults to false)") Boolean multiChoice) {
 | 
			
		||||
        Boolean pollMultiChoice = Objects.requireNonNullElse(multiChoice, false);
 | 
			
		||||
        Duration pollDuration = DurationUtils.parseDuration(duration);
 | 
			
		||||
        String[] pollOptions = options.split(",");
 | 
			
		||||
        MessagePollBuilder poll = MessagePollData.builder(pollTitle)
 | 
			
		||||
                .setDuration(pollDuration);
 | 
			
		||||
        for (String option: pollOptions) {
 | 
			
		||||
            poll.addAnswer(option);
 | 
			
		||||
        }
 | 
			
		||||
        event.getChannel().sendMessagePoll(poll.build()).queue();
 | 
			
		||||
        event.replyFormat("Created %s poll \"%s\" in %s which will last %s",
 | 
			
		||||
                (pollMultiChoice) ? "multi-choice" : "single-choice",
 | 
			
		||||
                pollTitle,
 | 
			
		||||
                event.getChannel().getAsMention(),
 | 
			
		||||
                duration).setEphemeral(true).queue();
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -7,7 +7,7 @@ import java.util.regex.Matcher;
 | 
			
		|||
import java.util.regex.Pattern;
 | 
			
		||||
 | 
			
		||||
public class DurationUtils {
 | 
			
		||||
    private static final Pattern timePattern = Pattern.compile("(\\d+)(?:([dhms]))?");
 | 
			
		||||
    private static final Pattern timePattern = Pattern.compile("(\\d+)([dhms])?");
 | 
			
		||||
    public static Duration parseDuration(String input) throws IllegalArgumentException {
 | 
			
		||||
        Matcher matcher = timePattern.matcher(input);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -28,6 +28,8 @@ public class DurationUtils {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    public static String getTimeDifference(OffsetDateTime offsetDateTime) {
 | 
			
		||||
        if (offsetDateTime == null) return "0 seconds";
 | 
			
		||||
 | 
			
		||||
        // Get the current Instant (current time)
 | 
			
		||||
        Instant now = Instant.now();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue