recipe grounwork

This commit is contained in:
Jill 2023-11-17 21:23:35 +03:00
parent c714596653
commit 77dbd8ee3f
Signed by: oat
GPG Key ID: 33489AA58A955108
5 changed files with 72 additions and 2 deletions

View File

@ -1,3 +1,5 @@
{
"token": "token"
"token": "token",
"sitePort": 15385,
"siteURL": "https://localhost:15385"
}

View File

@ -0,0 +1,27 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
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<void> }
*/
exports.down = function(knex) {
return knex.schema
.dropTable('craftingRecipes')
.dropTable('craftingRecipeItems');
};

30
src/commands/recipe.ts Normal file
View File

@ -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;

View File

@ -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...');

View File

@ -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<string, Command>;
}
}