use of toby.helpers.URLHelper in project toby-bot by ml404.
the class IntroSongCommand method handle.
@Override
public void handle(CommandContext ctx, String prefix, UserDto requestingUserDto, Integer deleteDelay) {
ICommand.deleteAfter(ctx.getMessage(), deleteDelay);
String volumePropertyName = ConfigDto.Configurations.VOLUME.getConfigValue();
String defaultVolume = configService.getConfigByName(volumePropertyName, ctx.getGuild().getId()).getValue();
String vol = ctx.getArgs().stream().filter(s -> s.matches("\\d+")).findFirst().orElse(defaultVolume);
int introVolume = Integer.parseInt(vol);
if (introVolume < 1)
introVolume = 1;
if (introVolume > 100)
introVolume = 100;
final TextChannel channel = ctx.getChannel();
if (!requestingUserDto.isSuperUser() && ctx.getMessage().getMentionedMembers().size() > 0) {
sendErrorMessage(ctx, channel, deleteDelay);
return;
}
List<Message.Attachment> attachments = ctx.getMessage().getAttachments();
List<URI> urlList = ctx.getArgs().stream().map(URLHelper::isValidURL).filter(Objects::nonNull).findFirst().stream().collect(Collectors.toList());
if (attachments.isEmpty() && urlList.isEmpty()) {
channel.sendMessage(getHelp(prefix)).queue(message -> ICommand.deleteAfter(message, deleteDelay));
} else if (attachments.isEmpty()) {
setIntroViaUrl(ctx, requestingUserDto, deleteDelay, channel, urlList, introVolume);
} else {
setIntroViaDiscordAttachment(ctx, requestingUserDto, deleteDelay, channel, attachments, introVolume);
}
}
Aggregations