diff --git a/src/equicordplugins/statusWhileActive.desktop/README.md b/src/equicordplugins/statusWhileActive.desktop/README.md new file mode 100644 index 000000000..bebfbd8e2 --- /dev/null +++ b/src/equicordplugins/statusWhileActive.desktop/README.md @@ -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. \ No newline at end of file diff --git a/src/equicordplugins/statusWhileActive.desktop/index.ts b/src/equicordplugins/statusWhileActive.desktop/index.ts new file mode 100644 index 000000000..b8b4d82ce --- /dev/null +++ b/src/equicordplugins/statusWhileActive.desktop/index.ts @@ -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 = ""; + } + } +}); diff --git a/src/equicordplugins/statusWhilePlaying.desktop/README.md b/src/equicordplugins/statusWhilePlaying.desktop/README.md deleted file mode 100644 index 5e3abf287..000000000 --- a/src/equicordplugins/statusWhilePlaying.desktop/README.md +++ /dev/null @@ -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. diff --git a/src/equicordplugins/statusWhilePlaying.desktop/index.ts b/src/equicordplugins/statusWhilePlaying.desktop/index.ts deleted file mode 100644 index 15524df46..000000000 --- a/src/equicordplugins/statusWhilePlaying.desktop/index.ts +++ /dev/null @@ -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); - } - } - } -});