Search in sources :

Example 46 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel in project pokeraidbot by magnusmickelsson.

the class StartUpEventListener method attachToGroupMessage.

private boolean attachToGroupMessage(Guild guild, Config config, RaidGroup raidGroup) {
    MessageChannel channel = null;
    try {
        final List<TextChannel> textChannels = guild.getTextChannels();
        for (TextChannel textChannel : textChannels) {
            if (textChannel.getName().equalsIgnoreCase(raidGroup.getChannel())) {
                channel = textChannel;
                break;
            }
        }
        final Locale locale = config.getLocale();
        Raid raid = raidRepository.getById(raidGroup.getRaidId());
        final EmoticonSignUpMessageListener emoticonSignUpMessageListener = new EmoticonSignUpMessageListener(botService, localeService, serverConfigRepository, raidRepository, pokemonRepository, gymRepository, raid.getId(), raidGroup.getStartsAt(), raidGroup.getCreatorId());
        emoticonSignUpMessageListener.setEmoteMessageId(raidGroup.getEmoteMessageId());
        emoticonSignUpMessageListener.setInfoMessageId(raidGroup.getInfoMessageId());
        final int delayTime = raid.isExRaid() ? 1 : 15;
        final TimeUnit delayTimeUnit = raid.isExRaid() ? TimeUnit.MINUTES : TimeUnit.SECONDS;
        final Callable<Boolean> groupEditTask = NewRaidGroupCommand.getMessageRefreshingTaskToSchedule(channel, raid, emoticonSignUpMessageListener, raidGroup.getInfoMessageId(), locale, raidRepository, localeService, clockService, executorService, botService, delayTimeUnit, delayTime, raidGroup.getId());
        executorService.submit(groupEditTask);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Found group message for raid " + raid + " in channel " + (channel == null ? "N/A" : channel.getName()) + " (server " + guild.getName() + "). Attaching to it.");
        }
        return true;
    } catch (UserMessedUpException e) {
        if (channel != null)
            channel.sendMessage(e.getMessage()).queue(m -> {
                m.delete().queueAfter(BotServerMain.timeToRemoveFeedbackInSeconds, TimeUnit.SECONDS);
            });
    } catch (ErrorResponseException e) {
        // We couldn't find the message in this channel or had permission issues, ignore
        LOGGER.info("Caught exception during startup: " + e.getMessage());
        LOGGER.warn("Cleaning up raidgroup...");
        cleanUpRaidGroup(raidGroup);
        LOGGER.debug("Stacktrace:", e);
    } catch (Throwable e) {
        LOGGER.warn("Cleaning up raidgroup due to exception: " + e.getMessage());
        cleanUpRaidGroup(raidGroup);
    }
    return false;
}
Also used : Locale(java.util.Locale) Raid(pokeraidbot.domain.raid.Raid) TextChannel(net.dv8tion.jda.core.entities.TextChannel) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) EmoticonSignUpMessageListener(pokeraidbot.domain.raid.signup.EmoticonSignUpMessageListener) TimeUnit(java.util.concurrent.TimeUnit) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) ErrorResponseException(net.dv8tion.jda.core.exceptions.ErrorResponseException)

Example 47 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel in project Ardent by adamint.

the class TriviaGame method finish.

public void finish(Shard shard, Command command) throws Exception {
    totalRounds = 9001;
    final int bonus = 250;
    final int perQuestion = 50;
    Trivia.gamesInSession.remove(this);
    Trivia.gamesSettingUp.remove(guildId);
    Guild guild = shard.jda.getGuildById(guildId);
    TextChannel channel = guild.getTextChannelById(textChannelId);
    channel.sendMessage(displayScores(shard, command).build()).queue();
    channel.sendMessage("Thanks for playing! You'll receive **$50** for every correct answer").queue();
    Map<String, Integer> sorted = MapUtils.sortByValue(scores);
    Iterator<Map.Entry<String, Integer>> iterator = sorted.entrySet().iterator();
    int current = 0;
    while (iterator.hasNext()) {
        Map.Entry<String, Integer> entry = iterator.next();
        User user = guild.getMemberById(entry.getKey()).getUser();
        Profile profile = Profile.get(user);
        profile.addMoney(perQuestion * entry.getValue());
        if (current == 0 && !isSolo() && scores.size() > 1) {
            profile.addMoney(bonus);
            channel.sendMessage(user.getAsMention() + ", you won a **$250** bonus for being so smart!").queue();
        }
        current++;
    }
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) User(net.dv8tion.jda.core.entities.User) Guild(net.dv8tion.jda.core.entities.Guild) HashMap(java.util.HashMap) Map(java.util.Map) Profile(tk.ardentbot.utils.rpg.profiles.Profile)

