Merge remote-tracking branch 'upstream/dev' into immediate-finds
This commit is contained in:
parent
7c8c2ff5b8
commit
82f9e36e5a
|
@ -35,6 +35,7 @@ export const ALLOWED_PROTOCOLS = [
|
|||
"steam:",
|
||||
"spotify:",
|
||||
"com.epicgames.launcher:",
|
||||
"tidal:"
|
||||
];
|
||||
|
||||
export const IS_VANILLA = /* @__PURE__ */ process.argv.includes("--vanilla");
|
||||
|
|
|
@ -24,12 +24,11 @@ import { closeAllModals } from "@utils/modal";
|
|||
import definePlugin, { OptionType } from "@utils/types";
|
||||
import { maybePromptToUpdate } from "@utils/updater";
|
||||
import { findByProps } from "@webpack";
|
||||
import { FluxDispatcher, NavigationRouter, SelectedChannelStore } from "@webpack/common";
|
||||
import { DraftType, FluxDispatcher, NavigationRouter, SelectedChannelStore } from "@webpack/common";
|
||||
|
||||
const CrashHandlerLogger = new Logger("CrashHandler");
|
||||
const ModalStack = findByProps("pushLazy", "popAll");
|
||||
const DraftManager = findByProps("clearDraft", "saveDraft");
|
||||
const { DraftType } = findByProps("DraftType");
|
||||
const { closeExpressionPicker } = findByProps("closeExpressionPicker", "openExpressionPicker");
|
||||
|
||||
const settings = definePluginSettings({
|
||||
|
@ -126,8 +125,11 @@ export default definePlugin({
|
|||
try {
|
||||
const channelId = SelectedChannelStore.getChannelId();
|
||||
|
||||
DraftManager.clearDraft(channelId, DraftType.ChannelMessage);
|
||||
DraftManager.clearDraft(channelId, DraftType.FirstThreadMessage);
|
||||
for (const key in DraftType) {
|
||||
if (!Number.isNaN(Number(key))) continue;
|
||||
|
||||
DraftManager.clearDraft(channelId, DraftType[key]);
|
||||
}
|
||||
} catch (err) {
|
||||
CrashHandlerLogger.debug("Failed to clear drafts.", err);
|
||||
}
|
||||
|
|
|
@ -24,13 +24,12 @@ import { getCurrentGuild } from "@utils/discord";
|
|||
import { Logger } from "@utils/Logger";
|
||||
import definePlugin, { OptionType } from "@utils/types";
|
||||
import { findByProps, findStore, webpackDependantLazy } from "@webpack";
|
||||
import { Alerts, ChannelStore, EmojiStore, FluxDispatcher, Forms, IconUtils, lodash, Parser, PermissionsBits, PermissionStore, UploadHandler, UserSettingsActionCreators, UserStore } from "@webpack/common";
|
||||
import { Alerts, ChannelStore, DraftType, EmojiStore, FluxDispatcher, Forms, IconUtils, lodash, Parser, PermissionsBits, PermissionStore, UploadHandler, UserSettingsActionCreators, UserStore } from "@webpack/common";
|
||||
import type { CustomEmoji } from "@webpack/types";
|
||||
import type { Message } from "discord-types/general";
|
||||
import { applyPalette, GIFEncoder, quantize } from "gifenc";
|
||||
import type { ReactElement, ReactNode } from "react";
|
||||
|
||||
const DRAFT_TYPE = 0;
|
||||
const StickerStore = findStore("StickersStore") as {
|
||||
getPremiumPacks(): StickerPack[];
|
||||
getAllGuildStickers(): Map<string, Sticker[]>;
|
||||
|
@ -806,7 +805,7 @@ export default definePlugin({
|
|||
gif.finish();
|
||||
|
||||
const file = new File([gif.bytesView()], `${stickerId}.gif`, { type: "image/gif" });
|
||||
UploadHandler.promptToUpload([file], ChannelStore.getChannel(channelId), DRAFT_TYPE);
|
||||
UploadHandler.promptToUpload([file], ChannelStore.getChannel(channelId), DraftType.ChannelMessage);
|
||||
},
|
||||
|
||||
canUseEmote(e: CustomEmoji, channelId: string) {
|
||||
|
|
|
@ -26,6 +26,7 @@ const ShortUrlMatcher = /^https:\/\/(spotify\.link|s\.team)\/.+$/;
|
|||
const SpotifyMatcher = /^https:\/\/open\.spotify\.com\/(track|album|artist|playlist|user|episode)\/(.+)(?:\?.+?)?$/;
|
||||
const SteamMatcher = /^https:\/\/(steamcommunity\.com|(?:help|store)\.steampowered\.com)\/.+$/;
|
||||
const EpicMatcher = /^https:\/\/store\.epicgames\.com\/(.+)$/;
|
||||
const TidalMatcher = /^https:\/\/tidal\.com\/browse\/(track|album|artist|playlist|user|video|mix)\/(.+)(?:\?.+?)?$/;
|
||||
|
||||
const settings = definePluginSettings({
|
||||
spotify: {
|
||||
|
@ -42,6 +43,11 @@ const settings = definePluginSettings({
|
|||
type: OptionType.BOOLEAN,
|
||||
description: "Open Epic Games links in the Epic Games Launcher",
|
||||
default: true,
|
||||
},
|
||||
tidal: {
|
||||
type: OptionType.BOOLEAN,
|
||||
description: "Open Tidal links in the Tidal app",
|
||||
default: true,
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -49,7 +55,7 @@ const Native = VencordNative.pluginHelpers.OpenInApp as PluginNative<typeof impo
|
|||
|
||||
export default definePlugin({
|
||||
name: "OpenInApp",
|
||||
description: "Open Spotify, Steam and Epic Games URLs in their respective apps instead of your browser",
|
||||
description: "Open Spotify, Tidal, Steam and Epic Games URLs in their respective apps instead of your browser",
|
||||
authors: [Devs.Ven],
|
||||
settings,
|
||||
|
||||
|
@ -127,6 +133,19 @@ export default definePlugin({
|
|||
return true;
|
||||
}
|
||||
|
||||
tidal: {
|
||||
if (!settings.store.tidal) break tidal;
|
||||
|
||||
const match = TidalMatcher.exec(url);
|
||||
if (!match) break tidal;
|
||||
|
||||
const [, type, id] = match;
|
||||
VencordNative.native.openExternal(`tidal://${type}/${id}`);
|
||||
|
||||
event?.preventDefault();
|
||||
return true;
|
||||
}
|
||||
|
||||
// in case short url didn't end up being something we can handle
|
||||
if (event?.defaultPrevented) {
|
||||
window.open(url, "_blank");
|
||||
|
|
|
@ -21,10 +21,9 @@ import { Devs } from "@utils/constants";
|
|||
import { makeLazy } from "@utils/lazy";
|
||||
import definePlugin from "@utils/types";
|
||||
import { findByProps } from "@webpack";
|
||||
import { UploadHandler, UserUtils } from "@webpack/common";
|
||||
import { DraftType, UploadHandler, UploadManager, UserUtils } from "@webpack/common";
|
||||
import { applyPalette, GIFEncoder, quantize } from "gifenc";
|
||||
|
||||
const DRAFT_TYPE = 0;
|
||||
const DEFAULT_DELAY = 20;
|
||||
const DEFAULT_RESOLUTION = 128;
|
||||
const FRAMES = 10;
|
||||
|
@ -59,9 +58,12 @@ async function resolveImage(options: Argument[], ctx: CommandContext, noServerPf
|
|||
for (const opt of options) {
|
||||
switch (opt.name) {
|
||||
case "image":
|
||||
const upload = UploadStore.getUploads(ctx.channel.id, DRAFT_TYPE)[0];
|
||||
const upload = UploadStore.getUpload(ctx.channel.id, opt.name, DraftType.SlashCommand);
|
||||
if (upload) {
|
||||
if (!upload.isImage) throw "Upload is not an image";
|
||||
if (!upload.isImage) {
|
||||
UploadManager.clearAll(ctx.channel.id, DraftType.SlashCommand);
|
||||
throw "Upload is not an image";
|
||||
}
|
||||
return upload.item.file;
|
||||
}
|
||||
break;
|
||||
|
@ -73,10 +75,12 @@ async function resolveImage(options: Argument[], ctx: CommandContext, noServerPf
|
|||
return user.getAvatarURL(noServerPfp ? void 0 : ctx.guild?.id, 2048).replace(/\?size=\d+$/, "?size=2048");
|
||||
} catch (err) {
|
||||
console.error("[petpet] Failed to fetch user\n", err);
|
||||
UploadManager.clearAll(ctx.channel.id, DraftType.SlashCommand);
|
||||
throw "Failed to fetch user. Check the console for more info.";
|
||||
}
|
||||
}
|
||||
}
|
||||
UploadManager.clearAll(ctx.channel.id, DraftType.SlashCommand);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -130,6 +134,7 @@ export default definePlugin({
|
|||
var url = await resolveImage(opts, cmdCtx, noServerPfp);
|
||||
if (!url) throw "No Image specified!";
|
||||
} catch (err) {
|
||||
UploadManager.clearAll(cmdCtx.channel.id, DraftType.SlashCommand);
|
||||
sendBotMessage(cmdCtx.channel.id, {
|
||||
content: String(err),
|
||||
});
|
||||
|
@ -147,6 +152,8 @@ export default definePlugin({
|
|||
canvas.width = canvas.height = resolution;
|
||||
const ctx = canvas.getContext("2d")!;
|
||||
|
||||
UploadManager.clearAll(cmdCtx.channel.id, DraftType.SlashCommand);
|
||||
|
||||
for (let i = 0; i < FRAMES; i++) {
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
|
@ -174,7 +181,7 @@ export default definePlugin({
|
|||
const file = new File([gif.bytesView()], "petpet.gif", { type: "image/gif" });
|
||||
// Immediately after the command finishes, Discord clears all input, including pending attachments.
|
||||
// Thus, setTimeout is needed to make this execute after Discord cleared the input
|
||||
setTimeout(() => UploadHandler.promptToUpload([file], cmdCtx.channel, DRAFT_TYPE), 10);
|
||||
setTimeout(() => UploadHandler.promptToUpload([file], cmdCtx.channel, DraftType.ChannelMessage), 10);
|
||||
},
|
||||
},
|
||||
]
|
||||
|
|
7
src/plugins/validReply/README.md
Normal file
7
src/plugins/validReply/README.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
# ValidReply
|
||||
|
||||
Fixes referenced (replied to) messages showing as "Message could not be loaded".
|
||||
|
||||
Hover the text to load the message!
|
||||
|
||||
![](https://github.com/Vendicated/Vencord/assets/45801973/d3286acf-e822-4b7f-a4e7-8ced18f581af)
|
106
src/plugins/validReply/index.ts
Normal file
106
src/plugins/validReply/index.ts
Normal file
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* Vencord, a Discord client mod
|
||||
* Copyright (c) 2024 Vendicated and contributors
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { Devs } from "@utils/constants";
|
||||
import definePlugin from "@utils/types";
|
||||
import { findByProps } from "@webpack";
|
||||
import { FluxDispatcher, RestAPI } from "@webpack/common";
|
||||
import { Message, User } from "discord-types/general";
|
||||
import { Channel } from "discord-types/general/index.js";
|
||||
|
||||
const enum ReferencedMessageState {
|
||||
Loaded,
|
||||
NotLoaded,
|
||||
Deleted
|
||||
}
|
||||
|
||||
interface Reply {
|
||||
baseAuthor: User,
|
||||
baseMessage: Message;
|
||||
channel: Channel;
|
||||
referencedMessage: { state: ReferencedMessageState; };
|
||||
compact: boolean;
|
||||
isReplyAuthorBlocked: boolean;
|
||||
}
|
||||
|
||||
const fetching = new Map<string, string>();
|
||||
let ReplyStore: any;
|
||||
|
||||
const { createMessageRecord } = findByProps("createMessageRecord");
|
||||
|
||||
export default definePlugin({
|
||||
name: "ValidReply",
|
||||
description: 'Fixes "Message could not be loaded" upon hovering over the reply',
|
||||
authors: [Devs.newwares],
|
||||
patches: [
|
||||
{
|
||||
find: "Messages.REPLY_QUOTE_MESSAGE_NOT_LOADED",
|
||||
replacement: {
|
||||
match: /Messages\.REPLY_QUOTE_MESSAGE_NOT_LOADED/,
|
||||
replace: "$&,onMouseEnter:()=>$self.fetchReply(arguments[0])"
|
||||
}
|
||||
},
|
||||
{
|
||||
find: "ReferencedMessageStore",
|
||||
replacement: {
|
||||
match: /constructor\(\)\{\i\(this,"_channelCaches",new Map\)/,
|
||||
replace: "$&;$self.setReplyStore(this);"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
setReplyStore(store: any) {
|
||||
ReplyStore = store;
|
||||
},
|
||||
|
||||
async fetchReply(reply: Reply) {
|
||||
const { channel_id: channelId, message_id: messageId } = reply.baseMessage.messageReference!;
|
||||
|
||||
if (fetching.has(messageId)) {
|
||||
return;
|
||||
}
|
||||
fetching.set(messageId, channelId);
|
||||
|
||||
RestAPI.get({
|
||||
url: `/channels/${channelId}/messages`,
|
||||
query: {
|
||||
limit: 1,
|
||||
around: messageId
|
||||
},
|
||||
retries: 2
|
||||
})
|
||||
.then(res => {
|
||||
const reply: Message | undefined = res?.body?.[0];
|
||||
if (!reply) return;
|
||||
|
||||
if (reply.id !== messageId) {
|
||||
ReplyStore.set(channelId, messageId, {
|
||||
state: ReferencedMessageState.Deleted
|
||||
});
|
||||
|
||||
FluxDispatcher.dispatch({
|
||||
type: "MESSAGE_DELETE",
|
||||
channelId: channelId,
|
||||
message: messageId
|
||||
});
|
||||
} else {
|
||||
ReplyStore.set(reply.channel_id, reply.id, {
|
||||
state: ReferencedMessageState.Loaded,
|
||||
message: createMessageRecord(reply)
|
||||
});
|
||||
|
||||
FluxDispatcher.dispatch({
|
||||
type: "MESSAGE_UPDATE",
|
||||
message: reply
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(() => { })
|
||||
.finally(() => {
|
||||
fetching.delete(messageId);
|
||||
});
|
||||
}
|
||||
});
|
|
@ -485,7 +485,11 @@ export const Devs = /* #__PURE__*/ Object.freeze({
|
|||
xocherry: {
|
||||
name: "xocherry",
|
||||
id: 221288171013406720n
|
||||
}
|
||||
},
|
||||
ScattrdBlade: {
|
||||
name: "ScattrdBlade",
|
||||
id: 678007540608532491n
|
||||
},
|
||||
} satisfies Record<string, Dev>);
|
||||
|
||||
// iife so #__PURE__ works correctly
|
||||
|
|
|
@ -24,12 +24,7 @@ export const Flux = findByProps<t.Flux>("connectStores");
|
|||
|
||||
export type GenericStore = t.FluxStore & Record<string, any>;
|
||||
|
||||
export enum DraftType {
|
||||
ChannelMessage = 0,
|
||||
ThreadSettings = 1,
|
||||
FirstThreadMessage = 2,
|
||||
ApplicationLauncherCommand = 3
|
||||
}
|
||||
export const { DraftType }: { DraftType: typeof t.DraftType; } = findByPropsLazy("DraftType");
|
||||
|
||||
// This is not actually a FluxStore
|
||||
export const PrivateChannelsStore = findByProps("openPrivateChannel");
|
||||
|
|
9
src/webpack/common/types/stores.d.ts
vendored
9
src/webpack/common/types/stores.d.ts
vendored
|
@ -173,6 +173,15 @@ export class DraftStore extends FluxStore {
|
|||
getThreadSettings(channelId: string): any | null;
|
||||
}
|
||||
|
||||
export enum DraftType {
|
||||
ChannelMessage,
|
||||
ThreadSettings,
|
||||
FirstThreadMessage,
|
||||
ApplicationLauncherCommand,
|
||||
Poll,
|
||||
SlashCommand,
|
||||
}
|
||||
|
||||
export class GuildStore extends FluxStore {
|
||||
getGuild(guildId: string): Guild;
|
||||
getGuildCount(): number;
|
||||
|
|
|
@ -107,6 +107,8 @@ export function showToast(message: string, type = ToastType.MESSAGE) {
|
|||
}
|
||||
|
||||
export const UserUtils = findByProps<t.UserUtils>("getUser", "fetchCurrentUser");
|
||||
|
||||
export const UploadManager = findByProps("clearAll", "addFile");
|
||||
export const UploadHandler = findByProps<t.UploadHandler>("showUploadFileSizeExceededError", "promptToUpload");
|
||||
|
||||
export const ApplicationAssetUtils = findByProps<t.ApplicationAssetUtils>("fetchAssetIds", "getAssetImage");
|
||||
|
|
|
@ -684,7 +684,7 @@ export async function extractAndLoadChunks(code: string[], matcher: RegExp = Def
|
|||
}
|
||||
|
||||
const [, rawChunkIds, entryPointId] = match;
|
||||
if (Number.isNaN(entryPointId)) {
|
||||
if (Number.isNaN(Number(entryPointId))) {
|
||||
const err = new Error("extractAndLoadChunks: Matcher didn't return a capturing group with the chunk ids array, or the entry point id returned as the second group wasn't a number");
|
||||
logger.warn(err, "Code:", code, "Matcher:", matcher);
|
||||
|
||||
|
|
Loading…
Reference in a new issue