use of toby.command.ICommand in project toby-bot by ml404.
the class CommandManager method handle.
public void handle(GuildMessageReceivedEvent event) {
String prefix = configService.getConfigByName(ConfigDto.Configurations.PREFIX.getConfigValue(), event.getGuild().getId()).getValue();
Integer deleteDelay = Integer.parseInt(configService.getConfigByName(ConfigDto.Configurations.DELETE_DELAY.getConfigValue(), event.getGuild().getId()).getValue());
String[] split = event.getMessage().getContentRaw().replaceFirst("(?i)" + Pattern.quote(prefix), "").split("\\s+");
String volumePropertyName = ConfigDto.Configurations.VOLUME.getConfigValue();
String defaultVolume = configService.getConfigByName(volumePropertyName, event.getGuild().getId()).getValue();
int introVolume = Integer.parseInt(defaultVolume);
UserDto requestingUserDto = calculateUserDto(event.getGuild().getIdLong(), event.getAuthor().getIdLong(), Objects.requireNonNull(event.getMember()).isOwner(), userService, introVolume);
String invoke = split[0].toLowerCase();
ICommand cmd = this.getCommand(invoke);
if (cmd != null) {
event.getChannel().sendTyping().queue();
List<String> args = Arrays.asList(split).subList(1, split.length);
CommandContext ctx = new CommandContext(event, args);
cmd.handle(ctx, prefix, requestingUserDto, deleteDelay);
} else {
getCommand("help");
}
}
use of toby.command.ICommand in project toby-bot by ml404.
the class CommandManagerTest method testCommandManagerFindsAllCommands.
@Test
public void testCommandManagerFindsAllCommands() {
CommandManager commandManager = new CommandManager(configService, brotherService, userService, musicFileService, excuseService, waiter);
List<Class<? extends ICommand>> availableCommands = Arrays.asList(HelpCommand.class, SetConfigCommand.class, KickCommand.class, MoveCommand.class, RollCommand.class, MemeCommand.class, HelloThereCommand.class, BrotherCommand.class, ChCommand.class, ShhCommand.class, TalkCommand.class, PollCommand.class, JoinCommand.class, LeaveCommand.class, PlayCommand.class, NowDigOnThisCommand.class, SetVolumeCommand.class, PauseCommand.class, ResumeCommand.class, LoopCommand.class, StopCommand.class, SkipCommand.class, NowPlayingCommand.class, QueueCommand.class, ShuffleCommand.class, AdjustUserCommand.class, IntroSongCommand.class, EventWaiterCommand.class, UserInfoCommand.class, RandomCommand.class, Kf2RandomMapCommand.class, DbdRandomKillerCommand.class, ExcuseCommand.class, SocialCreditCommand.class);
assertTrue(availableCommands.containsAll(commandManager.getAllCommands().stream().map(ICommand::getClass).collect(Collectors.toList())));
assertEquals(34, commandManager.getAllCommands().size());
}
use of toby.command.ICommand in project toby-bot by ml404.
the class HelpCommand method handle.
@Override
public void handle(CommandContext ctx, String prefix, UserDto requestingUserDto, Integer deleteDelay) {
ICommand.deleteAfter(ctx.getMessage(), deleteDelay);
List<String> args = ctx.getArgs();
TextChannel channel = ctx.getChannel();
if (args.isEmpty()) {
StringBuilder builder = new StringBuilder();
Consumer<ICommand> commandConsumer = (command) -> builder.append('`').append(prefix).append(command.getName()).append('`').append(String.format(" Aliases are: '%s'", String.join(",", command.getAliases()))).append("\n");
builder.append(String.format("List of all current commands below. If you want to find out how to use one of the commands try doing `%shelp commandName`\n", prefix));
builder.append("**Music Commands**:\n");
manager.getMusicCommands().forEach(commandConsumer);
builder.append("**Miscellaneous Commands**:\n");
manager.getMiscCommands().forEach(commandConsumer);
builder.append("**Moderation Commands**:\n");
manager.getModerationCommands().forEach(commandConsumer);
builder.append("**Fetch Commands**:\n");
manager.getFetchCommands().forEach(commandConsumer);
channel.sendMessage(builder.toString()).queue(message -> ICommand.deleteAfter(message, deleteDelay));
return;
}
String search = args.get(0);
ICommand command = manager.getCommand(search);
if (command == null) {
channel.sendMessage("Nothing found for " + search).queue(message -> ICommand.deleteAfter(message, deleteDelay));
return;
}
channel.sendMessage(command.getHelp(prefix)).queue(message -> ICommand.deleteAfter(message, deleteDelay));
}
Aggregations