diff options
author | Joe Rayhawk <jrayhawk@omgwallhack.org> | 2018-06-13 10:26:16 -0700 |
---|---|---|
committer | Joe Rayhawk <jrayhawk@omgwallhack.org> | 2018-06-13 10:26:16 -0700 |
commit | 8e4a48825ae67f61973922e836d4180dc576be97 (patch) | |
tree | 3564e2fe2fd93564313e61502c21d1f7a0c3b75e /go/acronym.go | |
parent | 1da7017cdcec48d1d199511ebb315c5460d7a9f6 (diff) | |
download | twitchtools-8e4a48825ae67f61973922e836d4180dc576be97.tar.gz twitchtools-8e4a48825ae67f61973922e836d4180dc576be97.zip |
acronym.go: generalizing first-letter indexing
Diffstat (limited to 'go/acronym.go')
-rw-r--r-- | go/acronym.go | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/go/acronym.go b/go/acronym.go index 955f256..ef92ef4 100644 --- a/go/acronym.go +++ b/go/acronym.go @@ -8,7 +8,7 @@ import( "net" "os" "regexp" - "strings" + //"strings" "time" ) @@ -26,19 +26,9 @@ func main() { defer dictfile.Close() scanner := bufio.NewScanner( dictfile ) scanner.Split(bufio.ScanLines) - var clines []string - var blines []string - var klines []string + dict := make( map[string][]string ) for scanner.Scan() { - if strings.HasPrefix( scanner.Text(), "c" ) { - clines = append(clines, scanner.Text()) - } - if strings.HasPrefix( scanner.Text(), "b" ) { - blines = append(blines, scanner.Text()) - } - if strings.HasPrefix( scanner.Text(), "k" ) { - klines = append(klines, scanner.Text()) - } + dict[scanner.Text()[:1]] = append(dict[scanner.Text()[:1]], scanner.Text()) } r := regexp.MustCompile( "^[0-9]{2}:[0-9]{2} <(.bungmonkey|.cornbugs|.wishapb|@[a-zA-Z0-9_]+)> +!cbk" ) @@ -52,7 +42,7 @@ func main() { } if r.MatchString( logline.Text ) { var cbk string - cbk = fmt.Sprintf( "%s %s %s\n", clines[ rand.Intn( len( clines ) ) ], blines[ rand.Intn( len( blines ) ) ], klines[ rand.Intn( len( klines ) ) ] ) + cbk = fmt.Sprintf( "%s %s %s\n", dict["c"][ rand.Intn( len( dict["c"] ) ) ], dict["b"][ rand.Intn( len( dict["b"] ) ) ], dict["k"][ rand.Intn( len( dict["k"] ) ) ] ) fmt.Printf( "%v", cbk ) ircsocket, err := net.Dial( "unix", os.ExpandEnv( "${HOME}/.irssi/twitch-cornbugs-socket" ) ) check( err ) |