use of toby.jpa.dto.UserDto in project toby-bot by ml404.
the class ExcuseCommand method approvePendingExcuse.
private void approvePendingExcuse(CommandContext ctx, UserDto requestingUserDto, TextChannel channel, String pendingExcuse, Integer deleteDelay) {
if (requestingUserDto.isSuperUser()) {
String excuseId = pendingExcuse.split(" ", 3)[2];
ExcuseDto excuseById = excuseService.getExcuseById(Integer.parseInt(excuseId));
if (!excuseById.isApproved()) {
excuseById.setApproved(true);
excuseService.updateExcuse(excuseById);
channel.sendMessage(String.format("Approved excuse '%s'.", excuseById.getExcuse())).queue(message -> ICommand.deleteAfter(message, deleteDelay));
} else
channel.sendMessage("I've heard that excuse before, keep up.").queue(message -> ICommand.deleteAfter(message, deleteDelay));
} else
sendErrorMessage(ctx, channel, deleteDelay);
}
use of toby.jpa.dto.UserDto in project toby-bot by ml404.
the class RollCommand 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();
Random rand = ThreadLocalRandom.current();
String rollValue = (!args.isEmpty()) ? args.get(0) : "";
int diceRoll = !rollValue.isEmpty() ? Integer.parseInt(rollValue) : 6;
// This results in 1 - 6 (instead of 0 - 5) for default value
int roll = rand.nextInt(diceRoll) + 1;
channel.sendMessage("Your roll: " + roll).flatMap((v) -> roll <= (diceRoll / 2), // Send another message if the roll was bad (less than half top value)
sentMessage -> channel.sendMessage("...shit be cool\n")).queue(message -> ICommand.deleteAfter(message, deleteDelay));
}
use of toby.jpa.dto.UserDto in project toby-bot by ml404.
the class AdjustUserCommand 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();
Message message = ctx.getMessage();
final Member member = ctx.getMember();
List<Member> mentionedMembers = channelAndArgumentValidation(prefix, requestingUserDto, args, channel, message, member, deleteDelay);
if (mentionedMembers == null)
return;
mentionedMembers.forEach(targetMember -> {
UserDto targetUserDto = userService.getUserById(targetMember.getIdLong(), targetMember.getGuild().getIdLong());
// Check to see if the database contained an entry for the user we have made a request against
if (targetUserDto != null) {
boolean isSameGuild = requestingUserDto.getGuildId().equals(targetUserDto.getGuildId());
boolean requesterCanAdjustPermissions = userAdjustmentValidation(requestingUserDto, targetUserDto) || member.isOwner();
if (requesterCanAdjustPermissions && isSameGuild) {
validateArgumentsAndUpdateUser(channel, targetUserDto, args, member.isOwner(), deleteDelay);
channel.sendMessageFormat("Updated user %s's permissions", targetMember.getNickname()).queue(message1 -> ICommand.deleteAfter(message1, deleteDelay));
} else
channel.sendMessageFormat("User '%s' is not allowed to adjust the permissions of user '%s'.", member.getNickname(), targetMember.getNickname()).queue(message1 -> ICommand.deleteAfter(message1, deleteDelay));
} else {
createNewUser(channel, targetMember, deleteDelay);
}
});
}
use of toby.jpa.dto.UserDto in project toby-bot by ml404.
the class UserPersistenceImpl method getUserById.
@Override
public UserDto getUserById(Long discordId, Long guildId) {
Query userQuery = em.createNamedQuery("UserDto.getById", UserDto.class);
userQuery.setParameter("discordId", discordId);
userQuery.setParameter("guildId", guildId);
return (UserDto) userQuery.getSingleResult();
}
use of toby.jpa.dto.UserDto 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");
}
}
Aggregations