Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cook): add attachment option (WIP) #272

Closed
wants to merge 11 commits into from
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,19 @@
},
"homepage": "https://github.com/discordextend/discord-oversimplified#readme",
"dependencies": {
"@discordjs/builders": "^0.12.0",
"@discordjs/builders": "^0.13.0-dev.1644797188.0dfdb2c",
"@sapphire/decorators": "^4.0.2",
"@sapphire/framework": "^3.0.0-next.18259a7.0",
"@sapphire/plugin-logger": "^2.0.2",
"common-tags": "^1.8.0",
"discord-api-types": "^0.26.1",
"discord.js": "github:monbrey/discord.js#attachment-option",
"discord-oversimplified": "^0.6.5-next.d3e32eb.0",
"discord.js": "^13.6.0",
"dotenv": "^10.0.0",
"dotenv-parse-variables": "^2.0.0",
"sequelize": "^6.9.0",
"sqlite3": "^5.0.2",
"tslib": "^2.3.1",
"valid-url": "^1.0.9"
"tslib": "^2.3.1"
},
"devDependencies": {
"@babel/core": "^7.15.8",
Expand Down
6 changes: 2 additions & 4 deletions src/commands/change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ export class ChangeCommand extends Command {
registry,
this.defaultChatInputCommand
.addStringOption((input) => input.setName("order").setRequired(true).setDescription("The order to change the image of").setAutocomplete(true))
.addStringOption((input) =>
input.setName("image").setRequired(true).setDescription("The url of the image to use")
)
.addAttachmentOption((input) => input.setName("image").setRequired(true).setDescription("The image to use"))
);
}

