rename shitpost

This commit is contained in:
amy 2025-05-23 08:55:08 +03:30
parent ef03b23fa9
commit 994e4f72b2
No known key found for this signature in database
2 changed files with 52 additions and 1 deletions

View file

@ -0,0 +1,51 @@
import {Command} from "../command.ts";
import {
ApplicationIntegrationType, type AutocompleteFocusedOption, AutocompleteInteraction,
ChatInputCommandInteraction,
InteractionContextType,
SlashCommandBuilder
} from "discord.js";
import { config, type Config } from "../config.ts";
import {DOWNLOAD_FOLDER_PATH, getFilesInFolder} from "./shitpost.ts";
import fs from "node:fs";
import path from "node:path";
export default class RenameshitpostCommand extends Command {
async run(interaction: ChatInputCommandInteraction, config: Config, ) {
await interaction.deferReply();
const originalname = interaction.options.getString("originalname")!;
const newname = interaction.options.getString("newname")!;
fs.renameSync(path.join(DOWNLOAD_FOLDER_PATH, originalname), path.join(DOWNLOAD_FOLDER_PATH, newname));
await interaction.followUp("uhhh this shit shouldve worked")
}
async autoComplete(interaction: AutocompleteInteraction, config: Config, option: AutocompleteFocusedOption): Promise<void> {
if (option.name === 'originalname') {
const files = await getFilesInFolder(DOWNLOAD_FOLDER_PATH);
const focusedValue = option.value.toLowerCase();
const filteredFiles = files.filter(choice => choice.name.toLowerCase().includes(focusedValue));
await interaction.respond(
filteredFiles.slice(0, 25)
);
}
}
slashCommand = new SlashCommandBuilder()
.setName("renameshitpost")
.setDescription("rename the shitpost").setIntegrationTypes([
ApplicationIntegrationType.UserInstall
]).addStringOption(option => {
return option.setName("originalname").setRequired(true).setDescription("the original shitpost name")
.setAutocomplete(true)
}).addStringOption(option => {
return option.setName("newname").setRequired(true).setDescription("the new shitpost name")
})
.setContexts([
InteractionContextType.BotDM,
InteractionContextType.Guild,
InteractionContextType.PrivateChannel
]);
}

View file

@ -16,7 +16,7 @@ const __dirname = path.dirname(__filename);
export const BUCKETNAME = "shitposts" as const;
export const DOWNLOAD_FOLDER_PATH = path.join(__dirname, '..', '..', 'shitposts');
async function getFilesInFolder(folderPath: string): Promise<{ name: string, value: string }[]> {
export async function getFilesInFolder(folderPath: string): Promise<{ name: string, value: string }[]> {
try {
const files = await fs.readdir(folderPath);
const fileList: { name: string, value: string }[] = [];