diff options
author | Joe Rayhawk <jrayhawk@action.fairlystable.org> | 2019-08-07 02:44:36 -0700 |
---|---|---|
committer | Joe Rayhawk <jrayhawk@action.fairlystable.org> | 2019-08-07 02:45:01 -0700 |
commit | c11cd7da47327b423f40c9cd54d2c8f9612cea5a (patch) | |
tree | 896e433398164b6ab171f7dd5c27671d117223aa /go | |
parent | 11a1bb42f5953fd25bd822d4823342f49ddbb870 (diff) | |
download | twitchtools-c11cd7da47327b423f40c9cd54d2c8f9612cea5a.tar.gz twitchtools-c11cd7da47327b423f40c9cd54d2c8f9612cea5a.zip |
go/acronym.go: remove !cbk command, add german !akronym command
Diffstat (limited to 'go')
-rw-r--r-- | go/acronym.go | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/go/acronym.go b/go/acronym.go index 52c4323..b6ead6b 100644 --- a/go/acronym.go +++ b/go/acronym.go @@ -31,8 +31,19 @@ func main() { dict[ strings.ToLower( scanner.Text()[:1] ) ] = append( dict[ strings.ToLower( scanner.Text()[:1] ) ], scanner.Text() ) } - cbkr := regexp.MustCompile( "^[0-9]{2}:[0-9]{2} <(.bungmonkey|.cornbugs|.wishapb|@[a-zA-Z0-9_]+)> +!cbk" ) - backronymr := regexp.MustCompile( "^[0-9]{2}:[0-9]{2} <(.bungmonkey|.cornbugs|.wishapb|.nottobiii|@[a-zA-Z0-9_]+)> +!backronym ([a-zA-Z]{1,12})( |$)" ) + gdictfile, err := os.Open( "/usr/share/dict/ngerman" ) + check( err ) + + defer gdictfile.Close() + gscanner := bufio.NewScanner( gdictfile ) + gscanner.Split( bufio.ScanLines ) + gdict := make( map[string][]string ) + for gscanner.Scan() { + gdict[ strings.ToLower( gscanner.Text()[:1] ) ] = append( gdict[ strings.ToLower( gscanner.Text()[:1] ) ], gscanner.Text() ) + } + + backronymr := regexp.MustCompile( "^[0-9]{2}:[0-9]{2} <(.bungmonkey|.cornbugs|.wishapb|.ameera|.bungmonkey|.nottobiii|.sash_isynergy|@[a-zA-Z0-9_]+)> +!backronym ([a-zA-Z]{1,12})( |$)" ) + akronymr := regexp.MustCompile( "^[0-9]{2}:[0-9]{2} <(.bungmonkey|.cornbugs|.wishapb|.ameera|.bungmonkey|.nottobiii|.sash_isynergy|@[a-zA-Z0-9_]+)> +!akronym ([a-zA-Z]{1,12})( |$)" ) bungr := regexp.MustCompile( "^[0-9]{2}:[0-9]{2} <.bungmonkey> +!cbk" ) logfile, err := tail.TailFile( os.ExpandEnv( "${HOME}/irclogs/twitch/#bungmonkey.log" ), tail.Config{ Follow: true, Location: &tail.SeekInfo{ 0, os.SEEK_END } } ) check( err ) @@ -41,17 +52,6 @@ func main() { if bungr.MatchString( logline.Text ) { time.Sleep( time.Second ) } - if cbkr.MatchString( logline.Text ) { - var cbk string - 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-bungmonkey-socket" ) ) - check( err ) - byteswritten, err := ircsocket.Write( []byte( cbk ) ) - ircsocket.Close() - check( err ) - fmt.Printf( "%v bytes written\n", byteswritten ) - } if backronymr.MatchString( logline.Text ) { var commandarg []string var backronymarr []string @@ -62,14 +62,32 @@ func main() { backronymarr = append( backronymarr, dict[ strings.ToLower( string( char ) )][ rand.Intn( len( dict[ strings.ToLower( string( char ) ) ] ) ) ] ) } backronymstring = strings.Join( backronymarr, " " ) - ircsocket, err := net.Dial( "unix", os.ExpandEnv( "${HOME}/.irssi/twitch-bungmonkey-socket" ) ) + ircsocket, err := net.Dial( "unix", os.ExpandEnv( "${HOME}/.irssi/twitch-socket" ) ) check( err ) - backronymstring = fmt.Sprintf( "%s\n", backronymstring ) + backronymstring = fmt.Sprintf( "#bungmonkey %s\n", backronymstring ) byteswritten, err := ircsocket.Write( []byte( backronymstring ) ) ircsocket.Close() fmt.Printf( "%v\n", backronymstring ) fmt.Printf( "%v bytes written\n", byteswritten ) } + if akronymr.MatchString( logline.Text ) { + var gcommandargg []string + var gbackronymarr []string + var gbackronymstring string + + gcommandargg = akronymr.FindStringSubmatch( logline.Text ) + for _, char := range( gcommandargg[2] ) { + gbackronymarr = append( gbackronymarr, gdict[ strings.ToLower( string( char ) )][ rand.Intn( len( gdict[ strings.ToLower( string( char ) ) ] ) ) ] ) + } + gbackronymstring = strings.Join( gbackronymarr, " " ) + ircsocket, err := net.Dial( "unix", os.ExpandEnv( "${HOME}/.irssi/twitch-socket" ) ) + check( err ) + gbackronymstring = fmt.Sprintf( "#bungmonkey %s\n", gbackronymstring ) + byteswritten, err := ircsocket.Write( []byte( gbackronymstring ) ) + ircsocket.Close() + fmt.Printf( "%v\n", gbackronymstring ) + fmt.Printf( "%v bytes written\n", byteswritten ) + } } } |