• If you need help or want to discuss things, you now can also join us on our Discord Server!
  • A first preview of the unlimited version of SinusBot can be found in the Upcoming Changes thread. A version for Windows will follow, but we don't have a release date, yet.

EN Little help with a fun project

Status
Not open for further replies.

Sarantis

Member
Code:
registerPlugin({
    name: 'Online Time Counter',
    version: '0.1',
    description: 'Counts how long someone is listening',
    author: 'Sarantis <[email protected]>',
    vars: [
        {
            name: 'baseUrl',
            title: 'BaseUrl For http api',
            type: 'string'
        },
    ]
}, function (sinusbot, config) {
    var baseUrl = config.baseUrl || 'http://csongo.gr/ts/online.php?apikey=%apikey%&';
    var ClearOnline = function () {
        sinusbot.http({
            method: 'POST',
            url: baseUrl + '&type=clean'
        });
    }
    ClearOnline();


    sinusbot.on('clientMove', function (ev) {
        if (ev.newChannel == 0) {
            sendUserConnect(ev.clientUid, ev.clientNick);
        } else if (ev.oldChannel == 0) {
            sendUserDisconnect(ev.clientUid, ev.clientNick);
        }
    });

    sinusbot.on('chat', function (ev) {
        if (ev.text != null) {
            sinusbot.log(ev.text);
            cmd = ev.text[1].toLowerCase(); // command trigger
            par = ev.text[2]; // command area
            text = ev.text[3]; // args
            if (par == 'steam') {
                updateUserSteam(ev.clientUid, text);
            }
        }
    });

    function sendUserConnect(uuid, name) {
        sinusbot.http({
            method: 'POST',
            url: baseUrl + '&type=connect&clientId=' + encodeURIComponent(uuid) + '&name=' + encodeURIComponent(name)
        });
    }

    function sendUserDisconnect(uuid, name) {
        sinusbot.http({
            method: 'POST',
            url: baseUrl + '&type=disconnect&clientId=' + encodeURIComponent(uuid) + '&name=' + encodeURIComponent(name)
        });
    }

    function updateUserSteam(uuid, steam) {
        sinusbot.http({
            method: 'POST',
            url: baseUrl + '&type=disconnect&clientId=' + encodeURIComponent(uuid) + '&steam=' + encodeURIComponent(steam)
        });
    }

    function Time(uptime) {
        var send = 'Listen time: ';
        if (uptime == null) {
            send = 'You have no uptimes';
        }

        var seconds = uptime;
        var numyears = Math.floor(seconds / 31536000);
        var numdays = Math.floor((seconds % 31536000) / 86400);
        var numhours = Math.floor(((seconds % 31536000) % 86400) / 3600);
        var numminutes = Math.floor((((seconds % 31536000) % 86400) % 3600) / 60);
        var numseconds = (((seconds % 31536000) % 86400) % 3600) % 60;

        if (numyears != 0) {
            send = send + numyears + " years ";
        }
        if (numdays != 0) {
            send = send + numdays + " days ";
        }
        if (numhours != 0) {
            send = send + numhours + " hours ";
        }
        if (numminutes != 0) {
            send = send + numminutes + " minutes ";
        }
        if (numseconds != 0) {
            send = send + numseconds + " seconds";
        }

        return send;
    }
});
hallo, i am trying to make a addon that will help me log user activity. this is my source i cant get it to work. thanks in advance.
 
Status
Not open for further replies.
Top