Improve permission checks on several plugins (#1746)

Co-authored-by: V <vendicated@riseup.net>
This commit is contained in:
Hugo C 2023-09-24 16:42:53 +02:00 committed by GitHub
parent 0b7fca864a
commit 044f64e446
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 41 additions and 25 deletions

@ -24,11 +24,9 @@ import { Margins } from "@utils/margins";
import { ModalContent, ModalHeader, ModalRoot, openModalLazy } from "@utils/modal"; import { ModalContent, ModalHeader, ModalRoot, openModalLazy } from "@utils/modal";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
import { findByCodeLazy, findStoreLazy } from "@webpack"; import { findByCodeLazy, findStoreLazy } from "@webpack";
import { EmojiStore, FluxDispatcher, Forms, GuildStore, Menu, PermissionStore, React, RestAPI, Toasts, Tooltip, UserStore } from "@webpack/common"; import { EmojiStore, FluxDispatcher, Forms, GuildStore, Menu, PermissionsBits, PermissionStore, React, RestAPI, Toasts, Tooltip, UserStore } from "@webpack/common";
import { Promisable } from "type-fest"; import { Promisable } from "type-fest";
const MANAGE_EMOJIS_AND_STICKERS = 1n << 30n;
const StickersStore = findStoreLazy("StickersStore"); const StickersStore = findStoreLazy("StickersStore");
const uploadEmoji = findByCodeLazy('"EMOJI_UPLOAD_START"', "GUILD_EMOJIS("); const uploadEmoji = findByCodeLazy('"EMOJI_UPLOAD_START"', "GUILD_EMOJIS(");
@ -120,7 +118,7 @@ function getGuildCandidates(data: Data) {
return Object.values(GuildStore.getGuilds()).filter(g => { return Object.values(GuildStore.getGuilds()).filter(g => {
const canCreate = g.ownerId === meId || const canCreate = g.ownerId === meId ||
BigInt(PermissionStore.getGuildPermissions({ id: g.id }) & MANAGE_EMOJIS_AND_STICKERS) === MANAGE_EMOJIS_AND_STICKERS; (PermissionStore.getGuildPermissions({ id: g.id }) & PermissionsBits.CREATE_GUILD_EXPRESSIONS) === PermissionsBits.CREATE_GUILD_EXPRESSIONS;
if (!canCreate) return false; if (!canCreate) return false;
if (data.t === "Sticker") return true; if (data.t === "Sticker") return true;

@ -0,0 +1,5 @@
# MessageClickActions
Allows you to double click to edit/reply to a message or delete it if you hold the backspace key
![](https://github.com/Vendicated/Vencord/assets/55940580/6885aca2-4021-4910-b636-bb40f877a816)

@ -21,18 +21,17 @@ import { definePluginSettings, Settings } 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 { findByPropsLazy } from "@webpack"; import { findByPropsLazy } from "@webpack";
import { FluxDispatcher, PermissionStore, UserStore } from "@webpack/common"; import { FluxDispatcher, PermissionsBits, PermissionStore, UserStore } from "@webpack/common";
let isDeletePressed = false; let isDeletePressed = false;
const keydown = (e: KeyboardEvent) => e.key === "Backspace" && (isDeletePressed = true); const keydown = (e: KeyboardEvent) => e.key === "Backspace" && (isDeletePressed = true);
const keyup = (e: KeyboardEvent) => e.key === "Backspace" && (isDeletePressed = false); const keyup = (e: KeyboardEvent) => e.key === "Backspace" && (isDeletePressed = false);
const MANAGE_CHANNELS = 1n << 4n;
const settings = definePluginSettings({ const settings = definePluginSettings({
enableDeleteOnClick: { enableDeleteOnClick: {
type: OptionType.BOOLEAN, type: OptionType.BOOLEAN,
description: "Enable delete on click", description: "Enable delete on click while holding backspace",
default: true default: true
}, },
enableDoubleClickToEdit: { enableDoubleClickToEdit: {
@ -72,6 +71,7 @@ export default definePlugin({
if (!isDeletePressed) { if (!isDeletePressed) {
if (event.detail < 2) return; if (event.detail < 2) return;
if (settings.store.requireModifier && !event.ctrlKey && !event.shiftKey) return; if (settings.store.requireModifier && !event.ctrlKey && !event.shiftKey) return;
if (!PermissionStore.can(PermissionsBits.SEND_MESSAGES, channel)) return;
if (isMe) { if (isMe) {
if (!settings.store.enableDoubleClickToEdit || EditStore.isEditing(channel.id, msg.id)) return; if (!settings.store.enableDoubleClickToEdit || EditStore.isEditing(channel.id, msg.id)) return;
@ -89,7 +89,7 @@ export default definePlugin({
showMentionToggle: channel.guild_id !== null showMentionToggle: channel.guild_id !== null
}); });
} }
} else if (settings.store.enableDeleteOnClick && (isMe || PermissionStore.can(MANAGE_CHANNELS, channel))) { } else if (settings.store.enableDeleteOnClick && (isMe || PermissionStore.can(PermissionsBits.MANAGE_MESSAGES, channel))) {
if (msg.deleted) { if (msg.deleted) {
FluxDispatcher.dispatch({ FluxDispatcher.dispatch({
type: "MESSAGE_DELETE", type: "MESSAGE_DELETE",

@ -0,0 +1,5 @@
# QuickMention
Adds a mention icon to the messages action bar
![](https://github.com/Vendicated/Vencord/assets/55940580/82d3fec7-4196-4917-b3c2-6e652b2aff9e)

@ -20,7 +20,7 @@ import { addButton, removeButton } from "@api/MessagePopover";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import { insertTextIntoChatInputBox } from "@utils/discord"; import { insertTextIntoChatInputBox } from "@utils/discord";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
import { ChannelStore } from "@webpack/common"; import { ChannelStore, PermissionsBits, PermissionStore } from "@webpack/common";
export default definePlugin({ export default definePlugin({
name: "QuickMention", name: "QuickMention",
@ -30,11 +30,14 @@ export default definePlugin({
start() { start() {
addButton("QuickMention", msg => { addButton("QuickMention", msg => {
const channel = ChannelStore.getChannel(msg.channel_id);
if (!PermissionStore.can(PermissionsBits.SEND_MESSAGES, channel)) return null;
return { return {
label: "Quick Mention", label: "Quick Mention",
icon: this.Icon, icon: this.Icon,
message: msg, message: msg,
channel: ChannelStore.getChannel(msg.channel_id), channel,
onClick: () => insertTextIntoChatInputBox(`<@${msg.author.id}> `) onClick: () => insertTextIntoChatInputBox(`<@${msg.author.id}> `)
}; };
}); });

@ -0,0 +1,6 @@
# QuickReply
Reply to (ctrl + up/down) and edit (ctrl + shift + up/down) messages via keybinds
![](https://github.com/Vendicated/Vencord/assets/55940580/df79a27a-6529-4c70-8870-3c17d3637e4f)

@ -20,7 +20,7 @@ import { definePluginSettings, Settings } 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 { findByPropsLazy } from "@webpack"; import { findByPropsLazy } from "@webpack";
import { ChannelStore, FluxDispatcher as Dispatcher, MessageStore, SelectedChannelStore, UserStore } from "@webpack/common"; import { ChannelStore, FluxDispatcher as Dispatcher, MessageStore, PermissionsBits, PermissionStore, SelectedChannelStore, UserStore } from "@webpack/common";
import { Message } from "discord-types/general"; import { Message } from "discord-types/general";
const Kangaroo = findByPropsLazy("jumpToMessage"); const Kangaroo = findByPropsLazy("jumpToMessage");
@ -172,6 +172,7 @@ function shouldMention(message) {
// handle next/prev reply // handle next/prev reply
function nextReply(isUp: boolean) { function nextReply(isUp: boolean) {
if (!PermissionStore.can(PermissionsBits.SEND_MESSAGES, ChannelStore.getChannel(SelectedChannelStore.getChannelId()))) return;
const message = getNextMessage(isUp, true); const message = getNextMessage(isUp, true);
if (!message) if (!message)
@ -179,7 +180,6 @@ function nextReply(isUp: boolean) {
type: "DELETE_PENDING_REPLY", type: "DELETE_PENDING_REPLY",
channelId: SelectedChannelStore.getChannelId(), channelId: SelectedChannelStore.getChannelId(),
}); });
const channel = ChannelStore.getChannel(message.channel_id); const channel = ChannelStore.getChannel(message.channel_id);
const meId = UserStore.getCurrentUser().id; const meId = UserStore.getCurrentUser().id;
@ -196,14 +196,14 @@ function nextReply(isUp: boolean) {
// handle next/prev edit // handle next/prev edit
function nextEdit(isUp: boolean) { function nextEdit(isUp: boolean) {
if (!PermissionStore.can(PermissionsBits.SEND_MESSAGES, ChannelStore.getChannel(SelectedChannelStore.getChannelId()))) return;
const message = getNextMessage(isUp, false); const message = getNextMessage(isUp, false);
if (!message) if (!message)
Dispatcher.dispatch({ return Dispatcher.dispatch({
type: "MESSAGE_END_EDIT", type: "MESSAGE_END_EDIT",
channelId: SelectedChannelStore.getChannelId() channelId: SelectedChannelStore.getChannelId()
}); });
else {
Dispatcher.dispatch({ Dispatcher.dispatch({
type: "MESSAGE_START_EDIT", type: "MESSAGE_START_EDIT",
channelId: message.channel_id, channelId: message.channel_id,
@ -212,5 +212,4 @@ function nextEdit(isUp: boolean) {
_isQuickEdit: true _isQuickEdit: true
}); });
jumpIfOffScreen(message.channel_id, message.id); jumpIfOffScreen(message.channel_id, message.id);
}
} }

@ -21,7 +21,7 @@ import { Devs } from "@utils/constants";
import { LazyComponent } from "@utils/react"; import { LazyComponent } from "@utils/react";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
import { findByCode, findByCodeLazy } from "@webpack"; import { findByCode, findByCodeLazy } from "@webpack";
import { ChannelStore, i18n, Menu, SelectedChannelStore } from "@webpack/common"; import { ChannelStore, i18n, Menu, PermissionsBits, PermissionStore, SelectedChannelStore } from "@webpack/common";
import { Message } from "discord-types/general"; import { Message } from "discord-types/general";
const ReplyIcon = LazyComponent(() => findByCode("M10 8.26667V4L3 11.4667L10 18.9333V14.56C15 14.56 18.5 16.2667 21 20C20 14.6667 17 9.33333 10 8.26667Z")); const ReplyIcon = LazyComponent(() => findByCode("M10 8.26667V4L3 11.4667L10 18.9333V14.56C15 14.56 18.5 16.2667 21 20C20 14.6667 17 9.33333 10 8.26667Z"));
@ -31,9 +31,9 @@ const replyFn = findByCodeLazy("showMentionToggle", "TEXTAREA_FOCUS", "shiftKey"
const messageContextMenuPatch: NavContextMenuPatchCallback = (children, { message }: { message: Message; }) => () => { const messageContextMenuPatch: NavContextMenuPatchCallback = (children, { message }: { message: Message; }) => () => {
// make sure the message is in the selected channel // make sure the message is in the selected channel
if (SelectedChannelStore.getChannelId() !== message.channel_id) return; if (SelectedChannelStore.getChannelId() !== message.channel_id) return;
const channel = ChannelStore.getChannel(message?.channel_id); const channel = ChannelStore.getChannel(message?.channel_id);
if (!channel) return; if (!channel) return;
if (!PermissionStore.can(PermissionsBits.SEND_MESSAGES, channel)) return;
// dms and group chats // dms and group chats
const dmGroup = findGroupChildrenByChildId("pin", children); const dmGroup = findGroupChildrenByChildId("pin", children);