Search in sources :

Example 1 with DiscordUserService

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);
    });
}
Also used : DiscordUser(gg.projecteden.nexus.models.discord.DiscordUser) DiscordUserService(gg.projecteden.nexus.models.discord.DiscordUserService) Component(net.kyori.adventure.text.Component)

Example 2 with DiscordUserService

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);
        });
    }
}
Also used : DiscordUser(gg.projecteden.nexus.models.discord.DiscordUser) DiscordUserService(gg.projecteden.nexus.models.discord.DiscordUserService) Component(net.kyori.adventure.text.Component)

Example 3 with DiscordUserService

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);
}
Also used : DiscordUser(gg.projecteden.nexus.models.discord.DiscordUser) Purchase(gg.projecteden.nexus.models.store.Contributor.Purchase) ContributorService(gg.projecteden.nexus.models.store.ContributorService) Contributor(gg.projecteden.nexus.models.store.Contributor) BadgeUserService(gg.projecteden.nexus.models.badge.BadgeUserService) DiscordUserService(gg.projecteden.nexus.models.discord.DiscordUserService) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path)

Example 4 with DiscordUserService

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;
}
Also used : MatchTasks(gg.projecteden.nexus.features.minigames.models.Match.MatchTasks) VoiceChannelCategory(gg.projecteden.utils.DiscordId.VoiceChannelCategory) JsonBuilder(gg.projecteden.nexus.utils.JsonBuilder) LocalDateTime(java.time.LocalDateTime) OptionalPlayer(me.lexikiq.OptionalPlayer) HashMap(java.util.HashMap) Member(net.dv8tion.jda.api.entities.Member) Player(org.bukkit.entity.Player) MatchData(gg.projecteden.nexus.features.minigames.models.MatchData) Name(gg.projecteden.nexus.utils.Name) Match(gg.projecteden.nexus.features.minigames.models.Match) MinigamerQuitEvent(gg.projecteden.nexus.features.minigames.models.events.matches.MinigamerQuitEvent) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Guild(net.dv8tion.jda.api.entities.Guild) MatchEndEvent(gg.projecteden.nexus.features.minigames.models.events.matches.MatchEndEvent) RandomUtils(gg.projecteden.nexus.utils.RandomUtils) Component(net.kyori.adventure.text.Component) Map(java.util.Map) Team(gg.projecteden.nexus.features.minigames.models.Team) Minigames(gg.projecteden.nexus.features.minigames.Minigames) ChatColor(net.md_5.bungee.api.ChatColor) Nexus(gg.projecteden.nexus.Nexus) DiscordUserService(gg.projecteden.nexus.models.discord.DiscordUserService) Minigamer(gg.projecteden.nexus.features.minigames.models.Minigamer) Set(java.util.Set) EqualsAndHashCode(lombok.EqualsAndHashCode) Collectors(java.util.stream.Collectors) Discord(gg.projecteden.nexus.features.discord.Discord) Arena(gg.projecteden.nexus.features.minigames.models.Arena) MinigamerDeathEvent(gg.projecteden.nexus.features.minigames.models.events.matches.minigamers.MinigamerDeathEvent) DiscordId(gg.projecteden.utils.DiscordId) MatchTaskType(gg.projecteden.nexus.features.minigames.models.Match.MatchTasks.MatchTaskType) TickTime(gg.projecteden.utils.TimeUtils.TickTime) Nullable(org.jetbrains.annotations.Nullable) DiscordUser(gg.projecteden.nexus.models.discord.DiscordUser) List(java.util.List) Data(lombok.Data) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) Collections(java.util.Collections) MultiplayerMechanic(gg.projecteden.nexus.features.minigames.models.mechanics.multiplayer.MultiplayerMechanic) DiscordUser(gg.projecteden.nexus.models.discord.DiscordUser) OptionalPlayer(me.lexikiq.OptionalPlayer) Player(org.bukkit.entity.Player) DiscordUserService(gg.projecteden.nexus.models.discord.DiscordUserService) Guild(net.dv8tion.jda.api.entities.Guild) Member(net.dv8tion.jda.api.entities.Member) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with DiscordUserService

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);
}
Also used : Color(java.awt.Color) Arrays(java.util.Arrays) Getter(lombok.Getter) SneakyThrows(lombok.SneakyThrows) JsonBuilder(gg.projecteden.nexus.utils.JsonBuilder) BiFunction(java.util.function.BiFunction) Async(gg.projecteden.annotations.Async) Arg(gg.projecteden.nexus.framework.commands.models.annotations.Arg) HashMap(java.util.HashMap) Group(gg.projecteden.nexus.framework.commands.models.annotations.Permission.Group) Bot(gg.projecteden.nexus.features.discord.Bot) ArrayList(java.util.ArrayList) Nullables.isNullOrEmpty(gg.projecteden.nexus.utils.Nullables.isNullOrEmpty) HashSet(java.util.HashSet) PlayerUtils(gg.projecteden.nexus.utils.PlayerUtils) Role(net.dv8tion.jda.api.entities.Role) Gson(com.google.gson.Gson) Map(java.util.Map) Permission(gg.projecteden.nexus.framework.commands.models.annotations.Permission) Nickname(gg.projecteden.nexus.models.nickname.Nickname) Nexus(gg.projecteden.nexus.Nexus) Message(net.dv8tion.jda.api.entities.Message) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path) Nerd(gg.projecteden.nexus.models.nerd.Nerd) TimeUtil(net.dv8tion.jda.api.utils.TimeUtil) Rank(gg.projecteden.nexus.models.nerd.Rank) DiscordUserService(gg.projecteden.nexus.models.discord.DiscordUserService) CustomCommand(gg.projecteden.nexus.framework.commands.models.CustomCommand) FileUtils(org.apache.commons.io.FileUtils) UUID(java.util.UUID) Discord(gg.projecteden.nexus.features.discord.Discord) Utils(gg.projecteden.nexus.utils.Utils) OfflinePlayer(org.bukkit.OfflinePlayer) DiscordId(gg.projecteden.utils.DiscordId) Consumer(java.util.function.Consumer) DiscordUser(gg.projecteden.nexus.models.discord.DiscordUser) IOUtils(gg.projecteden.nexus.utils.IOUtils) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) CommandEvent(gg.projecteden.nexus.framework.commands.models.events.CommandEvent) MessageBuilder(net.dv8tion.jda.api.MessageBuilder) Data(lombok.Data) TextChannel(gg.projecteden.utils.DiscordId.TextChannel) AllArgsConstructor(lombok.AllArgsConstructor) Confirm(gg.projecteden.nexus.framework.commands.models.annotations.Confirm) DiscordUser(gg.projecteden.nexus.models.discord.DiscordUser) HashMap(java.util.HashMap) Role(net.dv8tion.jda.api.entities.Role) JsonBuilder(gg.projecteden.nexus.utils.JsonBuilder) OfflinePlayer(org.bukkit.OfflinePlayer) ArrayList(java.util.ArrayList) List(java.util.List) DiscordUserService(gg.projecteden.nexus.models.discord.DiscordUserService) UUID(java.util.UUID) HashSet(java.util.HashSet) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path) Async(gg.projecteden.annotations.Async)

