summaryrefslogtreecommitdiffstats
path: root/scripts/wordscramble.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/wordscramble.pl
parentInitial commit. (diff)
downloadirssi-scripts-upstream/20231031.tar.xz
irssi-scripts-upstream/20231031.zip
Adding upstream version 20231031.upstream/20231031upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--scripts/wordscramble.pl160
1 files changed, 160 insertions, 0 deletions
diff --git a/scripts/wordscramble.pl b/scripts/wordscramble.pl
new file mode 100644
index 0000000..a05cab3
--- /dev/null
+++ b/scripts/wordscramble.pl
@@ -0,0 +1,160 @@
+use Irssi;
+use strict;
+use vars qw($VERSION %IRSSI);
+
+$VERSION = '0.0.3';
+%IRSSI = (
+ authors => 'Koenraad Heijlen',
+ contact => 'vipie@ulyssis.org',
+ commands => 'ws',
+ name => 'word_scramble',
+ description => 'A script that scrambles all the letters in a word except the first and last.',
+ license => 'GNU GPL version 2',
+ url => 'http://vipie.studentenweb.org/dev/irssi/wordscramble',
+ changed => '2018-05-11'
+);
+
+#--------------------------------------------------------------------
+# Changelog
+#--------------------------------------------------------------------
+#
+# word_scramble.pl 0.0.3 (2018-05-11)- bw1
+# - fixed the help bug
+#
+# word_scramble.pl 0.0.2 (2003-09-17)- Koenraad Heijlen
+# - fixed the four letter word bug
+# - fixed the non alphanummeric characters bug
+# - some improvement in returning \n
+#
+# word_scramble.pl 0.0.1 (2003-09-15) - Koenraad Heijlen
+# - first draft
+#
+#--------------------------------------------------------------------
+
+#--------------------------------------------------------------------
+# Public Variables
+#--------------------------------------------------------------------
+my %myHELP = ();
+
+
+#--------------------------------------------------------------------
+# Help function
+#--------------------------------------------------------------------
+sub cmd_help {
+ my ($about) = @_;
+
+ %myHELP = (
+ ws =>
+"%9ws - wordscramble%9
+
+ /ws <text>
+
+scrambles the text you type,
+and outputs it in the current (active) channel
+or query.
+",
+ );
+
+ if ( $about =~ /(ws)/i ) {
+ Irssi::print($myHELP{ws},MSGLEVEL_CLIENTCRAP);
+ Irssi::signal_stop;
+ }
+}
+
+#--------------------------------------------------------------------
+# scrambles one word
+#--------------------------------------------------------------------
+sub scrambleWord {
+ # 0 : first
+ # length : last-1
+ # length+1 : last
+ #substr EXPR,OFFSET,LENGTH,REPLACEMENT
+ my $l = 0;
+ my $r = 0;
+ my $out = "";
+ my $word = shift;
+ chomp($word);
+
+ if (length($word) <= 3) {
+ return $word;
+ }
+ my $l = length($word)-2;
+ $l = $l;
+ $out = substr($word,0,1);
+ while ($l != 1) {
+ $r = int(rand()*$l+1);
+
+ if ($r == 0) {
+ next;
+ }
+ #$r == $l is no marginalcase.
+
+ $out .= substr($word,$r,1);
+ substr($word,$r,1,substr($word,$l,1));
+ $l--;
+ }
+ $out .= substr($word,$l,1);
+ $out .= substr($word,length($word)-1,1);
+ return $out;
+}
+
+#--------------------------------------------------------------------
+# scrambles line
+#--------------------------------------------------------------------
+sub scrambleLine{
+ my $line = shift;
+ my $outline = "";
+ my $word = "";
+ my $i=0;
+ my @splitLine;
+
+ #we leave the \n at the end, less interference.
+ #chomp($line);
+ @splitLine=split(/(\W)/,$line);
+
+ # every other item in the array is the split string
+ for ($i=0; $i<= $#splitLine;$i++) {
+ $outline .= scrambleWord($splitLine[$i]);
+ $i++;
+ if ($i <= $#splitLine) {
+ $outline .= $splitLine[$i];
+ }
+ }
+ return $outline;
+}
+
+#--------------------------------------------------------------------
+# Defintion of /ws
+#--------------------------------------------------------------------
+sub cmd_ws {
+ my ($args, $server, $witem) = @_;
+
+ if (!$server || !$server->{connected}) {
+ Irssi::print("Not connected to server");
+ return;
+ }
+
+ my $scrambledLine = scrambleLine($args);
+ if ($witem && ($witem->{type} eq "CHANNEL" ||
+ $witem->{type} eq "QUERY")) {
+ # there's query/channel active in window
+ $witem->command("MSG ".$witem->{name}." $scrambledLine");
+ } else {
+ Irssi::print("Nick not given, and no active channel/query in window");
+ }
+}
+
+#--------------------------------------------------------------------
+# Irssi::Settings / Irssi::command_bind
+#--------------------------------------------------------------------
+
+Irssi::command_bind("ws", "cmd_ws", "Scramble Line");
+Irssi::command_bind("help","cmd_help", "Irssi commands");
+
+#--------------------------------------------------------------------
+# This text is printed at Load time.
+#--------------------------------------------------------------------
+
+#nothing
+
+#- end