vd-plugins/plugins/Commands/index.ts

167 lines
4.4 KiB
TypeScript
Raw Normal View History

import { registerCommand } from "@vendetta/commands";
import { storage } from "@vendetta/plugin";
import {
2025-10-07 11:45:12 +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 {
2025-10-07 11:45:12 +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 {
friendInviteCreateCommand,
friendInviteViewCommand,
friendInviteRevokeCommand,
} from "./src/commands/friendinvites";
import settings from "./settings/settings";
import patchSidebar from "./sidebar";
if (!storage.factSettings) {
2025-10-07 11:45:12 +02:00
storage.factSettings = {
sendAsReply: true,
includeCitation: false,
};
}
if (!storage.listSettings) {
2025-10-07 11:45:12 +02:00
storage.listSettings = {
pluginListAlwaysDetailed: false,
themeListAlwaysDetailed: false,
};
}
2025-10-01 15:41:01 +02:00
if (!storage.garySettings) {
2025-10-07 11:45:12 +02:00
storage.garySettings = {
imageSource: "gary",
};
2025-10-01 15:41:01 +02:00
}
if (!storage.enabledCommands) {
2025-10-07 11:45:12 +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) {
2025-10-07 11:45:12 +02:00
storage.hiddenSettings = {
enabled: false,
visible: false,
konochanBypassNsfw: false,
};
}
// sidebar enabled setting
if (storage.sidebarEnabled === undefined) {
storage.sidebarEnabled = true;
}
const commandMap = {
2025-10-07 11:45:12 +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 {
2025-10-07 11:45:12 +02:00
onLoad: () => {
console.log("[Commands Plugin] Loading...");
// 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);
}
}
// Register commands
2025-10-07 11:45:12 +02:00
for (const [key, command] of Object.entries(commandMap)) {
if (storage.enabledCommands[key]) {
try {
2026-01-24 00:27:30 +01:00
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,
);
}
2025-10-07 11:45:12 +02:00
}
}
},
onUnload: () => {
console.log("[Commands Plugin] Unloading...");
// Unregister commands
commands.forEach((unregister) => {
try {
unregister();
} catch (error) {
// Ignore errors during cleanup
}
});
2025-10-07 11:45:12 +02:00
commands = [];
// 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);
}
}
2025-10-07 11:45:12 +02:00
},
settings,
};