Question #61580 on Pidgin changed:
https://answers.launchpad.net/pidgin/+question/61580

Description changed to:
I have written a simple perl plugin for pidgin that automaticaly closes all 
conversations that have been idle for one minute...
This is becose I want to write a instant messenger bot, so when someone stops 
talking, close conversation to reduce number of open conversations....

It has a problem that I can't explain.... If someone send's me message,
and I close conversation manually, conv_closed si evaluated OK, but, it
doesn't stop timeout properly ... so after timeout, close_conv in
evaluated (as it should if I left conversation open) and when it tries
to destroy conversation, pidgin crashes....

Is this a bug or lack of my knowledge of pidgin and perl ???

Here is the code:


sub plugin_load {
        our $plugin = shift;
        our %conv_list;
        
        Purple::Debug::info('auto_close_conv', "plugin_load(): plugin 
loaded.\n");

        Purple::Signal::connect(Purple::Conversations::get_handle(), 
'conversation-created', $plugin, \&conv_created, 'conversation-created');
        Purple::Signal::connect(Purple::Conversations::get_handle(), 
'deleting-conversation', $plugin, \&conv_closed, 'deleting-conversation');
        Purple::Signal::connect(Purple::Conversations::get_handle(), 
'received-im-msg', $plugin, \&im_received, 'received-im-msg');

        foreach $conv (Purple::get_conversations()) {
                $conv_list{$conv->get_name()} = $conv;
                $conv->{'timeout_handle'} = Purple::timeout_add($plugin, 60, 
\&close_conv, $conv);
        }

}

sub plugin_unload {
        Purple::Debug::info('auto_close_conv', "plugin_unload(): plugin 
unloaded.\n");
}

sub conv_created {
        my ($conv, $data) = @_;
        Purple::Debug::info('auto_close_conv', "conv_created()\n");
        $conv_list{$conv->get_name()} = $conv;
        $conv->{'timeout_handle'} = Purple::timeout_add($plugin, 60, 
\&close_conv, $conv);
}

sub conv_closed {
        my ($conv, $data) = @_;
        Purple::Debug::info('auto_close_conv', "conv_closed()\n");
        Purple::timeout_remove($conv->{'timeout_handle'});
        delete $conv->{'timeout_handle'};
        delete $conv_list{$conv->get_name()};
}

sub im_received {
        my ($account, $sender, $msg, $flags) = @_;
        Purple::Debug::info('auto_close_conv', "im_received()\n");
        if (defined($conv_list{$sender})) {
                Purple::timeout_remove($conv_list{$sender}->{'timeout_handle'});
                $conv_list{$sender}->{'timeout_handle'} = 
Purple::timeout_add($plugin, 60, \&close_conv, $conv_list{$sender});
        }
}

sub close_conv {
        my ($conv) = @_;
        Purple::Debug::info('auto_close_conv', "close_conv()\n");
        if (ref($conv) ne 'HASH') {
                Purple::Debug::info('auto_close_conv', "close_conv(): closing 
...\n");
                $conv->destroy();
        }
}

-- 
You received this question notification because you are a member of
Pidgin Rocks, which is an answer contact for Pidgin.

_______________________________________________
Mailing list: https://launchpad.net/~pidgin-rocks
Post to     : pidgin-rocks@lists.launchpad.net
Unsubscribe : https://launchpad.net/~pidgin-rocks
More help   : https://help.launchpad.net/ListHelp

Reply via email to