use of net.dv8tion.jda.core.entities.User in project MOOTBoot by LeshDev.
the class userInfo method sendInfo.
public static void sendInfo(Member member, TextChannel channel) {
EmbedBuilder eB = new EmbedBuilder();
User u = member.getUser();
eB.setAuthor("Infocard >> " + u.getName(), null, u.getEffectiveAvatarUrl());
eB.addField("**User**:", u.getAsMention(), true);
eB.addField("**ID**:", "" + u.getIdLong(), true);
eB.addField("**Message Frequency**:", "" + channel.getHistory().retrievePast(MESSAGE_LOOKBACK_COUNT).complete().stream().filter(e -> e.getAuthor().equals(u)).count() / ((double) MESSAGE_LOOKBACK_COUNT), true);
eB.addField("**Created**:", "" + u.getCreationTime(), true);
eB.addField("**Roles**:", "" + member.getRoles().stream().map(Role::getName).collect(Collectors.joining(" - ")), true);
eB.setThumbnail(u.getEffectiveAvatarUrl());
eB.setColor(java.awt.Color.CYAN);
channel.sendMessage(eB.build()).queue();
}
use of net.dv8tion.jda.core.entities.User in project MantaroBot by Mantaro.
the class CurrencyCmds method transferItems.
@Command
public static void transferItems(CommandRegistry cr) {
cr.register("itemtransfer", new SimpleCommand(Category.CURRENCY) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
if (args.length < 2) {
onError(event);
return;
}
List<User> mentionedUsers = event.getMessage().getMentionedUsers();
if (mentionedUsers.size() == 0)
event.getChannel().sendMessage(EmoteReference.ERROR + "You need to mention a user").queue();
else {
User giveTo = mentionedUsers.get(0);
if (event.getAuthor().getId().equals(giveTo.getId())) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot transfer an item to yourself!").queue();
return;
}
Item item = Items.fromAny(args[1]).orElse(null);
if (item == null) {
event.getChannel().sendMessage("There isn't an item associated with this emoji.").queue();
} else {
Player player = MantaroData.db().getPlayer(event.getAuthor());
Player giveToPlayer = MantaroData.db().getPlayer(giveTo);
if (args.length == 2) {
if (player.getInventory().containsItem(item)) {
if (item.isHidden()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot transfer this item!").queue();
return;
}
if (giveToPlayer.getInventory().asMap().getOrDefault(item, new ItemStack(item, 0)).getAmount() >= 5000) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Don't do that").queue();
return;
}
player.getInventory().process(new ItemStack(item, -1));
giveToPlayer.getInventory().process(new ItemStack(item, 1));
event.getChannel().sendMessage(EmoteReference.OK + event.getAuthor().getAsMention() + " gave 1 " + item.getName() + " to " + giveTo.getAsMention()).queue();
} else {
event.getChannel().sendMessage(EmoteReference.ERROR + "You don't have any of these items in your inventory").queue();
}
player.saveAsync();
giveToPlayer.saveAsync();
return;
}
try {
int amount = Math.abs(Integer.parseInt(args[2]));
if (player.getInventory().containsItem(item) && player.getInventory().getAmount(item) >= amount) {
if (item.isHidden()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot transfer this item!").queue();
return;
}
if (giveToPlayer.getInventory().asMap().getOrDefault(item, new ItemStack(item, 0)).getAmount() + amount >= 5000) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Don't do that").queue();
return;
}
player.getInventory().process(new ItemStack(item, amount * -1));
giveToPlayer.getInventory().process(new ItemStack(item, amount));
event.getChannel().sendMessage(EmoteReference.OK + event.getAuthor().getAsMention() + " gave " + amount + " " + item.getName() + " to " + giveTo.getAsMention()).queue();
} else
event.getChannel().sendMessage(EmoteReference.ERROR + "You don't have enough of this item " + "to do that").queue();
} catch (NumberFormatException nfe) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Invalid number provided").queue();
}
player.saveAsync();
giveToPlayer.saveAsync();
}
}
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Transfer Items command").setDescription("**Transfers items from you to another player.**").addField("Usage", "`~>itemtransfer <@user> <item emoji> <amount (optional)>` - **Transfers the item to player x**", false).addField("Parameters", "`@user` - user to send the item to\n" + "`item emoji` - write out the emoji of the item you want to send\n" + "`amount` - optional, send a specific amount of an item to someone.", false).addField("Important", "You cannot send more items than what you already have", false).build();
}
});
cr.registerAlias("itemtransfer", "transferitems");
}
use of net.dv8tion.jda.core.entities.User in project Ardent by adamint.
the class Tinder method setupSubcommands.
@Override
public void setupSubcommands() throws Exception {
subcommands.add(new Subcommand("Match yourself with someone in the server!", "matchme", "matchme") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
ArrayList<TinderMatch> matches = queryAsArrayList(TinderMatch.class, r.table("tinder_matches").filter(row -> row.g("user_id").eq(user.getId())).run(connection));
User potentialMatch = getPotentialMatch(user, guild, matches);
EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
String matchMe = "Match me | Tinder";
builder.setAuthor(matchMe, getShard().url, getShard().bot.getAvatarUrl());
builder.setThumbnail(potentialMatch.getAvatarUrl());
StringBuilder description = new StringBuilder();
description.append("**" + matchMe + "**");
description.append("\nTheir name: " + UserUtils.getNameWithDiscriminator(potentialMatch.getId()));
description.append("Swipe right (rightreaction) to connect with this person, or swipe left (left reaction) to pass them " + "by\nType /tinder connect to connect with the people you've swiped right on");
Message sent = sendEmbed(builder.setDescription(description.toString()), channel, user, ":arrow_left:", ":arrow_right:");
interactiveReaction(channel, sent, user, 15, messageReaction -> {
String name = messageReaction.getEmote().getName();
if (name != null) {
if (name.equals("➡")) {
r.table("tinder_matches").insert(r.json(gson.toJson(new TinderMatch(user.getId(), potentialMatch.getId(), true)))).run(connection);
sendEditedTranslation("You swiped right on {0}! Connect with them using /tinder connect", user, channel, potentialMatch.getName());
} else if (name.equals("⬅")) {
r.table("tinder_matches").insert(r.json(gson.toJson(new TinderMatch(user.getId(), potentialMatch.getId(), false)))).run(connection);
sendEditedTranslation("You swiped right on {0} - Don't worry, you can find better!", user, channel, potentialMatch.getName());
} else
sendTranslatedMessage("You reacted with an unexpected emoji :thinking:", channel, user);
}
});
}
});
subcommands.add(new Subcommand("Connect with the people you've swiped right on", "connect", "connect") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
String yourMatches = "Discord Tinder | Your Matches";
String swipedRightOnYou = "Swiped right on you";
EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
builder.setAuthor(yourMatches, getShard().url, getShard().bot.getAvatarUrl());
builder.setThumbnail(user.getAvatarUrl());
StringBuilder description = new StringBuilder();
description.append("**" + yourMatches + "**");
ArrayList<TinderMatch> matches = queryAsArrayList(TinderMatch.class, r.table("tinder_matches").filter(r.hashMap("user_id", user.getId()).with("swipedRight", true)).run(connection));
if (matches.size() == 0) {
description.append("\nYou don't have any connections :frowning:");
} else {
for (int i = 0; i < matches.size(); i++) {
String swipedRightWithId = matches.get(i).getPerson_id();
boolean mutual = swipedRightWith(user.getId(), swipedRightWithId);
String yesNo;
if (mutual)
yesNo = EmojiParser.parseToUnicode(":white_check_mark:");
else
yesNo = EmojiParser.parseToAliases(":x:");
description.append("\n#" + (i + 1) + ": " + UserUtils.getNameWithDiscriminator(swipedRightWithId) + " | " + swipedRightOnYou + ": " + yesNo);
}
}
description.append("\n\nUse /tinder message [number on connection list] to message that person. However, they must have " + "swiped right on you as well to be able to contact them");
sendEmbed(builder.setDescription(description), channel, user);
}
});
subcommands.add(new Subcommand("Message one of your mutual connections!", "message [number in connection list]", "message") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
if (args.length == 2) {
sendTranslatedMessage("Usage: /tinder message [person's number in /tinder connect] [message here]", channel, user);
return;
}
if (message.getRawContent().split(" ").length == 3) {
sendTranslatedMessage("You need to include a message to send that person!", channel, user);
return;
}
try {
int number = Integer.parseInt(args[2]) - 1;
if (number < 0)
sendTranslatedMessage("Usage: /tinder message [person's number in /tinder connect] [message here]", channel, user);
else {
ArrayList<TinderMatch> matches = queryAsArrayList(TinderMatch.class, r.table("tinder_matches").filter(r.hashMap("user_id", user.getId()).with("swipedRight", true)).run(connection));
if (number >= matches.size()) {
sendTranslatedMessage("Sorry, but you don't have this many matches!", channel, user);
return;
}
TinderMatch selected = matches.get(number);
if (!swipedRightWith(user.getId(), selected.getPerson_id())) {
sendTranslatedMessage("That person hasn't swiped right on you!", channel, user);
return;
}
User toMessage = UserUtils.getUserById(selected.getPerson_id());
try {
toMessage.openPrivateChannel().queue(privateChannel -> privateChannel.sendMessage("One of your Tinder " + "matches, **" + UserUtils.getNameWithDiscriminator(user.getId()) + "**, sent you " + "a message!\n\n**" + user.getName() + "**: " + replace(message.getRawContent(), 3)).queue());
if (!sentTo.contains(toMessage.getId())) {
toMessage.openPrivateChannel().queue(privateChannel -> {
privateChannel.sendMessage("To stop receiving messages from this person, remove them from your match " + "list with /tinder remove [number on the /tinder connect list]\n" + "\n" + "To send a message back to this person, type /tinder message [number on your /tinder connect " + "list] [message here] in a server - meet other tinder savvy people on the Ardent guild (where" + " we have a dedicated Tinder channel)! - https://discordapp.com/invite/rfGSxNA").queue();
sentTo.add(toMessage.getId());
});
}
sendTranslatedMessage("Ok! I sent that person your message :wink:", channel, user);
} catch (Exception e) {
sendTranslatedMessage("I was unable to message that person :frowning:", channel, user);
}
}
} catch (NumberFormatException e) {
sendTranslatedMessage("Usage: /tinder message [person's number in /tinder connect] [message here]", channel, user);
}
}
});
subcommands.add(new Subcommand("Remove one of your connections", "remove [number in connection list]", "remove") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
if (args.length == 2) {
sendTranslatedMessage("Usage: /tinder remove [person's number in /tinder connect]", channel, user);
return;
}
try {
int number = Integer.parseInt(args[2]) - 1;
if (number < 0)
sendTranslatedMessage("Usage: /tinder remove [person's number in /tinder connect]", channel, user);
else {
ArrayList<TinderMatch> matches = queryAsArrayList(TinderMatch.class, r.table("tinder_matches").filter(r.hashMap("user_id", user.getId()).with("swipedRight", true)).run(connection));
if (number >= matches.size()) {
sendTranslatedMessage("Sorry, but you don't have this many matches!", channel, user);
return;
}
TinderMatch selected = matches.get(number);
r.table("tinder_matches").filter(r.hashMap("user_id", user.getId()).with("person_id", selected.getPerson_id())).delete().run(connection);
sendTranslatedMessage(":ok_hand: Removed that person from your connection list", channel, user);
}
} catch (NumberFormatException e) {
sendTranslatedMessage("Usage: /tinder remove [person's number in /tinder connect]", channel, user);
}
}
});
}
use of net.dv8tion.jda.core.entities.User 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.User in project Ardent by adamint.
the class ProfileUpdater method updateProfiles.
public static void updateProfiles() {
Cursor<HashMap> profiles = r.db("data").table("profiles").run(connection);
profiles.forEach(hashMap -> {
Profile profile = asPojo(hashMap, Profile.class);
if (profile.getUser() == null && !Ardent.testingBot) {
r.table("profiles").get(profile.user_id).delete().run(connection);
return;
}
for (Iterator<Badge> iterator = profile.getBadges().iterator(); iterator.hasNext(); ) {
Badge badge = iterator.next();
if (badge.getExpirationEpochSeconds() < Instant.now().getEpochSecond() && badge.getExpirationEpochSeconds() != 1) {
User user = profile.getUser();
if (user != null) {
user.openPrivateChannel().queue(privateChannel -> {
Ardent.shard0.help.sendTranslatedMessage("Your badge with the ID of **" + badge.getName() + "** has " + "expired" + ".", privateChannel, user);
r.db("data").table("badges").filter(row -> row.g("user_id").eq(user.getId()).and(row.g("badge_id").eq(badge.getId()))).delete().run(connection);
iterator.remove();
});
}
}
}
});
}
Aggregations