mirror of
https://github.com/gissleh/irc.git
synced 2026-09-29 00:05:34 +00:00
Started on 'irc repl', added Status() shorthand for client to get status target
This commit is contained in:
@@ -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)
|
||||
|
||||
Executable
BIN
Binary file not shown.
@@ -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())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user