1048 lines
36 KiB
TypeScript
1048 lines
36 KiB
TypeScript
/*
|
|
* Vencord, a Discord client mod
|
|
* Copyright (c) 2026 Vendicated and contributors
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*/
|
|
|
|
import { NavContextMenuPatchCallback } from "@api/ContextMenu";
|
|
import { definePluginSettings } from "@api/Settings";
|
|
import ErrorBoundary from "@components/ErrorBoundary";
|
|
import { sendMessage } from "@utils/discord";
|
|
import definePlugin, { OptionType } from "@utils/types";
|
|
import { findComponentByCodeLazy } from "@webpack";
|
|
import {
|
|
ChannelActionCreators,
|
|
ChannelStore,
|
|
GuildStore,
|
|
Menu,
|
|
React,
|
|
RestAPI,
|
|
Select,
|
|
SettingsRouter,
|
|
TextInput,
|
|
UserStore,
|
|
VoiceStateStore,
|
|
} from "@webpack/common";
|
|
|
|
const HeaderBarIcon = findComponentByCodeLazy(".HEADER_BAR_BADGE_BOTTOM,", 'position:"bottom"');
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Types
|
|
// ---------------------------------------------------------------------------
|
|
|
|
interface MoveItem {
|
|
id: string;
|
|
userId: string;
|
|
guildId: string;
|
|
enabled: boolean;
|
|
/** true = disconnect on join, false = auto-move loop */
|
|
disconnectOnJoin: boolean;
|
|
/** delay between moves in ms (default: 2000) */
|
|
delay: number;
|
|
/** server-mute on join */
|
|
serverMute: boolean;
|
|
/** server-deafen on join */
|
|
serverDeafen: boolean;
|
|
sendDm: boolean;
|
|
dmMessage: string;
|
|
}
|
|
|
|
interface MoveState {
|
|
timer: ReturnType<typeof setTimeout> | null;
|
|
guildId: string;
|
|
}
|
|
|
|
const ACTION_DELAY_MS = 1000;
|
|
|
|
/** Pause for a given number of milliseconds */
|
|
const wait = (ms: number) => new Promise<void>((r) => setTimeout(r, ms));
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// State
|
|
// ---------------------------------------------------------------------------
|
|
|
|
const activeMoves = new Map<string, MoveState>();
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Settings
|
|
// ---------------------------------------------------------------------------
|
|
|
|
const settings = definePluginSettings({
|
|
moveListManager: {
|
|
type: OptionType.COMPONENT,
|
|
description: "Manage auto-move targets",
|
|
component: () => <MoveListManager />,
|
|
},
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Persistence helpers
|
|
// ---------------------------------------------------------------------------
|
|
|
|
function getMoveList(): MoveItem[] {
|
|
try {
|
|
const stored = Vencord.Settings.plugins.autoMover?.moveList;
|
|
return stored ? JSON.parse(stored) : [];
|
|
} catch {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
function setMoveList(list: MoveItem[]) {
|
|
Vencord.Settings.plugins.autoMover.moveList = JSON.stringify(list);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Move logic
|
|
// ---------------------------------------------------------------------------
|
|
|
|
function stopMoving(userId: string) {
|
|
const state = activeMoves.get(userId);
|
|
if (state) {
|
|
if (state.timer) clearTimeout(state.timer);
|
|
activeMoves.delete(userId);
|
|
}
|
|
}
|
|
|
|
function getRandomVoiceChannel(
|
|
guildId: string,
|
|
excludeChannelId: string,
|
|
): string | null {
|
|
const channels = ChannelStore.getMutableGuildChannelsForGuild(guildId);
|
|
// Channel type 2 = GUILD_VOICE
|
|
const voiceChannels = Object.values(channels).filter(
|
|
(c) => (c as any).type === 2 && c.id !== excludeChannelId,
|
|
);
|
|
|
|
if (voiceChannels.length === 0) return null;
|
|
return voiceChannels[Math.floor(Math.random() * voiceChannels.length)].id;
|
|
}
|
|
|
|
async function moveUser(userId: string, guildId: string, channelId: string) {
|
|
try {
|
|
await RestAPI.patch({
|
|
url: `/guilds/${guildId}/members/${userId}`,
|
|
body: { channel_id: channelId },
|
|
});
|
|
} catch (e) {
|
|
console.error("[autoMover] Failed to move user:", e);
|
|
}
|
|
}
|
|
|
|
async function disconnectUser(userId: string, guildId: string) {
|
|
try {
|
|
await RestAPI.patch({
|
|
url: `/guilds/${guildId}/members/${userId}`,
|
|
body: { channel_id: null },
|
|
});
|
|
} catch (e) {
|
|
console.error("[autoMover] Failed to disconnect user:", e);
|
|
}
|
|
}
|
|
|
|
async function serverMuteUser(userId: string, guildId: string) {
|
|
try {
|
|
await RestAPI.patch({
|
|
url: `/guilds/${guildId}/members/${userId}`,
|
|
body: { mute: true },
|
|
});
|
|
} catch (e) {
|
|
console.error("[autoMover] Failed to server-mute user:", e);
|
|
}
|
|
}
|
|
|
|
async function serverDeafenUser(userId: string, guildId: string) {
|
|
try {
|
|
await RestAPI.patch({
|
|
url: `/guilds/${guildId}/members/${userId}`,
|
|
body: { deaf: true },
|
|
});
|
|
} catch (e) {
|
|
console.error("[autoMover] Failed to server-deafen user:", e);
|
|
}
|
|
}
|
|
|
|
async function sendDmToUser(item: MoveItem) {
|
|
const message = item.dmMessage;
|
|
if (!message) return;
|
|
|
|
try {
|
|
let dmChannelId = ChannelStore.getDMFromUserId(item.userId);
|
|
if (!dmChannelId) {
|
|
await ChannelActionCreators.openPrivateChannel(item.userId);
|
|
await new Promise((r) => setTimeout(r, 500));
|
|
dmChannelId = ChannelStore.getDMFromUserId(item.userId);
|
|
}
|
|
|
|
if (dmChannelId) {
|
|
await sendMessage(dmChannelId, { content: message });
|
|
}
|
|
} catch (e) {
|
|
console.error("[autoMover] Failed to send DM:", e);
|
|
}
|
|
}
|
|
|
|
function scheduleMove(item: MoveItem) {
|
|
const { userId, guildId } = item;
|
|
|
|
// Check if item is still in the list and enabled
|
|
const list = getMoveList();
|
|
const current = list.find((i) => i.id === item.id);
|
|
if (!current || !current.enabled || current.disconnectOnJoin) {
|
|
stopMoving(userId);
|
|
return;
|
|
}
|
|
|
|
// Check if user is still in a voice channel in this guild
|
|
const voiceState = VoiceStateStore.getVoiceStateForUser(userId);
|
|
|
|
if (
|
|
!voiceState ||
|
|
!voiceState.channelId ||
|
|
(voiceState.guildId && voiceState.guildId !== guildId)
|
|
) {
|
|
stopMoving(userId);
|
|
return;
|
|
}
|
|
|
|
// Pick a random voice channel different from current
|
|
const nextChannelId = getRandomVoiceChannel(guildId, voiceState.channelId);
|
|
if (!nextChannelId) {
|
|
stopMoving(userId);
|
|
return;
|
|
}
|
|
|
|
moveUser(userId, guildId, nextChannelId);
|
|
|
|
// Schedule next move using the configured delay
|
|
const state = activeMoves.get(userId);
|
|
if (state) {
|
|
state.timer = setTimeout(() => scheduleMove(item), current.delay);
|
|
}
|
|
}
|
|
|
|
async function startMoving(item: MoveItem) {
|
|
// Stop any existing move for this user
|
|
stopMoving(item.userId);
|
|
|
|
// 1. Send DM if enabled
|
|
if (item.sendDm) {
|
|
await sendDmToUser(item);
|
|
await wait(ACTION_DELAY_MS);
|
|
}
|
|
|
|
// 2. Server mute if enabled
|
|
if (item.serverMute) {
|
|
await serverMuteUser(item.userId, item.guildId);
|
|
await wait(ACTION_DELAY_MS);
|
|
}
|
|
|
|
// 3. Server deafen if enabled
|
|
if (item.serverDeafen) {
|
|
await serverDeafenUser(item.userId, item.guildId);
|
|
await wait(ACTION_DELAY_MS);
|
|
}
|
|
|
|
// 4. Disconnect or start move loop
|
|
if (item.disconnectOnJoin) {
|
|
await disconnectUser(item.userId, item.guildId);
|
|
} else if (item.enabled) {
|
|
const state: MoveState = { timer: null, guildId: item.guildId };
|
|
activeMoves.set(item.userId, state);
|
|
scheduleMove(item);
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Context Menu (right-click user → toggle autoMover / autoDisconnect)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
interface UserContextProps {
|
|
channel: any;
|
|
guildId?: string;
|
|
user: { id: string };
|
|
}
|
|
|
|
/**
|
|
* Toggle an entry for the given user.
|
|
* @param disconnectMode false = auto-move, true = auto-disconnect.
|
|
*/
|
|
function toggleUserInList(
|
|
userId: string,
|
|
guildId: string | undefined,
|
|
disconnectMode: boolean,
|
|
) {
|
|
const list = getMoveList();
|
|
const gid = guildId ?? "*";
|
|
const existing = list.find((i) => i.userId === userId && i.guildId === gid);
|
|
|
|
if (existing) {
|
|
const wasActive = existing.enabled;
|
|
|
|
// If clicking the already-active mode, toggle off
|
|
if (existing.enabled && existing.disconnectOnJoin === disconnectMode) {
|
|
existing.enabled = !existing.enabled;
|
|
} else {
|
|
// Switch mode (or enable from off)
|
|
existing.enabled = true;
|
|
existing.disconnectOnJoin = disconnectMode;
|
|
}
|
|
setMoveList(list);
|
|
|
|
// Always stop any running loop before potentially restarting
|
|
if (wasActive) stopMoving(userId);
|
|
|
|
if (!existing.enabled) {
|
|
stopMoving(userId);
|
|
} else {
|
|
// If user is already in a VC, start immediately
|
|
tryStartIfInVoice(existing);
|
|
}
|
|
} else {
|
|
// Create new entry
|
|
const newItem: MoveItem = {
|
|
id: Date.now().toString(),
|
|
userId,
|
|
guildId: gid,
|
|
enabled: true,
|
|
disconnectOnJoin: disconnectMode,
|
|
delay: 2000,
|
|
serverMute: false,
|
|
serverDeafen: false,
|
|
sendDm: false,
|
|
dmMessage: "",
|
|
};
|
|
setMoveList([...list, newItem]);
|
|
|
|
// If user is already in a VC, start immediately
|
|
tryStartIfInVoice(newItem);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Toggle serverMute or serverDeafen for a user.
|
|
* Creates an entry if none exists yet (with move/disconnect disabled).
|
|
*/
|
|
function toggleServerAction(
|
|
userId: string,
|
|
guildId: string | undefined,
|
|
key: "serverMute" | "serverDeafen",
|
|
) {
|
|
const list = getMoveList();
|
|
const gid = guildId ?? "*";
|
|
const existing = list.find((i) => i.userId === userId && i.guildId === gid);
|
|
|
|
if (existing) {
|
|
(existing as any)[key] = !(existing as any)[key];
|
|
setMoveList(list);
|
|
|
|
// If toggling on and user is in VC, apply immediately
|
|
if ((existing as any)[key]) {
|
|
const voiceState = VoiceStateStore.getVoiceStateForUser(userId);
|
|
if (
|
|
voiceState?.channelId &&
|
|
(existing.guildId === "*" ||
|
|
voiceState.guildId === existing.guildId)
|
|
) {
|
|
if (key === "serverMute") {
|
|
serverMuteUser(
|
|
userId,
|
|
voiceState.guildId || existing.guildId,
|
|
);
|
|
} else {
|
|
serverDeafenUser(
|
|
userId,
|
|
voiceState.guildId || existing.guildId,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
const newItem: MoveItem = {
|
|
id: Date.now().toString(),
|
|
userId,
|
|
guildId: gid,
|
|
enabled: false,
|
|
disconnectOnJoin: false,
|
|
delay: 2000,
|
|
serverMute: key === "serverMute",
|
|
serverDeafen: key === "serverDeafen",
|
|
sendDm: false,
|
|
dmMessage: "",
|
|
};
|
|
setMoveList([...list, newItem]);
|
|
|
|
// Apply immediately if user is in VC
|
|
const voiceState = VoiceStateStore.getVoiceStateForUser(userId);
|
|
if (
|
|
voiceState?.channelId &&
|
|
(newItem.guildId === "*" || voiceState.guildId === newItem.guildId)
|
|
) {
|
|
if (key === "serverMute") {
|
|
serverMuteUser(userId, voiceState.guildId || newItem.guildId);
|
|
} else {
|
|
serverDeafenUser(userId, voiceState.guildId || newItem.guildId);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/** If the item's user is currently in a matching voice channel, start */
|
|
function tryStartIfInVoice(item: MoveItem) {
|
|
if (
|
|
(!item.enabled && !item.serverMute && !item.serverDeafen) ||
|
|
activeMoves.has(item.userId)
|
|
)
|
|
return;
|
|
|
|
const voiceState = VoiceStateStore.getVoiceStateForUser(item.userId);
|
|
if (!voiceState?.channelId) return;
|
|
|
|
// guildId is optional on VoiceState — only block on explicit mismatch
|
|
if (
|
|
item.guildId !== "*" &&
|
|
voiceState.guildId &&
|
|
voiceState.guildId !== item.guildId
|
|
)
|
|
return;
|
|
|
|
startMoving(item);
|
|
}
|
|
|
|
const UserContextMenuPatch: NavContextMenuPatchCallback = (
|
|
children,
|
|
{ user, guildId }: UserContextProps,
|
|
) => {
|
|
if (!user) return;
|
|
|
|
const list = getMoveList();
|
|
const existing = list.find(
|
|
(i) => i.userId === user.id && i.guildId === (guildId ?? "*"),
|
|
);
|
|
|
|
const moveChecked = existing
|
|
? existing.enabled && !existing.disconnectOnJoin
|
|
: false;
|
|
const disconnectChecked = existing
|
|
? existing.enabled && existing.disconnectOnJoin
|
|
: false;
|
|
const muteChecked = existing ? existing.serverMute : false;
|
|
const deafenChecked = existing ? existing.serverDeafen : false;
|
|
|
|
children.push(
|
|
<Menu.MenuCheckboxItem
|
|
id="vc-automover-toggle"
|
|
label="Auto Mover"
|
|
checked={moveChecked}
|
|
action={() => toggleUserInList(user.id, guildId, false)}
|
|
/>,
|
|
<Menu.MenuCheckboxItem
|
|
id="vc-automover-disconnect-toggle"
|
|
label="Auto Disconnect"
|
|
checked={disconnectChecked}
|
|
action={() => toggleUserInList(user.id, guildId, true)}
|
|
/>,
|
|
<Menu.MenuCheckboxItem
|
|
id="vc-automover-mute-toggle"
|
|
label="Auto Server Mute"
|
|
checked={muteChecked}
|
|
action={() => toggleServerAction(user.id, guildId, "serverMute")}
|
|
/>,
|
|
<Menu.MenuCheckboxItem
|
|
id="vc-automover-deafen-toggle"
|
|
label="Auto Server Deafen"
|
|
checked={deafenChecked}
|
|
action={() => toggleServerAction(user.id, guildId, "serverDeafen")}
|
|
/>,
|
|
);
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Settings UI Component
|
|
// ---------------------------------------------------------------------------
|
|
|
|
function MoveListManager() {
|
|
const [moveList, setMoveListState] =
|
|
React.useState<MoveItem[]>(getMoveList());
|
|
const [newUserId, setNewUserId] = React.useState("");
|
|
const [newGuildId, setNewGuildId] = React.useState("*");
|
|
const [newDisconnect, setNewDisconnect] = React.useState(false);
|
|
const [newDelay, setNewDelay] = React.useState("2000");
|
|
const [newServerMute, setNewServerMute] = React.useState(false);
|
|
const [newServerDeafen, setNewServerDeafen] = React.useState(false);
|
|
const [newSendDm, setNewSendDm] = React.useState(false);
|
|
const [newDmMessage, setNewDmMessage] = React.useState("");
|
|
|
|
const guilds = Object.values(GuildStore.getGuilds()) as any[];
|
|
|
|
const addEntry = () => {
|
|
if (!newUserId.trim()) return;
|
|
const newItem: MoveItem = {
|
|
id: Date.now().toString(),
|
|
userId: newUserId.trim(),
|
|
guildId: newGuildId,
|
|
enabled: true,
|
|
disconnectOnJoin: newDisconnect,
|
|
delay: parseInt(newDelay, 10) || 2000,
|
|
serverMute: newServerMute,
|
|
serverDeafen: newServerDeafen,
|
|
sendDm: newSendDm,
|
|
dmMessage: newDmMessage,
|
|
};
|
|
const newList = [...moveList, newItem];
|
|
setMoveListState(newList);
|
|
setMoveList(newList);
|
|
setNewUserId("");
|
|
setNewDmMessage("");
|
|
setNewSendDm(false);
|
|
setNewDisconnect(false);
|
|
setNewServerMute(false);
|
|
setNewServerDeafen(false);
|
|
setNewDelay("2000");
|
|
};
|
|
|
|
const removeEntry = (id: string) => {
|
|
const entry = moveList.find((i) => i.id === id);
|
|
if (entry) stopMoving(entry.userId);
|
|
const newList = moveList.filter((i) => i.id !== id);
|
|
setMoveListState(newList);
|
|
setMoveList(newList);
|
|
};
|
|
|
|
const toggleEnabled = (id: string) => {
|
|
const newList = moveList.map((i) => {
|
|
if (i.id === id) {
|
|
const updated = { ...i, enabled: !i.enabled };
|
|
if (!updated.enabled) {
|
|
stopMoving(i.userId);
|
|
} else {
|
|
// Restart if user is already in VC
|
|
tryStartIfInVoice(updated);
|
|
}
|
|
return updated;
|
|
}
|
|
return i;
|
|
});
|
|
setMoveListState(newList);
|
|
setMoveList(newList);
|
|
};
|
|
|
|
const toggleDisconnect = (id: string) => {
|
|
const newList = moveList.map((i) => {
|
|
if (i.id === id) {
|
|
// If toggling disconnect on, also enable and stop any move loop
|
|
if (!i.disconnectOnJoin) {
|
|
stopMoving(i.userId);
|
|
const updated = {
|
|
...i,
|
|
enabled: true,
|
|
disconnectOnJoin: true,
|
|
};
|
|
// Disconnect immediately if user is in VC
|
|
tryStartIfInVoice(updated);
|
|
return updated;
|
|
}
|
|
// Toggling disconnect off → switch to move mode
|
|
stopMoving(i.userId);
|
|
const updated = { ...i, disconnectOnJoin: false };
|
|
// Restart move loop if user is in VC
|
|
tryStartIfInVoice(updated);
|
|
return updated;
|
|
}
|
|
return i;
|
|
});
|
|
setMoveListState(newList);
|
|
setMoveList(newList);
|
|
};
|
|
|
|
const toggleSendDm = (id: string) => {
|
|
const newList = moveList.map((i) =>
|
|
i.id === id ? { ...i, sendDm: !i.sendDm } : i,
|
|
);
|
|
setMoveListState(newList);
|
|
setMoveList(newList);
|
|
};
|
|
|
|
const toggleServerMute = (id: string) => {
|
|
const newList = moveList.map((i) => {
|
|
if (i.id === id) {
|
|
const updated = { ...i, serverMute: !i.serverMute };
|
|
// Apply immediately if user is in VC
|
|
if (updated.serverMute) {
|
|
const voiceState = VoiceStateStore.getVoiceStateForUser(
|
|
i.userId,
|
|
);
|
|
if (
|
|
voiceState?.channelId &&
|
|
(i.guildId === "*" || voiceState.guildId === i.guildId)
|
|
) {
|
|
serverMuteUser(
|
|
i.userId,
|
|
voiceState.guildId || i.guildId,
|
|
);
|
|
}
|
|
}
|
|
return updated;
|
|
}
|
|
return i;
|
|
});
|
|
setMoveListState(newList);
|
|
setMoveList(newList);
|
|
};
|
|
|
|
const toggleServerDeafen = (id: string) => {
|
|
const newList = moveList.map((i) => {
|
|
if (i.id === id) {
|
|
const updated = { ...i, serverDeafen: !i.serverDeafen };
|
|
// Apply immediately if user is in VC
|
|
if (updated.serverDeafen) {
|
|
const voiceState = VoiceStateStore.getVoiceStateForUser(
|
|
i.userId,
|
|
);
|
|
if (
|
|
voiceState?.channelId &&
|
|
(i.guildId === "*" || voiceState.guildId === i.guildId)
|
|
) {
|
|
serverDeafenUser(
|
|
i.userId,
|
|
voiceState.guildId || i.guildId,
|
|
);
|
|
}
|
|
}
|
|
return updated;
|
|
}
|
|
return i;
|
|
});
|
|
setMoveListState(newList);
|
|
setMoveList(newList);
|
|
};
|
|
|
|
const updateDmMessage = (id: string, message: string) => {
|
|
const newList = moveList.map((i) =>
|
|
i.id === id ? { ...i, dmMessage: message } : i,
|
|
);
|
|
setMoveListState(newList);
|
|
setMoveList(newList);
|
|
};
|
|
|
|
const updateDelay = (id: string, delayStr: string) => {
|
|
const delay = parseInt(delayStr, 10) || 2000;
|
|
const newList = moveList.map((i) =>
|
|
i.id === id ? { ...i, delay } : i,
|
|
);
|
|
setMoveListState(newList);
|
|
setMoveList(newList);
|
|
};
|
|
|
|
const getUserDisplay = (userId: string) => {
|
|
const user = UserStore.getUser(userId);
|
|
return user ? `${user.username} (${userId})` : userId;
|
|
};
|
|
|
|
const getGuildDisplay = (guildId: string) => {
|
|
if (guildId === "*") return "All Servers";
|
|
const guild = GuildStore.getGuild(guildId);
|
|
return guild ? guild.name : guildId;
|
|
};
|
|
|
|
return (
|
|
<div>
|
|
<section>
|
|
<h4>Add New Entry</h4>
|
|
|
|
<div style={{ marginBottom: "8px", marginTop: "12px" }}>
|
|
User ID
|
|
</div>
|
|
<TextInput
|
|
placeholder="Enter user ID..."
|
|
value={newUserId}
|
|
onChange={setNewUserId}
|
|
/>
|
|
|
|
<div style={{ marginTop: "12px", marginBottom: "8px" }}>
|
|
Server
|
|
</div>
|
|
<Select
|
|
options={[
|
|
{ label: "All Servers (*)", value: "*" },
|
|
...guilds.map((g) => ({ label: g.name, value: g.id })),
|
|
]}
|
|
select={setNewGuildId}
|
|
isSelected={(v) => v === newGuildId}
|
|
serialize={(v) => v}
|
|
/>
|
|
|
|
<div style={{ marginTop: "12px", marginBottom: "8px" }}>
|
|
<label
|
|
style={{
|
|
display: "flex",
|
|
alignItems: "center",
|
|
gap: "5px",
|
|
}}
|
|
>
|
|
<input
|
|
type="checkbox"
|
|
checked={newDisconnect}
|
|
onChange={(e) => setNewDisconnect(e.target.checked)}
|
|
/>
|
|
Auto Disconnect (instead of auto-move)
|
|
</label>
|
|
</div>
|
|
|
|
{!newDisconnect && (
|
|
<div style={{ marginTop: "12px", marginBottom: "8px" }}>
|
|
<div>Delay between moves (ms)</div>
|
|
<TextInput
|
|
placeholder="1000"
|
|
value={newDelay}
|
|
onChange={setNewDelay}
|
|
/>
|
|
</div>
|
|
)}
|
|
|
|
<div style={{ marginTop: "12px", marginBottom: "8px" }}>
|
|
<label
|
|
style={{
|
|
display: "flex",
|
|
alignItems: "center",
|
|
gap: "5px",
|
|
}}
|
|
>
|
|
<input
|
|
type="checkbox"
|
|
checked={newSendDm}
|
|
onChange={(e) => setNewSendDm(e.target.checked)}
|
|
/>
|
|
Send DM on start
|
|
</label>
|
|
</div>
|
|
|
|
{newSendDm && (
|
|
<TextInput
|
|
placeholder="DM message..."
|
|
value={newDmMessage}
|
|
onChange={setNewDmMessage}
|
|
/>
|
|
)}
|
|
|
|
<div style={{ marginTop: "12px", marginBottom: "8px" }}>
|
|
<label
|
|
style={{
|
|
display: "flex",
|
|
alignItems: "center",
|
|
gap: "5px",
|
|
}}
|
|
>
|
|
<input
|
|
type="checkbox"
|
|
checked={newServerMute}
|
|
onChange={(e) => setNewServerMute(e.target.checked)}
|
|
/>
|
|
Server Mute on join
|
|
</label>
|
|
</div>
|
|
|
|
<div style={{ marginTop: "8px", marginBottom: "8px" }}>
|
|
<label
|
|
style={{
|
|
display: "flex",
|
|
alignItems: "center",
|
|
gap: "5px",
|
|
}}
|
|
>
|
|
<input
|
|
type="checkbox"
|
|
checked={newServerDeafen}
|
|
onChange={(e) =>
|
|
setNewServerDeafen(e.target.checked)
|
|
}
|
|
/>
|
|
Server Deafen on join
|
|
</label>
|
|
</div>
|
|
|
|
<div style={{ marginTop: "12px", marginBottom: "8px" }}>
|
|
<button
|
|
style={{
|
|
padding: "6px 16px",
|
|
cursor: "pointer",
|
|
background: "var(--button-positive-background)",
|
|
color: "var(--white-500)",
|
|
border: "none",
|
|
borderRadius: "4px",
|
|
}}
|
|
onClick={addEntry}
|
|
>
|
|
Add Entry
|
|
</button>
|
|
</div>
|
|
</section>
|
|
|
|
<h4 style={{ marginTop: "16px" }}>Move List ({moveList.length})</h4>
|
|
|
|
{moveList.length === 0 ? (
|
|
<div>No entries configured</div>
|
|
) : (
|
|
moveList.map((item) => (
|
|
<div
|
|
key={item.id}
|
|
style={{
|
|
display: "flex",
|
|
justifyContent: "space-between",
|
|
alignItems: "flex-start",
|
|
background: "var(--background-secondary-alt)",
|
|
padding: "12px",
|
|
borderRadius: "8px",
|
|
marginBottom: "8px",
|
|
gap: "8px",
|
|
}}
|
|
>
|
|
<div style={{ flex: 1 }}>
|
|
<div>
|
|
<strong>User:</strong>{" "}
|
|
{getUserDisplay(item.userId)}
|
|
</div>
|
|
<div>
|
|
<strong>Server:</strong>{" "}
|
|
{getGuildDisplay(item.guildId)}
|
|
</div>
|
|
<div>
|
|
<strong>Mode:</strong>{" "}
|
|
{item.disconnectOnJoin ? "Disconnect" : "Move"}
|
|
{!item.disconnectOnJoin && ` (${item.delay}ms)`}
|
|
{item.serverMute && " 🔇Mute"}
|
|
{item.serverDeafen && " 🔇Deafen"}
|
|
</div>
|
|
<div
|
|
style={{
|
|
display: "flex",
|
|
flexWrap: "wrap",
|
|
gap: "16px",
|
|
marginTop: "8px",
|
|
}}
|
|
>
|
|
<label
|
|
style={{
|
|
display: "flex",
|
|
alignItems: "center",
|
|
gap: "4px",
|
|
fontSize: "13px",
|
|
}}
|
|
>
|
|
<input
|
|
type="checkbox"
|
|
checked={item.enabled}
|
|
onChange={() => toggleEnabled(item.id)}
|
|
/>
|
|
Enabled
|
|
</label>
|
|
<label
|
|
style={{
|
|
display: "flex",
|
|
alignItems: "center",
|
|
gap: "4px",
|
|
fontSize: "13px",
|
|
}}
|
|
>
|
|
<input
|
|
type="checkbox"
|
|
checked={item.disconnectOnJoin}
|
|
onChange={() =>
|
|
toggleDisconnect(item.id)
|
|
}
|
|
/>
|
|
Disconnect
|
|
</label>
|
|
<label
|
|
style={{
|
|
display: "flex",
|
|
alignItems: "center",
|
|
gap: "4px",
|
|
fontSize: "13px",
|
|
}}
|
|
>
|
|
<input
|
|
type="checkbox"
|
|
checked={item.sendDm}
|
|
onChange={() => toggleSendDm(item.id)}
|
|
/>
|
|
Send DM
|
|
</label>
|
|
<label
|
|
style={{
|
|
display: "flex",
|
|
alignItems: "center",
|
|
gap: "4px",
|
|
fontSize: "13px",
|
|
}}
|
|
>
|
|
<input
|
|
type="checkbox"
|
|
checked={item.serverMute}
|
|
onChange={() =>
|
|
toggleServerMute(item.id)
|
|
}
|
|
/>
|
|
Server Mute
|
|
</label>
|
|
<label
|
|
style={{
|
|
display: "flex",
|
|
alignItems: "center",
|
|
gap: "4px",
|
|
fontSize: "13px",
|
|
}}
|
|
>
|
|
<input
|
|
type="checkbox"
|
|
checked={item.serverDeafen}
|
|
onChange={() =>
|
|
toggleServerDeafen(item.id)
|
|
}
|
|
/>
|
|
Server Deafen
|
|
</label>
|
|
</div>
|
|
{!item.disconnectOnJoin && (
|
|
<div
|
|
style={{
|
|
marginTop: "6px",
|
|
display: "flex",
|
|
alignItems: "center",
|
|
gap: "8px",
|
|
}}
|
|
>
|
|
<span style={{ fontSize: "13px" }}>
|
|
Delay (ms):
|
|
</span>
|
|
<TextInput
|
|
placeholder="1000"
|
|
value={String(item.delay)}
|
|
onChange={(v) =>
|
|
updateDelay(item.id, v)
|
|
}
|
|
/>
|
|
</div>
|
|
)}
|
|
{item.sendDm && (
|
|
<div style={{ marginTop: "6px" }}>
|
|
<TextInput
|
|
placeholder="DM message..."
|
|
value={item.dmMessage}
|
|
onChange={(v) =>
|
|
updateDmMessage(item.id, v)
|
|
}
|
|
/>
|
|
</div>
|
|
)}
|
|
</div>
|
|
<button
|
|
style={{
|
|
padding: "4px 12px",
|
|
cursor: "pointer",
|
|
background: "var(--button-danger-background)",
|
|
color: "var(--white-500)",
|
|
border: "none",
|
|
borderRadius: "4px",
|
|
whiteSpace: "nowrap",
|
|
}}
|
|
onClick={() => removeEntry(item.id)}
|
|
>
|
|
Remove
|
|
</button>
|
|
</div>
|
|
))
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Toolbar Button
|
|
// ---------------------------------------------------------------------------
|
|
|
|
function AutoMoverButton() {
|
|
return (
|
|
<HeaderBarIcon
|
|
className="vc-automover-btn"
|
|
onClick={() => SettingsRouter.open("VencordPlugins")}
|
|
tooltip="autoMover Settings"
|
|
icon={() => (
|
|
<svg
|
|
width="20"
|
|
height="20"
|
|
viewBox="0 0 24 24"
|
|
fill="currentColor"
|
|
>
|
|
<path d="M18 4l-4 4h3v4h2V8h3l-4-4zm-4 12h-2v-4H9l4-4 4 4h-3v4zm-8 4l4-4H7v-4H5v4H2l4 4z" />
|
|
</svg>
|
|
)}
|
|
/>
|
|
);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Plugin definition
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export default definePlugin({
|
|
name: "autoMover",
|
|
description:
|
|
"Automatically moves target users randomly between voice channels when they connect, or disconnects them",
|
|
authors: [{ name: "You", id: 0n }],
|
|
settings,
|
|
|
|
patches: [
|
|
{
|
|
// Inject button into the toolbar next to inbox
|
|
find: "toolbar:function",
|
|
replacement: {
|
|
match: /(function \i\(\i\){var \i=\i\.className.*?children):\[(\i\.useMemo[^}]+"div",{className:\i\(\).*?}\),)/,
|
|
replace: "$1:[$self.ToolbarButton(),$2",
|
|
},
|
|
},
|
|
],
|
|
|
|
ToolbarButton: ErrorBoundary.wrap(AutoMoverButton, { noop: true }),
|
|
|
|
contextMenus: {
|
|
"user-context": UserContextMenuPatch,
|
|
},
|
|
|
|
flux: {
|
|
VOICE_STATE_UPDATES({ voiceStates }: { voiceStates: any[] }) {
|
|
const moveList = getMoveList();
|
|
if (moveList.length === 0) return;
|
|
|
|
for (const state of voiceStates) {
|
|
const { userId, channelId, guildId } = state;
|
|
if (!channelId) continue;
|
|
|
|
for (const item of moveList) {
|
|
if (!item.enabled && !item.serverMute && !item.serverDeafen)
|
|
continue;
|
|
if (item.userId !== userId) continue;
|
|
if (item.guildId !== "*" && item.guildId !== guildId)
|
|
continue;
|
|
|
|
// Already moving this user — skip
|
|
if (activeMoves.has(userId)) continue;
|
|
|
|
startMoving(item);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
start() {
|
|
console.log("autoMover started");
|
|
},
|
|
|
|
stop() {
|
|
for (const userId of activeMoves.keys()) {
|
|
stopMoving(userId);
|
|
}
|
|
console.log("autoMover stopped");
|
|
},
|
|
});
|