use of gg.projecteden.nexus.models.discord.DiscordUserService in project Nexus by ProjectEdenGG.
the class JoinQuit method quit.
public static void quit(Player player, QuitReason reason) {
// Denizen Discord: https://discord.com/channels/315163488085475337/315163488085475337/929117355223695360
if (!player.isOnline())
return;
if (isDuplicate(player, "quit"))
return;
String message = "&c[player] &5has left the server";
if (player.hasPermission("jq.custom") && quitMessages.size() > 0)
message = RandomUtils.randomElement(quitMessages);
final String finalMessage = message;
final String ingame = formatQuit(player, finalMessage);
final Component component = AdventureUtils.fromLegacyAmpersandText(ingame);
final Component staffComponent = AdventureUtils.fromLegacyAmpersandText(ingame + " (" + StringUtils.camelCase(reason.name()) + ")");
OnlinePlayers.getAll().forEach(_player -> {
if (!MuteMenuUser.hasMuted(_player, MuteMenuItem.JOIN_QUIT)) {
if (reason != QuitReason.DISCONNECTED && Rank.of(_player).isStaff())
_player.sendMessage(player, staffComponent, MessageType.CHAT);
else
_player.sendMessage(player, component, MessageType.CHAT);
}
});
Jingle.QUIT.playAll();
Tasks.async(() -> {
DiscordUser user = new DiscordUserService().get(player);
RoleManager.update(user);
final String discord = discordize(finalMessage).replaceAll("\\[player]", "**" + Nickname.discordOf(player) + "**");
Discord.send("<:red_arrow_left:331808021267218432> " + discord, TextChannel.BRIDGE);
});
}
use of gg.projecteden.nexus.models.discord.DiscordUserService in project Nexus by ProjectEdenGG.
the class JoinQuit method join.
public static void join(Player player) {
if (isDuplicate(player, "join"))
return;
String message = "&a[player] &5has joined the server";
if (player.hasPermission("jq.custom") && joinMessages.size() > 0)
message = RandomUtils.randomElement(joinMessages);
final String finalMessage = message;
if (player.isOnline()) {
final String ingame = formatJoin(player, finalMessage);
final Component component = AdventureUtils.fromLegacyAmpersandText(ingame);
OnlinePlayers.getAll().forEach(_player -> {
if (!MuteMenuUser.hasMuted(_player, MuteMenuItem.JOIN_QUIT))
_player.sendMessage(player, component, MessageType.CHAT);
});
if (!player.hasPlayedBefore())
Jingle.FIRST_JOIN.playAll();
else
Jingle.JOIN.playAll();
Tasks.async(() -> {
DiscordUser user = new DiscordUserService().get(player);
RoleManager.update(user);
final String discord = discordize(finalMessage).replaceAll("\\[player]", "**" + Nickname.discordOf(player) + "**");
Discord.send("<:blue_arrow_right:883811353641517126> " + discord, TextChannel.BRIDGE);
});
}
}
use of gg.projecteden.nexus.models.discord.DiscordUserService in project Nexus by ProjectEdenGG.
the class HandlePurchaseCommand method run.
@Path("<data...>")
void run(String data) {
Nexus.log("Purchase caught; processing... " + data);
String[] args = data.split("\\|");
Purchase purchase = Purchase.builder().id(UUID.randomUUID()).name(args[0]).uuid(UUID.fromString(uuidFormat(args[1]))).transactionId(args[2]).price(Double.parseDouble(args[3])).currency(args[4]).timestamp(LocalDateTime.parse(args[6] + " " + args[5], formatter)).email(args[7]).ip(args[8]).packageId(args[9]).packagePrice(Double.parseDouble(args[10])).packageExpiry(args[11]).packageName(args[12]).purchaserName(args[13]).purchaserUuid(UUID.fromString(uuidFormat(args[14]))).build();
String discordMessage = purchase.toDiscordString();
final ContributorService contributorService = new ContributorService();
final Contributor contributor = contributorService.get(purchase.getPurchaserUuid());
Package packageType = Package.getPackage(purchase.getPackageId());
if (packageType == null)
discordMessage += "\nPackage not recognized!";
else {
if (purchase.getPrice() > 0) {
send(purchase.getUuid(), PREFIX + "Thank you for buying &e" + purchase.getPackageName() + "&3! " + "Your contribution is &3&ogreatly &3appreciated and will be put to good use.");
if (contributor.isBroadcasts())
if (packageType == Package.CUSTOM_DONATION) {
Koda.say("Thank you for your custom donation, " + purchase.getNickname() + "! " + "We greatly appreciate your selfless contribution &4❤");
// this is not necessarily what they donated
// if they make a custom donation and purchase items at the same
// time, i have no way to break down the price from the payload
// but that is very rare, so its better than nothing i guess
contributor.giveCredit(purchase.getPrice());
} else
Koda.say("Thank you for your purchase, " + purchase.getNickname() + "! " + "Enjoy your " + purchase.getPackageName() + " perk!");
if (packageType.getCategory() == StoreCategory.BOOSTS)
send(purchase.getUuid(), PREFIX + "Make sure you activate your boost with &c/boost menu");
if (isV4Uuid(purchase.getPurchaserUuid())) {
new BadgeUserService().edit(purchase.getPurchaserUuid(), badgeUser -> badgeUser.give(Badge.SUPPORTER));
DiscordUser user = new DiscordUserService().get(purchase.getPurchaserUuid());
if (user.getUserId() != null)
Discord.addRole(user.getUserId(), Role.SUPPORTER);
else
discordMessage += "\nUser does not have a linked discord account";
}
} else {
send(purchase.getUuid(), PREFIX + "Your free " + purchase.getPackageName() + " has been successfully processed, enjoy!");
}
packageType.apply(purchase.getUuid());
discordMessage += "\nPurchase successfully processed.";
}
Discord.send(discordMessage, TextChannel.ADMIN_LOG);
contributor.add(purchase);
contributorService.save(contributor);
}
use of gg.projecteden.nexus.models.discord.DiscordUserService in project Nexus by ProjectEdenGG.
the class TeamMechanic method getVoiceChannelMember.
@Nullable
public static Member getVoiceChannelMember(@NotNull OptionalPlayer hasPlayer) {
Player player = hasPlayer.getPlayer();
if (player == null)
return null;
Guild guild = Discord.getGuild();
if (guild == null)
return null;
DiscordUser discordUser = new DiscordUserService().get(player);
Member member = discordUser.getMember();
if (member == null) {
// user has no linked account, find a disc account with matching (nick)name
Optional<Member> optionalMember = guild.getMembers().stream().filter(fmember -> (fmember.getNickname() != null && fmember.getNickname().equalsIgnoreCase(Name.of(player))) || fmember.getUser().getName().equalsIgnoreCase(Name.of(player))).findAny();
if (optionalMember.isPresent())
member = optionalMember.get();
else
return null;
}
if (member.getVoiceState() == null || !member.getVoiceState().inAudioChannel())
return null;
return member;
}
use of gg.projecteden.nexus.models.discord.DiscordUserService in project Nexus by ProjectEdenGG.
the class BridgeCommand method archive_findDuplicateRoles.
@Async
@Path("archive findDuplicateRoles [page]")
void archive_findDuplicateRoles(@Arg("1") int page) {
Map<UUID, List<String>> duplicates = new HashMap<>() {
{
for (String roleId : archive.getRoleMap().keySet()) {
Role role = Discord.getGuild().getRoleById(roleId);
DiscordUser user = new DiscordUserService().getFromRoleId(roleId);
String name = user == null ? role == null ? null : role.getName() : user.getIngameName();
if (!isNullOrEmpty(name)) {
UUID uuid = PlayerUtils.getPlayer(name).getUniqueId();
List<String> roleIds = getOrDefault(uuid, new ArrayList<>());
roleIds.add(roleId);
put(uuid, roleIds);
}
}
}
};
for (UUID uuid : new HashSet<>(duplicates.keySet())) {
if (duplicates.get(uuid).size() == 1)
duplicates.remove(uuid);
}
BiFunction<UUID, String, JsonBuilder> formatter = (uuid, index) -> {
OfflinePlayer player = PlayerUtils.getPlayer(uuid);
int size = duplicates.get(uuid).size();
JsonBuilder json = json(index + " &e" + Nickname.of(player) + " &7- " + size + " roles").newline();
for (String roleId : duplicates.get(uuid)) json.next(" &7" + roleId + " - " + archive.getRoleMap().get(roleId).size() + " messages").newline();
return json;
};
paginate(Utils.sortByValue(new HashMap<UUID, Integer>() {
{
duplicates.forEach((k, v) -> put(k, v.size()));
}
}).keySet(), formatter, "/bridge archive findDuplicateRoles", page);
}
Aggregations