File size: 3,712 Bytes
1fef695
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const fetch = require('node-fetch');
const { generateWAMessageFromContent, prepareWAMessageMedia } = require('@adiwajshing/baileys');
const { proto } = require('@adiwajshing/baileys');

let handler = async (m, { conn, text, usedPrefix, command }) => {
  let response = await fetch("https://api.jikan.moe/v4/seasons/now?filter=tv");
  let data = await response.json();
  
  // Ambil data anime dengan detail
  let animeList = await Promise.all(data.data.map(async anime => {
    return {
      imageUrl: anime.images.jpg.large_image_url,
      title: anime.title,
      genres: anime.genres,
      type: anime.type,
      season: anime.season,
      year: anime.year,
      source: anime.source,
      episodes: anime.episodes,
      status: anime.status,
      duration: anime.duration,
      studios: anime.studios,
      rating: anime.rating,
      score: anime.score,
      popularity: anime.popularity
    };
  }));

  const createImageMessage = async (url) => {
    const { imageMessage } = await prepareWAMessageMedia({ image: { url } }, { upload: conn.waUploadToServer });
    return imageMessage;
  }

  const cards = await Promise.all(animeList.map(async (a) => {
    const imageMessage = await createImageMessage(a.imageUrl);

    // Deskripsi anime yang lebih lengkap
    const description = `*• Title:* ${a.title}
*• Genre:* *[ ${a.genres.map(g => g.name).join(", ")} ]*
*• Type:* ${a.type}
*• Season:* ${a.season} *[ ${a.year} ]*
*• Source:* ${a.source}
*• Total episodes:* ${a.episodes}
*• Status:* ${a.status}
*• Duration:* ${a.duration}
*• Studio:* *[ ${a.studios.map(s => s.name).join(", ")} ]*
*• Rating:* ${a.rating}
*• Score:* ${a.score}/10.0
*• Popularity:* ${a.popularity}`;

    return {
      body: proto.Message.InteractiveMessage.Body.fromObject({
        text: description,
      }),
      footer: proto.Message.InteractiveMessage.Footer.fromObject({
        text: "Powered by Jikan API",
      }),
      header: proto.Message.InteractiveMessage.Header.fromObject({
        title: '',
        hasMediaAttachment: true,
        imageMessage: imageMessage,
      }),
      nativeFlowMessage: proto.Message.InteractiveMessage.NativeFlowMessage.fromObject({
        buttons: [
          {
            name: "cta_url",
            buttonParamsJson: JSON.stringify({
              display_text: "Lihat Gambar",
              cta_type: "1",
              url: a.imageUrl
            })
          }
          // Tombol "SEARCH AGAIN" dihapus
        ]
      })
    };
  }));

  // Kirim pesan interaktif
  const interactiveMessage = proto.Message.InteractiveMessage.create({
    body: proto.Message.InteractiveMessage.Body.fromObject({
      text: "List of Anime Images",
    }),
    footer: proto.Message.InteractiveMessage.Footer.fromObject({
      text: "Powered by Jikan API",
    }),
    header: proto.Message.InteractiveMessage.Header.fromObject({
      title: "Anime Carousel",
      hasMediaAttachment: false,
    }),
    carouselMessage: proto.Message.InteractiveMessage.CarouselMessage.fromObject({
      cards: cards,
    }),
  });

  const messageContent = proto.Message.fromObject({
    viewOnceMessage: {
      message: {
        messageContextInfo: {
          deviceListMetadata: {},
          deviceListMetadataVersion: 2,
        },
        interactiveMessage,
      },
    },
  });

  const msgs = await generateWAMessageFromContent(m.chat, messageContent, {
    userJid: conn.user.jid,
    quoted: m,
    upload: conn.waUploadToServer,
  });

  await conn.relayMessage(m.chat, msgs.message, {
    messageId: msgs.key.id,
  });
};

handler.help = ["animeupdate"];
handler.tags = ["anime"];
handler.command = ["animeupdate"];
module.exports = handler;