StatusWhilePlaying plugin (#423)

* StatusWhileInVC plugin

A plugin that automatically updates the user's Discord status when joining or leaving a voice channel.

* ok

* Update README.md

* I have no idea if this works

* I hate how this works

* Migration

---------

Co-authored-by: thororen1234 <78185467+thororen1234@users.noreply.github.com>
This commit is contained in:
smuki 2025-09-29 17:42:10 +03:00 • committed by GitHub
parent 4824993e9a
commit 353854f0b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 125 additions and 66 deletions

View file

@ -0,0 +1,5 @@
# StatusWhileActive
This plugin automatically updates your online status when playing games or joining a voice channel.
It will change your status back to the prior status when the activity is stopped.

View file

@ -0,0 +1,120 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { definePluginSettings, migratePluginSettings } from "@api/Settings";
import { getUserSettingLazy } from "@api/UserSettings";
import { Devs, EquicordDevs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { VoiceState } from "@vencord/discord-types";
import { PresenceStore, UserStore, VoiceStateStore } from "@webpack/common";
let savedStatus: string | null = null;
const StatusSettings = getUserSettingLazy("status", "status");
const settings = definePluginSettings({
trigger: {
type: OptionType.SELECT,
description: "When to change your status",
options: [
{
label: "While playing a game",
value: "game",
default: true,
},
{
label: "While in a voice channel",
value: "vc",
},
{
label: "While playing or in a voice channel",
value: "either",
},
]
},
statusToSet: {
type: OptionType.SELECT,
description: "Status to set",
options: [
{
label: "Online",
value: "online",
},
{
label: "Idle",
value: "idle",
},
{
label: "Do Not Disturb",
value: "dnd",
default: true,
},
{
label: "Invisible",
value: "invisible",
}
]
}
});
function setStatus(preq, status) {
if (preq) {
if (status !== settings.store.statusToSet) {
savedStatus = status;
StatusSettings?.updateSetting(settings.store.statusToSet);
}
} else if (savedStatus && savedStatus !== settings.store.statusToSet) {
StatusSettings?.updateSetting(savedStatus);
savedStatus = null;
}
}
migratePluginSettings("StatusWhileActive", "StatusWhilePlaying");
export default definePlugin({
name: "StatusWhileActive",
description: "Automatically updates your online status when playing games or in a voice channel.",
authors: [Devs.thororen, EquicordDevs.smuki],
settings,
flux: {
RUNNING_GAMES_CHANGE({ games }) {
const { trigger } = settings.store;
if (trigger === "vc") return;
const userId = UserStore.getCurrentUser().id;
const status = PresenceStore.getStatus(userId);
setStatus(games.length > 0, status);
},
VOICE_STATE_UPDATES({ voiceStates }: { voiceStates: VoiceState[]; }) {
const { trigger } = settings.store;
if (trigger === "game") return;
const userId = UserStore.getCurrentUser().id;
const myState = voiceStates.find(state => state.userId === userId);
if (!myState) return;
const status = PresenceStore.getStatus(userId);
const inVoiceChannel = !!VoiceStateStore.getVoiceStateForUser(userId)?.channelId;
setStatus(inVoiceChannel, status);
},
VOICE_CHANNEL_STATUS_UPDATE() {
const { trigger } = settings.store;
if (trigger === "game") return;
const userId = UserStore.getCurrentUser().id;
const status = PresenceStore.getStatus(userId);
const inVoiceChannel = !!VoiceStateStore.getVoiceStateForUser(userId)?.channelId;
setStatus(inVoiceChannel, status);
}
},
stop() {
if (savedStatus) {
StatusSettings?.updateSetting(savedStatus);
savedStatus = "";
}
}
});

View file

@ -1,5 +0,0 @@
# StatusWhilePlaying
This plugin automatically updates your online status (online, idle, dnd) when launching games.
It will change your status back to the prior status when the game is closed.

View file

@ -1,61 +0,0 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { definePluginSettings } from "@api/Settings";
import { getUserSettingLazy } from "@api/UserSettings";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { PresenceStore, UserStore } from "@webpack/common";
let savedStatus = "";
const StatusSettings = getUserSettingLazy("status", "status");
const settings = definePluginSettings({
statusToSet: {
type: OptionType.SELECT,
description: "Status to set while playing a game",
options: [
{
label: "Online",
value: "online",
},
{
label: "Idle",
value: "idle",
},
{
label: "Do Not Disturb",
value: "dnd",
default: true
},
{
label: "Invisible",
value: "invisible",
}
]
}
});
export default definePlugin({
name: "StatusWhilePlaying",
description: "Automatically updates your online status (online, idle, dnd) when launching games",
authors: [Devs.thororen],
settings,
flux: {
RUNNING_GAMES_CHANGE({ games }) {
const userId = UserStore.getCurrentUser().id;
const status = PresenceStore.getStatus(userId);
if (games.length > 0) {
if (status !== settings.store.statusToSet) {
savedStatus = status;
StatusSettings?.updateSetting(settings.store.statusToSet);
}
} else if (savedStatus && savedStatus !== settings.store.statusToSet) {
StatusSettings?.updateSetting(savedStatus);
}
}
}
});