From 822480deb38d4c2543f04bff4491a1ea96327a89 Mon Sep 17 00:00:00 2001 From: pdbogen Date: Wed, 19 Oct 2011 18:27:36 +0000 Subject: [PATCH] Twitter usage and backronym git-svn-id: https://www.cernu.us/~pdbogen/svn/destult2@120 088b83a4-0077-4247-935c-42ec02c2848b --- commands.yaml | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/commands.yaml b/commands.yaml index 828e1ef..be831e0 100644 --- a/commands.yaml +++ b/commands.yaml @@ -1984,6 +1984,11 @@ TWITTER: |- $heap->{ 'twitterUsers' } = {}; } } + + if( $what =~ /^\s*$/ ) { + $kernel->post( $src, $replypath, "Usage: TWITTER ", $dest ); + return; + } if( exists( $heap->{ 'twitterUsers' }->{ uc( $who ) } ) ) { if( $heap->{ 'twitterUsers' }->{ uc( $who ) }->{ "state" } == 0 ) { @@ -2143,3 +2148,40 @@ VERSION: |- $page =~ m/

(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 ); + } -- 2.11.0