Plugins: Bug Fixes For A Few

This commit is contained in:
thororen1234 2025-09-27 11:11:05 -04:00
parent 06578b9d53
commit 4de296d780
No known key found for this signature in database
4 changed files with 69 additions and 44 deletions

View file

@ -10,7 +10,6 @@ import { definePluginSettings } from "@api/Settings";
import { classNameFactory } from "@api/Styles";
import { DeleteIcon, PlusIcon } from "@components/Icons";
import { Devs } from "@utils/constants";
import { getIntlMessage } from "@utils/discord";
import definePlugin, { OptionType } from "@utils/types";
import { Button, Forms, TextInput } from "@webpack/common";
@ -78,8 +77,8 @@ export default definePlugin({
{
find: "#{intl::BAN_REASON_OPTION_SPAM_ACCOUNT}",
replacement: [{
match: /\[(\{name:\i\.\i\.\i\(\i\.\i\.\i\),value:(\i\.\i\.\i\(\i\.\i\.\i\)|"other")\},?)+\]/,
replace: "$self.getReasons()"
match: /(\[\{name:\i\.\i\.\i\(\i\.\i\.\i\),.+?"other"\}\])/,
replace: "$self.getReasons($1)"
},
{
match: /useState\(null\)(?=.{0,300}targetUserId:)/,
@ -87,16 +86,15 @@ export default definePlugin({
}]
}
],
getReasons() {
getReasons(defaults) {
const storedReasons = settings.store.reasons.filter((r: string) => r.trim());
const reasons: string[] = storedReasons.length
? storedReasons
: [
getIntlMessage("BAN_REASON_OPTION_SPAM_ACCOUNT"),
getIntlMessage("BAN_REASON_OPTION_HACKED_ACCOUNT"),
getIntlMessage("BAN_REASON_OPTION_BREAKING_RULES"),
];
return reasons.map(s => ({ name: s, value: s }));
: [];
return [
...reasons.map(s => ({ name: s, value: s })),
...defaults
];
},
getDefaultState: () => settings.store.isTextInputDefault ? 1 : 0,
settings,

View file

@ -14,6 +14,7 @@ export const settings = definePluginSettings({
frequentEmojis: {
description: "Use frequently used emojis instead of favourite emojis",
type: OptionType.BOOLEAN,
restartNeeded: true,
default: true
},
rows: {
@ -54,8 +55,9 @@ export default definePlugin({
find: "this.favoriteEmojisWithoutFetchingLatest.concat",
replacement: {
match: /(this\.favoriteEmojisWithoutFetchingLatest)\.concat/,
replace: "($self.settings.store.frequentEmojis?[]:$1).concat"
}
replace: "[].concat"
},
predicate: () => settings.store.frequentEmojis
},
{
find: "#{intl::ADD_REACTION_NAMED}",
@ -69,7 +71,7 @@ export default definePlugin({
// Add a custom class to identify the quick reactions have been modified and a CSS variable for the number of columns to display
{
match: /className:(\i)\.wrapper,/,
replace: "className:\"vc-better-quick-react \"+($self.settings.store.compactMode?\"vc-better-quick-react-compact \":\"\")+$1.wrapper,style:{\"--vc-better-quick-react-columns\":$self.settings.store.columns},"
replace: "className:\"vc-better-quick-react \"+(Vencord.Settings.plugins.BetterQuickReact.compactMode?\"vc-better-quick-react-compact \":\"\")+$1.wrapper,style:{\"--vc-better-quick-react-columns\":$self.settings.store.columns},"
},
// Scroll handler + Apply the emoji count limit from earlier with custom logic
{

View file

@ -7,7 +7,7 @@
import { definePluginSettings, Settings } from "@api/Settings";
import { EquicordDevs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { MessageJSON } from "@vencord/discord-types";
import { Message } from "@vencord/discord-types";
let blockedKeywords: Array<RegExp>;
@ -38,6 +38,35 @@ const settings = definePluginSettings({
},
});
export function containsBlockedKeywords(message: Message) {
if (blockedKeywords.length === 0) { return false; }
// can't use forEach because we need to return from inside the loop
// message content loop
for (let wordIndex = 0; wordIndex < blockedKeywords.length; wordIndex++) {
if (blockedKeywords[wordIndex].test(message.content)) {
return true;
}
}
// embed content loop (e.g. twitter embeds)
for (let embedIndex = 0; embedIndex < message.embeds.length; embedIndex++) {
const embed = message.embeds[embedIndex];
for (let wordIndex = 0; wordIndex < blockedKeywords.length; wordIndex++) {
// doing this because undefined strings get converted to the string "undefined" in regex tests
// @ts-ignore
const descriptionHasKeywords = embed.rawDescription != null && blockedKeywords[wordIndex].test(embed.rawDescription);
// @ts-ignore
const titleHasKeywords = embed.rawTitle != null && blockedKeywords[wordIndex].test(embed.rawTitle);
if (descriptionHasKeywords || titleHasKeywords) {
return true;
}
}
}
return false;
}
export default definePlugin({
name: "BlockKeywords",
description: "Blocks messages containing specific user-defined keywords, as if the user sending them was blocked.",
@ -45,12 +74,14 @@ export default definePlugin({
patches: [
{
find: '"_channelMessages",{})',
predicate: () => settings.store.blockedWords.length > 0,
replacement: {
match: /static commit\((.{1,2})\){/g,
replace: "$&$1=$self.blockMessagesWithKeywords($1);"
}
},
...[
'"MessageStore"',
'"ReadStateStore"'
].map(find => ({
find,
@ -65,6 +96,7 @@ export default definePlugin({
],
settings,
containsBlockedKeywords,
start() {
const blockedWordsList: Array<string> = Settings.plugins.BlockKeywords.blockedWords.split(",");
@ -84,35 +116,6 @@ export default definePlugin({
console.log(blockedKeywords);
},
containsBlockedKeywords(message: MessageJSON) {
if (blockedKeywords.length === 0) { return false; }
// can't use forEach because we need to return from inside the loop
// message content loop
for (let wordIndex = 0; wordIndex < blockedKeywords.length; wordIndex++) {
if (blockedKeywords[wordIndex].test(message.content)) {
return true;
}
}
// embed content loop (e.g. twitter embeds)
for (let embedIndex = 0; embedIndex < message.embeds.length; embedIndex++) {
const embed = message.embeds[embedIndex];
for (let wordIndex = 0; wordIndex < blockedKeywords.length; wordIndex++) {
// doing this because undefined strings get converted to the string "undefined" in regex tests
// @ts-ignore
const descriptionHasKeywords = embed.rawDescription != null && blockedKeywords[wordIndex].test(embed.rawDescription);
// @ts-ignore
const titleHasKeywords = embed.rawTitle != null && blockedKeywords[wordIndex].test(embed.rawTitle);
if (descriptionHasKeywords || titleHasKeywords) {
return true;
}
}
}
return false;
},
blockMessagesWithKeywords(messageList: any) {
return messageList.reset(messageList.map(
message => message.set("blocked", message.blocked || this.containsBlockedKeywords(message))

View file

@ -16,7 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { definePluginSettings, migratePluginSetting } from "@api/Settings";
import { definePluginSettings, migratePluginSetting, Settings } from "@api/Settings";
import { containsBlockedKeywords } from "@equicordplugins/blockKeywords";
import { Devs, EquicordDevs } from "@utils/constants";
import { Logger } from "@utils/Logger";
import definePlugin, { OptionType } from "@utils/types";
@ -187,6 +188,16 @@ export default definePlugin({
repliedMessage = messageReference ? MessageStore.getMessage(messageReference.channel_id, messageReference.message_id) : null;
}
const { BlockKeywords } = Settings.plugins;
if (
BlockKeywords &&
BlockKeywords.enabled &&
BlockKeywords.ignoreBlockedMessages &&
containsBlockedKeywords(message)
) {
return true;
}
return repliedMessage && this.isBlocked(repliedMessage) ? repliedMessage : false;
} catch (e) {
new Logger("NoBlockedMessages").error("Failed to check if referenced message is blocked or ignored:", e);
@ -196,6 +207,17 @@ export default definePlugin({
isBlocked(message: Message) {
try {
if (RelationshipStore.isBlocked(message.author.id)) return true;
const { BlockKeywords } = Settings.plugins;
if (
BlockKeywords &&
BlockKeywords.enabled &&
BlockKeywords.ignoreBlockedMessages &&
containsBlockedKeywords(message)
) {
return true;
}
return settings.store.alsoHideIgnoredUsers && RelationshipStore.isIgnored(message.author.id);
} catch (e) {
new Logger("NoBlockedMessages").error("Failed to check if message is blocked or ignored:", e);