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");
}
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();
});
}
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();
}
});
}
Aggregations