summaryrefslogtreecommitdiffstats
path: root/scripts/sana_cmd.pl
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 20:19:02 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 20:19:02 +0000
commit03929dac2a29664878d2c971648a4fe1fb698462 (patch)
tree02c5e2b3e006234aa29545f7a93a1ce01b291a8b /scripts/sana_cmd.pl
parentInitial commit. (diff)
downloadirssi-scripts-03929dac2a29664878d2c971648a4fe1fb698462.tar.xz
irssi-scripts-03929dac2a29664878d2c971648a4fe1fb698462.zip
Adding upstream version 20231031.upstream/20231031upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'scripts/sana_cmd.pl')
-rw-r--r--scripts/sana_cmd.pl57
1 files changed, 57 insertions, 0 deletions
diff --git a/scripts/sana_cmd.pl b/scripts/sana_cmd.pl
new file mode 100644
index 0000000..5278871
--- /dev/null
+++ b/scripts/sana_cmd.pl
@@ -0,0 +1,57 @@
+# /sana command, translates english-finnish-english.
+
+# BUGS: Doesn't handle UTF-8.
+
+use warnings;
+use strict;
+use HTML::Entities ();
+use Irssi ();
+use LWP::Simple ();
+
+use vars qw($VERSION %IRSSI);
+
+$VERSION = "0.1";
+%IRSSI = (
+ authors => 'Johan "Ion" Kiviniemi, idea taken from Riku Voipio\'s sana.pl',
+ contact => 'ion at hassers.org',
+ name => 'sana-cmd',
+ description => '/sana command, translates english-finnish-english.',
+ license => 'Public Domain',
+ url => 'http://ion.amigafin.org/irssi/',
+ changed => 'Sat Mar 16 06:20 EET 2002',
+);
+
+Irssi::command_bind(
+ 'sana' => sub {
+ my @params = split /\s+/, shift;
+ unless (@params) {
+ Irssi::print("Sana: Usage: "
+ . (substr(Irssi::settings_get_str('cmdchars'), 0, 1) || "/")
+ . "sana word");
+ return;
+ }
+
+ my $word = $params[0];
+ $word =~ s/ /+/g;
+ $word =~ s/(\W)/'%' . unpack "H*", $1/eg;
+
+ if (my $content =
+ LWP::Simple::get(
+ 'http://www.tracetech.net:8081/?word=' . $word))
+ {
+ $content = HTML::Entities::decode($content);
+ $content =~ s/\015?\012/ /g;
+ $content =~ s/<[^>]+>/ /g; # Ugly, but it does the trick here.
+
+ my @words = $content =~ /(\S+)\s+(\(\S+?\))/g;
+
+ if (@words) {
+ Irssi::print("Sana: $word: @words");
+ } else {
+ Irssi::print("Sana: $word: No translations.");
+ }
+ } else {
+ Irssi::print("Sana failed.");
+ }
+ }
+);