Skip to content

Commit

Permalink
fix webpack searches & css for discord update
Browse files Browse the repository at this point in the history
  • Loading branch information
Penguin-Spy committed Nov 3, 2023
1 parent e85b3f5 commit 64c45f6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"github": "Penguin-Spy"
},
"source": "https://github.com/Penguin-Spy/replugged-pronoundb",
"version": "1.3.5",
"version": "1.3.6",
"updater": {
"type": "store",
"id": "dev.penguinspy.pronoundb"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "replugged-pronoundb",
"version": "1.3.5",
"version": "1.3.6",
"description": "Shows users' PronounDB pronouns in chat so that you don't accidentally misgender people.",
"author": "Penguin_Spy",
"scripts": {
Expand Down
11 changes: 6 additions & 5 deletions src/discordPronouns.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { getByProps, getBySource, getFunctionBySource } from "replugged/webpack"

export const UserProfileStore = getByProps("getUserProfile")
const { getUserProfile, getGuildMemberProfile } = UserProfileStore
const fetchUserProfile = getFunctionBySource(getBySource(/withMutualGuilds,.=.\.withMutualFriendsCount,.=.\.guildId/), "apply")
//const fetchUserProfile = getFunctionBySource(getBySource(/withMutualGuilds,.=.\.withMutualFriendsCount,.=.\.guildId/), "apply")
const { fetchProfile } = getByProps("fetchProfile")

// wait 750 ms between queue processes (it's basically impossible to get rate-limited with this delay)
const QUEUE_PROCESS_DELAY = 750
Expand All @@ -12,9 +13,9 @@ const queuedProfiles = []
let queueTimeout = undefined

// processes one item in the queue, and sets the timeout again if it's not empty
function fetchProfile() {
function processFetchQueue() {
const [user_id, guild_id] = queuedProfiles.pop().split("-")
fetchUserProfile(user_id, { // this (discord) function fetches the profile and dispatches it to the UserProfileStore
fetchProfile(user_id, { // this (discord) function fetches the profile and dispatches it to the UserProfileStore
guildId: guild_id !== "null" ? guild_id : undefined, // don't send the string "null" (when in DMs)
withMutualFriendsCount: false, // these 2 params match what discord sets them to when clicking on the profile
withMutualGuilds: true
Expand All @@ -23,7 +24,7 @@ function fetchProfile() {

// if there are more profiles to fetch, set the timeout again
if(queuedProfiles.length > 0) {
queueTimeout = setTimeout(fetchProfile, QUEUE_PROCESS_DELAY)
queueTimeout = setTimeout(processFetchQueue, QUEUE_PROCESS_DELAY)
}
}

Expand All @@ -36,7 +37,7 @@ export function usePronouns(user_id, guild_id) {

queuedProfiles.push(profileIdentifier)
if(!queueTimeout) { // only set the timeout if it's not set yet
queueTimeout = setTimeout(fetchProfile, QUEUE_PROCESS_DELAY)
queueTimeout = setTimeout(processFetchQueue, QUEUE_PROCESS_DELAY)
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ const settings = await SettingsManager.init(PLUGIN_ID, DefaultSettings)
export async function start() {
// pronouns in message header
if(settings.get("show_in_chat")) {
webpack.waitForModule(webpack.filters.bySource(/.=.\.renderPopout,.=.\.renderRemixTag,/))
webpack.waitForModule(webpack.filters.byProps("UsernameDecorationTypes"))
.then(MessageHeaderUsername => {
const functionKey = Object.entries(MessageHeaderUsername).find(e => typeof e[1] === "function")[0]

inject.after(MessageHeaderUsername, functionKey, ([props], res) => {
inject.after(MessageHeaderUsername, "default", ([props], res) => {
if(props.message.author.bot) { return } // bots can never have pronouns (transphobic?), and trying to render them makes an invalid API call to Discord
const headerItems = res.props.children

Expand Down
3 changes: 3 additions & 0 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ span[id^="message-username-"]:not(:hover) > :is(
.pronoundb-settings-notice {
margin-bottom: 20px;
}
.pronoundb-settings-notice a:hover {
text-decoration: underline;
}

0 comments on commit 64c45f6

Please sign in to comment.