From 4b34881adc9c508c59b4461f89708e300d04a34e Mon Sep 17 00:00:00 2001 From: David Phillips Date: Sun, 21 May 2017 20:06:53 +1200 Subject: Separate functionalities into modules --- plugin/tittilate.pm | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 plugin/tittilate.pm (limited to 'plugin/tittilate.pm') diff --git a/plugin/tittilate.pm b/plugin/tittilate.pm new file mode 100644 index 0000000..a1ea7f3 --- /dev/null +++ b/plugin/tittilate.pm @@ -0,0 +1,36 @@ +#!/usr/bin/env perl + +package plugin::tittilate; + +use strict; +use warnings; + +my %config; + +sub configure { + my $self = $_[0]; + my $cref = $_[1]; + %config = %$cref; + return $self; +} + +sub message { + my ($self, $me, $who, $where, $what) = @_; + my $gathered = ""; + my @expressions = (keys %{$config{triggers}}); + my $expression = join '|', @expressions; + while ($what =~ /($expression)/gi) { + my $matched = $1; + my $key; + # figure out which key matched + foreach (@expressions) { + if ($matched =~ /$_/i) { + $key = $_; + last; + } + } + $gathered .= $config{triggers}->{$key}; + } + return $gathered; +} +1; -- cgit v1.1