Equicord/src/equicordplugins/statusWhilePlaying/index.ts

64 lines
1.9 KiB
TypeScript
Raw Normal View History

/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
2024-07-19 13:37:41 -04:00
import { definePluginSettings, migratePluginSettings } from "@api/Settings";
import { EquicordDevs } from "@utils/constants";
2024-07-19 13:37:41 -04:00
import definePlugin, { OptionType } from "@utils/types";
import { findByCodeLazy } from "@webpack";
import { FluxDispatcher, PresenceStore, UserStore } from "@webpack/common";
2024-07-19 13:37:41 -04:00
const updateAsync = findByCodeLazy("updateAsync", "status");
2024-07-19 13:37:41 -04:00
const settings = definePluginSettings({
statusToSet: {
type: OptionType.SELECT,
description: "Status set while playing a game",
options: [
{
label: "Online",
value: "online",
},
{
label: "Idle",
value: "idle",
},
{
label: "Do Not Disturb",
value: "dnd",
},
{
label: "Invisible",
value: "invisible",
}
]
}
2024-07-19 13:37:41 -04:00
});
2024-07-19 13:37:41 -04:00
migratePluginSettings("StatusWhilePlaying", "DNDWhilePlaying");
export default definePlugin({
2024-07-19 13:37:41 -04:00
name: "StatusWhilePlaying",
description: "Automatically updates your status when playing games",
authors: [EquicordDevs.thororen],
2024-07-19 13:37:41 -04:00
settings,
runningGamesChange(event) {
let savedStatus = "";
if (event.games.length > 0) {
const currentUser = UserStore.getCurrentUser();
const status = PresenceStore.getStatus(currentUser.id);
savedStatus = status;
updateAsync(settings.store.statusToSet);
} else if (event.games.length === 0) {
updateAsync(savedStatus);
}
},
start() {
2024-07-19 13:37:41 -04:00
FluxDispatcher.subscribe("RUNNING_GAMES_CHANGE", this.runningGamesChange);
},
stop() {
2024-07-19 13:37:41 -04:00
FluxDispatcher.unsubscribe("RUNNING_GAMES_CHANGE", this.runningGamesChange);
}
});