use of net.dv8tion.jda.core.entities.Message in project DiscordBot by LXGaming.
the class DiscordThread method process.
private void process() {
if (DiscordBot.getInstance().getDiscord().getMessageSender().getMessages() == null || DiscordBot.getInstance().getDiscord().getMessageSender().getMessages().isEmpty()) {
return;
}
for (Iterator<Message> iterator = DiscordBot.getInstance().getDiscord().getMessageSender().getMessages().iterator(); iterator.hasNext(); ) {
Message message = iterator.next();
if (message == null || message.getCreationTime() == null) {
iterator.remove();
continue;
}
if (message.getCreationTime().toInstant().toEpochMilli() < (System.currentTimeMillis() - DiscordBot.getInstance().getConfig().getDeleteTime())) {
message.delete().queue();
iterator.remove();
}
}
return;
}
use of net.dv8tion.jda.core.entities.Message in project Ardent by adamint.
the class TrackScheduler method onTrackStart.
@Override
public void onTrackStart(AudioPlayer player, AudioTrack track) {
if (manager.isShouldAnnounce()) {
if (manager.getLastAnnouncementId() != null) {
try {
manager.getChannel().getMessageById(manager.getLastAnnouncementId()).queue(message -> message.delete().queue());
} catch (Exception ignored) {
}
}
User me = manager.getChannel().getGuild().getSelfMember().getUser();
AudioTrackInfo info = track.getInfo();
EmbedBuilder builder = MessageUtils.getDefaultEmbed(me);
builder.setAuthor("Now playing " + info.title, "https://ardentbot.tk", "https://s-media-cache-ak0.pinimg" + ".com/736x/69/96/5c/69965c2849ec9b7148a5547ce6714735.jpg");
builder.setThumbnail("https://s-media-cache-ak0.pinimg.com/736x/69/96/5c/69965c2849ec9b7148a5547ce6714735.jpg");
builder.addField("Title", info.title, true).addField("Author", info.author, true).addField("Duration", Music.getDuration(track), true).addField("URL", info.uri, true).addField("Is Stream", String.valueOf(info.isStream), true);
Message m = GuildUtils.getShard(manager.getChannel().getJDA()).help.sendEmbed(builder, manager.getChannel(), me);
manager.setLastAnnouncementId(m.getId());
}
}
use of net.dv8tion.jda.core.entities.Message in project Ardent by adamint.
the class RPGMoney method setupSubcommands.
@Override
public void setupSubcommands() throws Exception {
subcommands.add(new Subcommand("See who has the most money - globally!", "top", "top") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
if (args.length == 2) {
HashMap<User, Double> moneyAmounts = new HashMap<>();
Cursor<HashMap> top = r.db("data").table("profiles").orderBy().optArg("index", r.desc("money")).limit(20).run(connection);
top.forEach(hashMap -> {
Profile profile = asPojo(hashMap, Profile.class);
assert profile.getUser() != null;
moneyAmounts.put(profile.getUser(), profile.getMoney());
});
Map<User, Double> sortedAmounts = MapUtils.sortByValue(moneyAmounts);
String topMoney = "Global Richest Users";
EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
builder.setAuthor(topMoney, getShard().url, guild.getIconUrl());
StringBuilder description = new StringBuilder();
final int[] current = { 0 };
sortedAmounts.forEach((u, money) -> {
if (u != null) {
description.append("\n#" + (current[0] + 1) + ": **" + u.getName() + "** " + RPGUtils.formatMoney(money));
current[0]++;
}
});
description.append("\n\nGet money by sending commands or asking questions on our support server ( https://ardentbot" + ".tk/guild )\n\nSee people's money by doing /money @User or see yours by just using /money");
sendEmbed(builder.setDescription(description.toString()), channel, user);
return;
}
try {
int page = Integer.parseInt(args[2]) - 1;
HashMap<User, Double> moneyAmounts = new HashMap<>();
Cursor<HashMap> top = r.db("data").table("profiles").orderBy().optArg("index", r.desc("money")).slice((page * 20), (page * 20) + 11).limit(25).run(connection);
top.forEach(hashMap -> {
Profile profile = asPojo(hashMap, Profile.class);
assert profile.getUser() != null;
moneyAmounts.put(profile.getUser(), profile.getMoney());
});
Map<User, Double> sortedAmounts = MapUtils.sortByValue(moneyAmounts);
String topMoney = "Global Richest Users | Page " + page;
EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
builder.setAuthor(topMoney, getShard().url, guild.getIconUrl());
StringBuilder description = new StringBuilder();
final int[] current = { 0 };
sortedAmounts.forEach((u, money) -> {
if (u != null) {
description.append("\n#" + ((page * 20) + current[0] + 1) + ": **" + u.getName() + "** " + RPGUtils.formatMoney(money));
current[0]++;
}
});
description.append("\n\nGet money by sending commands or asking questions on our support server ( https://ardentbot" + ".tk/guild )\n\nSee people's money by doing /money @User or see yours by just using /money");
sendEmbed(builder.setDescription(description.toString()), channel, user);
} catch (NumberFormatException e) {
sendTranslatedMessage("You need to specify a valid page number!", channel, user);
}
}
});
subcommands.add(new Subcommand("See who has the most money in your server", "server", "server", "guild", "topguild") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
if (!generatedFirstTimeFor.contains(guild.getId())) {
sendTranslatedMessage("Please wait a second, generating and caching your server's statistics", channel, user);
generatedFirstTimeFor.add(guild.getId());
}
HashMap<User, Double> moneyAmounts = new HashMap<>();
guild.getMembers().forEach(member -> {
User u = member.getUser();
moneyAmounts.put(u, Profile.get(u).getMoney());
});
Map<User, Double> sortedAmounts = MapUtils.sortByValue(moneyAmounts);
EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
builder.setAuthor("Richest Users | This Server", getShard().url, guild.getIconUrl());
StringBuilder description = new StringBuilder();
description.append("**Richest Users in this Server**");
final int[] current = { 0 };
sortedAmounts.forEach((u, money) -> {
if (current[0] < 10) {
description.append("\n#" + (current[0] + 1) + ": **" + u.getName() + "** " + RPGUtils.formatMoney(money));
current[0]++;
}
});
description.append("\n\nGet money by sending commands or asking questions on our support server ( https://ardentbot" + ".tk/guild )\n\nSee people's money by doing /money @User or see yours by just using /money");
sendEmbed(builder.setDescription(description.toString()), channel, user);
}
});
}
use of net.dv8tion.jda.core.entities.Message in project Ardent by adamint.
the class GuildInfo method noArgs.
@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
builder.setAuthor("Server Info", guild.getIconUrl(), guild.getIconUrl());
builder.addField("Number of users", String.valueOf(guild.getMembers().size()), true);
builder.addField("Online users", String.valueOf(guild.getMembers().stream().filter(m -> m.getOnlineStatus() == OnlineStatus.ONLINE).count()), true);
builder.addField("Prefix", GuildUtils.getPrefix(guild), true);
builder.addField("Premium Server", String.valueOf(EntityGuild.get(guild).isPremium()), true);
builder.addField("Owner", UserUtils.getNameWithDiscriminator(guild.getOwner().getUser().getId()), true);
builder.addField("Creation Date", guild.getCreationTime().toLocalDate().toString(), true);
builder.addField("Public channel", guild.getPublicChannel().getAsMention(), true);
builder.addField("# of Voice Channels", String.valueOf(guild.getVoiceChannels().size()), true);
builder.addField("# of Text Channels", String.valueOf(guild.getTextChannels().size()), true);
builder.addField("# of Roles", String.valueOf(guild.getRoles().size()), true);
builder.addField("Region", guild.getRegion().getName(), true);
builder.addField("Verification Level", String.valueOf(guild.getVerificationLevel()), true);
sendEmbed(builder, channel, user);
}
use of net.dv8tion.jda.core.entities.Message in project Ardent by adamint.
the class Bet method setupSubcommands.
@Override
public void setupSubcommands() throws Exception {
subcommands.add(new Subcommand("Bet a specified amount of money", "start", "start") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
if (args.length == 2) {
sendTranslatedMessage("You need to specify a bet amount", channel, user);
return;
}
try {
double amountToBet = Double.parseDouble(args[2]);
Profile profile = Profile.get(user);
if (amountToBet <= 0 || profile.getMoney() < amountToBet) {
sendTranslatedMessage("Invalid amount - either it was more than what you have or less than $0", channel, user);
return;
}
sendEditedTranslation("Are you sure you want to bet **{0}**? Type **yes** if so, or **no** to cancel", user, channel, RPGUtils.formatMoney(amountToBet));
interactiveOperation(channel, message, (returnedMessage) -> {
if (returnedMessage.getContent().equalsIgnoreCase("yes")) {
sendTranslatedMessage("Type 1 or 2 below - choose wisely!", channel, user);
interactiveOperation(channel, message, (numberInput) -> {
try {
int num = Integer.parseInt(numberInput.getContent());
if (num > 0 && num <= 2) {
int generated = new SecureRandom().nextInt(2) + 1;
if (num == generated || new Random().nextInt(20) == 5) {
profile.addMoney(profile.afterCredit(amountToBet));
sendTranslatedMessage("Congrats! You won " + RPGUtils.formatMoney(profile.afterCredit(amountToBet)), channel, user);
} else {
sendTranslatedMessage("Sorry, you lost " + RPGUtils.formatMoney(amountToBet) + " :frowning: " + "The correct answer " + "was " + generated, channel, user);
profile.removeMoney(amountToBet);
}
} else
sendTranslatedMessage("You specified an invalid number", channel, user);
} catch (Exception ex) {
sendTranslatedMessage("You specified an invalid number", channel, user);
}
});
} else {
sendTranslatedMessage("Ok, cancelled your bet", channel, user);
}
});
} catch (NumberFormatException e) {
sendTranslatedMessage("That's not a number!", channel, user);
}
}
});
subcommands.add(new Subcommand("Bet all your money", "all", "all") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
Profile profile = Profile.get(user);
if (profile.getMoney() < 0) {
sendTranslatedMessage("You can't bet if you're in debt!", channel, user);
return;
}
sendEditedTranslation("Are you sure you want to bet all? Type **yes** if so, or **no** to cancel", user, channel, RPGUtils.formatMoney(profile.getMoney()));
interactiveOperation(channel, message, (returnedMessage) -> {
if (returnedMessage.getContent().equalsIgnoreCase("yes")) {
sendTranslatedMessage("Type 1 or 2 below - choose wisely!", channel, user);
interactiveOperation(channel, message, (numberInput) -> {
try {
int num = Integer.parseInt(numberInput.getContent());
if (num > 0 && num <= 2) {
int generated = new SecureRandom().nextInt(2) + 1;
if (num == generated || new Random().nextInt(20) == 5) {
profile.addMoney(profile.afterCredit(profile.getMoney()));
sendTranslatedMessage("Congrats! You won " + RPGUtils.formatMoney(profile.afterCredit(profile.getMoney())), channel, user);
} else {
sendTranslatedMessage("Sorry, you lost " + RPGUtils.formatMoney(profile.getMoney()) + " :frowning: The correct answer " + "was " + generated, channel, user);
profile.setZero();
}
} else
sendTranslatedMessage("You specified an invalid number", channel, user);
} catch (Exception ex) {
sendTranslatedMessage("You specified an invalid number", channel, user);
}
});
} else {
sendTranslatedMessage("Ok, cancelled your bet", channel, user);
}
});
}
});
}
Aggregations