Search in sources :

Example 1 with PollBuilder

use of net.kodehawa.mantarobot.commands.interaction.polls.PollBuilder in project MantaroBot by Mantaro.

the class MiscCmds method createPoll.

@Subscribe
public void createPoll(CommandRegistry registry) {
    registry.register("createpoll", new SimpleCommand(Category.MISC) {

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            Map<String, Optional<String>> opts = StringUtils.parse(args);
            PollBuilder builder = Poll.builder();
            if (!opts.containsKey("time") || !opts.get("time").isPresent()) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "You didn't include either the `-time` argument or it was empty!\n" + "Example: `~>poll -options \"hi there\",\"wew\",\"owo what's this\" -time 10m20s -name \"test poll\"").queue();
                return;
            }
            if (!opts.containsKey("options") || !opts.get("options").isPresent()) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "You didn't include either the `-options` argument or it was empty!\n" + "Example: ~>poll -options \"hi there\",\"wew\",\"owo what's this\" -time 10m20s -name \"test poll\"").queue();
                return;
            }
            if (!opts.containsKey("name") || !opts.get("name").isPresent()) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "You didn't include either the `-name` argument or it was empty!\n" + "Example: ~>poll -options \"hi there\",\"wew\",\"owo what's this\" -time 10m20s -name \"test poll\"").queue();
                return;
            }
            if (opts.containsKey("name") || opts.get("name").isPresent()) {
                builder.setName(opts.get("name").get().replaceAll(String.valueOf('"'), ""));
            }
            String[] options = opts.get("options").get().replaceAll(String.valueOf('"'), "").split(",");
            long timeout = Utils.parseTime(opts.get("time").get());
            builder.setEvent(event).setTimeout(timeout).setOptions(options).build().startPoll();
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Poll Command").setDescription("**Creates a poll**").addField("Usage", "`~>poll [-options <options>] [-time <time>] [-name <name>]`", false).addField("Parameters", "`-options` The options to add. Minimum is 2 and maximum is 9. For instance: `Pizza,Spaghetti,Pasta,\"Spiral Nudels\"` (Enclose options with multiple words in double quotes).\n" + "`-time` The time the operation is gonna take. The format is as follows `1m29s` for 1 minute and 21 seconds. Maximum poll runtime is 45 minutes.\n" + "`-name` The name of the poll for reference.", false).addField("Considerations", "To cancel the running poll type &cancelpoll. Only the person who started it or an Admin can cancel it.", false).addField("Example", "~>poll -options \"hi there\",\"wew\",\"owo what's this\" -time 10m20s -name \"test poll\"", false).build();
        }
    });
    registry.registerAlias("createpoll", "poll");
}
Also used : MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) PollBuilder(net.kodehawa.mantarobot.commands.interaction.polls.PollBuilder) Map(java.util.Map) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

Subscribe (com.google.common.eventbus.Subscribe)1 Map (java.util.Map)1 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)1 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)1 PollBuilder (net.kodehawa.mantarobot.commands.interaction.polls.PollBuilder)1 SimpleCommand (net.kodehawa.mantarobot.core.modules.commands.SimpleCommand)1