package Plugin::Correction; use strict; use warnings; use Encode qw/decode/; use Data::Munge qw/replace/; use IdaliusConfig qw/assert_scalar/; my $config; my $root_config; sub configure { my $self = shift; shift; # cmdref shift; # run_command $config = shift; $root_config = shift; IdaliusConfig::assert_scalar($config, $self, "chance"); die "chance must be from 0 to 100" unless $config->{chance} >= 0 && $config->{chance} <= 100; IdaliusConfig::assert_dict($config, $self, "corrections"); return $self; } sub on_message { my ($self, $logger, $who, $where, $raw_what, $what, $irc) = @_; if (ref($where) eq "ARRAY") { $where = $where->[0]; } $what = Encode::decode('utf8', $what); foreach my $mistake (keys %{$config->{corrections}}) { if ($what =~ /$mistake/i) { my $response = replace($what, qr/$mistake/i, "\x02$config->{corrections}->{$mistake}\x02", "g"); return unless rand(100) < $config->{chance}; return $response; } } return; } sub on_action { on_message(@_); } 1;