diff --git a/config.example.json b/config.example.json index acfbde2..f7d4828 100644 --- a/config.example.json +++ b/config.example.json @@ -1,3 +1,5 @@ { - "token": "token" + "token": "token", + "sitePort": 15385, + "siteURL": "https://localhost:15385" } \ No newline at end of file diff --git a/migrations/20231117173052_craftingRecipes.js b/migrations/20231117173052_craftingRecipes.js new file mode 100644 index 0000000..1bb6ae4 --- /dev/null +++ b/migrations/20231117173052_craftingRecipes.js @@ -0,0 +1,27 @@ +/** + * @param { import("knex").Knex } knex + * @returns { Promise } + */ +exports.up = function(knex) { + return knex.schema + .createTable('craftingRecipes', (table) => { + table.increments('id'); + table.string('table'); + }) + .createTable('craftingRecipeItems', (table) => { + table.integer('id').references('id').inTable('craftingRecipes').notNullable(); + table.integer('item').notNullable(); + table.integer('quantity').defaultTo(1); + table.enum('type', ['input', 'output', 'requirement']); + }); +}; + +/** + * @param { import("knex").Knex } knex + * @returns { Promise } + */ +exports.down = function(knex) { + return knex.schema + .dropTable('craftingRecipes') + .dropTable('craftingRecipeItems'); +}; diff --git a/src/commands/recipe.ts b/src/commands/recipe.ts new file mode 100644 index 0000000..0042ab2 --- /dev/null +++ b/src/commands/recipe.ts @@ -0,0 +1,30 @@ +import { CommandInteraction, SlashCommandBuilder } from 'discord.js'; +import { Command } from '../types/index'; + +export default { + data: new SlashCommandBuilder() + .setName('recipe') + .setDescription('[ADMIN] Manage custom recipes for items') + .addSubcommand(sub => + sub + .setName('create') + .setDescription('[ADMIN] Create a custom recipe') + ) + .setDMPermission(false) + .setDefaultMemberPermissions(0), + + execute: async (interaction: CommandInteraction) => { + if (!interaction.isChatInputCommand()) return; + + interaction.deferReply({ ephemeral: true }); + + const sub = interaction.options.getSubcommand(true); + + if (sub === 'create') { + interaction.reply({ + ephemeral: true, + content: `To create a recipe, go here: ${interaction.client.config.siteURL}/create-recipe\nOnce done, click the button below and paste the resulting string in.` + }); + } + } +} satisfies Command; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 6aab7eb..30ed419 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ import { Client, GatewayIntentBits, Events, Collection, CommandInteraction, CommandInteractionOption, ApplicationCommandOptionType } from 'discord.js'; import * as fs from 'fs'; -const { token } = JSON.parse(fs.readFileSync('./config.json', 'utf8')); +const { token, sitePort, siteURL } = JSON.parse(fs.readFileSync('./config.json', 'utf8')); import * as path from 'path'; import { initializeAnnouncements } from './lib/subscriptions'; import * as log from './lib/log'; @@ -20,6 +20,10 @@ const bot = new Client({ ], }); +bot.config = { + token, sitePort, siteURL +}; + async function init() { log.nonsense('booting chip...'); diff --git a/src/types/index.d.ts b/src/types/index.d.ts index 4b89a84..31e3b8f 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -8,8 +8,15 @@ export interface Command { serverWhitelist?: string[], } +export interface Config { + token: string, + sitePort: number, + siteURL: string +} + declare module 'discord.js' { export interface Client { + config: Config, commands: Collection; } } \ No newline at end of file