Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-03-2004, 11:44 AM   #1
Registered: Mar 2004
Distribution: Fedora 10
Posts: 182

Rep: Reputation: 30
Perl guys! Time delay 4 Eliza bot Gaim response - want to have fun :)

Hey everyone!

I was wondering if you could help me. There's this IM bot called Eliza for Gaim.

I would like to fool a few friends... but it answers too damn fast. do you know how to modify it to set a time delay?

I have posted the code for convenience.

It could only be a few lines? If you could help it would be much appreciated.

#ElizaLovesYou v0.2 - Rogerian psychotherapist for Gaim
#Copyright (C) 2004 Scott Wolchok

#This program is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License
#as published by the Free Software Foundation; either version 2
#of the License, or (at your option) any later version.

#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#GNU General Public License for more details.

#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#(You can find the GPL at

#You'll need to install Chatbot::Eliza from CPAN before this will work.
#Run 'perl -MCPAN -e "shell"' and answer the questions, then type
#'install Chatbot::Eliza' at the prompt. That should do it!

#Please note that this plugin is just a hook for the Perl Chatbot::Eliza
#module - the credit for the actual "bot" goes to the John Nolan, the
#writer of that module.

#Superdug is great!!!!

use Gaim;
use Chatbot::Eliza;
use strict;

my %bots;
my $plugin;
#my @timeouts; #Gaim segfaults if we leave the send_message timeout and unload the plugin

perl_api_version => 2,
name => "ElizaLovesYou",
version => "0.2",
summary => "Rogerian psychotherapist for Gaim",
description => "Automatically responds to incoming messages on all accounts using the Eliza algorithm",
author => "Scott Wolchok <evilsporkman\>",
url => "none",

load => "plugin_load",
unload => "plugin_unload"

sub plugin_init {
return %::PLUGIN_INFO;

sub do_eliza {
Gaim::debug_info($::PLUGIN_INFO{name}, "Entering do_eliza\n");
my ($account, $sender, $message, $flags) = @_;
Gaim::debug_info($::PLUGIN_INFO{name}, "Displayed: $message\n");
$bots{$sender} = new Chatbot::Eliza unless $bots{$sender};

while($message =~ s/<.*?>//) {}; #HTML si t3h sux0r!

my $theIM = getIM($sender);

#Tried to use a queue to hold timeouts so we could remove them at plugin_unload - the thing segfaults if there's a timeout pending and you unload it
# push @timeouts, Gaim::timeout_add($plugin,10,\&send_message,[$theIM,$bots{$sender}->transform($message)]);

Gaim::debug_info($::PLUGIN_INFO{name}, "Leaving do_eliza\n");

sub send_message {
Gaim::debug_info($::PLUGIN_INFO{name}, "Entering send_message\n");
my ($IM, $message) = @{$_[0]};

#Gaim::debug_info($::PLUGIN_INFO{name}, "Shifting timeouts\n");
#shift @timeouts;

Gaim::debug_info($::PLUGIN_INFO{name}, "Sending message\n");

return undef;
sub plugin_load {
$plugin = shift;

Gaim::signal_connect(Gaim::Conversations::handle, "received-im-msg", $plugin, \&do_eliza, 0);

sub plugin_unload {
my $plugin = shift;

# for my $timeout (@timeouts) {
# Gaim::timeout_remove($timeout);
# }

#Note: I got this from forsaken in #gaim on FreeNode and renamed it to getIM, his original credit follows:
#From and edited.
#Michael Wozniak <> and Anthony Noto <>
sub getIM
my $thing = $_[0];
my @im_array = Gaim::ims(); #get the array of IM's
foreach my $element (@im_array)
if ( Gaim::Conversation::get_name( Gaim::Conversation::IM::get_conversation ( $element ) ) eq $thing )
return $element; #return the correct IM

return undef;
Old 10-03-2004, 12:04 PM   #2
Registered: Mar 2004
Distribution: Fedora 10
Posts: 182

Original Poster
Rep: Reputation: 30
Ah, I got it.

Set Gaim::timeout_add($plugin,1,\&send_message,[$theIM,$bots{$sender}->transform($message)]);

to Gaim::timeout_add($plugin,5,\&send_message,[$theIM,$bots{$sender}->transform($message)]);

for a realistic reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl 403 HTTP Response barkers Linux - Software 4 04-27-2005 08:07 AM
How you guys have fun on linux ? snop General 52 02-19-2004 06:21 PM
Slowdown in pc response time dregoma Linux - Newbie 1 02-11-2004 01:19 PM
More perl scripting fun BertsBackyard Programming 12 01-30-2003 08:54 AM
Keyboard response time niyaah Linux - Newbie 0 10-13-2002 09:20 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:14 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration