revamp TODO's; add Client.Join() and Client.Part()
This commit is contained in:
parent
eb547066fa
commit
07d9aac94f
@ -22,7 +22,9 @@ func main() {
|
||||
|
||||
client := girc.New(conf)
|
||||
|
||||
client.AddCallback(girc.CONNECTED, registerConnect)
|
||||
client.AddCallback(girc.CONNECTED, func(c *girc.Client, e girc.Event) {
|
||||
c.Join("#dev", "")
|
||||
})
|
||||
|
||||
if err := client.Connect(); err != nil {
|
||||
log.Fatalf("an error occurred while attempting to connect: %s", err)
|
||||
@ -30,13 +32,3 @@ func main() {
|
||||
|
||||
client.Wait()
|
||||
}
|
||||
|
||||
func registerConnect(c *girc.Client, e girc.Event) {
|
||||
c.Send(&girc.Event{Command: girc.JOIN, Params: []string{"#dev"}})
|
||||
|
||||
// go func() {
|
||||
// time.Sleep(5 * time.Second)
|
||||
|
||||
// c.Quit("This is a test!")
|
||||
// }()
|
||||
}
|
||||
|
@ -2,9 +2,6 @@ package girc
|
||||
|
||||
import "time"
|
||||
|
||||
// TODO: would be cool to track things like SERVERNAME, VERSION, UMODES, CMODES, etc.
|
||||
// -- https://github.com/Liamraystanley/Code/blob/master/core/triggers.py#L40-L67
|
||||
|
||||
func (c *Client) registerHelpers() {
|
||||
c.AddBgCallback(SUCCESS, handleWelcome)
|
||||
c.AddCallback(PING, handlePING)
|
||||
@ -50,7 +47,6 @@ func nickCollisionHandler(c *Client, e Event) {
|
||||
|
||||
// handlePING helps respond to ping requests from the server
|
||||
func handlePING(c *Client, e Event) {
|
||||
// TODO: we should be sending pings too.
|
||||
c.Send(&Event{Command: PONG, Params: e.Params, Trailing: e.Trailing})
|
||||
}
|
||||
|
||||
|
31
main.go
31
main.go
@ -12,7 +12,16 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// TODO: See all todos!
|
||||
// TODO's:
|
||||
// * needs PRIVMSG (Msg?), ACTION (Me? Action?), NOTICE (Notice?), SendRaw?
|
||||
// * ClearCallbacks()
|
||||
// * ClearCallback(CODE)
|
||||
// * RunCallbacks(Event)
|
||||
// * track connection time (conntime? in state)
|
||||
// * would be cool to track things like SERVERNAME, VERSION, UMODES, CMODES, etc.
|
||||
// -- https://github.com/Liamraystanley/Code/blob/master/core/triggers.py#L40-L67
|
||||
// * client should support ping tracking (sending PING's to the server)
|
||||
// * users need to be exposed in state somehow (other than GetChannels())
|
||||
|
||||
// Client contains all of the information necessary to run a single IRC client
|
||||
type Client struct {
|
||||
@ -271,3 +280,23 @@ func (c *Client) GetChannels() map[string]*Channel {
|
||||
func (c *Client) Who(target string) {
|
||||
c.Send(&Event{Command: WHO, Params: []string{target, "%tcuhn,1"}})
|
||||
}
|
||||
|
||||
// Join attempts to enter an IRC channel with an optional password
|
||||
func (c *Client) Join(channel, password string) {
|
||||
if password != "" {
|
||||
c.Send(&Event{Command: JOIN, Params: []string{channel, password}})
|
||||
return
|
||||
}
|
||||
|
||||
c.Send(&Event{Command: JOIN, Params: []string{channel}})
|
||||
}
|
||||
|
||||
// Part leaves an IRC channel with an optional leave message
|
||||
func (c *Client) Part(channel, message string) {
|
||||
if message != "" {
|
||||
c.Send(&Event{Command: JOIN, Params: []string{channel}, Trailing: message})
|
||||
return
|
||||
}
|
||||
|
||||
c.Send(&Event{Command: JOIN, Params: []string{channel}})
|
||||
}
|
||||
|
3
state.go
3
state.go
@ -6,8 +6,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// TODO: conntime, uptime
|
||||
|
||||
// State represents the actively-changing variables within the client runtime
|
||||
type State struct {
|
||||
m sync.RWMutex // lock, primarily used for writing things in state
|
||||
@ -26,7 +24,6 @@ type User struct {
|
||||
|
||||
// Channel represents an IRC channel and the state attached to it
|
||||
type Channel struct {
|
||||
// TODO: users needs to be exposed
|
||||
Name string // name of the channel, always lowercase
|
||||
users map[string]*User
|
||||
Joined time.Time // when the channel was joined
|
||||
|
Loading…
Reference in New Issue
Block a user