Search in sources :

Example 6 with UserDto

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

the class IntroSongCommand method setIntroViaUrl.

private void setIntroViaUrl(CommandContext ctx, UserDto requestingUserDto, Integer deleteDelay, TextChannel channel, List<URI> urlList, int introVolume) {
    List<Member> mentionedMembers = ctx.getMessage().getMentionedMembers();
    String url = urlList.get(0).toString();
    if (mentionedMembers.size() > 0 && requestingUserDto.isSuperUser()) {
        mentionedMembers.forEach(member -> {
            UserDto userDto = calculateUserDto(member.getGuild().getIdLong(), member.getIdLong(), member.isOwner(), userService, introVolume);
            persistMusicUrl(userDto, deleteDelay, channel, url, url, member.getEffectiveName(), introVolume);
        });
    } else
        persistMusicUrl(requestingUserDto, deleteDelay, channel, url, url, ctx.getAuthor().getName(), introVolume);
}
Also used : UserDto(toby.jpa.dto.UserDto) UserDtoHelper.calculateUserDto(toby.helpers.UserDtoHelper.calculateUserDto) Member(net.dv8tion.jda.api.entities.Member)

Example 7 with UserDto

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

the class UserDtoHelper method calculateUserDto.

public static UserDto calculateUserDto(long guildId, long discordId, boolean isSuperUser, IUserService userService, int introVolume) {
    Optional<UserDto> dbUserDto = userService.listGuildUsers(guildId).stream().filter(userDto -> userDto.getGuildId().equals(guildId) && userDto.getDiscordId().equals(discordId)).findFirst();
    if (dbUserDto.isEmpty()) {
        UserDto userDto = new UserDto();
        userDto.setDiscordId(discordId);
        userDto.setGuildId(guildId);
        userDto.setSuperUser(isSuperUser);
        MusicDto musicDto = new MusicDto(userDto.getDiscordId(), userDto.getGuildId(), null, introVolume, null);
        userDto.setMusicDto(musicDto);
        return userService.createNewUser(userDto);
    }
    return userService.getUserById(discordId, guildId);
}
Also used : UserDto(toby.jpa.dto.UserDto) Optional(java.util.Optional) IUserService(toby.jpa.service.IUserService) MusicDto(toby.jpa.dto.MusicDto) UserDto(toby.jpa.dto.UserDto) MusicDto(toby.jpa.dto.MusicDto)

Example 8 with UserDto

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

the class DbdRandomKillerCommand method handle.

@Override
@SuppressWarnings("unchecked")
public void handle(CommandContext ctx, String prefix, UserDto requestingUserDto, Integer deleteDelay) {
    ICommand.deleteAfter(ctx.getMessage(), deleteDelay);
    final TextChannel channel = ctx.getChannel();
    try {
        WikiFetcher wikiFetcher = new WikiFetcher(cache);
        List<String> dbdKillers = wikiFetcher.fetchFromWiki(cacheName, dbdWebUrl, className, cssQuery);
        channel.sendMessage(RandomCommand.getRandomElement(dbdKillers)).queue(message -> ICommand.deleteAfter(message, deleteDelay));
    } catch (IOException ignored) {
        channel.sendMessage("Huh, the website I pull data from must have returned something unexpected.").queue(message -> ICommand.deleteAfter(message, deleteDelay));
    }
}
Also used : CommandContext(toby.command.CommandContext) WikiFetcher(toby.helpers.WikiFetcher) Arrays(java.util.Arrays) List(java.util.List) UserDto(toby.jpa.dto.UserDto) ICommand(toby.command.ICommand) Cache(toby.helpers.Cache) IOException(java.io.IOException) TextChannel(net.dv8tion.jda.api.entities.TextChannel) RandomCommand(toby.command.commands.misc.RandomCommand) TextChannel(net.dv8tion.jda.api.entities.TextChannel) WikiFetcher(toby.helpers.WikiFetcher) IOException(java.io.IOException)

Example 9 with UserDto

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

the class MemeCommand method handle.

