vd-plugins/plugins/Commands/index.ts

167 lines
4.8 KiB
TypeScript
Raw Normal View History

import { registerCommand } from "@vendetta/commands";
import { storage } from "@vendetta/plugin";
import {
2026-05-09 10:20:55 +02:00
catFactCommand,
dogFactCommand,
uselessFactCommand,
} from "./src/commands/facts";
import { pluginListCommand, themeListCommand } from "./src/commands/lists";
import { petPetCommand } from "./src/commands/petpet";
import { konoSelfCommand, konoSendCommand } from "./src/commands/konochan";
import { firstMessageCommand } from "./src/commands/firstmessage";
2025-09-30 19:03:33 +02:00
import { sysinfoCommand } from "./src/commands/sysinfo";
import {
2026-05-09 10:20:55 +02:00
spotifyTrackCommand,
spotifyAlbumCommand,
spotifyArtistsCommand,
spotifyCoverCommand,
2025-09-30 19:03:33 +02:00
} from "./src/commands/spotify";
2025-10-01 15:41:01 +02:00
import { garyCommand } from "./src/commands/gary";
2025-10-01 21:10:41 +02:00
import { lovefemboysCommand } from "./src/commands/lovefemboys";
2025-10-02 23:23:14 +02:00
import { ipCommand } from "./src/commands/ip";
import { nekoslifeCommand } from "./src/commands/nekoslife";
2025-10-07 11:45:12 +02:00
import {
2026-05-09 10:20:55 +02:00
friendInviteCreateCommand,
friendInviteViewCommand,
friendInviteRevokeCommand,
2025-10-07 11:45:12 +02:00
} from "./src/commands/friendinvites";
import settings from "./settings/settings";
import patchSidebar from "./sidebar";
if (!storage.factSettings) {
2026-05-09 10:20:55 +02:00
storage.factSettings = {
sendAsReply: true,
includeCitation: false,
};
}
if (!storage.listSettings) {
2026-05-09 10:20:55 +02:00
storage.listSettings = {
pluginListAlwaysDetailed: false,
themeListAlwaysDetailed: false,
};
}
2025-10-01 15:41:01 +02:00
if (!storage.garySettings) {
2026-05-09 10:20:55 +02:00
storage.garySettings = {
imageSource: "gary",
};
2025-10-01 15:41:01 +02:00
}
if (!storage.enabledCommands) {
2026-05-09 10:20:55 +02:00
storage.enabledCommands = {
catfact: true,
dogfact: true,
useless: true,
petpet: true,
pluginList: true,
themeList: true,
konoself: true,
konosend: true,
firstmessage: true,
sysinfo: true,
spotifyTrack: true,
spotifyAlbum: true,
spotifyArtists: true,
spotifyCover: true,
gary: true,
ip: true,
lovefemboys: false,
nekoslife: false,
friendInviteCreate: true,
friendInviteView: true,
friendInviteRevoke: true,
};
2025-10-01 21:10:41 +02:00
}
if (!storage.hiddenSettings) {
2026-05-09 10:20:55 +02:00
storage.hiddenSettings = {
enabled: false,
visible: false,
konochanBypassNsfw: false,
};
}
// sidebar enabled setting
if (storage.sidebarEnabled === undefined) {
2026-07-02 10:20:05 +02:00
storage.sidebarEnabled = true;
}
const commandMap = {
2026-05-09 10:20:55 +02:00
catfact: catFactCommand,
dogfact: dogFactCommand,
useless: uselessFactCommand,
petpet: petPetCommand,
pluginList: pluginListCommand,
themeList: themeListCommand,
konoself: konoSelfCommand,
konosend: konoSendCommand,
firstmessage: firstMessageCommand,
sysinfo: sysinfoCommand,
spotifyTrack: spotifyTrackCommand,
spotifyAlbum: spotifyAlbumCommand,
spotifyArtists: spotifyArtistsCommand,
spotifyCover: spotifyCoverCommand,
gary: garyCommand,
ip: ipCommand,
lovefemboys: lovefemboysCommand,
nekoslife: nekoslifeCommand,
friendInviteCreate: friendInviteCreateCommand,
friendInviteView: friendInviteViewCommand,
friendInviteRevoke: friendInviteRevokeCommand,
};
let commands: Array<() => void> = [];
let sidebarUnpatch: (() => void) | undefined;
export default {
2026-05-09 10:20:55 +02:00
onLoad: () => {
console.log("[Commands Plugin] Loading...");
2026-05-24 16:35:16 +02:00
// Patch sidebar if enabled
if (storage.sidebarEnabled !== false) {
try {
sidebarUnpatch = patchSidebar();
console.log("[Commands Plugin] Sidebar patched successfully");
} catch (error) {
console.error("[Commands Plugin] Failed to patch sidebar:", error);
}
}
2026-05-09 10:20:55 +02:00
// Register commands
for (const [key, command] of Object.entries(commandMap)) {
if (storage.enabledCommands[key]) {
try {
commands.push(registerCommand(command as any));
console.log(`[Commands Plugin] Registered command: ${key}`);
} catch (error) {
console.error(
`[Commands Plugin] Failed to register command ${key}:`,
error,
);
}
}
}
2026-05-09 10:20:55 +02:00
},
onUnload: () => {
console.log("[Commands Plugin] Unloading...");
2026-05-09 10:20:55 +02:00
// Unregister commands
commands.forEach((unregister) => {
try {
unregister();
2026-07-02 10:20:05 +02:00
} catch {
2026-05-09 10:20:55 +02:00
// Ignore errors during cleanup
}
});
commands = [];
2026-05-24 16:35:16 +02:00
// Unpatch sidebar
if (sidebarUnpatch) {
try {
sidebarUnpatch();
sidebarUnpatch = undefined;
console.log("[Commands Plugin] Sidebar unpatched");
} catch (error) {
console.error("[Commands Plugin] Failed to unpatch sidebar:", error);
}
}
2026-05-09 10:20:55 +02:00
},
settings,
};