Force avatar image refresh by using timestamps
JustBuddy opened this issue ยท 2 comments
I stumbled upon the fact that discord caches the images that we query from the avatar API for a very long time. Since the filenames in the Avatar API (Like minotar) does not change when you set a new Avatar, Discords long image caching takes effect. By using timestamps in the request, we could circumvent this.
Setting in Question: Experiment_EmbedAvatarUrl
Currently {username} and {size} are a thing there, I could not get PAPI's {localtime_time} placeholder to work there. (I downloaded it with /papi ecloud download LocalTime)
If I could run https://mineskin.de/helm/{username}/{size}.{localtime_time}.png
(or its UUID equivalent), it would allow me to force discord to not cache the avatar icons in the new join/leave messages.
Minotar delivers anything you throw at it, if I request https://minotar.net/helm/Buddy_DE/128.08062020-1947.png from them, they just straight up deliver me the image without issues.
The time it takes to refresh an avatar would then be up to the API alone.
Here is a part of the log that shows that we cache a different file if I add any text to the filename as suffix.
08.06 19:47:57 [Server] INFO [DiscordSRV] [DEBUG] [JDA] MESSAGE_UPDATE -> {"guild_id":"711852210140479538","id":"719608671922946049","embeds":[{"color":16711680,"author":{"icon_url":"https://mineskin.de/helm/Buddy_DE/128.08062020-1947.png","name":"Buddy_DE left the server","proxy_icon_url":"https://images-ext-1.discordapp.net/external/jjAPlO0rccCkm1jvIm_XrPP806mEmQn_0UL5UGRLigU/https/mineskin.de/helm/Buddy_DE/128.08062020-1947.png"},"type":"rich"}],"channel_id":"711852210761367571"}
(I used mineskin.de in the logged part, the result is the same for minotar.)
Guideline questions answered:
Reboot, no reload.
Running on DiscordSRV 1.19.0
DebugLevel: 1 DebugJDA: true DebugJDARestActions: true
Log attached: Relevant part attached.
Reference GitHub issue about the caching in the Discord GitHub; discord/discord-rpc#155
08.06 21:33:21 [Server] WARN [DiscordSRV] Task #471 for DiscordSRV v1.19.1-SNAPSHOT generated an exception
08.06 21:33:21 [Server] INFO java.lang.IllegalArgumentException: URL must be a valid http(s) or attachment url.
08.06 21:33:21 [Server] INFO at github.scarsz.discordsrv.dependencies.jda.internal.utils.Checks.check(Checks.java:43) ~[?:?]
08.06 21:33:21 [Server] INFO at github.scarsz.discordsrv.dependencies.jda.api.EmbedBuilder.urlCheck(EmbedBuilder.java:832) ~[?:?]
08.06 21:33:21 [Server] INFO at github.scarsz.discordsrv.dependencies.jda.api.EmbedBuilder.setAuthor(EmbedBuilder.java:654) ~[?:?]
08.06 21:33:21 [Server] INFO at github.scarsz.discordsrv.DiscordSRV.translateMessage(DiscordSRV.java:1388) ~[?:?]
08.06 21:33:21 [Server] INFO at github.scarsz.discordsrv.listeners.PlayerJoinLeaveListener.lambda$onPlayerJoin$1(PlayerJoinLeaveListener.java:111) ~[?:?]
08.06 21:33:21 [Server] INFO at org.bukkit.craftbukkit.v1_15_R1.scheduler.CraftTask.run(CraftTask.java:84) ~[patched_1.15.2.jar:git-Paper-334]
08.06 21:33:21 [Server] INFO at org.bukkit.craftbukkit.v1_15_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:461) ~[patched_1.15.2.jar:git-Paper-334]
08.06 21:33:21 [Server] INFO at net.minecraft.server.v1_15_R1.MinecraftServer.b(MinecraftServer.java:1256) ~[patched_1.15.2.jar:git-Paper-334]
08.06 21:33:21 [Server] INFO at net.minecraft.server.v1_15_R1.DedicatedServer.b(DedicatedServer.java:430) ~[patched_1.15.2.jar:git-Paper-334]
08.06 21:33:21 [Server] INFO at net.minecraft.server.v1_15_R1.MinecraftServer.a(MinecraftServer.java:1173) ~[patched_1.15.2.jar:git-Paper-334]
08.06 21:33:21 [Server] INFO at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:962) ~[patched_1.15.2.jar:git-Paper-334]
08.06 21:33:21 [Server] INFO at java.lang.Thread.run(Thread.java:748) [?:1.8.0_242]
Sadly, I am unable to get it to work.
Attempted settings formatting:
Experiment_EmbedAvatarUrl: https://minotar.net/helm/{username}/{size}.%localtime_time%.png
Experiment_EmbedAvatarUrl: https://minotar.net/helm/{username}/{size}.{localtime_time}.png
Experiment_EmbedAvatarUrl: https://minotar.net/helm/{username}/{size}.{%localtime_time%}.png
What would be the correct one?
Latest Dev-Snapshot, rebooted server.
ed5ff42 - added PAPI support, https://snapshot.discordsrv.com