summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--go/acronym.go33
1 files changed, 26 insertions, 7 deletions
diff --git a/go/acronym.go b/go/acronym.go
index ef92ef4..52c4323 100644
--- a/go/acronym.go
+++ b/go/acronym.go
@@ -8,7 +8,7 @@ import(
"net"
"os"
"regexp"
- //"strings"
+ "strings"
"time"
)
@@ -25,32 +25,51 @@ func main() {
defer dictfile.Close()
scanner := bufio.NewScanner( dictfile )
- scanner.Split(bufio.ScanLines)
+ scanner.Split( bufio.ScanLines )
dict := make( map[string][]string )
for scanner.Scan() {
- dict[scanner.Text()[:1]] = append(dict[scanner.Text()[:1]], scanner.Text())
+ dict[ strings.ToLower( scanner.Text()[:1] ) ] = append( dict[ strings.ToLower( scanner.Text()[:1] ) ], scanner.Text() )
}
- r := regexp.MustCompile( "^[0-9]{2}:[0-9]{2} <(.bungmonkey|.cornbugs|.wishapb|@[a-zA-Z0-9_]+)> +!cbk" )
+ 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})( |$)" )
bungr := regexp.MustCompile( "^[0-9]{2}:[0-9]{2} <.bungmonkey> +!cbk" )
- logfile, err := tail.TailFile( os.ExpandEnv( "${HOME}/irclogs/twitch/#cornbugs.log" ), tail.Config{ Follow: true, Location: &tail.SeekInfo{ 0, os.SEEK_END } } )
+ logfile, err := tail.TailFile( os.ExpandEnv( "${HOME}/irclogs/twitch/#bungmonkey.log" ), tail.Config{ Follow: true, Location: &tail.SeekInfo{ 0, os.SEEK_END } } )
check( err )
for logline := range logfile.Lines {
if bungr.MatchString( logline.Text ) {
time.Sleep( time.Second )
}
- if r.MatchString( logline.Text ) {
+ 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-cornbugs-socket" ) )
+ 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
+ var backronymstring string
+
+ commandarg = backronymr.FindStringSubmatch( logline.Text )
+ for _, char := range( commandarg[2] ) {
+ 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" ) )
+ check( err )
+ backronymstring = fmt.Sprintf( "%s\n", backronymstring )
+ byteswritten, err := ircsocket.Write( []byte( backronymstring ) )
+ ircsocket.Close()
+ fmt.Printf( "%v\n", backronymstring )
+ fmt.Printf( "%v bytes written\n", byteswritten )
+ }
}
}