Automattic / node-canvas

Node canvas is a Cairo backed Canvas implementation for NodeJS.
10.16k stars 1.17k forks source link

Discord Bot Project #2284

Closed Bhargav230m closed 1 year ago

Bhargav230m commented 1 year ago

Issue or Feature

Hello, I was creating a discord bot using discord.js So i was creating userVerifier which uses 4 layers of verification to verify users and check if they are safe or not and i was using canvas and nsfwjs to make sure users have apporpriate profile picture and nsfwjs need a proper file format and i use canvas for it but the problem is somewhere in const image = await loadImage(imageData); and it just frezzes there and doesn't continue .

Snippet

 const avatarUrl = await member.user.displayAvatarURL({
      size: 1024,
      dynamic: false,
    });
    console.log(avatarUrl);
    if (avatarUrl) {
      //USER-VERIFIER LAYER 3
      try {
        const response = await axios.get(avatarUrl, {
          responseType: "arraybuffer",
        });

          // Convert the response.data buffer to Uint8Array
        const imageData = new Uint8Array(response.data);

        // Convert the image to an HTMLImageElement-like object using node-canvas
        const image = await loadImage(imageData);
        const predictions = await nsfwModel.classify(image);
        const nsfwProbability = predictions[0].probability["nsfw"];

        if (nsfwProbability > 0.5) {
          const embed2 = new EmbedBuilder()
            .setTitle("Inpropriate Avatar Detected")
            .setDescription(
              "Our system has detected that your Avatar contains inpropriate image and you have been kicked, Please change your Avatar and join again"
            )
            .setColor("Red");
          channel.send({
            content: "New User Kicked",
            embeds: [
              LogEmbed.setDescription(
                `\`TAG-${member.user.tag}, ID-${member.user.id}\` has been kicked from the server because the user's account contained inpropriate avatar`
              ),
            ],
          });
          member
            .send({
              content:
                "*You have been kicked by the bot because our Advanced User-Verifier system has detected that your account contains inpropriate avatar*",
              embeds: [embed2],
            })
            .then(() => {
              member.kick({ Reason: "Kicked for inpropriate avatar" });
            });
        }
      } catch (e) {
        console.log(e);
      }
    }

Your Environment

Bhargav230m commented 1 year ago

Please i would like a quick response from anyone

zbjornson commented 1 year ago

This question would be better suited to StackOverflow unless you can reduce it to a reproduction that only needs node-canvas to demonstrate a bug.

Bhargav230m commented 1 year ago

ok