Untitled

 avatar
unknown
plain_text
a year ago
2.4 kB
15
Indexable
var config = {
    betAmount: {
        value: 20,
        type: 'text',
        label: 'Amount to bet (in bits)'
    },
    cashOut: {
        value: 1.10,
        type: 'text',
        label: 'Cash out multiplier'
    },
    discordWebhook: {
        value: '',
        type: 'text',
        label: 'Discord Webhook URL'
    }
};

var socket = new WebSocket('ws://localhost:8080/chat');

        // Event listener for when the WebSocket connection is established
        socket.onopen = function(event) {
            console.log('Connected to WebSocket server');
        
            socket.send('You have succesfully connected to the BAB WS Client');
        };

        // Event listener for when the client receives a message from the server
        socket.onmessage = function(event) {
            console.log('Received message from server:', event.data);

            if (event.data == "place_bet"){
                console.log('placing new bet!');
            }

            if(event.data == "cash_out"){
                console.log("cashing out");
            }

        };

        // Event listener for when the WebSocket connection is closed
        socket.onclose = function(event) {
            console.log('Connection to WebSocket server closed');
        };

        // Event listener for handling errors
        socket.onerror = function(error) {
            console.error('WebSocket error:', error);
        };

// Function to send a message to Discord
function sendMessageToDiscord(message) {
    const webhookURL = config.discordWebhook.value;

    if (!webhookURL) {
        console.log('Discord Webhook URL not provided.');
        return;
    }

    fetch(webhookURL, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify({ content: message })
    })
    .then(response => {
        if (!response.ok) {
            throw new Error('Network response was not ok');
        }
        console.log('Message sent to Discord.');
    })
    .catch(error => {
        console.error('Error sending message to Discord:', error);
    });
}


// Counter for tracking games

engine.on('GAME_STARTING', function() {
    socket.send('GAME_STARTING_CB');
});

engine.on('GAME_ENDED', function() {
    socket.send('GAME_ENDED_CB');
});
Editor is loading...
Leave a Comment