aboutsummaryrefslogtreecommitdiff
path: root/Plugin/Hmm.pm
blob: f6a3c0778b39a6e778543722fd1a1e734c1a9cac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package Plugin::Hmm;

use strict;
use warnings;

my $root_config;
my $config;
my %current_alarm;
my %lines_since;

sub configure {
	my $self = shift;
	shift; # cmdref
	shift; # run_command
	$config = shift;
	$root_config = shift;

	IdaliusConfig::assert_scalar($config, $self, "min_delay_sec");
	IdaliusConfig::assert_scalar($config, $self, "max_delay_sec");
	IdaliusConfig::assert_scalar($config, $self, "lines_break");

	return $self;
}

# FIXME dedup with Natural.pm
sub some {
	my @choices = @_;
	return $choices[rand(@choices)];
}

sub on_message {
	my ($self, $logger, $who, $where, $raw_what, $what, $irc) = @_;
	my $nick = (split /!/, $who)[0];

	# Don't perform this in q to users
	return if ref($where) ne "ARRAY";
	$where = $where->[0];

	# Require some minimum number of lines in a channel before hmming again
	return unless $lines_since{$where}++ >= $config->{lines_break};

	if (defined $current_alarm{$where}) {
		$irc->delay_remove($current_alarm{$where});
	}

	my $response = some("Hmm", "hmm", "hmmmmmm", "oof", "mmm", "Hi Animatronio!");

	$current_alarm{$where} = $irc->delay([privmsg => $where => $response],
		$config->{min_delay_sec} + rand($config->{max_delay_sec} - $config->{min_delay_sec}));

	$lines_since{$where} = 0;

	return;
}

sub on_action {
	on_message @_;
}
1;