Download bot.js from VortexCr/zeki-bot: direct link, hf CLI and curl.
- Browser
- Download file 4.08 kB
-
https://huggingface.co/spaces/VortexCr/zeki-bot/resolve/main/bot.js
- Command line
-
hf download hf://spaces/VortexCr/zeki-bot/bot.js
-
curl -L -o bot.js https://huggingface.co/spaces/VortexCr/zeki-bot/resolve/main/bot.js
4.08 kB
| /** | |
| * Zeki Bot - Gelişmiş Otomatik Yanıt Sistemi | |
| * Sürüm: 1.3.0 (Security & DNS Fix) | |
| */ | |
| const { | |
| Client, | |
| GatewayIntentBits, | |
| Partials, | |
| PermissionFlagsBits, | |
| SlashCommandBuilder, | |
| REST, | |
| Routes | |
| } = require('discord.js'); | |
| const fs = require('fs'); | |
| const path = require('path'); | |
| const express = require('express'); | |
| // --- HUGGING FACE UYANIK TUTMA SERVİSİ --- | |
| const app = express(); | |
| app.get('/', (req, res) => res.send('Bot Sistemi Aktif ve Güvende!')); | |
| app.listen(7860, () => console.log('✅ Sistem Port 7860 üzerinden yayında.')); | |
| // TOKENİ GÜVENLİ ŞEKİLDE ÇEKİYORUZ | |
| // Settings -> Secrets kısmına eklediğin DISCORD_TOKEN'ı okur. | |
| const TOKEN = process.env.DISCORD_TOKEN; | |
| const CLIENT_ID = '1477703339612311685'; | |
| const client = new Client({ | |
| intents: [ | |
| GatewayIntentBits.Guilds, | |
| GatewayIntentBits.GuildMessages, | |
| GatewayIntentBits.MessageContent, | |
| GatewayIntentBits.GuildMembers | |
| ], | |
| partials: [Partials.Message, Partials.Channel, Partials.Reaction] | |
| }); | |
| const dbPath = path.join(__dirname, 'triggers.json'); | |
| if (!fs.existsSync(dbPath)) fs.writeFileSync(dbPath, JSON.stringify({})); | |
| let triggers = JSON.parse(fs.readFileSync(dbPath, 'utf8')); | |
| // DEĞİŞKEN DÖNÜŞTÜRÜCÜ | |
| function parseVariables(content, message) { | |
| const now = new Date(); | |
| const timeStr = now.toLocaleTimeString('tr-TR', { hour: '2-digit', minute: '2-digit' }); | |
| const dateStr = now.toLocaleDateString('tr-TR'); | |
| return content | |
| .replace(/!user/g, `<@${message.author.id}>`) | |
| .replace(/!time/g, timeStr) | |
| .replace(/!date/g, dateStr) | |
| .replace(/!sw/g, message.guild.name); | |
| } | |
| // SLASH KOMUTLARI | |
| const commands = [ | |
| new SlashCommandBuilder() | |
| .setName('tetikekle') | |
| .setDescription('Yeni bir otomatik yanıt ekler.') | |
| .addStringOption(o => o.setName('tetik').setDescription('Tetikleyici kelime').setRequired(true)) | |
| .addStringOption(o => o.setName('cevap').setDescription('Botun vereceği cevap').setRequired(true)) | |
| .setDefaultMemberPermissions(PermissionFlagsBits.Administrator) | |
| ].map(c => c.toJSON()); | |
| const rest = new REST({ version: '10' }).setToken(TOKEN); | |
| // DNS/INTERNET HATASINA KARŞI DİRENÇLİ KAYIT | |
| async function registerCommands() { | |
| if (!TOKEN) return console.error("❌ HATA: DISCORD_TOKEN bulunamadı! Settings -> Secrets kısmına ekle."); | |
| try { | |
| console.log('🔄 Slash komutları yüklenmeye çalışılıyor...'); | |
| await rest.put(Routes.applicationCommands(CLIENT_ID), { body: commands }); | |
| console.log('✅ Slash komutları başarıyla kaydedildi.'); | |
| } catch (error) { | |
| console.error('❌ Bağlantı hatası! 15 saniye sonra tekrar denenecek...'); | |
| setTimeout(registerCommands, 15000); | |
| } | |
| } | |
| registerCommands(); | |
| client.once('ready', () => { | |
| console.log(`🚀 ${client.user.tag} olarak giriş yapıldı!`); | |
| }); | |
| client.on('interactionCreate', async interaction => { | |
| if (!interaction.isChatInputCommand()) return; | |
| if (interaction.commandName === 'tetikekle') { | |
| const tetik = interaction.options.getString('tetik').toLowerCase(); | |
| const cevap = interaction.options.getString('cevap'); | |
| triggers[tetik] = cevap; | |
| fs.writeFileSync(dbPath, JSON.stringify(triggers, null, 4)); | |
| await interaction.reply({ content: `✅ Tetik başarıyla eklendi: **${tetik}**`, ephemeral: true }); | |
| } | |
| }); | |
| client.on('messageCreate', async message => { | |
| if (message.author.bot || !message.guild) return; | |
| const content = message.content.toLowerCase(); | |
| if (triggers[content]) { | |
| try { | |
| await message.reply(parseVariables(triggers[content], message)); | |
| } catch (err) { | |
| console.error('Mesaj hatası:', err); | |
| } | |
| } | |
| }); | |
| // LOGIN MEKANİZMASI | |
| function startBot() { | |
| if (!TOKEN) return; | |
| client.login(TOKEN).catch(() => { | |
| console.error("❌ Discord'a bağlanılamadı, internet bekleniyor (20sn)..."); | |
| setTimeout(startBot, 20000); | |
| }); | |
| } | |
| startBot(); |