File size: 4,075 Bytes
bd263db
 
8251605
bd263db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8251605
 
bd263db
8251605
 
 
6a0b1c1
bd263db
 
 
 
 
 
 
 
 
 
 
 
6a0b1c1
bd263db
 
8251605
bd263db
 
 
 
 
6a0b1c1
bd263db
 
6a0b1c1
bd263db
 
8251605
bd263db
 
 
8251605
 
 
bd263db
6a0b1c1
bd263db
 
 
8251605
6a0b1c1
8251605
bd263db
8251605
bd263db
8251605
bd263db
8251605
6a0b1c1
bd263db
6a0b1c1
bd263db
6a0b1c1
 
8251605
 
 
bd263db
 
 
 
 
 
 
 
8251605
bd263db
 
 
 
 
 
 
8251605
 
 
 
 
bd263db
 
 
8251605
6a0b1c1
8251605
6a0b1c1
8251605
6a0b1c1
 
 
 
 
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
/**
 * 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();