bot.js aktualisiert
This commit is contained in:
		
							
								
								
									
										76
									
								
								bot.js
									
									
									
									
									
								
							
							
						
						
									
										76
									
								
								bot.js
									
									
									
									
									
								
							@@ -170,6 +170,35 @@ const sendQueuedReportsToAdmin = (adminId) => {
 | 
			
		||||
    fs.writeFileSync(reportFilePath, JSON.stringify(reportsData, null, 2)); // Speichern der aktualisierten Daten
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Urlaubsdaten speichern
 | 
			
		||||
let vacationData = {};
 | 
			
		||||
 | 
			
		||||
// Befehl /urlaub zum Eintragen von Urlaub
 | 
			
		||||
bot.onText(/\/urlaub (.+)/, (msg, match) => {
 | 
			
		||||
    const chatId = msg.chat.id;
 | 
			
		||||
    const userId = msg.from.id.toString();
 | 
			
		||||
    const vacationInfo = match[1].trim();
 | 
			
		||||
 | 
			
		||||
    // Überprüfen, ob der Benutzer ein Admin ist
 | 
			
		||||
    if (!isAdmin(userId)) {
 | 
			
		||||
        bot.sendMessage(chatId, '🚫 Nur Admins dürfen diesen Befehl verwenden.');
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Urlaubseintrag speichern
 | 
			
		||||
    vacationData[userId] = {
 | 
			
		||||
        vacationInfo: vacationInfo,
 | 
			
		||||
        date: new Date().toLocaleString()
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    // Benutzer über den Urlaub informieren
 | 
			
		||||
    bot.sendMessage(chatId, `✅ Du hast deinen Urlaub eingetragen: "${vacationInfo}".`);
 | 
			
		||||
 | 
			
		||||
    // Alle Benutzer über den Urlaub informieren
 | 
			
		||||
    const message = `🔔 Hinweis: Admin ${msg.from.username || `${msg.from.first_name} ${msg.from.last_name}`} ist im Urlaub: "${vacationInfo}".`;
 | 
			
		||||
    bot.sendMessage(chatId, message);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
// Befehl zum Melden von Nachrichten
 | 
			
		||||
bot.onText(/\/report/, (msg) => {
 | 
			
		||||
    const chatId = msg.chat.id;
 | 
			
		||||
@@ -203,7 +232,7 @@ bot.onText(/\/report/, (msg) => {
 | 
			
		||||
 | 
			
		||||
bot.onText(/\/documentation/, (msg) => {
 | 
			
		||||
    const chatId = msg.chat.id;
 | 
			
		||||
    const documentationUrl = 'https://deine-dokumentation-url.com'; // Ersetze dies durch die tatsächliche URL
 | 
			
		||||
    const documentationUrl = 'https://git.viper.ipv64.net/M_Viper/support_bot_2024/src/branch/main/README.md'; // Ersetze dies durch die tatsächliche URL
 | 
			
		||||
 | 
			
		||||
    bot.sendMessage(chatId, 'Hier findest du die technische Dokumentation:', {
 | 
			
		||||
        reply_markup: {
 | 
			
		||||
@@ -450,6 +479,35 @@ function saveInviteLinks() {
 | 
			
		||||
// Objekt zur Speicherung von Einladungslinks (wird aus der Datei geladen)
 | 
			
		||||
let inviteLinks = loadInviteLinks();
 | 
			
		||||
 | 
			
		||||
// Funktion zum Hinzufügen eines Eintrags zum Log
 | 
			
		||||
const logUserJoin = (userId, username, inviteLink) => {
 | 
			
		||||
    const logEntry = {
 | 
			
		||||
        userId: userId,
 | 
			
		||||
        username: username,
 | 
			
		||||
        inviteLink: inviteLink,
 | 
			
		||||
        timestamp: new Date().toISOString()
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    // Log-Datei lesen und Eintrag hinzufügen
 | 
			
		||||
    fs.readFile(logFilePath, (err, data) => {
 | 
			
		||||
        let logData = [];
 | 
			
		||||
        if (!err) {
 | 
			
		||||
            logData = JSON.parse(data);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        logData.push(logEntry);
 | 
			
		||||
        
 | 
			
		||||
        // Log-Datei speichern
 | 
			
		||||
        fs.writeFile(logFilePath, JSON.stringify(logData, null, 2), (err) => {
 | 
			
		||||
            if (err) {
 | 
			
		||||
                console.error('Fehler beim Schreiben in die Log-Datei:', err);
 | 
			
		||||
            } else {
 | 
			
		||||
                console.log('Log-Eintrag erfolgreich hinzugefügt:', logEntry);
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// /einladung-Befehl für alle Benutzer
 | 
			
		||||
bot.onText(/\/einladung/, (msg) => {
 | 
			
		||||
    const chatId = msg.chat.id;
 | 
			
		||||
@@ -494,6 +552,20 @@ bot.onText(/\/einladung/, (msg) => {
 | 
			
		||||
        });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
// Beispiel: Handle den Beitritt eines Benutzers über einen Einladungslink
 | 
			
		||||
bot.on('new_chat_members', (msg) => {
 | 
			
		||||
    msg.new_chat_members.forEach(async (member) => {
 | 
			
		||||
        const userId = member.id;
 | 
			
		||||
        const username = member.username || 'unbekannt';
 | 
			
		||||
        
 | 
			
		||||
        // Hier den Einladungslink abfragen (z.B. aus einer Datenbank oder durch andere Mittel)
 | 
			
		||||
        const inviteLink = inviteLinks[member.invite_link.id] ? inviteLinks[member.invite_link.id].link : 'unbekannt';
 | 
			
		||||
 | 
			
		||||
        // Log den Beitritt
 | 
			
		||||
        logUserJoin(userId, username, inviteLink);
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
// Befehl zum Löschen der letzten n Nachrichten
 | 
			
		||||
bot.onText(/\/clear (\d+)/, async (msg, match) => {
 | 
			
		||||
    const chatId = msg.chat.id;
 | 
			
		||||
@@ -981,7 +1053,7 @@ bot.onText(/\/info/, (msg) => {
 | 
			
		||||
 | 
			
		||||
    // Hier die Bot-Informationen eintragen
 | 
			
		||||
    const botName = 'Support Bot';  // Ersetze dies durch den tatsächlichen Bot-Namen
 | 
			
		||||
    const botVersion = '1.5.9';     // Ersetze dies durch die tatsächliche Version
 | 
			
		||||
    const botVersion = '1.6.0';     // Ersetze dies durch die tatsächliche Version
 | 
			
		||||
    const botAuthor = 'M_Viper';   // Ersetze dies durch den tatsächlichen Autor
 | 
			
		||||
    const botLicense = 'MIT';       // Ersetze dies durch die tatsächliche Lizenz
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user