Skip to content

Commit

Permalink
node-fetch is no longer required as a dependency
Browse files Browse the repository at this point in the history
native fetch is already included since nodejs v18
  • Loading branch information
raluvy95 committed Apr 5, 2024
1 parent a5bedb8 commit c376329
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 18 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 4 additions & 5 deletions src/commands/fun/cat.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
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 :(";

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);
Expand Down
3 changes: 1 addition & 2 deletions src/commands/fun/dog.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
12 changes: 4 additions & 8 deletions src/commands/tools/addemoji.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -35,9 +34,8 @@ async function generator(msg: Message, args: string[]) {
? args[0].replace("<a:", "").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,
Expand All @@ -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!`,
);
})
Expand All @@ -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!`,
);
})
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/messageReference.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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())),
});
}
}
Expand Down

0 comments on commit c376329

Please sign in to comment.