net.dv8tion.jda.api.events.guild.GenericGuildEvent Java Examples
The following examples show how to use
net.dv8tion.jda.api.events.guild.GenericGuildEvent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GuildMemberListener.java From SkyBot with GNU Affero General Public License v3.0 | 5 votes |
@Nonnull private String parseGuildVars(String rawMessage, GenericGuildEvent event) { if (!(event instanceof GuildMemberJoinEvent) && !(event instanceof GuildMemberRemoveEvent)) { return "This code should never run"; } if (rawMessage == null || "".equals(rawMessage.trim())) { return ""; } final User user; if (event instanceof GuildMemberJoinEvent) { user = ((GuildMemberJoinEvent) event).getUser(); } else { user = ((GuildMemberRemoveEvent) event).getUser(); } final Guild guild = event.getGuild(); final GuildSettings s = GuildSettingsUtils.getGuild(guild, variables); final long welcomeLeaveChannel = s.getWelcomeLeaveChannel(); final Parser parser = CommandUtils.PARSER_SUPPLIER.get(); final String message = parser.put("user", user) .put("guild", event.getGuild()) .put("channel", event.getGuild().getTextChannelById(welcomeLeaveChannel)) .put("args", "") .parse(rawMessage); parser.clear(); return message; }
Example #2
Source File: ContextServiceImpl.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
@Override public void initContext(GenericEvent event) { Guild guild = null; User user = null; if (event instanceof GenericGuildMemberEvent) { GenericGuildMemberEvent memberEvent = (GenericGuildMemberEvent) event; guild = memberEvent.getMember().getGuild(); user = memberEvent.getMember().getUser(); } if (guild == null && event instanceof GenericGuildEvent) { guild = ((GenericGuildEvent) event).getGuild(); } if (guild == null || user == null) { Member member = resolverService.getMember(event); if (member != null) { guild = member.getGuild(); user = member.getUser(); } } if (guild == null) { guild = resolverService.getGuild(event); } if (user == null) { user = resolverService.getUser(event); } if (guild != null) { initContext(guild); } if (user != null) { initContext(user); } }
Example #3
Source File: PunishmentListener.java From Arraybot with Apache License 2.0 | 5 votes |
/** * Handles the punishment or punishment revocation. * @param event The event. * @param userObject The user object. * @param type The type of punishment. * @param roles The roles involved in the event, should be null unless it is a mute or unmute. * @param revoke True: revocation, false: punishment creation. */ private void handlePunishment(GenericGuildEvent event, User userObject, PunishmentType type, Role[] roles, boolean revoke) { Guild guild = event.getGuild(); if(!event.getGuild().getSelfMember().hasPermission(Permission.VIEW_AUDIT_LOGS)) { return; } long user = userObject.getIdLong(); guild.retrieveAuditLogs().queue(entries -> { if(entries.isEmpty()) { return; } AuditLogEntry entry = entries.get(0); if(!isPunishment(entry, user, type, roles) || entry.getUser() == null || entry.getUser().getIdLong() == guild.getSelfMember().getUser().getIdLong()) { return; } long staff = entry.getUser().getIdLong(); if(!revoke) { punishmentManager.punish(guild, user, type, staff, -1, true, entry.getReason()); } else { PunishmentObject punishmentObject = ULambda.INSTANCE.getSpecificGeneralizedPunishment(guild, user, type); if(punishmentObject == null) { return; } if(!punishmentManager.revoke(guild, punishmentObject, staff)) { Arraybot.INSTANCE.getLogger().error("Failed the revocation of the punishment number {} in the guild {}.", punishmentObject.getId(), guild.getIdLong()); } } }); }
Example #4
Source File: DynamicModifiers.java From MantaroBot with GNU General Public License v3.0 | 4 votes |
public DynamicModifiers mapEvent(String prefix, GenericGuildEvent event) { return this .mapGuild(k(prefix, "guild"), event.getGuild()) .mapMember(k(prefix, "me"), event.getGuild().getSelfMember()); }
Example #5
Source File: I18n.java From MantaroBot with GNU General Public License v3.0 | 4 votes |
public static I18n of(GenericGuildEvent event) { return of(event.getGuild().getId()); }