Aggregations

DiscordUserService (gg.projecteden.nexus.models.discord.DiscordUserService)16 DiscordUser (gg.projecteden.nexus.models.discord.DiscordUser)15 Path (gg.projecteden.nexus.framework.commands.models.annotations.Path)5 Async (gg.projecteden.annotations.Async)4 Nexus (gg.projecteden.nexus.Nexus)3 Discord (gg.projecteden.nexus.features.discord.Discord)3 Permission (gg.projecteden.nexus.framework.commands.models.annotations.Permission)3 Nickname (gg.projecteden.nexus.models.nickname.Nickname)3 JsonBuilder (gg.projecteden.nexus.utils.JsonBuilder)3 List (java.util.List)3 Role (net.dv8tion.jda.api.entities.Role)3 Component (net.kyori.adventure.text.Component)3 Command (gg.projecteden.discord.appcommands.annotations.Command)2 NexusAppCommand (gg.projecteden.nexus.features.discord.appcommands.NexusAppCommand)2 BadgeUserService (gg.projecteden.nexus.models.badge.BadgeUserService)2 Name (gg.projecteden.nexus.utils.Name)2 DiscordId (gg.projecteden.utils.DiscordId)2 TextChannel (gg.projecteden.utils.DiscordId.TextChannel)2 Color (java.awt.Color)2 ArrayList (java.util.ArrayList)2