From eff4beb0494cc38311a65d447335fa2d1b6de0bf Mon Sep 17 00:00:00 2001 From: Arnold Alejo Nunag Date: Thu, 3 Sep 2020 02:43:37 +0800 Subject: [PATCH] Add forgotten change, whoops --- .../java/sciwhiz12/janitor/utils/Util.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main/java/sciwhiz12/janitor/utils/Util.java b/src/main/java/sciwhiz12/janitor/utils/Util.java index 176ddcb..e797ef3 100644 --- a/src/main/java/sciwhiz12/janitor/utils/Util.java +++ b/src/main/java/sciwhiz12/janitor/utils/Util.java @@ -1,6 +1,6 @@ package sciwhiz12.janitor.utils; -import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.entities.*; import java.util.function.BiConsumer; import java.util.function.Consumer; @@ -14,7 +14,31 @@ public class Util { } public static String toString(final User user) { - return String.format("<%s#%s:%s>", user.getName(), user.getDiscriminator(), user.getId()); + return String.format("{User,%s#%s}:%s", user.getName(), user.getDiscriminator(), getID(user)); + } + + public static String toString(final MessageChannel channel) { + if (channel instanceof GuildChannel) { + GuildChannel gc = (GuildChannel) channel; + return String.format("[Channel:%s,%s@%s]%s", gc.getType(), gc.getName(), toString(gc.getGuild()), getID(channel)); + } + return String.format("[Channel:%s,%s]:%s", channel.getType(), channel.getName(), getID(channel)); + } + + public static String toString(final Guild guild) { + return String.format("(Guild:%s):%s", guild.getName(), getID(guild)); + } + + public static String getID(final ISnowflake snowflake) { + String prefix = "?"; + if (snowflake instanceof User) { + prefix = "@&"; + } else if (snowflake instanceof Role) { + prefix = "@!"; + } else if (snowflake instanceof MessageChannel) { + prefix = "#"; + } + return String.format("<%s%s>", prefix, snowflake.getIdLong()); } public static BiConsumer handle(final Consumer success,