From 003264a551114143b2a9a323fd2c7e8545703f26 Mon Sep 17 00:00:00 2001 From: Ushie Date: Thu, 21 May 2026 05:31:30 +0300 Subject: [PATCH] feat: PikachuGabe --- .../com/aliucord/gradle/repo/Authors.kt | 1 + plugins/TwitterDownloadFix/build.gradle | 34 ++++++++++ .../aluicord/plugins/TwitterDownloadFix.java | 68 +++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 plugins/TwitterDownloadFix/build.gradle create mode 100644 plugins/TwitterDownloadFix/src/main/java/com/aluicord/plugins/TwitterDownloadFix.java diff --git a/build-logic/src/main/kotlin/com/aliucord/gradle/repo/Authors.kt b/build-logic/src/main/kotlin/com/aliucord/gradle/repo/Authors.kt index ddfbabd..af00cdc 100644 --- a/build-logic/src/main/kotlin/com/aliucord/gradle/repo/Authors.kt +++ b/build-logic/src/main/kotlin/com/aliucord/gradle/repo/Authors.kt @@ -54,6 +54,7 @@ object Authors { val Derlan = Author("Derlan", 821545900807028757L) val Link = Author("Link", 725923756555501658L) val ArjixWasTaken = Author("ArjixWasTaken", 674710789138939916L) + val PikachuGabe = Author("pikachugabe", 701095070870274139L) } /** diff --git a/plugins/TwitterDownloadFix/build.gradle b/plugins/TwitterDownloadFix/build.gradle new file mode 100644 index 0000000..dab5b9a --- /dev/null +++ b/plugins/TwitterDownloadFix/build.gradle @@ -0,0 +1,34 @@ +import com.aliucord.gradle.repo.Authors +import com.aliucord.gradle.repo.author + +plugins { + id("com.aliucord.plugins-repo") +} + +version = "1.3.1" +description = "Make Twitter embed images download as `jpg` instead of `jpg:large`." + +aliucord { + author(Authors.PikachuGabe) + + changelog.set(""" + # 1.3.1 + Bluesky actually stores the files as @jpeg instead of .jpeg so changing the URL doesn't work, so I can't fix that right now. + Will have to figure out how to change the file type after downloading instead of just changing the download URL. + + # 1.3.0 + Added bluesky support because I noticed it uses `@` instead of `.` when denoting file type. Not updating plugin name as that would break the updater. + + # 1.2.0 + Fixed the plugin. Again. + Now downloads directly from twitter instead of through discord's external image stuff. + + # 1.1.0 + Fixed the plugin. + Switched to regex for file renaming. + Renamed plugin at Rushii's request. + + # 1.0.0 + Plugin release + """) +} \ No newline at end of file diff --git a/plugins/TwitterDownloadFix/src/main/java/com/aluicord/plugins/TwitterDownloadFix.java b/plugins/TwitterDownloadFix/src/main/java/com/aluicord/plugins/TwitterDownloadFix.java new file mode 100644 index 0000000..529fa72 --- /dev/null +++ b/plugins/TwitterDownloadFix/src/main/java/com/aluicord/plugins/TwitterDownloadFix.java @@ -0,0 +1,68 @@ +package com.aluicord.plugins; + +import android.content.Context; +import android.net.Uri; + +import com.aliucord.annotations.AliucordPlugin; +import com.aliucord.entities.Plugin; +import com.aliucord.patcher.PreHook; +import com.discord.utilities.io.NetworkUtils; + +import java.util.List; + +import kotlin.jvm.functions.Function1; + +@AliucordPlugin +public class TwitterDownloadFix extends Plugin { + + @Override + public void start(Context context) throws Throwable { + + patcher.patch( + NetworkUtils.class.getDeclaredMethod("downloadFile", Context.class, Uri.class, String.class, String.class, Function1.class, Function1.class), + new PreHook(param -> { + Uri uri = (Uri) param.args[1]; + + String Url = "tmp"; // I have to set up this variable before the if statements so the compiler can see them when it compiles the try/catch statement. + + String uriStr = uri.toString(); + // logger.verbose(uriStr); + + if (uri.getPath().contains(".twimg.com")) { + Url = "twt"; + // } else if (uri.getPath().contains("cdn.bsky.app")) { + // Url = "bsky"; + } else { + return; + } + + try { + if (Url == "twt") { + uriStr = uriStr.replaceAll("(?i)((\\.jpg:large)|(\\.jpg%3Alarge)|(\\.jpg_large)|(\\.jpg%5Flarge))$", ".jpg"); + uriStr = uriStr.replaceAll(".*https\\/", "https://"); + uri = Uri.parse(uriStr); + // } else if (Url == "bsky") { + // uriStr = uriStr.replaceAll("(?i)((@)|(%40))", "."); + // logger.verbose(uriStr); + // uriStr = uriStr.replaceAll(".*https\\/", "https://"); + // logger.verbose(uriStr); + // uri = Uri.parse(uriStr); + // Bluesky actually stores the files as @jpeg instead of .jpeg so changing the URL doesn't work, will have to figure out how to change the file type after downloading. + } + } catch (Exception e) { + logger.error(e); + } + + param.args[1] = uri; + }) + ); + + } + + @Override + public void stop(Context context) { + patcher.unpatchAll(); + } + + +}