aboutsummaryrefslogtreecommitdiff
path: root/Plugin/Jinx.pm
blob: 0c3f542df38e972b46e0590a96383da5b9a8ee4c (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
60
package Plugin::Jinx;

# Makes idalius join in on streaks of a person/some people saying the same
# thing more than once in a row

use strict;
use warnings;

# Last message we responded to with a jinx
my %last_response;

# Last message said on the channel
my %last;
my %config;

sub configure {
	my $self = $_[0];
	my $cmdref = $_[1];
	my $cref = $_[2];
	%config = %$cref;
	return $self;
}

sub on_message {
	my ($self, $logger, $me, $who, $where, $raw_what, $what, $irc) = @_;
	my $channel = $where->[0];

	return if $last_response{$channel} and $what eq $last_response{$channel};

	if ($last{$channel} and $last{$channel} eq $what) {
		$last_response{$channel} = $what;
		return $what;
	}

	$logger->("Storing on_message for $channel $what");

	$last{$channel} = $what;
	$last_response{$channel} = undef;
	return;
}

sub on_action {
	my ($self, $logger, $me, $who, $where, $raw_what, $what, $irc) = @_;
	my $channel = $where->[0];

	return if $last_response{$channel} and $what eq $last_response{$channel};

	if ($last{$channel} and $last{$channel} eq $what) {
		$last_response{$channel} = $what;
		$irc->yield(ctcp => $channel->[0] => "ACTION" => $what);
		return;
	}

	$logger->("Storing on_action for $channel $what");

	$last{$channel} = $what;
	$last_response{$channel} = undef;
	return;
}
1;