Added a Dictionary module for looking up definitions of words.
This commit is contained in:
1 parent
9288301259
commit
7a9230c75a
3 files changed
+106
No files matched your search
@@ -21,6 +21,7 @@ In this alpha4 release, we have added:
|
|||||||
* A ChanTopics module for advanced management of channel topics.
|
* A ChanTopics module for advanced management of channel topics.
|
||||||
* buildmod now generates HTML and man(1) pages from a module's POD.
|
* 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.
|
* server:ajoin now supports channel keys by spacing the name and key.
|
||||||
|
* A Dictionary module for looking up definitions of words.
|
||||||
|
|
||||||
Bug fixes:
|
Bug fixes:
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ Auto IRC Bot 3.0: Change Log
|
|||||||
|
|
||||||
3.0 Indev
|
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.
|
* server:ajoin now supports channel keys by spacing the name and key.
|
||||||
* Hooks can now block events by returning -1.
|
* Hooks can now block events by returning -1.
|
||||||
* bin/buildmod now retrieves the POD from modules and creates man(1) page
|
* bin/buildmod now retrieves the POD from modules and creates man(1) page
|
||||||
|
|||||||
@@ -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 <word>",
|
||||||
|
);
|
||||||
|
|
||||||
|
# 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
|
||||||
|
<http://www.cpan.org>.
|
||||||
|
|
||||||
|
This module is compatible with Auto v3.0.0a4+.
|
||||||
|
|
||||||
|
=back
|
||||||
Reference in new issue
Block a user