use of net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent in project JDA by DV8FromTheWorld.
the class GuildMemberAddHandler method handleInternally.
@Override
protected Long handleInternally(DataObject content) {
final long id = content.getLong("guild_id");
boolean setup = getJDA().getGuildSetupController().onAddMember(id, content);
if (setup)
return null;
GuildImpl guild = (GuildImpl) getJDA().getGuildById(id);
if (guild == null) {
getJDA().getEventCache().cache(EventCache.Type.GUILD, id, responseNumber, allContent, this::handle);
EventCache.LOG.debug("Caching member for guild that is not yet cached. Guild ID: {} JSON: {}", id, content);
return null;
}
// Update memberCount
guild.onMemberAdd();
MemberImpl member = getJDA().getEntityBuilder().createMember(guild, content);
getJDA().getEntityBuilder().updateMemberCache(member);
getJDA().handleEvent(new GuildMemberJoinEvent(getJDA(), responseNumber, member));
return null;
}
use of net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent in project Gary by help-chat.
the class LoggingHandler method execute.
@Override
protected void execute(GenericEvent event) {
switch(EventsEnum.fromEvent(event)) {
case MEMBER_JOIN:
GuildMemberJoinEvent e = (GuildMemberJoinEvent) event;
log(EventsEnum.MEMBER_JOIN, e.getJDA(), e.getGuild(), e.getUser());
break;
case MEMBER_LEAVE:
if (!wasBan) {
GuildMemberLeaveEvent e2 = (GuildMemberLeaveEvent) event;
log(EventsEnum.MEMBER_LEAVE, e2.getJDA(), e2.getGuild(), e2.getUser());
} else {
wasBan = false;
}
break;
case MEMBER_BANNED:
wasBan = true;
GuildBanEvent e3 = (GuildBanEvent) event;
log(EventsEnum.MEMBER_BANNED, e3.getJDA(), e3.getGuild(), e3.getUser());
break;
case MESSAGE_EDIT:
GuildMessageUpdateEvent e5 = (GuildMessageUpdateEvent) event;
if (!e5.getAuthor().isBot() && StringUtils.equalsIgnoreCase(e5.getChannel().getName(), Constants.CHANNELS)) {
log(EventsEnum.MESSAGE_EDIT, e5.getJDA(), e5.getGuild(), e5.getAuthor(), e5.getChannel(), e5.getMessage());
}
break;
case MESSAGE_DELETE:
GuildMessageDeleteEvent e6 = (GuildMessageDeleteEvent) event;
if ((StringUtils.equalsIgnoreCase(e6.getChannel().getName(), Constants.CHANNELS))) {
log(EventsEnum.MESSAGE_DELETE, e6.getJDA(), e6.getGuild(), MessageUtils.getAuthor(e6.getMessageIdLong()), e6.getChannel(), e6.getMessageIdLong(), MessageUtils.getMessage(e6.getMessageIdLong()));
}
break;
case MESSAGE_BULK_DELETE:
MessageBulkDeleteEvent e7 = (MessageBulkDeleteEvent) event;
if ((StringUtils.equalsIgnoreCase(e7.getChannel().getName(), Constants.CHANNELS))) {
log(EventsEnum.MESSAGE_BULK_DELETE, e7.getJDA(), e7.getGuild(), e7.getChannel(), e7.getMessageIds());
}
break;
case VOICE_JOIN:
GuildVoiceJoinEvent e8 = (GuildVoiceJoinEvent) event;
log(EventsEnum.VOICE_JOIN, e8.getJDA(), e8.getGuild(), e8.getMember().getUser(), e8.getChannelJoined());
break;
}
}
use of net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent in project Sx4 by sx4-discord-bot.
the class LoggerHandler method onGuildMemberJoin.
public void onGuildMemberJoin(GuildMemberJoinEvent event) {
Guild guild = event.getGuild();
Member member = event.getMember();
User user = event.getUser();
LoggerEvent loggerEvent = user.isBot() ? LoggerEvent.BOT_ADDED : LoggerEvent.MEMBER_JOIN;
LoggerContext loggerContext = new LoggerContext().setUser(user);
WebhookEmbedBuilder embed = new WebhookEmbedBuilder();
embed.setColor(this.bot.getConfig().getGreen());
embed.setTimestamp(Instant.now());
embed.setAuthor(new EmbedAuthor(user.getAsTag(), user.getEffectiveAvatarUrl(), null));
embed.setFooter(new EmbedFooter(String.format("%s ID: %s", user.isBot() ? "Bot" : "User", member.getId()), null));
this.bot.getMongo().aggregateLoggers(this.getPipeline(guild.getIdLong())).whenComplete((documents, exception) -> {
if (ExceptionUtility.sendErrorMessage(exception)) {
return;
}
if (documents.isEmpty()) {
return;
}
Document data = documents.get(0);
List<Document> loggers = LoggerUtility.getValidLoggers(data.getList("loggers", Document.class), loggerEvent, loggerContext);
if (loggers.isEmpty()) {
return;
}
if (user.isBot()) {
StringBuilder description = new StringBuilder(String.format("`%s` was just added to the server", member.getEffectiveName()));
if (guild.getSelfMember().hasPermission(Permission.VIEW_AUDIT_LOGS)) {
this.retrieveAuditLogsDelayed(guild, ActionType.BOT_ADD).whenComplete((logs, auditException) -> {
User moderator = logs == null ? null : logs.stream().filter(e -> e.getTargetIdLong() == member.getIdLong()).filter(e -> Duration.between(e.getTimeCreated(), ZonedDateTime.now(ZoneOffset.UTC)).toSeconds() <= 5).map(AuditLogEntry::getUser).findFirst().orElse(null);
if (moderator != null) {
loggerContext.setModerator(moderator);
description.append(" by **").append(moderator.getAsTag()).append("**");
}
embed.setDescription(description.toString());
this.queue(guild, loggers, loggerEvent, loggerContext, embed.build());
});
return;
}
embed.setDescription(description.toString());
} else {
embed.setDescription(String.format("`%s` just joined the server", member.getEffectiveName()));
}
this.queue(guild, loggers, loggerEvent, loggerContext, embed.build());
});
}
use of net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent in project c10ver by Gartham.
the class CloverGuildMemberJoinConsumer method consume.
@Override
public boolean consume(GuildMemberJoinEvent event, InputProcessor<? extends GuildMemberJoinEvent> processor, InputConsumer<GuildMemberJoinEvent> consumer) {
synchronized (this) {
var ge = (GuildMemberJoinEvent) event;
Invite inviteee = clover.getInviteTracker().calcUser(ge);
if (inviteee == null)
return false;
var u = inviteee.getInviter();
if (u == null || u.isBot())
return false;
var inviter = clover.getEconomy().getAccount(u.getId());
var joinee = clover.getEconomy().getUser(ge.getUser().getId());
var serv = clover.getEconomy().getServer(ge.getGuild().getId());
if (serv.getIgnoredInvites().contains(inviteee.getCode())) {
if (joinee.getJoinedGuilds().contains(ge.getGuild().getId())) {
print(joinee.getUser().getAsTag() + '[' + joinee.getUserID() + "] joined " + ge.getGuild().getName() + '[' + ge.getGuild().getId() + "] with an ignored invite, again.");
if (clover.getEconomy().hasServer(ge.getGuild().getId())) {
var g = clover.getEconomy().getServer(ge.getGuild().getId());
if (g.getGeneralChannel() != null) {
var gen = ge.getGuild().getTextChannelById(g.getGeneralChannel());
if (gen != null)
gen.sendMessage(ge.getUser().getAsMention() + " welcome back to the server. ^w^").queue();
}
}
} else {
print(joinee.getUser().getAsTag() + '[' + joinee.getUserID() + "] joined " + ge.getGuild().getName() + '[' + ge.getGuild().getId() + "] with an ignored invite, for the FIRST time.");
Multiplier mult = Multiplier.ofHr(3, BigDecimal.ONE);
joinee.addMultiplier(mult);
joinee.getJoinedGuilds().add(ge.getGuild().getId());
joinee.save();
if (clover.getEconomy().hasServer(ge.getGuild().getId())) {
var g = clover.getEconomy().getServer(ge.getGuild().getId());
if (g.getGeneralChannel() != null) {
var gen = ge.getGuild().getTextChannelById(g.getGeneralChannel());
if (gen != null)
gen.sendMessage(ge.getUser().getAsMention() + " welcome to the server. ^w^\nYou received a multiplier of " + Utilities.prettyPrintMultiplier(BigDecimal.ONE) + " that lasts for **3h**.").queue();
}
}
}
} else {
StringBuilder sb;
var inv = inviter.getUser().getUser();
var join = joinee.getUser();
sb = new StringBuilder(inv == null ? "#Deleted Acc" : inv.getAsTag());
sb.append('[').append(inv == null ? "#DelUser" : inv.getId()).append("] has invited ").append(join.getAsTag()).append('[').append(join.getId()).append("] to ").append(ge.getGuild().getName()).append('[').append(ge.getGuild().getId()).append(']');
if (joinee.getJoinedGuilds().contains(ge.getGuild().getId())) {
print(sb.append('.').toString());
if (clover.getEconomy().hasServer(ge.getGuild().getId())) {
var g = clover.getEconomy().getServer(ge.getGuild().getId());
if (g.getGeneralChannel() != null) {
var gen = ge.getGuild().getTextChannelById(g.getGeneralChannel());
if (gen != null)
gen.sendMessage(ge.getUser().getAsMention() + " welcome back to the server.\nYou were invited back by: " + (inv == null ? "a deleted user" : inv.getAsMention()) + ".").queue();
}
}
} else {
print(sb.append(" for the FIRST time.").toString());
Multiplier mult = Multiplier.ofHr(3, BigDecimal.ONE);
inviter.getUser().addMultiplier(mult);
inviter.getUser().save();
joinee.addMultiplier(mult);
joinee.getJoinedGuilds().add(ge.getGuild().getId());
joinee.save();
if (clover.getEconomy().hasServer(ge.getGuild().getId())) {
var g = clover.getEconomy().getServer(ge.getGuild().getId());
if (g.getGeneralChannel() != null) {
var gen = ge.getGuild().getTextChannelById(g.getGeneralChannel());
if (gen != null)
gen.sendMessage(ge.getUser().getAsMention() + " welcome to the server. \nYou and " + inviter.getUser().getUser().getAsMention() + " both got a " + Utilities.prettyPrintMultiplier(BigDecimal.ONE) + " multiplier that lasts for **3h**.").queue();
}
}
}
}
}
return false;
}
Aggregations