File size: 5,353 Bytes
45fbaf2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
require('dotenv').config()
const { Client, GatewayIntentBits, REST, Routes, EmbedBuilder, Events } = require('discord.js')
const axios = require('axios')

const TOKEN = process.env.DISCORD_TOKEN || "MTM4ODgwMjQ0OTQ5MzcyMTIxOA.G3-WAQ.VIESW3luPp36L5zP6VcsT0Ssjjc8xufThvSn4U"
const CLIENT_ID = process.env.CLIENT_ID || "1388802449493721218"
const GUILD_ID = process.env.GUILD_ID || "1388777582975254659"

const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] })

const rest = new REST({ version: '10' }).setToken(TOKEN)

const commands = [
  {
    name: 'uploadsong',
    description: 'Upload a song from a YouTube URL',
    options: [
      {
        name: 'url',
        type: 3,
        description: 'YouTube URL',
        required: true
      }
    ]
  }
]

const cooldowns = new Map()

async function registerCommands() {
  try {
    await rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), { body: commands })
    console.log('Slash commands registered')
  } catch (error) {
    console.error('Failed to register slash commands:', error)
  }
}

client.on(Events.MessageCreate, async (message) => {
  if (message.author.bot || !message.mentions.has(client.user)) return
  const args = message.content.trim().split(/\s+/)
  if (!args[1] || args[1].toLowerCase() !== 'uploadsong' || !args[2]) return
  const yturl = args[2]
  const uid = message.author.id
  const name = message.author.username
  const pic = message.author.displayAvatarURL()

  if (cooldowns.has(uid)) {
    const remaining = Math.ceil((cooldowns.get(uid) - Date.now()) / 1000)
    if (remaining > 0) {
      const cooldownEmbed = new EmbedBuilder()
        .setTitle('⏳ Cooldown')
        .setDescription(`Please wait **${remaining}s** before using this command again.`)
        .setColor('Orange')
      return message.reply({ embeds: [cooldownEmbed] })
    }
  }

  cooldowns.set(uid, Date.now() + 60000)

  const embed = new EmbedBuilder()
    .setTitle('⏱️ Reuploading song')
    .setDescription('πŸ“₯ Please wait while we upload the song.')
    .setColor('Yellow')

  const sent = await message.reply({ embeds: [embed] })

  try {
    const res = await axios.get(`https://jonell01-reuploadotherhruhh.hf.space/addsong?url=${encodeURIComponent(yturl)}`)
    if (res.data.success) {
      const song = res.data.song
      const success = new EmbedBuilder()
        .setTitle(`βœ… Reupload Song Successfully`)
        .setDescription(`🎡 **Song Title:** ${song.name}\nπŸ”Š **ID:** ${song.ID}\n<:folder:1333485662149545994> **Size:** ${song.size} MB`)
        .setFooter({ text: `🎧 Reuploaded song by : ${name}`, iconURL: pic })
        .setColor('Green')
      await sent.edit({ embeds: [success] })
    } else {
      throw new Error()
    }
  } catch {
    const fail = new EmbedBuilder()
      .setTitle('❌ Upload Failed')
      .setDescription('An error occurred while uploading.')
      .setColor('Red')
    await sent.edit({ embeds: [fail] })
  }
})

client.on(Events.InteractionCreate, async (interaction) => {
  if (!interaction.isChatInputCommand()) return
  if (interaction.commandName === 'uploadsong') {
    const uid = interaction.user.id
    const name = interaction.user.username
    const pic = interaction.user.displayAvatarURL()

    if (cooldowns.has(uid)) {
      const remaining = Math.ceil((cooldowns.get(uid) - Date.now()) / 1000)
      if (remaining > 0) {
        const cooldownEmbed = new EmbedBuilder()
          .setTitle('⏳ Cooldown')
          .setDescription(`Please wait **${remaining}s** before using this command again.`)
          .setColor('Orange')
        return interaction.reply({ embeds: [cooldownEmbed], ephemeral: true })
      }
    }

    cooldowns.set(uid, Date.now() + 60000)
    const yturl = interaction.options.getString('url')
    const embed = new EmbedBuilder()
      .setTitle('⏱️ Reuploading song')
      .setDescription('πŸ“₯ Please wait while we upload the song.')
      .setColor('Yellow')

    await interaction.reply({ embeds: [embed], fetchReply: true }).then(async (sent) => {
      try {
        const res = await axios.get(`https://jonell01-reuploadotherhruhh.hf.space/addsong?url=${encodeURIComponent(yturl)}`)
        if (res.data.success) {
          const song = res.data.song
          const success = new EmbedBuilder()
            .setTitle(`βœ… Reupload Song Successfully`)
            .setDescription(`🎡 **Song Title:** ${song.name}\nπŸ”Š **ID:** ${song.ID}\n<:folder:1333485662149545994> **Size:** ${song.size} MB`)
            .setFooter({ text: `🎧 Reuploaded song by : ${name}`, iconURL: pic })
            .setColor('Green')
          await interaction.editReply({ embeds: [success] })
        } else {
          throw new Error()
        }
      } catch {
        const fail = new EmbedBuilder()
          .setTitle('❌ Upload Failed')
          .setDescription('An error occurred while uploading.')
          .setColor('Red')
        await interaction.editReply({ embeds: [fail] })
      }
    })
  }
})

client.once(Events.ClientReady, () => {
  console.log(`βœ… Logged in as ${client.user.tag}`)
})

client.on('error', (err) => {
  console.error('❌ Bot connection error:', err)
})

registerCommands()
client.login(TOKEN).catch((err) => {
  console.error('❌ Failed to login:', err)
})