diff --git a/NEWS b/NEWS index ed6f957..4175362 100644 --- a/NEWS +++ b/NEWS @@ -21,6 +21,7 @@ In this alpha4 release, we have added: * A ChanTopics module for advanced management of channel topics. * buildmod now generates HTML and man(1) pages from a module's POD. * server:ajoin now supports channel keys by spacing the name and key. +* A Dictionary module for looking up definitions of words. Bug fixes: diff --git a/doc/CHANGELOG b/doc/CHANGELOG index 5e2fe30..c8e17ff 100644 --- a/doc/CHANGELOG +++ b/doc/CHANGELOG @@ -3,6 +3,7 @@ Auto IRC Bot 3.0: Change Log 3.0 Indev =============================================================================== + * Added a Dictionary module for looking up definitions of words. * server:ajoin now supports channel keys by spacing the name and key. * Hooks can now block events by returning -1. * bin/buildmod now retrieves the POD from modules and creates man(1) page diff --git a/modules/Dictionary.pm b/modules/Dictionary.pm new file mode 100644 index 0000000..34d0ed2 --- /dev/null +++ b/modules/Dictionary.pm @@ -0,0 +1,104 @@ +# Module: Dictionary. See below for documentation. +# Copyright (C) 2010-2011 Xelhua Development Group, et al. +# This program is free software; rights to this code are stated in doc/LICENSE. +package m_Dictionary; +use strict; +use warnings; +use Net::Dict; +use API::Std qw(cmd_add cmd_del trans); +use API::IRC qw(notice privmsg); + +# Initialization subroutine. +sub _init +{ + # Create the DICT command. + cmd_add('DICT', 0, 0, \%m_Dictionary::HELP_DICT, \&m_Dictionary::cmd_dict) or return; + + # Success. + return 1; +} + +# Void subroutine. +sub _void +{ + # Delete the DICT command. + cmd_del('DICT') or return; + + # Success. + return 1; +} + + +# Help hash for DICT. Spanish, French and German translations needed. +our %HELP_DICT = ( + 'en' => "This command allows you to lookup a word through Dict.org. \002Syntax:\002 DICT ", +); + +# Callback for DICT command. +sub cmd_dict +{ + my ($src, ($word)) = @_; + + # Check for needed parameters. + if (!defined $word) { + notice($src->{svr}, $src->{nick}, trans('Not enough parameters').q{.}); + return; + } + + # Create an instance of Net::Dict. + my $dictv = Net::Dict->new('dict.org'); + + # Get the definition for this word. + my $res = $dictv->define($word); + + # Check if there was a result. + if (defined $res) { + # Return the results. + privmsg($src->{svr}, $src->{chan}, "Results for \2$word\2:"); + foreach (@{ $res }) { + # Split the newlines. + my @lines = split m/\n/, @$_[1]; + foreach (@lines) { + if ($_ =~ m/[^\s]/) { + privmsg($src->{svr}, $src->{chan}, $_); + } + } + } + } + else { + # Else return no results. + privmsg($src->{svr}, $src->{chan}, "No results for \2$word\2."); + } + + return 1; +} + + +# Start initialization. +API::Std::mod_init('Dictionary', 'Xelhua', '1.00', '3.0.0d', __PACKAGE__); +# vim: set ai sw=4 ts=4: +# build: cpan=Net::Dict perl=5.010000 + +__END__ + +=head1 Dictionary + +=head2 Description + +=over + +This module allows users to lookup definitions for words from dict.org via the +DICT command. + +=back + +=head2 Technical + +=over + +This module adds an extra dependency: Net::Dict. You can get it from the CPAN +. + +This module is compatible with Auto v3.0.0a4+. + +=back