Search in sources :

Example 21 with UserDto

use of toby.jpa.dto.UserDto in project toby-bot by ml404.

the class UserPersistenceImpl method updateUser.

@Override
public UserDto updateUser(UserDto userDto) {
    UserDto dbUser = getUserById(userDto.getDiscordId(), userDto.getGuildId());
    MusicDto musicFileById = musicFileService.getMusicFileById(userDto.getMusicDto().getId());
    MusicDto requestMusicDto = dbUser.getMusicDto();
    if (!requestMusicDto.equals(musicFileById)) {
        musicFileService.updateMusicFile(requestMusicDto);
    }
    if (!userDto.equals(dbUser)) {
        em.merge(userDto);
        em.flush();
    }
    return userDto;
}
Also used : UserDto(toby.jpa.dto.UserDto) MusicDto(toby.jpa.dto.MusicDto)

Example 22 with UserDto

use of toby.jpa.dto.UserDto in project toby-bot by ml404.

the class MoveCommand method handle.

@Override
public void handle(CommandContext ctx, String prefix, UserDto requestingUserDto, Integer deleteDelay) {
    ICommand.deleteAfter(ctx.getMessage(), deleteDelay);
    final TextChannel channel = ctx.getChannel();
    final Message message = ctx.getMessage();
    final Member member = ctx.getMember();
    final List<String> args = ctx.getArgs();
    Guild guild = ctx.getGuild();
    if (message.getMentionedMembers().isEmpty()) {
        channel.sendMessage("You must mention 1 or more Users to move").queue(message1 -> ICommand.deleteAfter(message1, deleteDelay));
        return;
    }
    List<String> prefixlessList = args.stream().filter(s -> !s.matches(Message.MentionType.USER.getPattern().pattern())).collect(Collectors.toList());
    String channelName = String.join(" ", prefixlessList);
    ConfigDto channelConfig = configService.getConfigByName("DEFAULT_MOVE_CHANNEL", guild.getId());
    Optional<VoiceChannel> voiceChannelOptional = (!channelName.isBlank()) ? guild.getVoiceChannelsByName(channelName, true).stream().findFirst() : guild.getVoiceChannelsByName(channelConfig.getValue(), true).stream().findFirst();
    if (!voiceChannelOptional.isPresent()) {
        channel.sendMessageFormat("Could not find a channel on the server that matched name '%s'", channelName).queue(message1 -> ICommand.deleteAfter(message1, deleteDelay));
        return;
    }
    message.getMentionedMembers().forEach(target -> {
        if (doChannelValidation(ctx, channel, member, target, deleteDelay))
            return;
        VoiceChannel voiceChannel = voiceChannelOptional.get();
        guild.moveVoiceMember(target, voiceChannel).queue((__) -> channel.sendMessageFormat("Moved %s to '%s'", target.getEffectiveName(), voiceChannel.getName()).queue(message1 -> ICommand.deleteAfter(message1, deleteDelay)), (error) -> channel.sendMessageFormat("Could not move '%s'", error.getMessage()).queue(message1 -> ICommand.deleteAfter(message1, deleteDelay)));
    });
}
Also used : CommandContext(toby.command.CommandContext) net.dv8tion.jda.api.entities(net.dv8tion.jda.api.entities) IConfigService(toby.jpa.service.IConfigService) List(java.util.List) ConfigDto(toby.jpa.dto.ConfigDto) UserDto(toby.jpa.dto.UserDto) ICommand(toby.command.ICommand) Permission(net.dv8tion.jda.api.Permission) Optional(java.util.Optional) Collectors(java.util.stream.Collectors) ConfigDto(toby.jpa.dto.ConfigDto)

Example 23 with UserDto

use of toby.jpa.dto.UserDto in project toby-bot by ml404.

the class HelloThereCommand method handle.

@Override
public void handle(CommandContext ctx, String prefix, UserDto requestingUserDto, Integer deleteDelay) {
    ICommand.deleteAfter(ctx.getMessage(), deleteDelay);
    TextChannel channel = ctx.getChannel();
    List<String> args = ctx.getArgs();
    String dateformat = configService.getConfigByName("DATEFORMAT", ctx.getGuild().getId()).getValue();
    DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(dateformat);
    LocalDate EP3Date = LocalDate.parse("2005/05/19", dateTimeFormatter);
    if (args.size() == 0) {
        channel.sendMessage(getHelp(prefix)).queue();
    } else
        try {
            LocalDate dateGiven = LocalDate.parse(args.get(0), dateTimeFormatter);
            if (dateGiven.isBefore(EP3Date)) {
                channel.sendMessage("Hello.").queue(message -> ICommand.deleteAfter(message, deleteDelay));
            } else {
                channel.sendMessage("General Kenobi.").queue(message -> ICommand.deleteAfter(message, deleteDelay));
            }
        } catch (DateTimeParseException e) {
            channel.sendMessage(String.format("I don't recognise the format of the date you gave me, please use this format %s", dateformat)).queue(message -> ICommand.deleteAfter(message, deleteDelay));
        }
}
Also used : CommandContext(toby.command.CommandContext) IConfigService(toby.jpa.service.IConfigService) DateTimeParseException(java.time.format.DateTimeParseException) List(java.util.List) UserDto(toby.jpa.dto.UserDto) ICommand(toby.command.ICommand) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) TextChannel(net.dv8tion.jda.api.entities.TextChannel) DateTimeParseException(java.time.format.DateTimeParseException) TextChannel(net.dv8tion.jda.api.entities.TextChannel) DateTimeFormatter(java.time.format.DateTimeFormatter) LocalDate(java.time.LocalDate)

