• 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.

Solved Scripting: getChannelGroup() uses cached data

Status
Not open for further replies.

Ron

Donor
is awesome!
Hi!

Version: SinusBot 0.13.37-9791176
OS: Ubuntu 16.04, latest updates

At the moment, there's a bug with the scripting API (TS3 specifically), where if I try to use getChannelGroup() it'll use cached data,
so if a client switches channel, or someone changes his group, it still returns the old one.
 
Could you please provide a snippet to reproduce that issue?
 
Of course!

Simply message the bot with the command, change his group, and message him again.

JavaScript:
registerPlugin({
    name: 'Repro',
    version: '1.0',
    description: 'For reproduction purposes',
    author: 'Ron Melkhior <[email protected]>',
}, init);

function init(sinusbot, config) {
    var event = require('event');
    var engine = require('engine');
    var backend = require('backend');

    var g_client = backend.getBotClient();

    event.on('chat', onMessageReceived);
    event.on('connect', onConnectServer);

    function onMessageReceived(message) {
        if (message.text === '!checkgroup') {
            message.client.chat(g_client.getChannelGroup().name());
        }
    }

    function onConnectServer() {
        g_client = backend.getBotClient();
    }
}
 
Yep can confirm btw.

JavaScript:
event.on('chat', function (ev) {
    if (ev.text == "!foo") {
        ev.client.chat(ev.client.getChannelGroup().name());
    }
});
 
Okay, that example saves a copy of a client object from one event and uses it in another. So the caching there is actually intended, so that working with those objects is cheap and doesn't require costly lookups and such.
You could get a new client object by it's id using the id of the cached one to get up to date data. Maybe I'll add an update() function that refreshes the object itself / returns an updated one.

Does that make sense? :)
 
That example was a basic one, it also happens when trying to access Message.client, which supposedly should be "fresh".
I also just tested, and re-fetching the client using the ID like below does not work either:

JavaScript:
registerPlugin({
    name: 'Repro',
    version: '1.0',
    description: 'For reproduction purposes',
    author: 'Ron Melkhior <[email protected]>',
}, init);

function init(sinusbot, config) {
    var event = require('event');
    var engine = require('engine');
    var backend = require('backend');

    var g_client = backend.getBotClient();

    event.on('chat', onMessageReceived);
    event.on('connect', onConnectServer);

    function onMessageReceived(message) {
        var client = backend.getClientByID(message.client.id());

        if (message.text === '!checkgroup') {
            message.client.chat(client.getChannelGroup().name());
        }
    }

    function onConnectServer() {
        g_client = backend.getBotClient();
    }
}
 
Okay, thats definitely a bug then. Will check. Thanks!
 
Weird, an update a couple of months ago fixed the issue for me. What version are you running?
 
Status
Not open for further replies.
Back
Top Bottom