aboutsummaryrefslogtreecommitdiff
path: root/Plugin/Natural.pm
blob: f004707bd8589b38bd85a006be45a032fccaf797 (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
package Plugin::Natural;

use strict;
use warnings;
use threads;

my $root_config;

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

	return $self;
}

sub mention_odds {
	return int(rand(2)) == 1;
}

sub some {
	my @choices = @_;
	return $choices[rand(@choices)];
}

sub choose_response {
	my ($what, $nick) = @_;

	if ($what =~ /\b(hi|hey|sup|morning|hello|hiya)\b/i) {
		return some("hi $nick", "hey $nick", "sup $nick") . some("", ", how goes it?");
	} elsif ($what =~ /\b(thanks|thx|ta)\b/i) {
		return some("don't mention it", "that's ok", ":)", "not a problem");
	} elsif ($what =~ /\b(shush|(shit|shut)(\s+the\s+fuck|)\s+up|stfu)\b/i) {
		return some("$nick: shush yourself", "shut up, $nick", "nou $nick", "sorry $nick", ":(");
	} elsif ($what =~ /\b(fuck\s+(off?|you|u)|fucking)\b/i) {
		return some("$nick: take your meds", "stop harassing me", "ease up on the drink, mate", "ooh big boy angry $nick has come out to play");
	} elsif ($what =~ /\b(lol|g(g|j))\b/i) {
		return some(":)", ":D");
	} elsif ($what =~ /\bstop(|\s+it)\b/i) {
		return some(":(", "fine", "whatever, dude", "god");
	} elsif ($what =~ /\bhelp\b/i) {
		return some("D:", "ono");
	}
	return;
}

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

	if (ref($where) eq "ARRAY") {
		$where = $where->[0];
	}

	return unless $what =~ /\b\Q$root_config->{current_nick}\E\b/;
	return unless mention_odds();

	my $response = choose_response($what, $nick);
	$irc->delay([privmsg => $where => $response], rand(10)) if $response;

	return;
}

sub on_action {
	on_message @_;
}
1;