func main() { flag.Parse() client, err := dict.Dial("tcp", *addr) if err != nil { log.Fatal(err) } if *ls { dicts, err := client.Dicts() if err != nil { fmt.Fprintf(os.Stderr, "%v: %v\n", os.Args[0], err) os.Exit(1) } for _, dict := range dicts { fmt.Println(dict.Name + ":" + dict.Desc) } os.Exit(0) } for _, arg := range flag.Args() { defs, err := client.Define(*dn, arg) if err != nil { fmt.Fprintf(os.Stderr, "%v: %v\n", os.Args[0], err) os.Exit(1) } for _, def := range defs { fmt.Println(string(def.Text)) } } }
func main() { w, err := acme.New() if err != nil { log.Fatal(err) } w.Name("/dict/") d, err = dict.Dial("tcp", "216.93.242.2:dict") if err != nil { w.Write("body", []byte(err.Error())) return } w.Ctl("clean") go func() { dicts, err = d.Dicts() if err != nil { w.Write("body", []byte(err.Error())) return } for _, dict := range dicts { w.Fprintf("body", "%s\t%s\n", dict.Name, dict.Desc) } }() for word := range events(w) { go lookup(word) } }
//need to strip newlines within defs, server supplied format is stupid func Dictword(conn *irc.Connection, resp string, dn string, dword string) { c, err := dict.Dial("tcp", "dict.org:2628") if err != nil { fmt.Println(err) return } d, err := c.Define(dn, dword) c.Close() if len(d) <= 0 { conn.Privmsg(resp, "not found") } else { s := strings.Split(string(d[0].Text), "\n") i := 0 for _, v := range s { t := strings.TrimSpace(v) conn.Privmsgf(resp, t) time.Sleep(300 * time.Millisecond) i += 1 if i == 4 || i == 8 { time.Sleep(1 * time.Second) } if i == 10 { break } } } }
//need to strip newlines within defs, server supplied format is stupid func Dictword(conn *irc.Connection, channel string, dn string, dword string) { dconn, err := dict.Dial("tcp", "dict.org:2628") if err != nil { fmt.Println(err) return } dresult, err := dconn.Define(dn, dword) dconn.Close() if len(dresult) <= 0 { conn.Privmsg(channel, "not found") } else { s := strings.Split(string(dresult[0].Text), "\n") i := 0 for _, line := range s { t := strings.TrimSpace(line) conn.Privmsgf(channel, t) time.Sleep(300 * time.Millisecond) i += 1 if i == 4 || i == 8 { time.Sleep(1 * time.Second) } if i == 10 { break } } } }
func getDictClient() (*dict.Client, error) { client, err := dict.Dial("tcp", dictServer) if err != nil { log.Printf("Unable to connect to dict server at %s", dictServer) return nil, err } log.Println("Connected to", dictServer) return client, nil }