Browse Source

Started on 'irc repl', added Status() shorthand for client to get status target

master
Gisle Aune 6 years ago
parent
commit
4945166148
  1. 10
      client.go
  2. BIN
      cmd/ircrepl/ircrepl
  3. 58
      cmd/ircrepl/main.go

10
client.go

@ -444,6 +444,16 @@ func (client *Client) Target(kind string, name string) Target {
return nil 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. // Channel is a shorthand for getting a channel target and type asserting it.
func (client *Client) Channel(name string) *Channel { func (client *Client) Channel(name string) *Channel {
target := client.Target("channel", name) target := client.Target("channel", name)

BIN
cmd/ircrepl/ircrepl

58
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())
}
}
Loading…
Cancel
Save