Twitter usage and backronym
authorpdbogen <pdbogen@088b83a4-0077-4247-935c-42ec02c2848b>
Wed, 19 Oct 2011 18:27:36 +0000 (18:27 +0000)
committerpdbogen <pdbogen@088b83a4-0077-4247-935c-42ec02c2848b>
Wed, 19 Oct 2011 18:27:36 +0000 (18:27 +0000)
git-svn-id: https://www.cernu.us/~pdbogen/svn/destult2@120 088b83a4-0077-4247-935c-42ec02c2848b

commands.yaml

index 828e1ef..be831e0 100644 (file)
@@ -1984,6 +1984,11 @@ TWITTER: |-
         $heap->{ 'twitterUsers' } = {};
       }
     }
+
+    if( $what =~ /^\s*$/ ) {
+      $kernel->post( $src, $replypath, "Usage: TWITTER <message>", $dest );
+      return;
+    }
   
     if( exists( $heap->{ 'twitterUsers' }->{ uc( $who ) } ) ) {
       if( $heap->{ 'twitterUsers' }->{ uc( $who ) }->{ "state" } == 0 ) {
@@ -2143,3 +2148,40 @@ VERSION: |-
     $page =~ m/<h1>(Package: .*?)<\/h1>/s;
     $kernel->post( $src, $replypath, $1, $dest );
   }
+
+BACKRONYM: |-
+  sub {
+    my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_;
+    my $FH;
+    my $dict;
+    unless( exists $heap->{ "backronym_dict" } ) {
+      $dict = $heap->{ "backronym_dict" } = {};
+      if( -e "backronym.wordlist" ) {
+        print( "BACKRONYM: Using backronym.wordlist\n" );
+        open $FH, "<", "backronym.wordlist";
+      } elsif( -e "/usr/share/dict/words" ) {
+        print( "BACKRONYM: Using /usr/share/dict/words\n" );
+        open $FH, "<", "/usr/share/dict/words";
+      } else {
+        $kernel-post( $src, $replypath, "I can't find a wordlist. :(", $dest );
+        return;
+      }
+      while(<$FH>) {
+        chomp;
+        my $word = $_;
+        $word =~ tr/A-Z/a-z/;
+        my $ch = (substr $word, 0, 1);
+        $dict->{ $ch } = [] unless exists $dict->{ $ch };
+        push @{ $dict->{ $ch } }, $word;
+      }
+      close $FH;
+    } else {
+      $dict = $heap->{ "backronym_dict" };
+    }
+    my $response = "";
+    $what =~ tr/A-Z/a-z/;
+    for my $c (split( //, $what)) {
+      $response .= $dict->{ $c }->[ int( rand( scalar @{$dict->{$c}} ) ) ]." ";
+    }
+    $kernel->post( $src, $replypath, $response, $dest );
+  }