diff --git a/client.go b/client.go index 6e24178..2b925b2 100644 --- a/client.go +++ b/client.go @@ -444,6 +444,16 @@ func (client *Client) Target(kind string, name string) Target { return nil } +// Status gets the client's status target. +func (client *Client) Status() *Status { + target := client.Target("status", "Status") + if target == nil { + return nil + } + + return target.(*Status) +} + // Channel is a shorthand for getting a channel target and type asserting it. func (client *Client) Channel(name string) *Channel { target := client.Target("channel", name) diff --git a/cmd/ircrepl/ircrepl b/cmd/ircrepl/ircrepl new file mode 100755 index 0000000..db103a3 Binary files /dev/null and b/cmd/ircrepl/ircrepl differ diff --git a/cmd/ircrepl/main.go b/cmd/ircrepl/main.go new file mode 100644 index 0000000..4b0cedb --- /dev/null +++ b/cmd/ircrepl/main.go @@ -0,0 +1,58 @@ +package main + +import ( + "bufio" + "context" + "encoding/json" + "flag" + "fmt" + "os" + "strings" + + "git.aiterp.net/gisle/irc" +) + +var flagNick = flag.String("nick", "Test", "The client nick") +var flagAlts = flag.String("alts", "Test2,Test3,Test4,Test5", "Alternative nicks to use") +var flagUser = flag.String("user", "test", "The client user/ident") +var flagPass = flag.String("pass", "", "The server password") +var flagServer = flag.String("server", "localhost:6667", "The server to connect to") +var flagSsl = flag.Bool("ssl", false, "Wether to connect securely") + +func main() { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + flag.Parse() + + client := irc.New(ctx, irc.Config{ + Nick: *flagNick, + User: *flagUser, + Alternatives: strings.Split(*flagAlts, ","), + Password: *flagPass, + }) + + err := client.Connect(*flagServer, *flagSsl) + if err != nil { + fmt.Fprintf(os.Stderr, "Failed to connect: %s", err) + } + + irc.Handle(func(event *irc.Event, client *irc.Client) { + json, err := json.MarshalIndent(event, "", " ") + if err != nil { + return + } + + fmt.Println(string(json)) + }) + + reader := bufio.NewReader(os.Stdin) + for { + line, err := reader.ReadString('\n') + if err != nil { + break + } + + client.EmitInput(string(line[:len(line)-1]), client.Status()) + } +}