Example 48 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel in project Ardent by adamint.

the class ArdentMusicManager method setChannel.

public void setChannel(MessageChannel channel) {
    assert channel != null;
    this.channel = channel.getId();
    MusicSettingsModel guildMusicSettings = BaseCommand.asPojo(r.db("data").table("music_settings").get(((TextChannel) channel).getGuild().getId()).run(connection), MusicSettingsModel.class);
    shouldAnnounce = !(guildMusicSettings == null || !guildMusicSettings.announce_music);
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) MusicSettingsModel(tk.ardentbot.rethink.models.MusicSettingsModel)

Example 49 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel in project MantaroBot by Mantaro.

the class ImageboardUtils method getImage.

public static void getImage(ImageBoard<?> api, ImageRequestType type, boolean nsfwOnly, String imageboard, String[] args, String content, GuildMessageReceivedEvent event) {
    Rating rating = Rating.SAFE;
    boolean needRating = args.length >= 3;
    final TextChannel channel = event.getChannel();
    final Player player = MantaroData.db().getPlayer(event.getAuthor());
    final PlayerData playerData = player.getData();
    if (needRating && !nsfwOnly)
        rating = Rating.lookupFromString(args[2]);
    if (nsfwOnly)
        rating = Rating.EXPLICIT;
    if (rating == null) {
        channel.sendMessage(EmoteReference.ERROR + "You provided an invalid rating (Available types: questionable, explicit, safe)!").queue();
        return;
    }
    final Rating finalRating = rating;
    if (!nsfwCheck(event, nsfwOnly, false, finalRating)) {
        channel.sendMessage(EmoteReference.ERROR + "Cannot send a NSFW image in a non-nsfw channel :(").queue();
        return;
    }
    int page = Math.max(1, r.nextInt(25));
    String queryRating = nsfwOnly ? null : rating.getLongName();
    switch(type) {
        case GET:
            try {
                String arguments = content.replace("get ", "");
                String[] argumentsSplit = arguments.split(" ");
                api.get(page, queryRating).async(requestedImages -> {
                    if (isListNull(requestedImages, event))
                        return;
                    try {
                        int number;
                        List<BoardImage> images = (List<BoardImage>) requestedImages;
                        if (!nsfwOnly)
                            images = requestedImages.stream().filter(data -> data.getRating().equals(finalRating)).collect(Collectors.toList());
                        if (images.isEmpty()) {
                            channel.sendMessage(EmoteReference.SAD + "There are no images matching your search criteria...").queue();
                            return;
                        }
                        try {
                            number = Integer.parseInt(argumentsSplit[0]);
                        } catch (Exception e) {
                            number = r.nextInt(images.size());
                        }
                        BoardImage image = images.get(number);
                        String tags = image.getTags().stream().collect(Collectors.joining(", "));
                        if (foundMinorTags(event, tags, image.getRating())) {
                            return;
                        }
                        imageEmbed(image.getURL(), String.valueOf(image.getWidth()), String.valueOf(image.getHeight()), tags, image.getRating(), imageboard, channel);
                        if (image.getRating().equals(Rating.EXPLICIT)) {
                            if (playerData.addBadgeIfAbsent(Badge.LEWDIE)) {
                                player.saveAsync();
                            }
                            TextChannelGround.of(event).dropItemWithChance(13, 3);
                        }
                    } catch (Exception e) {
                        event.getChannel().sendMessage(EmoteReference.ERROR + "**There aren't any more images or no results found**! Please try with a lower " + "number or another search.").queue();
                    }
                }, failure -> event.getChannel().sendMessage(EmoteReference.SAD + "There was an error while looking for an image...").queue());
            } catch (NumberFormatException ne) {
                channel.sendMessage(EmoteReference.ERROR + "Wrong argument type. Check ~>help " + imageboard).queue(message -> message.delete().queueAfter(10, TimeUnit.SECONDS));
            } catch (Exception e) {
                event.getChannel().sendMessage(EmoteReference.SAD + "There was an error while looking an image...").queue();
            }
            break;
        case TAGS:
            try {
                String sNoArgs = content.replace("tags ", "");
                String[] arguments = sNoArgs.split(" ");
                String tags = arguments[0];
                DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
                if (dbGuild.getData().getBlackListedImageTags().contains(tags.toLowerCase())) {
                    event.getChannel().sendMessage(EmoteReference.ERROR + "This image tag has been blacklisted here by an administrator.").queue();
                    return;
                }
                api.search(tags, queryRating).async(requestedImages -> {
                    // account for this
                    if (isListNull(requestedImages, event))
                        return;
                    try {
                        List<BoardImage> filter = (List<BoardImage>) requestedImages;
                        if (!nsfwOnly)
                            filter = requestedImages.stream().filter(data -> data.getRating().equals(finalRating)).collect(Collectors.toList());
                        if (filter.isEmpty()) {
                            channel.sendMessage(EmoteReference.SAD + "There are no images matching your search criteria...").queue();
                            return;
                        }
                        int number;
                        try {
                            number = Integer.parseInt(arguments[1]);
                        } catch (Exception e) {
                            number = r.nextInt(filter.size() > 0 ? filter.size() - 1 : filter.size());
                        }
                        BoardImage image = filter.get(number);
                        String imageTags = image.getTags().stream().collect(Collectors.joining(", "));
                        if (foundMinorTags(event, imageTags, image.getRating())) {
                            return;
                        }
                        imageEmbed(image.getURL(), String.valueOf(image.getWidth()), String.valueOf(image.getHeight()), imageTags, image.getRating(), imageboard, channel);
                        if (image.getRating().equals(Rating.EXPLICIT)) {
                            if (playerData.addBadgeIfAbsent(Badge.LEWDIE)) {
                                player.saveAsync();
                            }
                            TextChannelGround.of(event).dropItemWithChance(13, 3);
                        }
                    } catch (Exception e) {
                        event.getChannel().sendMessage(EmoteReference.ERROR + "**There aren't any more images or no results found**! Please try with a lower " + "number or another search.").queue();
                    }
                }, failure -> event.getChannel().sendMessage(EmoteReference.SAD + "There was an error while looking for this tag...").queue());
            } catch (NumberFormatException numberEx) {
                channel.sendMessage(EmoteReference.ERROR + "Wrong argument type. Check ~>help " + imageboard).queue(message -> message.delete().queueAfter(10, TimeUnit.SECONDS));
            } catch (Exception exception) {
                event.getChannel().sendMessage(EmoteReference.SAD + "There was an error while looking for this tag...").queue();
            }
            break;
        case RANDOM:
            api.get(page, queryRating).async(requestedImages -> {
                try {
                    if (isListNull(requestedImages, event))
                        return;
                    List<BoardImage> filter = (List<BoardImage>) requestedImages;
                    if (!nsfwOnly)
                        filter = requestedImages.stream().filter(data -> data.getRating().equals(finalRating)).collect(Collectors.toList());
                    if (filter.isEmpty()) {
                        channel.sendMessage(EmoteReference.SAD + "There are no images matching your search criteria...").queue();
                        return;
                    }
                    int number = r.nextInt(filter.size());
                    BoardImage image = filter.get(number);
                    String tags = image.getTags().stream().collect(Collectors.joining(", "));
                    imageEmbed(image.getURL(), String.valueOf(image.getWidth()), String.valueOf(image.getHeight()), tags, image.getRating(), imageboard, channel);
                    if (image.getRating().equals(Rating.EXPLICIT)) {
                        if (playerData.addBadgeIfAbsent(Badge.LEWDIE)) {
                            player.saveAsync();
                        }
                        TextChannelGround.of(event).dropItemWithChance(13, 3);
                    }
                } catch (Exception e) {
                    event.getChannel().sendMessage(EmoteReference.SAD + "There was an unknown error while looking for a random image...").queue();
                }
            }, failure -> event.getChannel().sendMessage(EmoteReference.SAD + "There was an error while looking for a random image...").queue());
            break;
    }
}
Also used : Badge(net.kodehawa.mantarobot.commands.currency.profile.Badge) Player(net.kodehawa.mantarobot.db.entities.Player) PlayerData(net.kodehawa.mantarobot.db.entities.helpers.PlayerData) TextChannel(net.dv8tion.jda.core.entities.TextChannel) Random(java.util.Random) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) Collectors(java.util.stream.Collectors) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) TimeUnit(java.util.concurrent.TimeUnit) ImageBoard(net.kodehawa.lib.imageboards.ImageBoard) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) List(java.util.List) Rating(net.kodehawa.lib.imageboards.entities.Rating) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) BoardImage(net.kodehawa.lib.imageboards.entities.BoardImage) MantaroData(net.kodehawa.mantarobot.data.MantaroData) TextChannelGround(net.kodehawa.mantarobot.commands.currency.TextChannelGround) Player(net.kodehawa.mantarobot.db.entities.Player) BoardImage(net.kodehawa.lib.imageboards.entities.BoardImage) Rating(net.kodehawa.lib.imageboards.entities.Rating) TextChannel(net.dv8tion.jda.core.entities.TextChannel) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) List(java.util.List) PlayerData(net.kodehawa.mantarobot.db.entities.helpers.PlayerData)

Example 50 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel in project MantaroBot by Mantaro.

the class MessageCmds method prune.

private void prune(GuildMessageReceivedEvent event, List<Message> messageHistory) {
    messageHistory = messageHistory.stream().filter(message -> !message.getCreationTime().isBefore(OffsetDateTime.now().minusWeeks(2))).collect(Collectors.toList());
    TextChannel channel = event.getChannel();
    if (messageHistory.isEmpty()) {
        channel.sendMessage(EmoteReference.ERROR + "There are no messages newer than 2 weeks old, discord won't let me delete them.").queue();
        return;
    }
    final int size = messageHistory.size();
    if (messageHistory.size() < 3) {
        channel.sendMessage(EmoteReference.ERROR + "Too few messages to prune!").queue();
        return;
    }
    channel.deleteMessages(messageHistory).queue(success -> {
        channel.sendMessage(EmoteReference.PENCIL + "Successfully pruned " + size + " messages from this channel!").queue(message -> message.delete().queueAfter(15, TimeUnit.SECONDS));
        DBGuild db = MantaroData.db().getGuild(event.getGuild());
        db.getData().setCases(db.getData().getCases() + 1);
        db.saveAsync();
        ModLog.log(event.getMember(), null, "Pruned Messages", ModLog.ModAction.PRUNE, db.getData().getCases());
    }, error -> {
        if (error instanceof PermissionException) {
            PermissionException pe = (PermissionException) error;
            channel.sendMessage(String.format("%sLack of permission while pruning messages(No permission provided: %s)", EmoteReference.ERROR, pe.getPermission())).queue();
        } else {
            channel.sendMessage(String.format("%sUnknown error while pruning messages<%s>: %s", EmoteReference.ERROR, error.getClass().getSimpleName(), error.getMessage())).queue();
            error.printStackTrace();
        }
    });
}
Also used : PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) TextChannel(net.dv8tion.jda.core.entities.TextChannel) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild)

Aggregations

TextChannel (net.dv8tion.jda.core.entities.TextChannel)90 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)27 Guild (net.dv8tion.jda.core.entities.Guild)21 User (net.dv8tion.jda.core.entities.User)19 Member (net.dv8tion.jda.core.entities.Member)18 List (java.util.List)17 Message (net.dv8tion.jda.core.entities.Message)17 ArrayList (java.util.ArrayList)14 VoiceChannel (net.dv8tion.jda.core.entities.VoiceChannel)13 GuildWrapper (stream.flarebot.flarebot.objects.GuildWrapper)13 MessageUtils (stream.flarebot.flarebot.util.MessageUtils)13 Collectors (java.util.stream.Collectors)10 CommandType (stream.flarebot.flarebot.commands.CommandType)8 Role (net.dv8tion.jda.core.entities.Role)7 FlareBot (stream.flarebot.flarebot.FlareBot)7 Track (com.arsenarsen.lavaplayerbridge.player.Track)6 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)6 MantaroData (net.kodehawa.mantarobot.data.MantaroData)6 DBGuild (net.kodehawa.mantarobot.db.entities.DBGuild)6 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)6