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