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