Java Code Examples for net.dv8tion.jda.api.entities.Guild#getIdLong()
The following examples show how to use
net.dv8tion.jda.api.entities.Guild#getIdLong() .
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: PunishmentManager.java From Arraybot with Apache License 2.0 | 6 votes |
/** * Creates a new punishment. * @param guild The guild in which the punishment occurred. * @param punished The punished user. * @param type The punishment type. * @param staff The staff member. * @param viaAudit Whether or not the punishment has already occurred and the manager is just handling the result. * @param expiration The time, in milliseconds, when the punishment will expire. * @param reason The reason for the punishment. * @return True if the punishment was successful, false if it was not. */ public boolean punish(Guild guild, long punished, PunishmentType type, long staff, long expiration, boolean viaAudit, String reason) { reason = reason == null ? Message.PUNISH_EMBED_REASON_DEFAULT.getContent(guild.getIdLong()) : reason; Boolean revocation = null; if(!viaAudit) { Pair<Boolean, Boolean> result = type.getPunishment().punish(guild, punished, reason); if(!result.getA()) { return false; } revocation = result.getB(); } long guildId = guild.getIdLong(); GuildEntry guildEntry = (GuildEntry) Category.GUILD.getEntry(); int old = Integer.valueOf(guildEntry.fetch(guildEntry.getField(GuildEntry.Fields.COUNT_PUNISHMENT), guildId, null)); boolean revoke = revocation == null ? type == PunishmentType.KICK : revocation; PunishmentObject punishmentObject = new PunishmentObject(++old, punished, type, staff, expiration, revoke, reason); punishmentObject.toRedis(guild); schedulePunishmentRevocation(guild, punishmentObject); log(guild, punishmentObject, false, null); return true; }
Example 2
Source File: MemberListener.java From Arraybot with Apache License 2.0 | 6 votes |
/** * Applies the autorole to the specified member. * @param member The member. */ private void assignAutoRole(Member member) { Guild guild = member.getGuild(); long guildId = guild.getIdLong(); GuildEntry entry = (GuildEntry) Category.GUILD.getEntry(); boolean apply = Boolean.valueOf(entry.fetch(entry.getField(GuildEntry.Fields.AUTOROLE_ENABLED), guildId, null)); if(!apply) { return; } String roleId = entry.fetch(entry.getField(GuildEntry.Fields.AUTOROLE_ROLE), guildId, null); Role role = guild.getRoleById(roleId); if(role == null) { return; } try { guild.addRoleToMember(member, role).queue(); } catch(PermissionException exception) { logger.warn("Could not apply the autorole in the guild {} due to a permission error.", guildId); } }
Example 3
Source File: PunishmentObject.java From Arraybot with Apache License 2.0 | 6 votes |
/** * Saves the punishment object to Redis. * @param guild The guild. */ public void toRedis(Guild guild) { long guildId = guild.getIdLong(); SetEntry punishments = (SetEntry) Category.PUNISHMENT_IDS.getEntry(); punishments.add(guildId, id); PunishmentEntry punishmentEntry = (PunishmentEntry) Category.PUNISHMENT.getEntry(); punishmentEntry.push(punishmentEntry.getField(PunishmentEntry.Fields.PUNISHMENT_ID), guildId, id, id); punishmentEntry.push(punishmentEntry.getField(PunishmentEntry.Fields.USER), guildId, id, user); punishmentEntry.push(punishmentEntry.getField(PunishmentEntry.Fields.TYPE), guildId, id, type.toString()); punishmentEntry.push(punishmentEntry.getField(PunishmentEntry.Fields.STAFF), guildId, id, staff); punishmentEntry.push(punishmentEntry.getField(PunishmentEntry.Fields.EXPIRATION), guildId, id, expiration); punishmentEntry.push(punishmentEntry.getField(PunishmentEntry.Fields.REVOKED), guildId, id, revoked); punishmentEntry.push(punishmentEntry.getField(PunishmentEntry.Fields.REASON), guildId, id, reason); GuildEntry guildEntry = (GuildEntry) Category.GUILD.getEntry(); guildEntry.push(guildEntry.getField(GuildEntry.Fields.COUNT_PUNISHMENT), guildId, null, id); }
Example 4
Source File: AudioUtils.java From SkyBot with GNU Affero General Public License v3.0 | 5 votes |
public synchronized GuildMusicManager getMusicManager(Guild guild) { final long guildId = guild.getIdLong(); GuildMusicManager mng = musicManagers.get(guildId); if (mng == null) { mng = new GuildMusicManager(guild, variables); musicManagers.put(guildId, mng); } if (!LavalinkManager.ins.isEnabled() && guild.getAudioManager().getSendingHandler() == null) { guild.getAudioManager().setSendingHandler(mng.getSendHandler()); } return mng; }
Example 5
Source File: AudioUtils.java From SkyBot with GNU Affero General Public License v3.0 | 5 votes |
public synchronized void removeMusicManager(Guild guild) { final long guildId = guild.getIdLong(); final GuildMusicManager mng = musicManagers.get(guildId); if (mng != null) { mng.stopAndClear(); musicManagers.remove(guildId); } }
Example 6
Source File: PlayerServiceImpl.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
@Override @Transactional public void play(AudioPlaylist playlist, List<TrackRequest> requests) throws DiscordException { if (CollectionUtils.isEmpty(requests)) { return; } TrackRequest request = requests.get(0); Guild guild = discordService.getShardManager().getGuildById(request.getGuildId()); if (guild == null) { return; } PlaybackInstance instance = getOrCreate(guild); boolean store = true; if (playlist instanceof StoredPlaylist) { StoredPlaylist storedPlaylist = (StoredPlaylist) playlist; if (isActive(guild)) { if (Objects.equals(storedPlaylist.getPlaylistId(), instance.getPlaylistId())) { throw new DiscordException("discord.command.audio.playlistInQueue"); } } else if (storedPlaylist.getGuildId() == guild.getIdLong()) { instance.setPlaylistId(storedPlaylist.getPlaylistId()); instance.setPlaylistUuid(storedPlaylist.getPlaylistUuid()); store = false; } } if (store) { storedPlaylistService.storeToPlaylist(instance, requests); } play(request, instance); if (requests.size() > 1) { requests.subList(1, requests.size()).forEach(instance::offer); } }
Example 7
Source File: PunishmentManager.java From Arraybot with Apache License 2.0 | 5 votes |
/** * Gets all punishments for a guild. * @param guild The guild. * @return A list of all punishments. */ public List<PunishmentObject> getAllPunishments(Guild guild) { long guildId = guild.getIdLong(); SetEntry entry = (SetEntry) Category.PUNISHMENT_IDS.getEntry(); List<PunishmentObject> punishments = new ArrayList<>(); for(String punishment : entry.values(guildId)) { punishments.add(PunishmentObject.fromRedis(guild, Integer.valueOf(punishment))); } return punishments; }
Example 8
Source File: PunishmentObject.java From Arraybot with Apache License 2.0 | 5 votes |
/** * Gets the punishment from Redis. * @param guild The guild. * @param id The ID of the punishment. * @return A punishment object. */ public static PunishmentObject fromRedis(Guild guild, int id) { long guildId = guild.getIdLong(); PunishmentEntry entry = (PunishmentEntry) Category.PUNISHMENT.getEntry(); long user = Long.valueOf(entry.fetch(entry.getField(PunishmentEntry.Fields.USER), guildId, id)); PunishmentType type = PunishmentType.fromString(entry.fetch(entry.getField(PunishmentEntry.Fields.TYPE), guildId, id)); long staff = Long.valueOf(entry.fetch(entry.getField(PunishmentEntry.Fields.STAFF), guildId, id)); long expiration = Long.valueOf(entry.fetch(entry.getField(PunishmentEntry.Fields.EXPIRATION), guildId, id)); boolean revoked = Boolean.valueOf(entry.fetch(entry.getField(PunishmentEntry.Fields.REVOKED), guildId, id)); String reason = entry.fetch(entry.getField(PunishmentEntry.Fields.REASON), guildId, id); return new PunishmentObject(id, user, type, staff, expiration, revoked, reason); }
Example 9
Source File: FilterBypass.java From Arraybot with Apache License 2.0 | 5 votes |
/** * Gets the filter bypass type from Redis. * @param guild The guild. * @param id The unique bypass ID. * @return A bypass type, presuming the ID is valid. */ public static FilterBypass fromRedis(Guild guild, int id) { long guildId = guild.getIdLong(); FilterBypassEntry entry = (FilterBypassEntry) Category.FILTER_BYPASS.getEntry(); String rawType = entry.fetch(entry.getField(FilterBypassEntry.Fields.TYPE), guildId, id); long value = Long.valueOf(entry.fetch(entry.getField(FilterBypassEntry.Fields.VALUE), guildId, id)); return new FilterBypass(FilterBypassType.fromString(rawType), value); }
Example 10
Source File: InsufficientPermissionException.java From JDA with Apache License 2.0 | 5 votes |
private InsufficientPermissionException(@Nonnull Guild guild, @Nullable GuildChannel channel, @Nonnull Permission permission) { super(permission, "Cannot perform action due to a lack of Permission. Missing permission: " + permission.toString()); this.guildId = guild.getIdLong(); this.channelId = channel == null ? 0 : channel.getIdLong(); this.channelType = channel == null ? ChannelType.UNKNOWN : channel.getType(); }
Example 11
Source File: InsufficientPermissionException.java From JDA with Apache License 2.0 | 5 votes |
private InsufficientPermissionException(@Nonnull Guild guild, @Nullable GuildChannel channel, @Nonnull Permission permission, @Nonnull String reason) { super(permission, reason); this.guildId = guild.getIdLong(); this.channelId = channel == null ? 0 : channel.getIdLong(); this.channelType = channel == null ? ChannelType.UNKNOWN : channel.getType(); }
Example 12
Source File: PunishmentManager.java From Arraybot with Apache License 2.0 | 4 votes |
/** * Get the punishment embed. * @param guild The guild in which the punishment was invoked. * @param punishmentObject The punishment itself. * @param onRevoke If the punishment is being revoked. * @param revoker The person who revoked, null if it is not being revoked. * @return The embed. */ public CustomEmbedBuilder getEmbed(Guild guild, PunishmentObject punishmentObject, boolean onRevoke, Long revoker) { long guildId = guild.getIdLong(); String punishmentType; if(onRevoke) { switch(punishmentObject.getType()) { case TEMP_BAN: case BAN: punishmentType = Message.PUNISH_TYPE_UNBAN.getContent(guildId); break; case TEMP_MUTE: case MUTE: punishmentType = Message.PUNISH_TYPE_UNMUTE.getContent(guild.getIdLong()); break; default: punishmentType = Message.PUNISH_TYPE_UNKNOWN.getContent(guild.getIdLong()); } } else { punishmentType = punishmentObject.getType().getName().getContent(guild.getIdLong()); } CustomEmbedBuilder embed = UEmbed.getEmbed(guild) .setAuthor(Message.PUNISH_EMBED_TITLE.getContent(guild.getIdLong(), punishmentType, String.valueOf(punishmentObject.getId())), null, null) .addField(Message.PUNISH_EMBED_USER.getContent(guildId), UUser.asMention(punishmentObject.getUser()), false) .addField(Message.PUNISH_EMBED_STAFF.getContent(guildId), onRevoke ? revoker == null ? Message.PUNISH_EMBED_AUTOMATIC.getContent(guildId) : revoker == UDefaults.DEFAULT_UNKNOWN_SNOWFLAKE ? Message.PUNISH_EMBED_UNKNOWN.getContent(guildId) : UUser.asMention(revoker) : UUser.asMention(punishmentObject.getStaff()), false); if(!onRevoke) { embed.addField(Message.PUNISH_EMBED_REASON.getContent(guildId), punishmentObject.getReason(), false); if(punishmentObject.getExpiration() > 0) { embed.addField(Message.PUNISH_EMBED_EXPIRATION.getContent(guildId), UTime.getDisplayableTime(guild, punishmentObject.getExpiration()), false) .setFooter(Message.PUNISH_EMBED_EXPIRATION_FOOTER.getContent(guildId), null); } } return embed; }
Example 13
Source File: MemberListener.java From Arraybot with Apache License 2.0 | 4 votes |
/** * Logs a join/leave message. * @param event The event. * @param join True = join, false = leave. */ private void handleMemberMessages(GenericGuildMemberEvent event, boolean join) { Guild guild = event.getGuild(); long guildId = guild.getIdLong(); GuildEntry entry = (GuildEntry) Category.GUILD.getEntry(); GuildEntry.Fields field; GuildEntry.Fields channelId; GuildEntry.Fields messageId; if(join) { field = GuildEntry.Fields.JOIN_ANNOUNCER; channelId = GuildEntry.Fields.JOIN_CHANNEL; messageId = GuildEntry.Fields.JOIN_MESSAGE; } else { field = GuildEntry.Fields.LEAVE_ANNOUNCER; channelId = GuildEntry.Fields.LEAVE_CHANNEL; messageId = GuildEntry.Fields.LEAVE_MESSAGE; } boolean log = Boolean.valueOf(entry.fetch(entry.getField(field), guildId, null)); if(!log) { return; } String id = entry.fetch(entry.getField(channelId), guildId, null); TextChannel channel = guild.getTextChannelById(id); if(channel == null || UChannel.cantTalk(channel)) { return; } String message = entry.fetch(entry.getField(messageId), guildId, null); if(message.equals(UDefaults.DEFAULT_NULL)) { return; } message = UPlaceholder.replaceCore(event.getMember(), message); boolean privateMessage = false; String privateMessageParameter = "--pm"; if(message.contains(privateMessageParameter)) { privateMessage = true; message = message.replace(privateMessageParameter, ""); } if(message.length() > Limits.MESSAGE.getLimit()) { return; } final String finalMessage = message; if(privateMessage) { event.getMember().getUser().openPrivateChannel().queue(privateChannel -> privateChannel.sendMessage(finalMessage).queue()); return; } channel.sendMessage(finalMessage).queue(); }
Example 14
Source File: ConnectionRequest.java From JDA with Apache License 2.0 | 4 votes |
public ConnectionRequest(Guild guild) { this.stage = ConnectionStage.DISCONNECT; this.guildId = guild.getIdLong(); }