diff --git a/src/main/java/dev/logal/logalbot/Main.java b/src/main/java/dev/logal/logalbot/Main.java index 2cca058..e12197a 100644 --- a/src/main/java/dev/logal/logalbot/Main.java +++ b/src/main/java/dev/logal/logalbot/Main.java @@ -89,6 +89,10 @@ public final class Main { CommandManager.registerCommand("help", new Help(), false); // Fun Commands + CommandManager.registerCommand("dice", new Dice(), false); + CommandManager.registerCommandAlias("die", "dice"); + CommandManager.registerCommandAlias("random", "dice"); + CommandManager.registerCommandAlias("rng", "dice"); CommandManager.registerCommand("8ball", new EightBall(), false); // Audio Commands diff --git a/src/main/java/dev/logal/logalbot/commands/fun/Dice.java b/src/main/java/dev/logal/logalbot/commands/fun/Dice.java new file mode 100644 index 0000000..f9a8b83 --- /dev/null +++ b/src/main/java/dev/logal/logalbot/commands/fun/Dice.java @@ -0,0 +1,47 @@ +package dev.logal.logalbot.commands.fun; + +// Copyright 2019 Logan Fick + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// https://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import java.security.SecureRandom; +import java.util.concurrent.TimeUnit; + +import dev.logal.logalbot.commands.Command; +import dev.logal.logalbot.commands.CommandResponse; +import net.dv8tion.jda.core.entities.Member; +import net.dv8tion.jda.core.entities.TextChannel; + +public final class Dice implements Command { + private final SecureRandom rng = new SecureRandom(); + + @Override + public CommandResponse execute(String[] arguments, Member executor, TextChannel channel) { + if (arguments.length == 0) { + return new CommandResponse("game_die", + executor.getAsMention() + ", the dice rolled **" + (rng.nextInt(6) + 1) + "**."); + } else { + final int maximumRange; + try { + maximumRange = Integer.parseInt(arguments[0]); + } catch (final NumberFormatException exception) { + return new CommandResponse("x", + "Sorry " + executor.getAsMention() + ", but the maximum range must be an integer.") + .setDeletionDelay(30, TimeUnit.SECONDS); + } + + return new CommandResponse("game_die", + executor.getAsMention() + ", the dice rolled **" + (rng.nextInt(maximumRange) + 1) + "**."); + } + } +} \ No newline at end of file