use of gg.projecteden.nexus.models.discord.DiscordUserService in project Nexus by ProjectEdenGG.
the class DiscordAppCommand method forcelink.
@Verify
@RequiredRole("Staff")
@Command("Force link a Minecraft and Discord account")
void forcelink(@Desc("Minecraft account") DiscordUser player, @Desc("Discord account") Member discordUser) {
player.setUserId(discordUser.getId());
new DiscordUserService().save(player);
Discord.addRole(discordUser.getId(), DiscordId.Role.VERIFIED);
Discord.staffLog("**%s** Discord account force linked to **%s** by %s via Discord".formatted(player.getNickname(), player.getNameAndDiscrim(), user().getNickname()));
}
use of gg.projecteden.nexus.models.discord.DiscordUserService in project Nexus by ProjectEdenGG.
the class DiscordAppCommand method link.
@Command("Link your Discord and Minecraft accounts")
void link(@Desc("Minecraft account") DiscordUser player) {
DiscordUserService service = new DiscordUserService();
DiscordUser author = service.getFromUserId(member().getId());
if (author != null)
// Author already linked
if (!isNullOrEmpty(player.getUserId()))
if (author.getUserId().equals(player.getUserId()))
throw new InvalidInputException("You are already linked to that minecraft account");
else
throw new InvalidInputException("That minecraft account is already linked to a different Discord account. Type `/discord unlink` in-game to remove the link.");
else
throw new InvalidInputException("You are already linked to a different Minecraft account. Use `/discord unlink` in-game to remove the link.");
if (!isNullOrEmpty(player.getUserId()))
// Provided name is already linked
if (player.getUserId().equals(member().getId()))
// Lookup by user id failed?
throw new InvalidInputException("This should never happen <@" + User.GRIFFIN.getId() + ">");
else
throw new InvalidInputException("That Minecraft account is already linked to a different discord account. Type `/discord unlink` in-game to remove the link.");
String code = RandomStringUtils.randomAlphabetic(6);
Discord.getCodes().put(code, new DiscordUser(player.getUuid(), member().getId()));
Koda.console("Generated key " + code + " for " + Discord.getName(member().getId()));
replyEphemeral("Copy and paste the following command into minecraft to confirm the link ```/discord link %s```".formatted(code));
}
use of gg.projecteden.nexus.models.discord.DiscordUserService in project Nexus by ProjectEdenGG.
the class DiscordCaptchaListener method onGuildMemberJoin.
@Override
public void onGuildMemberJoin(@Nonnull GuildMemberJoinEvent event) {
Tasks.async(() -> {
final String id = event.getUser().getId();
DiscordCaptchaService captchaService = new DiscordCaptchaService();
DiscordCaptcha captcha = captchaService.get0();
CaptchaResult result = captcha.check(id);
if (result == CaptchaResult.CONFIRMED) {
Tasks.waitAsync(1, () -> {
Discord.addRole(id, Role.NERD);
DiscordUser user = new DiscordUserService().getFromUserId(id);
if (user != null)
Discord.addRole(id, Role.VERIFIED);
});
return;
}
Discord.staffLog("**[Captcha]** " + Discord.getName(event.getMember()) + " - Requiring verification");
captcha.require(id);
captchaService.save(captcha);
});
}
use of gg.projecteden.nexus.models.discord.DiscordUserService in project Nexus by ProjectEdenGG.
the class BridgeCommand method archive_editMessages_removeReference.
@Async
@Path("archive editMessages removeReference <roleId> [name]")
void archive_editMessages_removeReference(String roleId, String name) {
if (archive == null)
error("No archive loaded");
DiscordUser user = new DiscordUserService().getFromRoleId(roleId);
if (name == null)
if (user == null)
error("Role is not tied to a user, you must provide the name to use");
else
name = Nerd.of(user).getName();
List<String> messageIds = archive.getRoleMap().get(roleId);
send(PREFIX + "Editing " + messageIds.size() + " messages for user " + name);
for (String messageId : messageIds) updateRoleMention(roleId, "**" + name + "**", messageId);
send(json(PREFIX + "Done. Click here to remove the role").command("/bridge archive deleteRole " + roleId));
}
use of gg.projecteden.nexus.models.discord.DiscordUserService in project Nexus by ProjectEdenGG.
the class DiscordBridgeListener method onMessageReceived.
@Override
public void onMessageReceived(@NotNull MessageReceivedEvent event) {
Tasks.sync(() -> {
Optional<PublicChannel> channel = ChatManager.getChannelByDiscordId(event.getChannel().getId());
if (!channel.isPresent())
return;
if (event.getAuthor().isBot())
if (!event.getAuthor().getId().equals(User.UBER.getId()))
return;
final Message message = event.getMessage();
String content = stripColor(message.getContentDisplay().trim());
try {
content = EmojiParser.parseToAliases(content);
} catch (Throwable ignore) {
}
DiscordChatEvent discordChatEvent = new DiscordChatEvent(event.getMember(), channel.get(), content, content, !message.getAttachments().isEmpty(), channel.get().getPermission());
if (!discordChatEvent.callEvent()) {
Tasks.async(() -> message.delete().queue());
return;
}
content = discordChatEvent.getMessage();
DiscordUser user = new DiscordUserService().getFromUserId(event.getAuthor().getId());
JsonBuilder builder = new JsonBuilder();
builder.next(" " + channel.get().getDiscordColor() + "&l>&f");
if (content.length() > 0)
builder.next(" " + colorize(content.replaceAll("&", "&&f")));
for (Message.Attachment attachment : message.getAttachments()) builder.group().next(" &f&l[View Attachment]").url(attachment.getUrl());
Identity identity = user == null ? Identity.nil() : user.identity();
Broadcast.ingame().channel(channel.get()).sender(identity).message(viewer -> {
JsonBuilder json = new JsonBuilder(channel.get().getDiscordColor() + "[D]").hover("&5&lDiscord &fChannel").hover("&fMessages sent in &c#bridge &fon our").hover("&c/discord &fare shown in this channel").group().next(" ").group();
if (user != null)
json.next(Nerd.of(user.getUuid()).getChatFormat(viewer == null ? null : new ChatterService().get(viewer)));
else
json.next("&f" + Discord.getName(event.getMember(), event.getAuthor()));
return json.next(builder);
}).messageType(MessageType.CHAT).send();
});
}
Aggregations