@Override
public void handle(CommandContext ctx, String prefix, UserDto requestingUserDto, Integer deleteDelay) {
    ICommand.deleteAfter(ctx.getMessage(), deleteDelay);
    Gson gson = new Gson();
    final TextChannel channel = ctx.getChannel();
    List<String> args = ctx.getArgs();
    User member = ctx.getAuthor();
    if (!requestingUserDto.hasMemePermission()) {
        channel.sendMessageFormat("You do not have adequate permissions to use this command, talk to the server owner: %s", ctx.getGuild().getOwner().getNickname()).queue(message -> ICommand.deleteAfter(message, deleteDelay));
        return;
    }
    if (args.size() == 0) {
        channel.sendMessage(getHelp(prefix)).queue();
    } else {
        String subredditArg = args.get(0);
        String timePeriod;
        int limit;
        try {
            timePeriod = RedditAPIDto.TimePeriod.valueOf(args.get(1).toUpperCase()).toString().toLowerCase();
        } catch (IndexOutOfBoundsException e) {
            timePeriod = "day";
        } catch (IllegalArgumentException e) {
            timePeriod = "day";
            channel.sendMessage(String.format("You entered a time period not supported: **%s**\\. Please use one of: %s \n", args.get(1), Arrays.stream(RedditAPIDto.TimePeriod.values()).map(Enum::name).map(String::toLowerCase).collect(Collectors.joining("/"))) + String.format("Using default time period of %s", timePeriod)).queue(message -> ICommand.deleteAfter(message, deleteDelay));
        }
        try {
            limit = Integer.parseInt(args.get(2));
        } catch (IndexOutOfBoundsException e) {
            limit = 5;
        } catch (NumberFormatException e) {
            limit = 5;
            channel.sendMessage(String.format("Invalid number supplied, using default value %d", limit)).queue(message -> ICommand.deleteAfter(message, deleteDelay));
        }
        if (subredditArg.equals("sneakybackgroundfeet")) {
            channel.sendMessage("Don't talk to me.").queue(message -> ICommand.deleteAfter(message, deleteDelay));
        } else {
            WebUtils.ins.getJSONObject(String.format(RedditAPIDto.redditPrefix, subredditArg, limit, timePeriod)).async((json) -> {
                if ((json.get("data").get("dist").asInt() == 0)) {
                    channel.sendMessage(String.format("I think you typo'd the subreddit: '%s', I couldn't get anything from the reddit API", subredditArg)).queue(message -> ICommand.deleteAfter(message, deleteDelay));
                    return;
                }
                final JsonNode parentData = json.get("data");
                final JsonNode children = parentData.get("children");
                Random random = new Random();
                JsonNode meme = children.get(random.nextInt(children.size()));
                RedditAPIDto redditAPIDto = gson.fromJson(meme.get("data").toString(), RedditAPIDto.class);
                if (redditAPIDto.isNsfw()) {
                    channel.sendMessage(String.format("I received a NSFW subreddit from %s, or reddit gave me a NSFW meme, either way somebody shoot that guy", member)).queue(message -> ICommand.deleteAfter(message, deleteDelay));
                } else if (redditAPIDto.getVideo()) {
                    channel.sendMessage("I pulled back a video, whoops. Try again maybe? Or not, up to you.").queue(message -> ICommand.deleteAfter(message, deleteDelay));
                } else {
                    String title = redditAPIDto.getTitle();
                    String url = redditAPIDto.getUrl();
                    String image = redditAPIDto.getImage();
                    EmbedBuilder embed = EmbedUtils.embedImageWithTitle(title, String.format(RedditAPIDto.commentsPrefix, url), image);
                    embed.addField("Subreddit", subredditArg, false);
                    channel.sendMessage(embed.build()).queue();
                }
            });
        }
    }
}
Also used : CommandContext(toby.command.CommandContext) EmbedUtils(me.duncte123.botcommons.messaging.EmbedUtils) Arrays(java.util.Arrays) UserDto(toby.jpa.dto.UserDto) Random(java.util.Random) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) TextChannel(net.dv8tion.jda.api.entities.TextChannel) Collectors(java.util.stream.Collectors) User(net.dv8tion.jda.api.entities.User) List(java.util.List) Gson(com.google.gson.Gson) ICommand(toby.command.ICommand) JsonNode(com.fasterxml.jackson.databind.JsonNode) RedditAPIDto(toby.dto.web.RedditAPIDto) WebUtils(me.duncte123.botcommons.web.WebUtils) User(net.dv8tion.jda.api.entities.User) Gson(com.google.gson.Gson) JsonNode(com.fasterxml.jackson.databind.JsonNode) RedditAPIDto(toby.dto.web.RedditAPIDto) TextChannel(net.dv8tion.jda.api.entities.TextChannel) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Random(java.util.Random)

Example 10 with UserDto

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

the class ChCommand 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();
    String newMessage = Arrays.stream(message.getContentRaw().split(" ")).map(s -> {
        if (s.equalsIgnoreCase(String.format("%sch", prefix))) {
            return "";
        } else {
            int vowelIndex = 0;
            for (int i = 0; i < s.length(); i++) {
                char c = s.charAt(i);
                if (isVowel(String.valueOf(c))) {
                    vowelIndex = i;
                    break;
                }
            }
            if (s.substring(vowelIndex).toLowerCase().startsWith("ink")) {
                return "gamerword";
            } else
                return "ch" + s.substring(vowelIndex).toLowerCase();
        }
    }).collect(Collectors.joining(" "));
    channel.sendMessage("Oh! I think you mean: '" + newMessage.stripLeading() + "'").queue(message1 -> ICommand.deleteAfter(message1, deleteDelay));
}
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) Collectors(java.util.stream.Collectors) TextChannel(net.dv8tion.jda.api.entities.TextChannel) Message(net.dv8tion.jda.api.entities.Message)

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