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
{
match: /(?<=text:(\i)\.description,spacing:12,)children:/,
match: /(?<=text:(\i)\.description,spacing:12,.{0,50})children:/,
replace: "children:$1.component ? () => $self.renderBadgeComponent($1) :"
},
// conditionally override their onClick with badge.onClick if it exists

View file

@ -81,8 +81,8 @@ export default definePlugin({
find: "getRelationshipCounts(){",
replacement: {
predicate: () => Settings.plugins.ImplicitRelationships.sortByAffinity,
match: /\.sortBy\(\i=>\i\.comparator\)/,
replace: "$&.sortBy((row) => $self.sortList(row))"
match: /\}\)\.sortBy\((.+?)\)\.value\(\)/,
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
? -UserAffinitiesStore.getUserAffinity(row.user.id)?.affinity ?? 0
: row.comparator;
: comparator(row);
},
async fetchImplicitRelationships() {

View file

@ -17,7 +17,7 @@
*/
import { addClickListener, removeClickListener } from "@api/MessageEvents";
import { definePluginSettings, Settings } from "@api/Settings";
import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { findByProps } from "@webpack";
@ -84,11 +84,17 @@ export default definePlugin({
const EPHEMERAL = 64;
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({
type: "CREATE_PENDING_REPLY",
channel,
message: msg,
shouldMention: !Settings.plugins.NoReplyMention.enabled,
shouldMention,
showMentionToggle: channel.guild_id !== null
});
}

View file

@ -35,13 +35,25 @@ import { getCurrentUserInfo, readNotification } from "./reviewDbApi";
import { settings } from "./settings";
import { showToast } from "./utils";
const guildPopoutPatch: NavContextMenuPatchCallback = (children, props: { guild: Guild, onClose(): void; }) => {
const guildPopoutPatch: NavContextMenuPatchCallback = (children, { guild }: { guild: Guild, onClose(): void; }) => {
children.push(
<Menu.MenuItem
label="View Reviews"
id="vc-rdb-server-reviews"
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,
contextMenus: {
"guild-header-popout": guildPopoutPatch
"guild-header-popout": guildPopoutPatch,
"guild-context": guildPopoutPatch,
"user-context": userContextPatch,
"user-profile-actions": userContextPatch
},
patches: [

View file

@ -41,8 +41,8 @@ export default definePlugin({
patches: [{
find: "getRelationshipCounts(){",
replacement: {
match: /\.sortBy\(\i=>\i\.comparator\)/,
replace: "$&.sortBy((row) => $self.sortList(row))"
match: /\}\)\.sortBy\((.+?)\)\.value\(\)/,
replace: "}).sortBy(row => $self.wrapSort(($1), row)).value()"
}
}, {
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
? -this.getSince(row.user)
: row.comparator;
: comparator(row);
},
getSince(user: User) {

View file

@ -24,9 +24,14 @@ import definePlugin, { OptionType } from "@utils/types";
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({
nitroFirst: {
@ -48,7 +53,7 @@ const settings = definePluginSettings({
export default definePlugin({
name: "USRBG",
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,
patches: [
{
@ -80,8 +85,7 @@ export default definePlugin({
}
],
data,
data: null as UsrbgApiReturn | null,
settingsAboutComponent: () => {
return (
@ -91,9 +95,9 @@ export default definePlugin({
voiceBackgroundHook({ className, participantUserId }: any) {
if (className.includes("tile_")) {
if (data[participantUserId]) {
if (this.userHasBackground(participantUserId)) {
return {
backgroundImage: `url(${data[participantUserId]})`,
backgroundImage: `url(${this.getImageUrl(participantUserId)})`,
backgroundSize: "cover",
backgroundPosition: "center",
backgroundRepeat: "no-repeat"
@ -104,24 +108,35 @@ export default definePlugin({
useBannerHook({ displayProfile, user }: any) {
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) {
if (data[userId]) return 2;
if (this.userHasBackground(userId)) return 2;
},
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() {
enableStyle(style);
const res = await fetch(BASE_URL);
const res = await fetch(API_URL);
if (res.ok) {
data = await res.json();
this.data = data;
this.data = await res.json();
}
}
});