import { promises } from 'fs';
import { join } from 'path';
import axios from 'axios'; 

let handler = async function (m, { conn, __dirname }) {
  const githubRepoURL = 'https://github.com/PRINCE-GDS/THE-PRINCE-BOT';

  try {
  
    const [, username, repoName] = githubRepoURL.match(/github\.com\/([^/]+)\/([^/]+)/);

    const response = await axios.get(`https://api.github.com/repos/${username}/${repoName}`);

    if (response.status === 200) {
      const repoData = response.data;

      // Format the repository information with emojis
      const formattedInfo = `
â•­âŠ±âœ«ğŸ›¡ï¸�á‘­á–‡Iá‘�á‘•á•® á—·OTğŸ›¡ï¸�âœ«âŠ±â•®
â”‚âœ« - *ğŸ“‚Repository Name: ${repoData.name}*
â”‚âœ« - *ğŸ“ƒDescription: ${repoData.description}*
â”‚âœ« - *ğŸ›¡ï¸�Owner: ${repoData.owner.login}*
â”‚âœ« - *â­�Stars: ${repoData.stargazers_count}*
â”‚âœ« - *ğŸ’ŒForks: ${repoData.forks_count}*
â”‚âœ« - *ğŸŒ� URL: ${repoData.html_url}*
â•°â”�â”�â”�â”�â”�â”�â”�â”�â”�â”�â”�â”�â”�â”�â”�â”�â”�â•¯
      `.trim();

      // Send the formatted information as a message
      await conn.relayMessage(m.chat,  {
        requestPaymentMessage: {
          currencyCodeIso4217: 'Rupee',
          amount1000: 10000,
          requestFrom: m.sender,
          noteMessage: {
          extendedTextMessage: {
          text: formattedInfo,
          contextInfo: {
          externalAdReply: {
          showAdAttribution: true
          }}}}}}, {})
    } else {
      // Handle the case where the API request fails
      await conn.reply(m.chat, 'Unable to fetch repository information.', m);
    }
  } catch (error) {
    console.error(error);
    await conn.reply(m.chat, 'An error occurred while fetching repository information.', m);
  }
};

handler.help = ['script'];
handler.tags = ['main'];
handler.command = ['sc', 'repo', 'script', 'git', 'github'];

export default handler;
