Skip to content

Commit

Permalink
Merge branch 'master' into muaddib
Browse files Browse the repository at this point in the history
Conflicts:
	irssi/scripts/chatbot.pl
  • Loading branch information
pasky authored and Petr Baudis committed Feb 17, 2012
2 parents 6228f9e + e13a4bd commit b79e529
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 174 deletions.
3 changes: 3 additions & 0 deletions DEPS
@@ -0,0 +1,3 @@
Perl modules:
Hailo
Cstocs
12 changes: 4 additions & 8 deletions README
Expand Up @@ -3,16 +3,12 @@ a collection of irssi scripts providing various IRC services, and some
supporting infrastructure.

To run this thing, symlink everything in irssi/ to ~/.irssi/ and run
irssi from the root directory of this tree.
irssi from the root directory of this tree. (or run: irssi --home $WHERE)

irssi/ - the scripts themselves
Best way to learn chatbot new words is using hailo command bundled with
Hailo perl module, just be sure to save brain in $IRSSIHOME/papalala.brn

build_brain.pl - Megahal training from logs (by default, Megahal is
trained from conversations with it)
filter_logs.pl - Megahal log preprocessing for build_brain.pl
update_ban.pl - Megahal automatic word banlist extraction from logs
megahal_tcp.pl - Megahal server for the megahal script; must be running
for Megahal to work
irssi/ - the scripts themselves

wordstats.sql - SQL schema for the wordstats script; feed sqlite to
initialize the database
Expand Down
16 changes: 0 additions & 16 deletions build_brain.pl

This file was deleted.

41 changes: 0 additions & 41 deletions filter_logs.pl

This file was deleted.

1 change: 0 additions & 1 deletion irssi/scripts/autorun/fight.pl

This file was deleted.

1 change: 0 additions & 1 deletion irssi/scripts/autorun/google.pl

This file was deleted.

60 changes: 14 additions & 46 deletions irssi/scripts/chatbot.pl
@@ -1,14 +1,11 @@
###### TODO
## add multiple server support

use strict;
use warnings;

use Irssi;
use Irssi::Irc;

use IO::Socket::INET;
use Time::HiRes qw(usleep gettimeofday tv_interval);
use Hailo;

use vars qw($VERSION %IRSSI);

Expand All @@ -20,29 +17,30 @@
description => "megahal connector",
);

our $megahal;
our $hailo;

sub on_msg {
my ($server, $message, $nick, $hostmask, $channel) = @_;
my $mynick = $server->{nick};
my $isprivate = !defined $channel;
my $dst = $isprivate ? $nick : $channel;
my $trigger_chance = Irssi::settings_get_int('bot_megahal_triggerchance');
my $request;

return if grep {lc eq lc $nick} split(/ /, Irssi::settings_get_str('bot_megahal_ignore'));

if ($message !~ s/^\s*$mynick[,:]\s*(.*)$/$1/i) {
return
unless Irssi::settings_get_int('bot_megahal_triggerchance');
return
if (int(rand(Irssi::settings_get_int('bot_megahal_triggerchance'))));
# With very small chance, we will reply to the user.
if (!$trigger_chance or int(rand($trigger_chance))) {
Irssi::settings_get_bool('bot_megahal_learn_from_all') and $hailo->learn($message);
return;
}
}

# Ensure we do not reply ridiculously quickly:
my $delay = Irssi::settings_get_int('bot_megahal_mindelay');
my $t0 = [gettimeofday()];

my $response = megahal_response($message);
my $response = $hailo->learn_reply($message);

my $dt = tv_interval($t0, [gettimeofday()]) * 1000000;

Expand All @@ -52,45 +50,15 @@ sub on_msg {
$server->send_message($dst, "$nick: $response", 0);
}

sub megahal_response {
my ($data) = @_;
$data =~ s/\s+/ /;
$data =~ s/\s*$/\n/;

megahal_connect() unless defined $megahal;

return ">> Can't connect to megahal, try latter or alert my master"
unless defined $megahal;

if ($data =~ /koureni.*nekoureni/i) {
return "Bez do haje.";
}

$megahal->printflush($data);
my $response = $megahal->getline;

if (! defined $response) {
$megahal = undef;
goto &megahal_response; ## restart
}

chomp($response);
return $response;
}

sub megahal_connect {
my $address = Irssi::settings_get_str('bot_megahal');
$megahal = IO::Socket::INET->new(
PeerAddr => $address,
Type => SOCK_STREAM,
);
}

Irssi::signal_add('message public', 'on_msg');
Irssi::signal_add('message private', 'on_msg');

Irssi::settings_add_str('bot', 'bot_megahal', 'localhost:4566');
Irssi::settings_add_str('bot', 'bot_megahal_ignore', '');
# minimal response time in microseconds
Irssi::settings_add_int('bot', 'bot_megahal_mindelay', 0);
Irssi::settings_add_bool('bot', 'bot_megahal_learn_from_all', 1);
Irssi::settings_add_int('bot', 'bot_megahal_triggerchance', 1000);

##
$hailo = Hailo->new(brain => Irssi::get_irssi_dir()."/papalala.brn");

2 changes: 1 addition & 1 deletion irssi/scripts/decide.pl
Expand Up @@ -27,7 +27,7 @@ sub on_msg {

return unless $message =~ s/^${cp}decide\s*//;
my $time = time();
if ($time - $lastt > 60*60*48) {
if ($time - $lastt > 300) {
$lastt = $time;
}

Expand Down
60 changes: 0 additions & 60 deletions megahal_tcp.pl

This file was deleted.

0 comments on commit b79e529

Please sign in to comment.