aboutsummaryrefslogtreecommitdiff
path: root/Plugin/Jinx.pm
blob: a514bb8d1c349ff4085007ec4f5095ff0b8d8791 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
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 lc $what eq lc $last_response{$channel};

	if ($last{$channel} and lc $last{$channel} eq lc $what) {
		$last_response{$channel} = $what;
		return $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 lc $what eq lc $last_response{$channel};

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

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

# Even ignored nicks should be allowed to break a streak
sub on_message_yes_really_even_from_ignored_nicks {
	my ($self, $logger, $me, $who, $where, $raw_what, $what, $irc) = @_;
	my $channel = $where->[0];

	return if $last{$channel} and lc $last{$channel} eq lc $what;

	$last{$channel} = undef;

	return;
}

# Even ignored nicks should be allowed to break a streak
sub on_action_yes_really_even_from_ignored_nicks {
	on_message_yes_really_even_from_ignored_nicks(@_);
}
1;