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