validate id when getting user
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m11s
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m11s
This commit is contained in:
parent
38465f544d
commit
4ec65c8d6e
@ -85,9 +85,9 @@ public class PunishmentProfile extends Serializable {
|
|||||||
discordGuild.getName()
|
discordGuild.getName()
|
||||||
), false);
|
), false);
|
||||||
if (length != -1 && (type == PunishmentType.MUTE || type == PunishmentType.BAN)) {
|
if (length != -1 && (type == PunishmentType.MUTE || type == PunishmentType.BAN)) {
|
||||||
descriptionBuilder.appendLine("Length: %s".formatted(lengthFormatted), true);
|
descriptionBuilder.appendLine("Length: `%s`".formatted(lengthFormatted), true);
|
||||||
}
|
}
|
||||||
descriptionBuilder.appendLine("Reason: %s".formatted(reason), true);
|
descriptionBuilder.appendLine("Reason: `%s`".formatted(reason), true);
|
||||||
try {
|
try {
|
||||||
channel.sendMessage(descriptionBuilder.build()).complete();
|
channel.sendMessage(descriptionBuilder.build()).complete();
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
|
@ -11,6 +11,7 @@ import lombok.extern.log4j.Log4j2;
|
|||||||
import net.dv8tion.jda.api.entities.User;
|
import net.dv8tion.jda.api.entities.User;
|
||||||
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
|
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
|
||||||
import net.dv8tion.jda.api.events.user.update.UserUpdateGlobalNameEvent;
|
import net.dv8tion.jda.api.events.user.update.UserUpdateGlobalNameEvent;
|
||||||
|
import net.dv8tion.jda.api.utils.MiscUtil;
|
||||||
import net.jodah.expiringmap.ExpirationPolicy;
|
import net.jodah.expiringmap.ExpirationPolicy;
|
||||||
import net.jodah.expiringmap.ExpiringMap;
|
import net.jodah.expiringmap.ExpiringMap;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
@ -88,6 +89,16 @@ public class UserService implements EventListener {
|
|||||||
* @return The user
|
* @return The user
|
||||||
*/
|
*/
|
||||||
public BatUser getUser(@NonNull String id) {
|
public BatUser getUser(@NonNull String id) {
|
||||||
|
if (users.containsKey(id)) {
|
||||||
|
return users.get(id);
|
||||||
|
}
|
||||||
|
// Check if the ID is valid
|
||||||
|
try {
|
||||||
|
MiscUtil.parseSnowflake(id);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
User user = DiscordService.JDA.retrieveUserById(id).complete();
|
User user = DiscordService.JDA.retrieveUserById(id).complete();
|
||||||
if (user == null || user.isBot()) {
|
if (user == null || user.isBot()) {
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user