Compare commits
No commits in common. "3a76e62ba9e266f5928ab181f0739d8e56668c87" and "28ba2699a379800222af1a501946f710d0f4e3af" have entirely different histories.
3a76e62ba9
...
28ba2699a3
4 changed files with 3 additions and 59 deletions
|
@ -1,10 +1,4 @@
|
|||
<?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 timeout(GuildSlashEvent event,
|
||||
public void mute(GuildSlashEvent event,
|
||||
@AppOption(name = "member") Member member,
|
||||
@AppOption(name = "duration", description = "ex: 2h5m, must be between 1m and 7d") String duration) {
|
||||
@AppOption(name = "duration", description = "ex: 2h5m, must be between 1h and 7d") String duration) {
|
||||
Duration timeoutDuration = DurationUtils.parseDuration(duration);
|
||||
member.timeoutFor(timeoutDuration).queue();
|
||||
event.replyFormat("Timed out %s for %s", member.getAsMention(), duration).queue();
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
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,8 +28,6 @@ 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…
Reference in a new issue