Merge remote-tracking branch 'upstream/dev' into dev
This commit is contained in:
commit
edd0d84759
5 changed files with 51 additions and 71 deletions
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "equicord",
|
||||
"private": "true",
|
||||
"version": "1.13.5",
|
||||
"version": "1.13.6",
|
||||
"description": "The other cutest Discord client mod",
|
||||
"homepage": "https://github.com/Equicord/Equicord#readme",
|
||||
"bugs": {
|
||||
|
|
|
|||
|
|
@ -80,22 +80,19 @@ export type ChatBarButtonFactory = (props: ChatBarProps & { isMainChat: boolean;
|
|||
const buttonFactories = new Map<string, ChatBarButtonFactory>();
|
||||
const logger = new Logger("ChatButtons");
|
||||
|
||||
export function _injectButtons(buttons: { key: string, node: ReactNode; }[], order: Record<string, number | null>, props: ChatBarProps) {
|
||||
export function _injectButtons(buttons: ReactNode[], order: Record<string, number | null>, props: ChatBarProps) {
|
||||
if (props.disabled) return;
|
||||
|
||||
let anchorIndex = -1;
|
||||
|
||||
for (const [key, Button] of buttonFactories) {
|
||||
order[key] = anchorIndex;
|
||||
anchorIndex--;
|
||||
|
||||
buttons.push({
|
||||
key,
|
||||
node: <ErrorBoundary noop key={key} onError={e => logger.error(`Failed to render ${key}`, e.error)}>
|
||||
buttons.unshift(
|
||||
<ErrorBoundary noop key={key} onError={e => logger.error(`Failed to render ${key}`, e.error)}>
|
||||
<Button {...props} isMainChat={props.type.analyticsName === "normal"} />
|
||||
</ErrorBoundary>
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
return buttons;
|
||||
}
|
||||
|
||||
export const addChatBarButton = (id: string, button: ChatBarButtonFactory) => buttonFactories.set(id, button);
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ export default definePlugin({
|
|||
{
|
||||
find: '"sticker")',
|
||||
replacement: {
|
||||
match: /(?=\i&&(\i)\.push.{0,15}"submit".{0,100}?null!=(\i))/,
|
||||
replace: "Vencord.Api.ChatButtons._injectButtons($1,$2,arguments[0]),"
|
||||
match: /(?<=className:.{0,20}\.buttons.{0,50}children:)(\i)/,
|
||||
replace: "Vencord.Api.ChatButtons._injectButtons($1,arguments[0])"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -17,17 +17,12 @@
|
|||
*/
|
||||
|
||||
import { definePluginSettings } from "@api/Settings";
|
||||
import { getUserSettingLazy } from "@api/UserSettings";
|
||||
import { HeadingSecondary } from "@components/Heading";
|
||||
import { Link } from "@components/Link";
|
||||
import { Paragraph } from "@components/Paragraph";
|
||||
import { Devs } from "@utils/constants";
|
||||
import { Logger } from "@utils/Logger";
|
||||
import definePlugin, { OptionType } from "@utils/types";
|
||||
import { Activity, ActivityAssets, ActivityButton } from "@vencord/discord-types";
|
||||
import { ActivityFlags, ActivityStatusDisplayType, ActivityType } from "@vencord/discord-types/enums";
|
||||
import { findByPropsLazy } from "@webpack";
|
||||
import { ApplicationAssetUtils, FluxDispatcher } from "@webpack/common";
|
||||
import { ApplicationAssetUtils, FluxDispatcher, PresenceStore } from "@webpack/common";
|
||||
|
||||
interface TrackData {
|
||||
name: string;
|
||||
|
|
@ -46,17 +41,15 @@ const enum NameFormat {
|
|||
AlbumName = "album"
|
||||
}
|
||||
|
||||
const ShowCurrentGame = getUserSettingLazy<boolean>("status", "showCurrentGame")!;
|
||||
|
||||
const applicationId = "1108588077900898414";
|
||||
const placeholderId = "2a96cbd8b46e442fc41c2b86b821562f";
|
||||
// Last.fm API keys are essentially public information and have no access to your account, so including one here is fine.
|
||||
const API_KEY = "790c37d90400163a5a5fe00d6ca32ef0";
|
||||
const DISCORD_APP_ID = "1108588077900898414";
|
||||
const LASTFM_PLACEHOLDER_IMAGE_HASH = "2a96cbd8b46e442fc41c2b86b821562f";
|
||||
|
||||
const logger = new Logger("LastFMRichPresence");
|
||||
|
||||
const PresenceStore = findByPropsLazy("getLocalPresence");
|
||||
|
||||
async function getApplicationAsset(key: string): Promise<string> {
|
||||
return (await ApplicationAssetUtils.fetchAssetIds(applicationId, [key]))[0];
|
||||
return (await ApplicationAssetUtils.fetchAssetIds(DISCORD_APP_ID, [key]))[0];
|
||||
}
|
||||
|
||||
function setActivity(activity: Activity | null) {
|
||||
|
|
@ -69,25 +62,21 @@ function setActivity(activity: Activity | null) {
|
|||
|
||||
const settings = definePluginSettings({
|
||||
username: {
|
||||
description: "last.fm username",
|
||||
type: OptionType.STRING,
|
||||
},
|
||||
apiKey: {
|
||||
description: "last.fm api key",
|
||||
description: "Last.fm username",
|
||||
type: OptionType.STRING,
|
||||
},
|
||||
shareUsername: {
|
||||
description: "show link to last.fm profile",
|
||||
description: "Show link to Last.fm profile",
|
||||
type: OptionType.BOOLEAN,
|
||||
default: false,
|
||||
},
|
||||
shareSong: {
|
||||
description: "show link to song on last.fm",
|
||||
clickableLinks: {
|
||||
description: "Make track, artist and album names clickable links",
|
||||
type: OptionType.BOOLEAN,
|
||||
default: true,
|
||||
},
|
||||
hideWithSpotify: {
|
||||
description: "hide last.fm presence if spotify is running",
|
||||
description: "Hide Last.fm presence if spotify is running",
|
||||
type: OptionType.BOOLEAN,
|
||||
default: true,
|
||||
},
|
||||
|
|
@ -97,7 +86,7 @@ const settings = definePluginSettings({
|
|||
default: false,
|
||||
},
|
||||
statusName: {
|
||||
description: "custom status text",
|
||||
description: "Custom status text",
|
||||
type: OptionType.STRING,
|
||||
default: "some music",
|
||||
},
|
||||
|
|
@ -107,12 +96,12 @@ const settings = definePluginSettings({
|
|||
options: [
|
||||
{
|
||||
label: "Don't show (shows generic listening message)",
|
||||
value: "off",
|
||||
default: true
|
||||
value: "off"
|
||||
},
|
||||
{
|
||||
label: "Show artist name",
|
||||
value: "artist"
|
||||
value: "artist",
|
||||
default: true
|
||||
},
|
||||
{
|
||||
label: "Show track name",
|
||||
|
|
@ -152,7 +141,7 @@ const settings = definePluginSettings({
|
|||
],
|
||||
},
|
||||
useListeningStatus: {
|
||||
description: 'show "Listening to" status instead of "Playing"',
|
||||
description: 'Show "Listening to" status instead of "Playing"',
|
||||
type: OptionType.BOOLEAN,
|
||||
default: false,
|
||||
},
|
||||
|
|
@ -172,7 +161,7 @@ const settings = definePluginSettings({
|
|||
],
|
||||
},
|
||||
showLastFmLogo: {
|
||||
description: "show the Last.fm logo by the album cover",
|
||||
description: "Show the Last.fm logo by the album cover",
|
||||
type: OptionType.BOOLEAN,
|
||||
default: true,
|
||||
},
|
||||
|
|
@ -180,7 +169,11 @@ const settings = definePluginSettings({
|
|||
description: "Disable downloading album art",
|
||||
type: OptionType.BOOLEAN,
|
||||
default: false,
|
||||
}
|
||||
},
|
||||
apiKey: {
|
||||
description: "Custom Last.fm API key. You shouldn't need to set this",
|
||||
type: OptionType.STRING,
|
||||
},
|
||||
});
|
||||
|
||||
export default definePlugin({
|
||||
|
|
@ -188,22 +181,6 @@ export default definePlugin({
|
|||
description: "Little plugin for Last.fm rich presence",
|
||||
authors: [Devs.dzshn, Devs.RuiNtD, Devs.blahajZip, Devs.archeruwu],
|
||||
|
||||
settingsAboutComponent: () => (
|
||||
<>
|
||||
<HeadingSecondary>How to get an API key</HeadingSecondary>
|
||||
<Paragraph>
|
||||
An API key is required to fetch your current track. To get one, you can
|
||||
visit <Link href="https://www.last.fm/api/account/create">this page</Link> and
|
||||
fill in the following information: <br /> <br />
|
||||
|
||||
Application name: Discord Rich Presence <br />
|
||||
Application description: (personal use) <br /> <br />
|
||||
|
||||
And copy the API key (not the shared secret!)
|
||||
</Paragraph>
|
||||
</>
|
||||
),
|
||||
|
||||
settings,
|
||||
|
||||
start() {
|
||||
|
|
@ -216,13 +193,13 @@ export default definePlugin({
|
|||
},
|
||||
|
||||
async fetchTrackData(): Promise<TrackData | null> {
|
||||
if (!settings.store.username || !settings.store.apiKey)
|
||||
if (!settings.store.username)
|
||||
return null;
|
||||
|
||||
try {
|
||||
const params = new URLSearchParams({
|
||||
method: "user.getrecenttracks",
|
||||
api_key: settings.store.apiKey,
|
||||
api_key: settings.store.apiKey || API_KEY,
|
||||
user: settings.store.username,
|
||||
limit: "1",
|
||||
format: "json"
|
||||
|
|
@ -262,7 +239,7 @@ export default definePlugin({
|
|||
},
|
||||
|
||||
getLargeImage(track: TrackData): string | undefined {
|
||||
if (!settings.store.alwaysHideArt && track.imageUrl && !track.imageUrl.includes(placeholderId))
|
||||
if (!settings.store.alwaysHideArt && track.imageUrl && !track.imageUrl.includes(LASTFM_PLACEHOLDER_IMAGE_HASH))
|
||||
return track.imageUrl;
|
||||
|
||||
if (settings.store.missingArt === "placeholder")
|
||||
|
|
@ -271,13 +248,13 @@ export default definePlugin({
|
|||
|
||||
async getActivity(): Promise<Activity | null> {
|
||||
if (settings.store.hideWithActivity) {
|
||||
if (PresenceStore.getActivities().some(a => a.application_id !== applicationId)) {
|
||||
if (PresenceStore.getActivities().some(a => a.application_id !== DISCORD_APP_ID)) {
|
||||
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.application_id !== DISCORD_APP_ID)) {
|
||||
// there is already music status because of Spotify or richerCider (probably more)
|
||||
return null;
|
||||
}
|
||||
|
|
@ -308,12 +285,6 @@ export default definePlugin({
|
|||
url: `https://www.last.fm/user/${settings.store.username}`,
|
||||
});
|
||||
|
||||
if (settings.store.shareSong)
|
||||
buttons.push({
|
||||
label: "View Song",
|
||||
url: trackData.url,
|
||||
});
|
||||
|
||||
const statusName = (() => {
|
||||
switch (settings.store.nameFormat) {
|
||||
case NameFormat.ArtistFirst:
|
||||
|
|
@ -331,8 +302,8 @@ export default definePlugin({
|
|||
}
|
||||
})();
|
||||
|
||||
return {
|
||||
application_id: applicationId,
|
||||
const activity: Activity = {
|
||||
application_id: DISCORD_APP_ID,
|
||||
name: statusName,
|
||||
|
||||
details: trackData.name,
|
||||
|
|
@ -342,6 +313,7 @@ export default definePlugin({
|
|||
"artist": ActivityStatusDisplayType.STATE,
|
||||
"track": ActivityStatusDisplayType.DETAILS
|
||||
}[settings.store.statusDisplayType],
|
||||
|
||||
assets,
|
||||
|
||||
buttons: buttons.length ? buttons.map(v => v.label) : undefined,
|
||||
|
|
@ -352,5 +324,16 @@ export default definePlugin({
|
|||
type: settings.store.useListeningStatus ? ActivityType.LISTENING : ActivityType.PLAYING,
|
||||
flags: ActivityFlags.INSTANCE,
|
||||
};
|
||||
|
||||
if (settings.store.clickableLinks) {
|
||||
activity.details_url = trackData.url;
|
||||
activity.state_url = `https://www.last.fm/music/${encodeURIComponent(trackData.artist)}`;
|
||||
|
||||
if (trackData.album) {
|
||||
activity.assets!.large_url = `https://www.last.fm/music/${encodeURIComponent(trackData.artist)}/${encodeURIComponent(trackData.album)}`;
|
||||
}
|
||||
}
|
||||
|
||||
return activity;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -233,7 +233,7 @@ export default definePlugin({
|
|||
},
|
||||
// User Dms top large icon
|
||||
{
|
||||
find: ".EMPTY_GROUP_DM,children:",
|
||||
find: ".EMPTY_GROUP_DM)",
|
||||
replacement: {
|
||||
match: /(?<=SIZE_80,)(?=src:(.+?\))[,}])/,
|
||||
replace: (_, avatarUrl) => `onClick:()=>$self.openAvatar(${avatarUrl}),`
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue