package org.royaldev.thehumanity.commands.impl.ping.subcommands;
import org.jetbrains.annotations.NotNull;
import org.kitteh.irc.client.library.element.User;
import org.kitteh.irc.client.library.event.channel.ChannelMessageEvent;
import org.royaldev.thehumanity.TheHumanity;
import org.royaldev.thehumanity.commands.impl.ping.PingListSubcommand;
import org.royaldev.thehumanity.ping.PingRegistration;
import org.royaldev.thehumanity.ping.PingRegistry;
import xyz.cardstock.cardstock.commands.CallInfo;
import xyz.cardstock.cardstock.commands.Command;
import java.util.List;
import java.util.Optional;
@Command(
name = "add",
description = "Adds yourself to the registry.",
aliases = {"a", "register"}
)
public class AddSubcommand extends PingListSubcommand {
private final TheHumanity humanity;
public AddSubcommand(final TheHumanity humanity) {
this.humanity = humanity;
}
@Override
public void onSubcommand(@NotNull final ChannelMessageEvent event, @NotNull final CallInfo ci, @NotNull final List<String> args) {
final User u = event.getActor();
final Optional<String> account = u.getAccount();
if (!account.isPresent()) {
u.sendNotice("You must be registered with services to use this command.");
return;
}
final PingRegistry pr = this.humanity.getPingRegistry();
if (pr.hasRegistration(account.get())) {
u.sendNotice("You already have a registration.");
return;
}
final PingRegistration registration = pr.addRegistration(account.get());
u.sendNotice("Registration added for services account " + registration.getServicesAccount() + ".");
}
}