Search in sources :

Example 1 with CommandPermission

use of net.kodehawa.mantarobot.core.modules.commands.base.CommandPermission in project MantaroBot by Mantaro.

the class OwnerCmd method owner.

@Subscribe
public void owner(CommandRegistry cr) {
    cr.register("owner", new SimpleCommand(Category.OWNER) {

        @Override
        public CommandPermission permission() {
            return CommandPermission.OWNER;
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Owner command").setDescription("`~>owner premium add <id> <days>` - Adds premium to the specified user for x days.").build();
        }

        @Override
        public void call(GuildMessageReceivedEvent event, String content, String[] args) {
            if (args.length < 1) {
                onHelp(event);
                return;
            }
            String option = args[0];
            if (option.equals("premium")) {
                String sub = args[1].substring(0, args[1].indexOf(' '));
                if (sub.equals("add")) {
                    try {
                        String userId;
                        String[] values = SPLIT_PATTERN.split(args[1], 3);
                        try {
                            Long.parseLong(values[1]);
                            userId = values[1];
                        } catch (Exception e) {
                            if (!event.getMessage().getMentionedUsers().isEmpty()) {
                                userId = event.getMessage().getMentionedUsers().get(0).getId();
                                return;
                            } else {
                                event.getChannel().sendMessage(EmoteReference.ERROR + "Not a valid user id").queue();
                                return;
                            }
                        }
                        DBUser db = MantaroData.db().getUser(userId);
                        db.incrementPremium(TimeUnit.DAYS.toMillis(Long.parseLong(values[2])));
                        db.saveAsync();
                        event.getChannel().sendMessage(EmoteReference.CORRECT + "The premium feature for user " + db.getId() + " now is until " + new Date(db.getPremiumUntil())).queue();
                        return;
                    } catch (IndexOutOfBoundsException e) {
                        event.getChannel().sendMessage(EmoteReference.ERROR + "You need to specify id and number of days").queue();
                        e.printStackTrace();
                        return;
                    }
                }
                if (sub.equals("guild")) {
                    try {
                        String[] values = SPLIT_PATTERN.split(args[1], 3);
                        DBGuild db = MantaroData.db().getGuild(values[1]);
                        db.incrementPremium(TimeUnit.DAYS.toMillis(Long.parseLong(values[2])));
                        db.saveAsync();
                        event.getChannel().sendMessage(EmoteReference.CORRECT + "The premium feature for guild " + db.getId() + " now is until " + new Date(db.getPremiumUntil())).queue();
                        return;
                    } catch (IndexOutOfBoundsException e) {
                        event.getChannel().sendMessage(EmoteReference.ERROR + "You need to specify id and number of days").queue();
                        e.printStackTrace();
                        return;
                    }
                }
            }
            onHelp(event);
        }

        @Override
        public String[] splitArgs(String content) {
            return SPLIT_PATTERN.split(content, 2);
        }
    });
}
Also used : MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) DBUser(net.kodehawa.mantarobot.db.entities.DBUser) CommandPermission(net.kodehawa.mantarobot.core.modules.commands.base.CommandPermission) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) CompilationException(com.github.natanbc.javaeval.CompilationException) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

CompilationException (com.github.natanbc.javaeval.CompilationException)1 Subscribe (com.google.common.eventbus.Subscribe)1 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)1 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)1 SimpleCommand (net.kodehawa.mantarobot.core.modules.commands.SimpleCommand)1 CommandPermission (net.kodehawa.mantarobot.core.modules.commands.base.CommandPermission)1 DBGuild (net.kodehawa.mantarobot.db.entities.DBGuild)1 DBUser (net.kodehawa.mantarobot.db.entities.DBUser)1