# Type: Input # Category: Common # Description: Tells current version number of Orangutan # Author: Andriy Lesyuk new Orangutan::Context( response => [ '^(?:Please )?show changelog(?: for(?: version)?([0-9\.-]+))?!*\.*$', '^What(?:\'s| is)? new(?: in ([0-9\.-]+))?\?*!*\.*$' ], handler => sub { my ($context, $user, $item, $version) = @_; my $changelog = $main::config->Get('orangutan', 'changelog'); if (defined($changelog)) { my $load = 0; my @entries = ( ); if (open(CLOG, '<', $changelog)) { while () { if (/^Orangutan *\(([0-9\.-]+)\)/i) { if ($load) { last; } else { if (!defined($version)) { $version = $1; $load = 1; } elsif ($1 eq $version) { $load = 1; } } } elsif ($load) { if (/^\s*\*\s*(.+?)\s*\n$/) { push(@entries, $1); } elsif (scalar @entries > 0) { $entries[$#entries] .= $_; } } } close(CLOG); } if ($load) { if (scalar @entries > 0) { my $format = Orangutan::Context::Random( 'Here are changes for version %s', 'In version %s we have' ); my $message = sprintf($format, $version).":\n"; foreach my $entry (@entries) { $entry =~ s/\s{2,}/ /g; $entry =~ s/^\s*//g; $entry =~ s/\s*$//g; $message .= ' o '.$entry."\n"; } $user->SendMessage($message); } else { $user->SendMessage('Nothing...'); } } else { $user->SendMessage([ 'I never was of this version!..', "I can't find such version...", 'I never had such version.', 'Wrong version!' ]); } } else { $user->SendMessage([ 'My creator did not told me...', 'I have no idea...' ]); } } ); # kate: syntax perl