Example 24 with UserDto

use of toby.jpa.dto.UserDto 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));
}
Also used : CommandContext(toby.command.CommandContext) Consumer(java.util.function.Consumer) Arrays(java.util.Arrays) List(java.util.List) UserDto(toby.jpa.dto.UserDto) ICommand(toby.command.ICommand) CommandManager(toby.managers.CommandManager) TextChannel(net.dv8tion.jda.api.entities.TextChannel) TextChannel(net.dv8tion.jda.api.entities.TextChannel) ICommand(toby.command.ICommand)

Example 25 with UserDto

use of toby.jpa.dto.UserDto in project toby-bot by ml404.

the class UserInfoCommand method printUserInfo.

private void printUserInfo(TextChannel channel, Message message, UserDto requestingUserDto, Integer deleteDelay) {
    if (message.getMentionedMembers().isEmpty()) {
        if (requestingUserDto != null) {
            channel.sendMessage(String.format("Here are your permissions: '%s'.", requestingUserDto)).queue(message1 -> ICommand.deleteAfter(message1, deleteDelay));
            MusicDto musicDto = requestingUserDto.getMusicDto();
            if (musicDto != null) {
                if (musicDto.getFileName() == null || musicDto.getFileName().isBlank()) {
                    channel.sendMessage("There is no intro music file associated with your user.").queue(message1 -> ICommand.deleteAfter(message1, deleteDelay));
                } else if (musicDto.getFileName() != null) {
                    channel.sendMessage(String.format("Your intro song is currently set as: '%s'.", musicDto.getFileName())).queue(message1 -> ICommand.deleteAfter(message1, deleteDelay));
                }
            } else
                channel.sendMessage("I was unable to retrieve your music file.").queue(message1 -> ICommand.deleteAfter(message1, deleteDelay));
        }
    } else {
        if (requestingUserDto.isSuperUser()) {
            message.getMentionedMembers().forEach(member -> {
                UserDto mentionedUser = userService.getUserById(member.getIdLong(), member.getGuild().getIdLong());
                channel.sendMessageFormat("Here are the permissions for '%s': '%s'.", member.getEffectiveName(), mentionedUser).queue(message1 -> ICommand.deleteAfter(message1, deleteDelay));
                MusicDto musicDto = mentionedUser.getMusicDto();
                if (musicDto != null) {
                    if (musicDto.getFileName() == null || musicDto.getFileName().isBlank()) {
                        channel.sendMessageFormat("There is no intro music file associated with '%s'.", member.getEffectiveName()).queue(message1 -> ICommand.deleteAfter(message1, deleteDelay));
                    } else if (musicDto.getFileName() != null) {
                        channel.sendMessage(String.format("Their intro song is currently set as: '%s'.", musicDto.getFileName())).queue(message1 -> ICommand.deleteAfter(message1, deleteDelay));
                    }
                } else
                    channel.sendMessageFormat("I was unable to retrieve an associated music file for '%s'.", member.getNickname()).queue(message1 -> ICommand.deleteAfter(message1, deleteDelay));
            });
        } else
            channel.sendMessage("You do not have permission to view user permissions, if this is a mistake talk to the server owner").queue();
    }
}
Also used : Message(net.dv8tion.jda.api.entities.Message) CommandContext(toby.command.CommandContext) Arrays(java.util.Arrays) List(java.util.List) UserDto(toby.jpa.dto.UserDto) ICommand(toby.command.ICommand) TextChannel(net.dv8tion.jda.api.entities.TextChannel) IUserService(toby.jpa.service.IUserService) MusicDto(toby.jpa.dto.MusicDto) UserDto(toby.jpa.dto.UserDto) MusicDto(toby.jpa.dto.MusicDto)

Aggregations

UserDto (toby.jpa.dto.UserDto)27 CommandContext (toby.command.CommandContext)16 ICommand (toby.command.ICommand)16 List (java.util.List)15 TextChannel (net.dv8tion.jda.api.entities.TextChannel)14 Arrays (java.util.Arrays)10 MusicDto (toby.jpa.dto.MusicDto)9 Collectors (java.util.stream.Collectors)8 Message (net.dv8tion.jda.api.entities.Message)8 Member (net.dv8tion.jda.api.entities.Member)6 IUserService (toby.jpa.service.IUserService)6 IOException (java.io.IOException)4 Test (org.junit.jupiter.api.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 UserDtoHelper.calculateUserDto (toby.helpers.UserDtoHelper.calculateUserDto)4 ConfigDto (toby.jpa.dto.ConfigDto)4 IConfigService (toby.jpa.service.IConfigService)4 Objects (java.util.Objects)3 Optional (java.util.Optional)3 Random (java.util.Random)3