diff --git a/src/equicordplugins/clientSideBlock/index.tsx b/src/equicordplugins/clientSideBlock/index.tsx index 837d34da..3ce827ff 100644 --- a/src/equicordplugins/clientSideBlock/index.tsx +++ b/src/equicordplugins/clientSideBlock/index.tsx @@ -179,7 +179,7 @@ export default definePlugin({ find: ".GUILD_APPLICATION_PREMIUM_SUBSCRIPTION||", replacement: [ { - match: /let \i;let\{repliedAuthor:/, + match: /let \i,\{repliedAuthor:/, replace: "if(arguments[0] != null && arguments[0].referencedMessage.message != null) { if($self.shouldHideUser(arguments[0].referencedMessage.message.author.id, arguments[0].baseMessage.messageReference.channel_id)) { return $self.hiddenReplyComponent(); } }$&" } ] diff --git a/src/equicordplugins/customTimestamps/index.tsx b/src/equicordplugins/customTimestamps/index.tsx index 26078f2c..87930f6a 100644 --- a/src/equicordplugins/customTimestamps/index.tsx +++ b/src/equicordplugins/customTimestamps/index.tsx @@ -71,7 +71,7 @@ export default definePlugin({ find: "#{intl::MESSAGE_EDITED_TIMESTAMP_A11Y_LABEL}", replacement: [ { - match: /(?<=\i=\i\?)\(0,\i\.\i\)\((\i),"LT"\):\(0,\i\.\i\)\(\i,!0\)/, + match: /(?<=\i=null!=\i\?).{0,25}\((\i),"LT"\):\(0,\i\.\i\)\(\i,!0\)/, replace: '$self.format($1,"compactFormat","[calendar]"):$self.format($1,"cozyFormat","LT")', }, { diff --git a/src/equicordplugins/customUserColors/index.tsx b/src/equicordplugins/customUserColors/index.tsx index 57134557..9e825152 100644 --- a/src/equicordplugins/customUserColors/index.tsx +++ b/src/equicordplugins/customUserColors/index.tsx @@ -83,7 +83,7 @@ export default definePlugin({ // this also affects name headers in chats outside of servers find: '="SYSTEM_TAG"', replacement: { - match: /(?<=\i.gradientClassName]\),style:.{0,80}:void 0,)/, + match: /(?<=\i.gradientClassName]\),style:.{0,80}:void 0\}\)\(\),)/, replace: "style:{color:$self.colorIfServer(arguments[0])}," }, predicate: () => !Settings.plugins.IrcColors.enabled diff --git a/src/equicordplugins/messageLoggerEnhanced/index.tsx b/src/equicordplugins/messageLoggerEnhanced/index.tsx index d22f04d2..bbf4df3a 100644 --- a/src/equicordplugins/messageLoggerEnhanced/index.tsx +++ b/src/equicordplugins/messageLoggerEnhanced/index.tsx @@ -254,7 +254,7 @@ export default definePlugin({ ] }, { - find: "THREAD_STARTER_MESSAGE?null===", + find: "THREAD_STARTER_MESSAGE?null==", replacement: { match: /deleted:\i\.deleted, editHistory:\i\.editHistory,/, replace: "deleted:$self.getDeleted(...arguments), editHistory:$self.getEdited(...arguments)," diff --git a/src/equicordplugins/moreStickers/index.tsx b/src/equicordplugins/moreStickers/index.tsx index 6ee8628d..2388329f 100644 --- a/src/equicordplugins/moreStickers/index.tsx +++ b/src/equicordplugins/moreStickers/index.tsx @@ -56,7 +56,7 @@ export default definePlugin({ { find: ".gifts)", replacement: { - match: /,.{0,5}\(null===\(\w=\w\.stickers\)\|\|void 0.*?(\w)\.push\((\(0,\w\.jsx\))\((.+?),{disabled:\w,type:(\w)},"sticker"\)\)\)/, + match: /,.{0,5}\(null==\(\i=\i\.stickers\)\?void 0.*?(\i)\.push\((\(0,\w\.jsx\))\((.+?),{disabled:\i,type:(\i)},"sticker"\)\)\)/, replace: (m, _, jsx, compo, type) => { const c = "arguments[0].type"; return `${m},${c}?.submit?.button&&${_}.push(${jsx}(${compo},{disabled:!${c}?.submit?.button,type:${type},stickersType:"stickers+"},"stickers+"))`; diff --git a/src/equicordplugins/searchFix/index.tsx b/src/equicordplugins/searchFix/index.tsx index cb7f9f5e..5234537e 100644 --- a/src/equicordplugins/searchFix/index.tsx +++ b/src/equicordplugins/searchFix/index.tsx @@ -28,7 +28,7 @@ export default definePlugin({ { find: '"SearchStore",', replacement: { - match: /(\i)\.offset=null!==\((\i)=(\i)\.offset\)&&void 0!==(\i)\?(\i):0/i, + match: /(\i)\.offset=null!=\((\i)=(\i)\.offset\)\?(\i):0/i, replace: (_, v, v1, query, v3, v4) => `$self.main(${query}), ${v}.offset = null !== (${v1} = ${query}.offset) && void 0 !== ${v3} ? ${v4} : 0` } } diff --git a/src/equicordplugins/videoSpeed/index.tsx b/src/equicordplugins/videoSpeed/index.tsx index f066da2a..448d9ae7 100644 --- a/src/equicordplugins/videoSpeed/index.tsx +++ b/src/equicordplugins/videoSpeed/index.tsx @@ -27,7 +27,7 @@ export default definePlugin({ settings, patches: [ { - find: ".videoControls:", + find: /\.VIDEO\?\i\.videoControls:/, replacement: { match: /children:\[this\.renderPlayIcon\(\),.{0,200}\.setDurationRef}\),/, replace: "$&$self.SpeedButton()," diff --git a/src/plugins/_api/serverList.ts b/src/plugins/_api/serverList.ts index 00bf3054..37ed626a 100644 --- a/src/plugins/_api/serverList.ts +++ b/src/plugins/_api/serverList.ts @@ -39,7 +39,7 @@ export default definePlugin({ replace: "Vencord.Api.ServerList.renderAll(Vencord.Api.ServerList.ServerListRenderPosition.In).concat($&)" }, { - match: /discoveryIcon\}\)\}\)\]/, + match: /children:\i\}\)\]/, replace: "$&.concat(Vencord.Api.ServerList.renderAll(Vencord.Api.ServerList.ServerListRenderPosition.Below))" } ] diff --git a/src/plugins/consoleJanitor/index.tsx b/src/plugins/consoleJanitor/index.tsx index 5a3b3cd1..12fe231c 100644 --- a/src/plugins/consoleJanitor/index.tsx +++ b/src/plugins/consoleJanitor/index.tsx @@ -148,15 +148,15 @@ export default definePlugin({ { find: "is not a valid locale.", replacement: { - match: /\i\.error\(""\.concat\(\i," is not a valid locale."\)\);/, - replace: "" + match: /\i\.error(?=\(""\.concat\(\i," is not a valid locale."\)\))/, + replace: "$self.NoopLogger" } }, { find: '"AppCrashedFatalReport: getLastCrash not supported."', replacement: { - match: /console\.log\("AppCrashedFatalReport: getLastCrash not supported\."\);/, - replace: "" + match: /console\.log(?=\("AppCrashedFatalReport: getLastCrash not supported\."\))/, + replace: "$self.NoopLogger" } }, { diff --git a/src/plugins/customidle/index.ts b/src/plugins/customidle/index.ts index 97a77973..77e7d4e9 100644 --- a/src/plugins/customidle/index.ts +++ b/src/plugins/customidle/index.ts @@ -49,7 +49,7 @@ export default definePlugin({ replace: "$self.handleOnline()" }, { - match: /(setInterval\(\i,\.25\*)\i\.\i/, + match: /(setInterval\(\i,30\*)\i\.\i\.Millis\.SECOND/, replace: "$1$self.getIntervalDelay()" // For web installs } ] diff --git a/src/plugins/decor/ui/modals/CreateDecorationModal.tsx b/src/plugins/decor/ui/modals/CreateDecorationModal.tsx index eb39c16d..4afb7464 100644 --- a/src/plugins/decor/ui/modals/CreateDecorationModal.tsx +++ b/src/plugins/decor/ui/modals/CreateDecorationModal.tsx @@ -19,7 +19,7 @@ import { AvatarDecorationModalPreview } from "../components"; const FileUpload = findComponentByCodeLazy("fileUploadInput,"); -const { HelpMessage, HelpMessageTypes } = mapMangledModuleLazy('POSITIVE=3]="POSITIVE', { +const { HelpMessage, HelpMessageTypes } = mapMangledModuleLazy('POSITIVE="positive', { HelpMessageTypes: filters.byProps("POSITIVE", "WARNING", "INFO"), HelpMessage: filters.byCode(".iconDiv") }); diff --git a/src/plugins/ircColors/index.ts b/src/plugins/ircColors/index.ts index 5363acc0..237286e7 100644 --- a/src/plugins/ircColors/index.ts +++ b/src/plugins/ircColors/index.ts @@ -67,7 +67,7 @@ export default definePlugin({ { find: '="SYSTEM_TAG"', replacement: { - match: /(?<=\i.gradientClassName]\),style:.{0,80}:void 0,)/, + match: /(?<=\i.gradientClassName]\),style:.{0,80}:void 0\}\)\(\),)/, replace: "style:{color:$self.calculateNameColorForMessageContext(arguments[0])}," } }, diff --git a/src/plugins/lastfm/index.tsx b/src/plugins/lastfm/index.tsx index 75d9c7c3..c9ac96d1 100644 --- a/src/plugins/lastfm/index.tsx +++ b/src/plugins/lastfm/index.tsx @@ -19,7 +19,7 @@ import { definePluginSettings } from "@api/Settings"; import { getUserSettingLazy } from "@api/UserSettings"; import { Link } from "@components/Link"; -import { Devs } from "@utils/constants"; +import { Devs, EquicordDevs } from "@utils/constants"; import { Logger } from "@utils/Logger"; import definePlugin, { OptionType } from "@utils/types"; import { findByPropsLazy } from "@webpack"; @@ -44,10 +44,12 @@ interface Activity { timestamps?: { start?: number; }; - assets?: ActivityAssets; + assets?: ActivityAssets; // LastFM + assets2?: ActivityAssets; // StatsFM buttons?: Array; name: string; - application_id: string; + application_id: string; // LastFM + application_id2: string; // StatsFM metadata?: { button_urls?: Array; }; @@ -67,39 +69,91 @@ interface TrackData { const enum ActivityType { PLAYING = 0, LISTENING = 2, + STREAMING = 1, // Added Streaming ig as a alt to listening } const enum ActivityFlag { INSTANCE = 1 << 0, } -const enum NameFormat { +const enum NameFormat { // (2) = Statsfm config StatusName = "status-name", ArtistFirst = "artist-first", SongFirst = "song-first", ArtistOnly = "artist", SongOnly = "song", - AlbumName = "album" + AlbumName = "album", + AlbumName2 = "album2", // ^ + ArtistOnly2 = "artist2", // ^ + ArtistFirst2 = "ArtistFirst2", // ^ + SongFirst2 = "SongFirst2", // ^ + SongOnly2 = "SongOnly2", // ^ +} + +interface Albums { + id: number; + name: string; + image: string; +} + +interface Artists { + id: number; + name: string; + image: string; +} +interface ExternalIds { + spotify: string[]; + appleMusic: string[]; +} + + +interface Track { + albums: Albums[]; + artists: Artists[]; + durationMs: number; + explicit: boolean; + externalIds: ExternalIds; + id: number; + name: string; + spotifyPopularity: number; + spotifyPreview: string; + appleMusicPreview: string; +} + +interface Item { + date: string; + isPlaying: boolean; + progressMs: number; + deviceName: string; + track: Track; + platform: string; +} + +interface SFMR { + item: Item; } const ShowCurrentGame = getUserSettingLazy("status", "showCurrentGame")!; -const applicationId = "1108588077900898414"; +const applicationId = "1108588077900898414"; // LastFM Appid +const applicationId2 = "1325126169179197500"; // StatsFM Appid const placeholderId = "2a96cbd8b46e442fc41c2b86b821562f"; -const logger = new Logger("LastFMRichPresence"); +const logger = new Logger("LastFMRichPresence + StatsfmFMRichPresence"); const PresenceStore = findByPropsLazy("getLocalPresence"); async function getApplicationAsset(key: string): Promise { return (await ApplicationAssetUtils.fetchAssetIds(applicationId, [key]))[0]; } - +async function getApplicationAsset2(key: string): Promise { + return (await ApplicationAssetUtils.fetchAssetIds(applicationId2, [key]))[0]; +} function setActivity(activity: Activity | null) { FluxDispatcher.dispatch({ type: "LOCAL_ACTIVITY_UPDATE", activity, - socketId: "LastFM", + socketId: "LastFM + Statsfm", }); } @@ -108,6 +162,10 @@ const settings = definePluginSettings({ description: "last.fm username", type: OptionType.STRING, }, + statsfmusername: { + description: "stats.fm username", + type: OptionType.STRING, + }, apiKey: { description: "last.fm api key", type: OptionType.STRING, @@ -117,26 +175,51 @@ const settings = definePluginSettings({ type: OptionType.BOOLEAN, default: false, }, + shareUsernameStatsfm: { + description: "show link to stats.fm profile", + type: OptionType.BOOLEAN, + default: false, + }, shareSong: { description: "show link to song on last.fm", type: OptionType.BOOLEAN, default: true, }, + StatsfmSong: { + description: "show link to song on stats.fm", + type: OptionType.BOOLEAN, + default: true, + }, hideWithSpotify: { description: "hide last.fm presence if spotify is running", type: OptionType.BOOLEAN, default: true, }, + hidewithSpotifySFM: { + description: "hide stats.fm presence if spotify is running", + type: OptionType.BOOLEAN, + default: true, + }, hideWithActivity: { description: "Hide Last.fm presence if you have any other presence", type: OptionType.BOOLEAN, default: false, }, + hideStatsfmWithExternalRPC: { + description: "Hide Stats.fm presence if you have any other presence", + type: OptionType.BOOLEAN, + default: false, + }, enableGameActivity: { description: "Enable game activity for last.fm", type: OptionType.BOOLEAN, default: false, }, + enableGameActivitySFM: { + description: "Enable game activity for stats.fm", + type: OptionType.BOOLEAN, + default: false, + }, statusName: { description: "custom status text", type: OptionType.STRING, @@ -178,6 +261,11 @@ const settings = definePluginSettings({ type: OptionType.BOOLEAN, default: false, }, + useStreamingStatus: { + description: 'show "Streaming" status instead of "Playing"', + type: OptionType.BOOLEAN, + default: false, + }, missingArt: { description: "When album or album art is missing", type: OptionType.SELECT, @@ -187,6 +275,11 @@ const settings = definePluginSettings({ value: "lastfmLogo", default: true }, + { + label: "Use Large Stats.fm logo", + value: "StatsFMLogo", + default: false + }, { label: "Use generic placeholder", value: "placeholder" @@ -198,6 +291,11 @@ const settings = definePluginSettings({ type: OptionType.BOOLEAN, default: true, }, + showStatsFMLogo: { + description: "show the Stats.fm logo by the album cover", + type: OptionType.BOOLEAN, + default: false, + }, alwaysHideArt: { description: "Disable downloading album art", type: OptionType.BOOLEAN, @@ -207,8 +305,8 @@ const settings = definePluginSettings({ export default definePlugin({ name: "LastFMRichPresence", - description: "Little plugin for Last.fm rich presence", - authors: [Devs.dzshn, Devs.RuiNtD, Devs.blahajZip, Devs.archeruwu], + description: "Little plugin for Last.fm rich presence + Stats.fm rich presence", + authors: [Devs.dzshn, Devs.RuiNtD, Devs.blahajZip, Devs.archeruwu, EquicordDevs.Crxa], settingsAboutComponent: () => ( <> @@ -223,6 +321,12 @@ export default definePlugin({ And copy the API key (not the shared secret!) + + How to get Stats.fm Presence! + + STATSFM ONLY: + If you want to use stats.fm, you will need an account linked @ and have your listening history public. + ), @@ -236,7 +340,7 @@ export default definePlugin({ stop() { clearInterval(this.updateInterval); }, - + // Last.fm Fetching async fetchTrackData(): Promise { if (!settings.store.username || !settings.store.apiKey) return null; @@ -278,6 +382,33 @@ export default definePlugin({ return null; } }, + // Stats.fm Fetching + async fetchTrackDataStatsfm(): Promise { + if (!settings.store.statsfmusername) + return null; + try { + const res2 = await fetch(`https://api.stats.fm/api/v1/user/${settings.store.statsfmusername}/recent`); + if (!res2.ok) throw `${res2.status} ${res2.statusText}`; + + const json = await res2.json() as SFMR; + if (!json.item) { + logger.error("Error from Stats.fm API"), json; + return null; + } + const trackData2 = json.item.track; + if (!trackData2) return null; + return { + name: trackData2.name || "Unknown", + album: trackData2.albums.map(a => a.name).join(", ") || "Unknown", + artist: trackData2.artists[0].name ?? "Unknown", + url: `https://stats.fm/track/${trackData2.id}`, + imageUrl: trackData2.albums[0].image + }; + } catch (e) { + logger.error("Failed to query Stats.fm API, Report to Equicord Discord. https://discord.gg/equicord", e); + return null; + } + }, async updatePresence() { setActivity(await this.getActivity()); @@ -293,13 +424,14 @@ export default definePlugin({ async getActivity(): Promise { if (settings.store.hideWithActivity) { - if (PresenceStore.getActivities().some(a => a.application_id !== applicationId)) { + if (PresenceStore.getActivities().some(a => a.application_id !== applicationId && (!a.application_id2 || a.application_id2 !== applicationId2))) return null; + { } } if (settings.store.hideWithSpotify) { - if (PresenceStore.getActivities().some(a => a.type === ActivityType.LISTENING && a.application_id !== applicationId)) { + if (PresenceStore.getActivities().some(a => (a.type === ActivityType.LISTENING || a.type === ActivityType.STREAMING) && a.application_id !== applicationId)) { // there is already music status because of Spotify or richerCider (probably more) return null; } @@ -326,7 +458,21 @@ export default definePlugin({ large_image: await getApplicationAsset("lastfm-large"), large_text: trackData.album || undefined, }; - + // Stats.fm image stuff + const largeImage2 = this.getLargeImage(trackData); + const assets2: ActivityAssets = largeImage2 ? + { + large_image: await getApplicationAsset2(largeImage2), + large_text: trackData.album || undefined, + ...(settings.store.showStatsFMLogo && { + small_image: await getApplicationAsset2("statsfm-large"), + small_text: "Stats.fm" + }), + } : { + large_image: await getApplicationAsset2("statsfm-large"), + large_text: trackData.album || undefined, + }; + const trackData2 = await this.fetchTrackDataStatsfm(); const buttons: ActivityButton[] = []; if (settings.store.shareUsername) @@ -334,14 +480,24 @@ export default definePlugin({ label: "Last.fm Profile", url: `https://www.last.fm/user/${settings.store.username}`, }); - + // Stats.fm settings + if (settings.store.shareUsernameStatsfm) + buttons.push({ + label: "Stats.fm Profile", + url: `https://stats.fm/user/${settings.store.statsfmusername}`, + }); + if (settings.store.StatsfmSong) + buttons.push({ + label: "View Song", + url: trackData.url, + }); if (settings.store.shareSong) buttons.push({ label: "View Song", url: trackData.url, }); - const statusName = (() => { + const statusName = (() => { // Last.FM satus stuff dont touch switch (settings.store.nameFormat) { case NameFormat.ArtistFirst: return trackData.artist + " - " + trackData.name; @@ -353,6 +509,17 @@ export default definePlugin({ return trackData.name; case NameFormat.AlbumName: return trackData.album || settings.store.statusName; + // Stats.fm Status stuff + case NameFormat.ArtistFirst2: // hoping my code works + return trackData2?.artist ? `${trackData2.artist} - ${trackData2.name}` : settings.store.statusName; + case NameFormat.SongFirst2: + return trackData2?.name ? `${trackData2.name} - ${trackData2.artist}` : settings.store.statusName; + case NameFormat.ArtistOnly2: + return trackData2?.artist ?? settings.store.statusName; + case NameFormat.SongOnly2: + return trackData2?.name ?? settings.store.statusName; + case NameFormat.AlbumName2: + return trackData2?.album ?? settings.store.statusName; default: return settings.store.statusName; } @@ -360,18 +527,19 @@ export default definePlugin({ return { application_id: applicationId, + application_id2: applicationId2, // StatsFM Appid name: statusName, details: trackData.name, state: trackData.artist, assets, + assets2, // StatsFM assets buttons: buttons.length ? buttons.map(v => v.label) : undefined, metadata: { button_urls: buttons.map(v => v.url), }, - - type: settings.store.useListeningStatus ? ActivityType.LISTENING : ActivityType.PLAYING, + type: settings.store.useStreamingStatus ? ActivityType.STREAMING : settings.store.useListeningStatus ? ActivityType.LISTENING : ActivityType.PLAYING, flags: ActivityFlag.INSTANCE, }; } diff --git a/src/plugins/messageLogger/index.tsx b/src/plugins/messageLogger/index.tsx index ad974126..a2d205cd 100644 --- a/src/plugins/messageLogger/index.tsx +++ b/src/plugins/messageLogger/index.tsx @@ -433,7 +433,7 @@ export default definePlugin({ { // Updated message transformer(?) - find: "THREAD_STARTER_MESSAGE?null===", + find: "THREAD_STARTER_MESSAGE?null==", replacement: [ { // Pass through editHistory & deleted & original attachments to the "edited message" transformer diff --git a/src/plugins/newGuildSettings/index.tsx b/src/plugins/newGuildSettings/index.tsx index edddb968..49fc5f05 100644 --- a/src/plugins/newGuildSettings/index.tsx +++ b/src/plugins/newGuildSettings/index.tsx @@ -134,7 +134,7 @@ export default definePlugin({ { find: ",acceptInvite(", replacement: { - match: /INVITE_ACCEPT_SUCCESS.+?,(\i)=null!==.+?;/, + match: /INVITE_ACCEPT_SUCCESS.+?,(\i)=null!=.+?;/, replace: (m, guildId) => `${m}$self.applyDefaultSettings(${guildId});` } }, diff --git a/src/plugins/nsfwGateBypass/index.ts b/src/plugins/nsfwGateBypass/index.ts index e6f3ee40..6d0cb702 100644 --- a/src/plugins/nsfwGateBypass/index.ts +++ b/src/plugins/nsfwGateBypass/index.ts @@ -28,11 +28,11 @@ export default definePlugin({ find: ".nsfwAllowed=null", replacement: [ { - match: /(?<=\.nsfwAllowed=)null!==.+?(?=[,;])/, + match: /(?<=\.nsfwAllowed=)null!=.+?(?=[,;])/, replace: "true", }, { - match: /(?<=\.ageVerificationStatus=)null!==.+?(?=[,;])/, + match: /(?<=\.ageVerificationStatus=)null!=.+?(?=[,;])/, replace: "3", // VERIFIED_ADULT } ], diff --git a/src/webpack/patchWebpack.ts b/src/webpack/patchWebpack.ts index 802f9da9..2c212a9a 100644 --- a/src/webpack/patchWebpack.ts +++ b/src/webpack/patchWebpack.ts @@ -8,7 +8,6 @@ import { Settings } from "@api/Settings"; import { makeLazy } from "@utils/lazy"; import { Logger } from "@utils/Logger"; import { interpolateIfDefined } from "@utils/misc"; -import { canonicalizeReplacement } from "@utils/patches"; import { Patch, PatchReplacement } from "@utils/types"; import { reporterData } from "debug/reporterData";