Search in sources :

Example 11 with Command

use of net.kodehawa.mantarobot.modules.Command in project MantaroBot by Mantaro.

the class CurrencyCmds method rep.

@Command
public static void rep(CommandRegistry cr) {
    cr.register("rep", new SimpleCommand(Category.CURRENCY) {

        RateLimiter rateLimiter = new RateLimiter(TimeUnit.HOURS, 12);

        @Override
        public void call(GuildMessageReceivedEvent event, String content, String[] args) {
            if (event.getMessage().getMentionedUsers().isEmpty()) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "You need to mention at least one user.").queue();
                return;
            }
            if (event.getMessage().getMentionedUsers().get(0).isBot()) {
                event.getChannel().sendMessage(EmoteReference.THINKING + "You cannot rep a bot.").queue();
                return;
            }
            if (event.getMessage().getMentionedUsers().get(0).equals(event.getAuthor())) {
                event.getChannel().sendMessage(EmoteReference.THINKING + "You cannot rep yourself.").queue();
                return;
            }
            if (event.getMessage().getMentionedUsers().isEmpty()) {
                event.getChannel().sendMessage(EmoteReference.THINKING + "You need to mention one user.").queue();
                return;
            }
            if (!rateLimiter.process(event.getMember())) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "You can only rep once every 12 hours.\n**You'll be able to use this command again in " + Utils.getVerboseTime(rateLimiter.tryAgainIn(event.getMember())) + ".**").queue();
                return;
            }
            User mentioned = event.getMessage().getMentionedUsers().get(0);
            Player player = MantaroData.db().getPlayer(event.getGuild().getMember(mentioned));
            player.addReputation(1L);
            player.saveAsync();
            event.getChannel().sendMessage(EmoteReference.CORRECT + "Added reputation to **" + mentioned.getName() + "**").queue();
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Reputation command").setDescription("**Reps an user**").addField("Usage", "`~>rep <@user>` - **Gives reputation to x user**", false).addField("Parameters", "`@user` - user to mention", false).addField("Important", "Only usable every 24 hours.", false).build();
        }
    });
    cr.registerAlias("rep", "reputation");
}
Also used : Player(net.kodehawa.mantarobot.data.entities.Player) DBUser(net.kodehawa.mantarobot.data.entities.DBUser) User(net.dv8tion.jda.core.entities.User) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) RateLimiter(net.kodehawa.mantarobot.commands.currency.RateLimiter) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Command(net.kodehawa.mantarobot.modules.Command)

Example 12 with Command

use of net.kodehawa.mantarobot.modules.Command in project MantaroBot by Mantaro.

the class ActionCmds method onPostLoad.

@Command
public static void onPostLoad(PostLoadEvent e) {
    OptsCmd.registerOption("actionmention:toggle", event -> {
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        boolean toggler = guildData.isNoMentionsAction();
        guildData.setNoMentionsAction(!toggler);
        event.getChannel().sendMessage(EmoteReference.CORRECT + "Set no action mentions in chat to " + "**" + !toggler + "**").queue();
        dbGuild.save();
    });
}
Also used : GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Command(net.kodehawa.mantarobot.modules.Command)

Example 13 with Command

use of net.kodehawa.mantarobot.modules.Command in project MantaroBot by Mantaro.

the class CustomCmds method onPostLoad.

@Command
public static void onPostLoad(PostLoadEvent e) {
    db().getCustomCommands().forEach(custom -> {
        if (!NAME_PATTERN.matcher(custom.getName()).matches()) {
            String newName = INVALID_CHARACTERS_PATTERN.matcher(custom.getName()).replaceAll("_");
            log.warn("Custom Command with Invalid Characters '%s' found. Replacing with '%'", custom.getName());
            custom.deleteAsync();
            custom = CustomCommand.of(custom.getGuildId(), newName, custom.getValues());
            custom.saveAsync();
        }
        if (CommandProcessor.REGISTRY.commands().containsKey(custom.getName()) && !CommandProcessor.REGISTRY.commands().get(custom.getName()).equals(customCommand)) {
            custom.deleteAsync();
            custom = CustomCommand.of(custom.getGuildId(), "_" + custom.getName(), custom.getValues());
            custom.saveAsync();
        }
        CommandProcessor.REGISTRY.commands().put(custom.getName(), customCommand);
        customCommands.put(custom.getId(), custom.getValues());
    });
    OptsCmd.registerOption("admincustom", (event, args) -> {
        if (args.length == 0) {
            OptsCmd.onHelp(event);
            return;
        }
        String action = args[0];
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        try {
            guildData.setCustomAdminLock(Boolean.parseBoolean(action));
            dbGuild.save();
            String toSend = EmoteReference.CORRECT + (Boolean.parseBoolean(action) ? "``Permission -> User command creation " + "is now admin only.``" : "``Permission -> User command creation can be done by anyone.``");
            event.getChannel().sendMessage(toSend).queue();
        } catch (Exception ex) {
            event.getChannel().sendMessage(EmoteReference.ERROR + "Silly, that's not a boolean value!").queue();
        }
    });
}
Also used : GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) CustomCommand(net.kodehawa.mantarobot.data.entities.CustomCommand) Command(net.kodehawa.mantarobot.modules.Command) AbstractCommand(net.kodehawa.mantarobot.modules.commands.base.AbstractCommand)

Aggregations

Command (net.kodehawa.mantarobot.modules.Command)13 SimpleCommand (net.kodehawa.mantarobot.modules.commands.SimpleCommand)13 DBGuild (net.kodehawa.mantarobot.data.entities.DBGuild)9 GuildData (net.kodehawa.mantarobot.data.entities.helpers.GuildData)9 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)8 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)5 MantaroData (net.kodehawa.mantarobot.data.MantaroData)5 CommandRegistry (net.kodehawa.mantarobot.modules.CommandRegistry)5 Module (net.kodehawa.mantarobot.modules.Module)5 Category (net.kodehawa.mantarobot.modules.commands.base.Category)5 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)5 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)4 TextChannelGround (net.kodehawa.mantarobot.commands.currency.TextChannelGround)4 PostLoadEvent (net.kodehawa.mantarobot.modules.events.PostLoadEvent)4 Utils (net.kodehawa.mantarobot.utils.Utils)4 Color (java.awt.Color)3 TimeUnit (java.util.concurrent.TimeUnit)3 Slf4j (lombok.extern.slf4j.Slf4j)3