perlhexchat

HexChat Perl get network context instead of channel context


I have the following code in a channel message hook to get the server context and print to the server window:

my $network = HexChat::get_info('network');
my $networkContext = HexChat::find_context(undef, $network);
HexChat::set_context($networkContext);
HexChat::print('test');

It works if I already have the server window open, or a channel on a different server, but if the current window is a channel on the server I request the context for I get the context of the current channel instead of the server. Is there any way to force find_context to always get the server context so 'test' is printed in the server window instead of the current channel's window


Solution

  • Translate this snippet from one of my scripts to perl basically:

    for chan in hexchat.get_list('channels'):
        if chan.type == 1 and chan.id == hexchat.get_prefs('id'):
            SERVER_CONTEXT = chan.context
    

    find_context() goes off of strings which not very smart since they are not unique. Going of the unique id of the network is always correct and using the context type always gets the server tab (though note users can disable that).