Expand All @@ -42,7 +40,7 @@ export class ChangeCommand extends Command {
await interaction.deferReply();

const order = await this.getOrder(interaction, { chef: interaction.user.id });
const image = interaction.options.getString("image", true);
const image = interaction.options.getAttachment("image", true);

if (!this.isImage(image)) {
throw new Error("The image you specified is not a valid image.");
Expand Down
11 changes: 4 additions & 7 deletions src/commands/cook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@ import { Op } from "sequelize";
})
export class CookCommand extends Command {
public override registerApplicationCommands(registry: ApplicationCommandRegistry) {
this.registerPrivateChatInputCommand(
registry,
this.registerPrivateChatInputCommand(registry,
this.defaultChatInputCommand
.addStringOption((input) => input.setName("order").setRequired(true).setDescription("The order to cook").setAutocomplete(true))
.addStringOption((input) =>
input.setName("image").setRequired(true).setDescription("The url of the image to use")
)
.addStringOption((input) => input.setName("order").setDescription("The order to cook").setRequired(true).setAutocomplete(true))
.addAttachmentOption((input) => input.setName("image").setDescription("The image to use").setRequired(true))
);
}

Expand All @@ -42,7 +39,7 @@ export class CookCommand extends Command {
await interaction.deferReply();

const order = await this.getOrder(interaction, { chef: interaction.user.id });
const image = interaction.options.getString("image", true);
const image = interaction.options.getAttachment("image", true);

if (!this.isImage(image)) {
throw new Error("The image you specified is not a valid image.");
Expand Down
7 changes: 3 additions & 4 deletions src/lib/commands/OrderCommand.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { AutocompleteInteraction, CommandInteraction } from "discord.js";
import type { AutocompleteInteraction, CommandInteraction, MessageAttachment } from "discord.js";
import type { FindOptions, WhereOptions } from "sequelize";
import { Command } from "./Command";
import type { Order } from "../models/Order";
import { isUri } from "valid-url";
import { stripIndents } from "common-tags";

export abstract class OrderCommand extends Command {
Expand All @@ -26,8 +25,8 @@ export abstract class OrderCommand extends Command {
return `${name}date(?:: *(date|time|datetime))?`;
}

protected isImage(url: string) {
return Boolean(isUri(url) && /\.(gif|jpe?g|tiff?|png|webp|bmp)(\?[^#]*)?(#.*)?$/i.test(url));
protected isImage(image: MessageAttachment) {
return image.contentType?.match(/^image\/(gif|jpe?g|tiff?|png|webp|bmp)$/) !== null;
}

protected defaultDeliveryMessage = stripIndents`
Expand Down
6 changes: 3 additions & 3 deletions src/webhooks/ImageWebhook.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApplyOptions } from "@sapphire/decorators";
import type { Message } from "discord.js";
import type { Message, MessageAttachment } from "discord.js";
import { WebhookManager, WebhookManagerOptions } from "../lib/pieces/WebhookManager";

@ApplyOptions<WebhookManagerOptions>({
Expand All @@ -8,9 +8,9 @@ import { WebhookManager, WebhookManagerOptions } from "../lib/pieces/WebhookMana
webhookName: "Pixel Pizza Images"
})
export class ImageWebhook extends WebhookManager {
public sendImage(image: string) {
public sendImage(image: MessageAttachment) {
return this.send({
files: [image]
files: [image.url]
}) as Promise<Message>;
}
}
30 changes: 15 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1120,13 +1120,14 @@
tslib "^2.3.1"
zod "^3.11.6"

"@discordjs/builders@^0.12.0":
version "0.12.0"
resolved "https://registry.yarnpkg.com/@discordjs/builders/-/builders-0.12.0.tgz#5f6d95d1b231fa975a7e28ca3f8098e517676887"
integrity sha512-Vx2MjUZd6QVo1uS2uWt708Fd6cHWGFblAvbpL5EBO+kLl0BADmPwwvts+YJ/VfSywed6Vsk6K2cEooR/Ytjhjw==
"@discordjs/builders@^0.13.0-dev.1644797188.0dfdb2c":
version "0.13.0-dev.1645142857.f7257f0"
resolved "https://registry.yarnpkg.com/@discordjs/builders/-/builders-0.13.0-dev.1645142857.f7257f0.tgz#260758aac51e78cb3f78cbcac152ccf763309270"
integrity sha512-6YeMmxUzg/QU2FqcW3PMEYrlQ3LMIWx83vd2Zwz2C6CbEqylSA9pZBCaMxZQvDUETI1VCiOq3X7hVQ3+gaUDdA==
dependencies:
"@sindresorhus/is" "^4.3.0"
discord-api-types "^0.26.1"
"@sindresorhus/is" "^4.4.0"
discord-api-types "^0.27.0"
fast-deep-equal "^3.1.3"
ts-mixer "^6.0.0"
tslib "^2.3.1"
zod "^3.11.6"
Expand Down Expand Up @@ -1507,7 +1508,7 @@
resolved "https://registry.yarnpkg.com/@sapphire/utilities/-/utilities-3.3.0.tgz#62ff0a52cd86bd6169a94b2f217d72da6772a3cd"
integrity sha512-wWESfB03elALhci3GjcacRh8pnK89Qe5AEKCQplKyTCKabWl64SAFw52hQBth2fMmJStgK1fr87aGhRZAB8DNA==

"@sindresorhus/is@^4.2.0", "@sindresorhus/is@^4.3.0":
"@sindresorhus/is@^4.2.0", "@sindresorhus/is@^4.4.0":
version "4.4.0"
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-4.4.0.tgz#e277e5bdbdf7cb1e20d320f02f5e2ed113cd3185"
integrity sha512-QppPM/8l3Mawvh4rn9CNEYIU9bxpXUCRMaX9yUpvBk1nMKusLKpfXGDEKExKaPhLzcn3lzil7pR6rnJ11HgeRQ==
Expand Down Expand Up @@ -2721,6 +2722,11 @@ discord-api-types@^0.26.0, discord-api-types@^0.26.1:
resolved "https://registry.yarnpkg.com/discord-api-types/-/discord-api-types-0.26.1.tgz#726f766ddc37d60da95740991d22cb6ef2ed787b"
integrity sha512-T5PdMQ+Y1MEECYMV5wmyi9VEYPagEDEi4S0amgsszpWY0VB9JJ/hEvM6BgLhbdnKky4gfmZEXtEEtojN8ZKJQQ==

discord-api-types@^0.27.0:
version "0.27.2"
resolved "https://registry.yarnpkg.com/discord-api-types/-/discord-api-types-0.27.2.tgz#a9d3cbce6af41786e0b1abee02c90702be60b08b"
integrity sha512-70Uy283dXKpphwuVQIhQJCBAMIxLwCywdyjTKAjjrzFONZZIRQr9oupj3K1rS+hGnI6cp6y7eStRQvTbeSC+Zw==

discord-oversimplified@^0.6.5-next.d3e32eb.0:
version "0.6.5-next.d3e32eb.0"
resolved "https://registry.yarnpkg.com/discord-oversimplified/-/discord-oversimplified-0.6.5-next.d3e32eb.0.tgz#095e760a18816b90c025d86aed1bd1f20c832cec"
Expand All @@ -2734,10 +2740,9 @@ discord-oversimplified@^0.6.5-next.d3e32eb.0:
require-all "^3.0.0"
tslib "^2.3.1"

discord.js@^13.6.0:
discord.js@^13.6.0, "discord.js@github:monbrey/discord.js#attachment-option":
version "13.6.0"
resolved "https://registry.yarnpkg.com/discord.js/-/discord.js-13.6.0.tgz#d8a8a591dbf25cbcf9c783d5ddf22c4694860475"
integrity sha512-tXNR8zgsEPxPBvGk3AQjJ9ljIIC6/LOPjzKwpwz8Y1Q2X66Vi3ZqFgRHYwnHKC0jC0F+l4LzxlhmOJsBZDNg9g==
resolved "https://codeload.github.com/monbrey/discord.js/tar.gz/4b0733f1d0de1ed288bb1262a409a16c5b56e68e"
dependencies:
"@discordjs/builders" "^0.11.0"
"@discordjs/collection" "^0.4.0"
Expand Down Expand Up @@ -6367,11 +6372,6 @@ v8-to-istanbul@^8.1.0:
convert-source-map "^1.6.0"
source-map "^0.7.3"

valid-url@^1.0.9:
version "1.0.9"
resolved "https://registry.yarnpkg.com/valid-url/-/valid-url-1.0.9.tgz#1c14479b40f1397a75782f115e4086447433a200"
integrity sha1-HBRHm0DxOXp1eC8RXkCGRHQzogA=

validate-npm-package-license@^3.0.1:
version "3.0.4"
resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz#fc91f6b9c7ba15c857f4cb2c5defeec39d4f410a"
Expand Down