Poll command!!!!
This commit is contained in:
		
					parent
					
						
							
								28ba2699a3
							
						
					
				
			
			
				commit
				
					
						02fdfdd532
					
				
			
		
					 3 changed files with 56 additions and 0 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"> | ||||
|  |  | |||
							
								
								
									
										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(); | ||||
| 
 | ||||
|     } | ||||
| } | ||||
|  | @ -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
	
	 floppydiskette
				floppydiskette