Merge remote-tracking branch 'upstream/dev' into immediate-finds

This commit is contained in:
Nuckyz 2024-05-03 17:35:20 -03:00
commit 784ae0a02d
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9
6 changed files with 63 additions and 27 deletions

View file

@ -78,7 +78,7 @@ export default definePlugin({
}, },
// replace their component with ours if applicable // replace their component with ours if applicable
{ {
match: /(?<=text:(\i)\.description,spacing:12,)children:/, match: /(?<=text:(\i)\.description,spacing:12,.{0,50})children:/,
replace: "children:$1.component ? () => $self.renderBadgeComponent($1) :" replace: "children:$1.component ? () => $self.renderBadgeComponent($1) :"
}, },
// conditionally override their onClick with badge.onClick if it exists // conditionally override their onClick with badge.onClick if it exists

View file

@ -81,8 +81,8 @@ export default definePlugin({
find: "getRelationshipCounts(){", find: "getRelationshipCounts(){",
replacement: { replacement: {
predicate: () => Settings.plugins.ImplicitRelationships.sortByAffinity, predicate: () => Settings.plugins.ImplicitRelationships.sortByAffinity,
match: /\.sortBy\(\i=>\i\.comparator\)/, match: /\}\)\.sortBy\((.+?)\)\.value\(\)/,
replace: "$&.sortBy((row) => $self.sortList(row))" replace: "}).sortBy(row => $self.wrapSort(($1), row)).value()"
} }
}, },
@ -120,10 +120,10 @@ export default definePlugin({
} }
), ),
sortList(row: any) { wrapSort(comparator: Function, row: any) {
return row.type === 5 return row.type === 5
? -UserAffinitiesStore.getUserAffinity(row.user.id)?.affinity ?? 0 ? -UserAffinitiesStore.getUserAffinity(row.user.id)?.affinity ?? 0
: row.comparator; : comparator(row);
}, },
async fetchImplicitRelationships() { async fetchImplicitRelationships() {

View file

@ -17,7 +17,7 @@
*/ */
import { addClickListener, removeClickListener } from "@api/MessageEvents"; import { addClickListener, removeClickListener } from "@api/MessageEvents";
import { definePluginSettings, Settings } from "@api/Settings"; import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { findByProps } from "@webpack"; import { findByProps } from "@webpack";
@ -84,11 +84,17 @@ export default definePlugin({
const EPHEMERAL = 64; const EPHEMERAL = 64;
if (msg.hasFlag(EPHEMERAL)) return; if (msg.hasFlag(EPHEMERAL)) return;
const isShiftPress = event.shiftKey && !settings.store.requireModifier;
const NoReplyMention = Vencord.Plugins.plugins.NoReplyMention as any as typeof import("../noReplyMention").default;
const shouldMention = Vencord.Plugins.isPluginEnabled("NoReplyMention")
? NoReplyMention.shouldMention(msg, isShiftPress)
: !isShiftPress;
FluxDispatcher.dispatch({ FluxDispatcher.dispatch({
type: "CREATE_PENDING_REPLY", type: "CREATE_PENDING_REPLY",
channel, channel,
message: msg, message: msg,
shouldMention: !Settings.plugins.NoReplyMention.enabled, shouldMention,
showMentionToggle: channel.guild_id !== null showMentionToggle: channel.guild_id !== null
}); });
} }

View file

@ -35,13 +35,25 @@ import { getCurrentUserInfo, readNotification } from "./reviewDbApi";
import { settings } from "./settings"; import { settings } from "./settings";
import { showToast } from "./utils"; import { showToast } from "./utils";
const guildPopoutPatch: NavContextMenuPatchCallback = (children, props: { guild: Guild, onClose(): void; }) => { const guildPopoutPatch: NavContextMenuPatchCallback = (children, { guild }: { guild: Guild, onClose(): void; }) => {
children.push( children.push(
<Menu.MenuItem <Menu.MenuItem
label="View Reviews" label="View Reviews"
id="vc-rdb-server-reviews" id="vc-rdb-server-reviews"
icon={OpenExternalIcon} icon={OpenExternalIcon}
action={() => openReviewsModal(props.guild.id, props.guild.name)} action={() => openReviewsModal(guild.id, guild.name)}
/>
);
};
const userContextPatch: NavContextMenuPatchCallback = (children, { user }: { user?: User, onClose(): void; }) => {
if (!user) return;
children.push(
<Menu.MenuItem
label="View Reviews"
id="vc-rdb-user-reviews"
icon={OpenExternalIcon}
action={() => openReviewsModal(user.id, user.username)}
/> />
); );
}; };
@ -53,7 +65,10 @@ export default definePlugin({
settings, settings,
contextMenus: { contextMenus: {
"guild-header-popout": guildPopoutPatch "guild-header-popout": guildPopoutPatch,
"guild-context": guildPopoutPatch,
"user-context": userContextPatch,
"user-profile-actions": userContextPatch
}, },
patches: [ patches: [

View file

@ -41,8 +41,8 @@ export default definePlugin({
patches: [{ patches: [{
find: "getRelationshipCounts(){", find: "getRelationshipCounts(){",
replacement: { replacement: {
match: /\.sortBy\(\i=>\i\.comparator\)/, match: /\}\)\.sortBy\((.+?)\)\.value\(\)/,
replace: "$&.sortBy((row) => $self.sortList(row))" replace: "}).sortBy(row => $self.wrapSort(($1), row)).value()"
} }
}, { }, {
find: ".Messages.FRIEND_REQUEST_CANCEL", find: ".Messages.FRIEND_REQUEST_CANCEL",
@ -53,10 +53,10 @@ export default definePlugin({
} }
}], }],
sortList(row: any) { wrapSort(comparator: Function, row: any) {
return row.type === 3 || row.type === 4 return row.type === 3 || row.type === 4
? -this.getSince(row.user) ? -this.getSince(row.user)
: row.comparator; : comparator(row);
}, },
getSince(user: User) { getSince(user: User) {

View file

@ -24,9 +24,14 @@ import definePlugin, { OptionType } from "@utils/types";
import style from "./index.css?managed"; import style from "./index.css?managed";
const BASE_URL = "https://raw.githubusercontent.com/AutumnVN/usrbg/main/usrbg.json"; const API_URL = "https://usrbg.is-hardly.online/users";
let data = {} as Record<string, string>; interface UsrbgApiReturn {
endpoint: string
bucket: string
prefix: string
users: Record<string, string>
}
const settings = definePluginSettings({ const settings = definePluginSettings({
nitroFirst: { nitroFirst: {
@ -48,7 +53,7 @@ const settings = definePluginSettings({
export default definePlugin({ export default definePlugin({
name: "USRBG", name: "USRBG",
description: "Displays user banners from USRBG, allowing anyone to get a banner without Nitro", description: "Displays user banners from USRBG, allowing anyone to get a banner without Nitro",
authors: [Devs.AutumnVN, Devs.pylix, Devs.TheKodeToad], authors: [Devs.AutumnVN, Devs.katlyn, Devs.pylix, Devs.TheKodeToad],
settings, settings,
patches: [ patches: [
{ {
@ -80,8 +85,7 @@ export default definePlugin({
} }
], ],
data: null as UsrbgApiReturn | null,
data,
settingsAboutComponent: () => { settingsAboutComponent: () => {
return ( return (
@ -91,9 +95,9 @@ export default definePlugin({
voiceBackgroundHook({ className, participantUserId }: any) { voiceBackgroundHook({ className, participantUserId }: any) {
if (className.includes("tile_")) { if (className.includes("tile_")) {
if (data[participantUserId]) { if (this.userHasBackground(participantUserId)) {
return { return {
backgroundImage: `url(${data[participantUserId]})`, backgroundImage: `url(${this.getImageUrl(participantUserId)})`,
backgroundSize: "cover", backgroundSize: "cover",
backgroundPosition: "center", backgroundPosition: "center",
backgroundRepeat: "no-repeat" backgroundRepeat: "no-repeat"
@ -104,24 +108,35 @@ export default definePlugin({
useBannerHook({ displayProfile, user }: any) { useBannerHook({ displayProfile, user }: any) {
if (displayProfile?.banner && settings.store.nitroFirst) return; if (displayProfile?.banner && settings.store.nitroFirst) return;
if (data[user.id]) return data[user.id]; if (this.userHasBackground(user.id)) return this.getImageUrl(user.id);
}, },
premiumHook({ userId }: any) { premiumHook({ userId }: any) {
if (data[userId]) return 2; if (this.userHasBackground(userId)) return 2;
}, },
shouldShowBadge({ displayProfile, user }: any) { shouldShowBadge({ displayProfile, user }: any) {
return displayProfile?.banner && (!data[user.id] || settings.store.nitroFirst); return displayProfile?.banner && (!this.userHasBackground(user.id) || settings.store.nitroFirst);
},
userHasBackground(userId: string) {
return !!this.data?.users[userId];
},
getImageUrl(userId: string): string|null {
if (!this.userHasBackground(userId)) return null;
// We can assert that data exists because userHasBackground returned true
const { endpoint, bucket, prefix, users: { [userId]: etag } } = this.data!;
return `${endpoint}/${bucket}/${prefix}${userId}?${etag}`;
}, },
async start() { async start() {
enableStyle(style); enableStyle(style);
const res = await fetch(BASE_URL); const res = await fetch(API_URL);
if (res.ok) { if (res.ok) {
data = await res.json(); this.data = await res.json();
this.data = data;
} }
} }
}); });