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