From c3763295ea26ceede175af026381a0500dafcb0b Mon Sep 17 00:00:00 2001 From: raluvy95 Date: Fri, 5 Apr 2024 18:57:36 +0300 Subject: [PATCH] node-fetch is no longer required as a dependency native fetch is already included since nodejs v18 --- package.json | 1 - src/commands/fun/cat.ts | 9 ++++----- src/commands/fun/dog.ts | 3 +-- src/commands/tools/addemoji.ts | 12 ++++-------- src/plugins/messageReference.ts | 3 +-- 5 files changed, 10 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 8887cd9..e75fb63 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,6 @@ "@types/luxon": "^3.4.2", "@types/ms": "^0.7.34", "@types/node": "^20.12.4", - "@types/node-fetch": "^2.6.11", "nodemon": "^3.1.0", "rimraf": "^5.0.5", "rome": "^12.1.3", diff --git a/src/commands/fun/cat.ts b/src/commands/fun/cat.ts index ac64d69..9047a15 100644 --- a/src/commands/fun/cat.ts +++ b/src/commands/fun/cat.ts @@ -1,7 +1,6 @@ import { Message } from "eris"; import { client } from "../../client/Client"; import { MovCommand } from "../../client/Command"; -import fetch from "node-fetch"; function generator(msg: Message, _args: string[]) { const err = "There's something went wrong with cat. No cat for you :("; @@ -9,11 +8,11 @@ function generator(msg: Message, _args: string[]) { fetch("https://cataas.com/cat") .then(async (r) => { try { - const j = await r.buffer(); + + const j = await r.blob(); + const imgLink = URL.createObjectURL(j); client.createMessage( - msg.channel.id, - {}, - { file: j, name: "cat.png" }, + msg.channel.id, imgLink ); } catch { client.createMessage(msg.channel.id, err); diff --git a/src/commands/fun/dog.ts b/src/commands/fun/dog.ts index f42338c..5c643d7 100644 --- a/src/commands/fun/dog.ts +++ b/src/commands/fun/dog.ts @@ -1,14 +1,13 @@ import { Message } from "eris"; import { client } from "../../client/Client"; import { MovCommand } from "../../client/Command"; -import fetch from "node-fetch"; function generator(msg: Message, _args: string[]) { const err = "There's something went wrong with dog. No dog for you :("; try { fetch("https://dog.ceo/api/breeds/image/random").then(async (r) => { try { - const j = await r.json(); + const j = await r.json() as { message: string }; client.createMessage(msg.channel.id, j.message); } catch { client.createMessage(msg.channel.id, err); diff --git a/src/commands/tools/addemoji.ts b/src/commands/tools/addemoji.ts index dab39e2..0ff97cf 100644 --- a/src/commands/tools/addemoji.ts +++ b/src/commands/tools/addemoji.ts @@ -1,5 +1,4 @@ import { Message } from "eris"; -import fetch from "node-fetch"; import { client } from "../../client/Client"; import { MovCommand } from "../../client/Command"; import { urlToDataURI } from "../../utils/canvas"; @@ -35,9 +34,8 @@ async function generator(msg: Message, args: string[]) { ? args[0].replace("", "") : args[0].replace("<:", "").replace(">", ""); const [name, id] = emote.split(":"); - const url = `https://cdn.discordapp.com/emojis/${id}.${ - animated ? "gif" : "png" - }`; + const url = `https://cdn.discordapp.com/emojis/${id}.${animated ? "gif" : "png" + }`; client .createGuildEmoji(msg.guildID!, { name: name, @@ -46,8 +44,7 @@ async function generator(msg: Message, args: string[]) { .then((e) => { client.createMessage( msg.channel.id, - `I added <${e.animated ? "a" : ""}:${e.name}:${ - e.id + `I added <${e.animated ? "a" : ""}:${e.name}:${e.id }> to this guild!`, ); }) @@ -74,8 +71,7 @@ async function generator(msg: Message, args: string[]) { .then((e) => { client.createMessage( msg.channel.id, - `I added <${e.animated ? "a" : ""}:${e.name}:${ - e.id + `I added <${e.animated ? "a" : ""}:${e.name}:${e.id }> to this guild!`, ); }) diff --git a/src/plugins/messageReference.ts b/src/plugins/messageReference.ts index 771b103..6c77f0b 100644 --- a/src/plugins/messageReference.ts +++ b/src/plugins/messageReference.ts @@ -1,5 +1,4 @@ import { FileContent, MessageContent } from "eris"; -import fetch from "node-fetch"; import { client } from "../client/Client"; import { MovEmbed } from "../client/Embed"; import { MovPlugin } from "../client/Plugin"; @@ -47,7 +46,7 @@ export default new MovPlugin("messageReference", { for (const a of msgRef.attachments) { file.push({ name: a.filename, - file: await fetch(a.url).then((r) => r.buffer()), + file: URL.createObjectURL(await fetch(a.url).then((r) => r.blob())), }); } }