mirror of
https://github.com/cwinfo/matterbridge.git
synced 2024-11-22 21:50:28 +00:00
Update vendor lrstanley/girc
This commit is contained in:
parent
1ee6837f0e
commit
cc3c168162
2
vendor/github.com/lrstanley/girc/cap.go
generated
vendored
2
vendor/github.com/lrstanley/girc/cap.go
generated
vendored
@ -136,7 +136,7 @@ func handleCAP(c *Client, e Event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Let them know which ones we'd like to enable.
|
// Let them know which ones we'd like to enable.
|
||||||
c.write(&Event{Command: CAP, Params: []string{CAP_REQ}, Trailing: strings.Join(c.state.tmpCap, " ")})
|
c.write(&Event{Command: CAP, Params: []string{CAP_REQ}, Trailing: strings.Join(c.state.tmpCap, " "), EmptyTrailing: true})
|
||||||
|
|
||||||
// Re-initialize the tmpCap, so if we get multiple 'CAP LS' requests
|
// Re-initialize the tmpCap, so if we get multiple 'CAP LS' requests
|
||||||
// due to cap-notify, we can re-evaluate what we can support.
|
// due to cap-notify, we can re-evaluate what we can support.
|
||||||
|
61
vendor/github.com/lrstanley/girc/client.go
generated
vendored
61
vendor/github.com/lrstanley/girc/client.go
generated
vendored
@ -191,18 +191,6 @@ func (conf *Config) isValid() error {
|
|||||||
// connected.
|
// connected.
|
||||||
var ErrNotConnected = errors.New("client is not connected to server")
|
var ErrNotConnected = errors.New("client is not connected to server")
|
||||||
|
|
||||||
// ErrDisconnected is called when Config.Retries is less than 1, and we
|
|
||||||
// non-intentionally disconnected from the server.
|
|
||||||
var ErrDisconnected = errors.New("unexpectedly disconnected")
|
|
||||||
|
|
||||||
// ErrInvalidTarget should be returned if the target which you are
|
|
||||||
// attempting to send an event to is invalid or doesn't match RFC spec.
|
|
||||||
type ErrInvalidTarget struct {
|
|
||||||
Target string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *ErrInvalidTarget) Error() string { return "invalid target: " + e.Target }
|
|
||||||
|
|
||||||
// New creates a new IRC client with the specified server, name and config.
|
// New creates a new IRC client with the specified server, name and config.
|
||||||
func New(config Config) *Client {
|
func New(config Config) *Client {
|
||||||
c := &Client{
|
c := &Client{
|
||||||
@ -253,6 +241,37 @@ func (c *Client) String() string {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TLSConnectionState returns the TLS connection state from tls.Conn{}, which
|
||||||
|
// is useful to return needed TLS fingerprint info, certificates, verify cert
|
||||||
|
// expiration dates, etc. Will only return an error if the underlying
|
||||||
|
// connection wasn't established using TLS (see ErrConnNotTLS), or if the
|
||||||
|
// client isn't connected.
|
||||||
|
func (c *Client) TLSConnectionState() (*tls.ConnectionState, error) {
|
||||||
|
c.mu.RLock()
|
||||||
|
defer c.mu.RUnlock()
|
||||||
|
if c.conn == nil {
|
||||||
|
return nil, ErrNotConnected
|
||||||
|
}
|
||||||
|
|
||||||
|
c.conn.mu.RLock()
|
||||||
|
defer c.conn.mu.RUnlock()
|
||||||
|
|
||||||
|
if !c.conn.connected {
|
||||||
|
return nil, ErrNotConnected
|
||||||
|
}
|
||||||
|
|
||||||
|
if tlsConn, ok := c.conn.sock.(*tls.Conn); ok {
|
||||||
|
cs := tlsConn.ConnectionState()
|
||||||
|
return &cs, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, ErrConnNotTLS
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrConnNotTLS is returned when Client.TLSConnectionState() is called, and
|
||||||
|
// the connection to the server wasn't made with TLS.
|
||||||
|
var ErrConnNotTLS = errors.New("underlying connection is not tls")
|
||||||
|
|
||||||
// Close closes the network connection to the server, and sends a STOPPED
|
// Close closes the network connection to the server, and sends a STOPPED
|
||||||
// event. This should cause Connect() to return with nil. This should be
|
// event. This should cause Connect() to return with nil. This should be
|
||||||
// safe to call multiple times. See Connect()'s documentation on how
|
// safe to call multiple times. See Connect()'s documentation on how
|
||||||
@ -387,7 +406,7 @@ func (c *Client) ConnSince() (since *time.Duration, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IsConnected returns true if the client is connected to the server.
|
// IsConnected returns true if the client is connected to the server.
|
||||||
func (c *Client) IsConnected() (connected bool) {
|
func (c *Client) IsConnected() bool {
|
||||||
c.mu.RLock()
|
c.mu.RLock()
|
||||||
if c.conn == nil {
|
if c.conn == nil {
|
||||||
c.mu.RUnlock()
|
c.mu.RUnlock()
|
||||||
@ -395,7 +414,7 @@ func (c *Client) IsConnected() (connected bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c.conn.mu.RLock()
|
c.conn.mu.RLock()
|
||||||
connected = c.conn.connected
|
connected := c.conn.connected
|
||||||
c.conn.mu.RUnlock()
|
c.conn.mu.RUnlock()
|
||||||
c.mu.RUnlock()
|
c.mu.RUnlock()
|
||||||
|
|
||||||
@ -562,30 +581,30 @@ func (c *Client) NetworkName() (name string) {
|
|||||||
// supplied this information during connection. May be empty if the server
|
// supplied this information during connection. May be empty if the server
|
||||||
// does not support RPL_MYINFO. Will panic if used when tracking has been
|
// does not support RPL_MYINFO. Will panic if used when tracking has been
|
||||||
// disabled.
|
// disabled.
|
||||||
func (c *Client) ServerVersion() (version string) {
|
func (c *Client) ServerVersion() string {
|
||||||
c.panicIfNotTracking()
|
c.panicIfNotTracking()
|
||||||
|
|
||||||
version, _ = c.GetServerOption("VERSION")
|
version, _ := c.GetServerOption("VERSION")
|
||||||
|
|
||||||
return version
|
return version
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServerMOTD returns the servers message of the day, if the server has sent
|
// ServerMOTD returns the servers message of the day, if the server has sent
|
||||||
// it upon connect. Will panic if used when tracking has been disabled.
|
// it upon connect. Will panic if used when tracking has been disabled.
|
||||||
func (c *Client) ServerMOTD() (motd string) {
|
func (c *Client) ServerMOTD() string {
|
||||||
c.panicIfNotTracking()
|
c.panicIfNotTracking()
|
||||||
|
|
||||||
c.state.RLock()
|
c.state.RLock()
|
||||||
motd = c.state.motd
|
motd := c.state.motd
|
||||||
c.state.RUnlock()
|
c.state.RUnlock()
|
||||||
|
|
||||||
return motd
|
return motd
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lag is the latency between the server and the client. This is measured by
|
// Latency is the latency between the server and the client. This is measured
|
||||||
// determining the difference in time between when we ping the server, and
|
// by determining the difference in time between when we ping the server, and
|
||||||
// when we receive a pong.
|
// when we receive a pong.
|
||||||
func (c *Client) Lag() time.Duration {
|
func (c *Client) Latency() time.Duration {
|
||||||
c.mu.RLock()
|
c.mu.RLock()
|
||||||
c.conn.mu.RLock()
|
c.conn.mu.RLock()
|
||||||
delta := c.conn.lastPong.Sub(c.conn.lastPing)
|
delta := c.conn.lastPong.Sub(c.conn.lastPing)
|
||||||
|
10
vendor/github.com/lrstanley/girc/cmdhandler/cmd.go
generated
vendored
10
vendor/github.com/lrstanley/girc/cmdhandler/cmd.go
generated
vendored
@ -12,8 +12,9 @@ import (
|
|||||||
|
|
||||||
// Input is a wrapper for events, based around private messages.
|
// Input is a wrapper for events, based around private messages.
|
||||||
type Input struct {
|
type Input struct {
|
||||||
Origin *girc.Event
|
Origin *girc.Event
|
||||||
Args []string
|
Args []string
|
||||||
|
RawArgs string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command is an IRC command, supporting aliases, help documentation and easy
|
// Command is an IRC command, supporting aliases, help documentation and easy
|
||||||
@ -189,8 +190,9 @@ func (ch *CmdHandler) Execute(client *girc.Client, event girc.Event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
in := &Input{
|
in := &Input{
|
||||||
Origin: &event,
|
Origin: &event,
|
||||||
Args: args,
|
Args: args,
|
||||||
|
RawArgs: parsed[2],
|
||||||
}
|
}
|
||||||
|
|
||||||
go cmd.Fn(client, in)
|
go cmd.Fn(client, in)
|
||||||
|
240
vendor/github.com/lrstanley/girc/commands.go
generated
vendored
240
vendor/github.com/lrstanley/girc/commands.go
generated
vendored
@ -16,18 +16,13 @@ type Commands struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Nick changes the client nickname.
|
// Nick changes the client nickname.
|
||||||
func (cmd *Commands) Nick(name string) error {
|
func (cmd *Commands) Nick(name string) {
|
||||||
if !IsValidNick(name) {
|
|
||||||
return &ErrInvalidTarget{Target: name}
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.c.Send(&Event{Command: NICK, Params: []string{name}})
|
cmd.c.Send(&Event{Command: NICK, Params: []string{name}})
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Join attempts to enter a list of IRC channels, at bulk if possible to
|
// Join attempts to enter a list of IRC channels, at bulk if possible to
|
||||||
// prevent sending extensive JOIN commands.
|
// prevent sending extensive JOIN commands.
|
||||||
func (cmd *Commands) Join(channels ...string) error {
|
func (cmd *Commands) Join(channels ...string) {
|
||||||
// We can join multiple channels at once, however we need to ensure that
|
// We can join multiple channels at once, however we need to ensure that
|
||||||
// we are not exceeding the line length. (see maxLength)
|
// we are not exceeding the line length. (see maxLength)
|
||||||
max := maxLength - len(JOIN) - 1
|
max := maxLength - len(JOIN) - 1
|
||||||
@ -35,10 +30,6 @@ func (cmd *Commands) Join(channels ...string) error {
|
|||||||
var buffer string
|
var buffer string
|
||||||
|
|
||||||
for i := 0; i < len(channels); i++ {
|
for i := 0; i < len(channels); i++ {
|
||||||
if !IsValidChannel(channels[i]) {
|
|
||||||
return &ErrInvalidTarget{Target: channels[i]}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(buffer+","+channels[i]) > max {
|
if len(buffer+","+channels[i]) > max {
|
||||||
cmd.c.Send(&Event{Command: JOIN, Params: []string{buffer}})
|
cmd.c.Send(&Event{Command: JOIN, Params: []string{buffer}})
|
||||||
buffer = ""
|
buffer = ""
|
||||||
@ -53,91 +44,74 @@ func (cmd *Commands) Join(channels ...string) error {
|
|||||||
|
|
||||||
if i == len(channels)-1 {
|
if i == len(channels)-1 {
|
||||||
cmd.c.Send(&Event{Command: JOIN, Params: []string{buffer}})
|
cmd.c.Send(&Event{Command: JOIN, Params: []string{buffer}})
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// JoinKey attempts to enter an IRC channel with a password.
|
// JoinKey attempts to enter an IRC channel with a password.
|
||||||
func (cmd *Commands) JoinKey(channel, password string) error {
|
func (cmd *Commands) JoinKey(channel, password string) {
|
||||||
if !IsValidChannel(channel) {
|
|
||||||
return &ErrInvalidTarget{Target: channel}
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.c.Send(&Event{Command: JOIN, Params: []string{channel, password}})
|
cmd.c.Send(&Event{Command: JOIN, Params: []string{channel, password}})
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Part leaves an IRC channel.
|
// Part leaves an IRC channel.
|
||||||
func (cmd *Commands) Part(channel, message string) error {
|
func (cmd *Commands) Part(channels ...string) {
|
||||||
if !IsValidChannel(channel) {
|
for i := 0; i < len(channels); i++ {
|
||||||
return &ErrInvalidTarget{Target: channel}
|
cmd.c.Send(&Event{Command: PART, Params: []string{channels[i]}})
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.c.Send(&Event{Command: JOIN, Params: []string{channel}})
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PartMessage leaves an IRC channel with a specified leave message.
|
// PartMessage leaves an IRC channel with a specified leave message.
|
||||||
func (cmd *Commands) PartMessage(channel, message string) error {
|
func (cmd *Commands) PartMessage(channel, message string) {
|
||||||
if !IsValidChannel(channel) {
|
cmd.c.Send(&Event{Command: PART, Params: []string{channel}, Trailing: message, EmptyTrailing: true})
|
||||||
return &ErrInvalidTarget{Target: channel}
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.c.Send(&Event{Command: JOIN, Params: []string{channel}, Trailing: message})
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendCTCP sends a CTCP request to target. Note that this method uses
|
// SendCTCP sends a CTCP request to target. Note that this method uses
|
||||||
// PRIVMSG specifically.
|
// PRIVMSG specifically. ctcpType is the CTCP command, e.g. "FINGER", "TIME",
|
||||||
func (cmd *Commands) SendCTCP(target, ctcpType, message string) error {
|
// "VERSION", etc.
|
||||||
|
func (cmd *Commands) SendCTCP(target, ctcpType, message string) {
|
||||||
out := encodeCTCPRaw(ctcpType, message)
|
out := encodeCTCPRaw(ctcpType, message)
|
||||||
if out == "" {
|
if out == "" {
|
||||||
return errors.New("invalid CTCP")
|
panic(fmt.Sprintf("invalid CTCP: %s -> %s: %s", target, ctcpType, message))
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd.Message(target, out)
|
cmd.Message(target, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendCTCPf sends a CTCP request to target using a specific format. Note that
|
// SendCTCPf sends a CTCP request to target using a specific format. Note that
|
||||||
// this method uses PRIVMSG specifically.
|
// this method uses PRIVMSG specifically. ctcpType is the CTCP command, e.g.
|
||||||
func (cmd *Commands) SendCTCPf(target, ctcpType, format string, a ...interface{}) error {
|
// "FINGER", "TIME", "VERSION", etc.
|
||||||
return cmd.SendCTCP(target, ctcpType, fmt.Sprintf(format, a...))
|
func (cmd *Commands) SendCTCPf(target, ctcpType, format string, a ...interface{}) {
|
||||||
|
cmd.SendCTCP(target, ctcpType, fmt.Sprintf(format, a...))
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendCTCPReplyf sends a CTCP response to target using a specific format.
|
// SendCTCPReplyf sends a CTCP response to target using a specific format.
|
||||||
// Note that this method uses NOTICE specifically.
|
// Note that this method uses NOTICE specifically. ctcpType is the CTCP
|
||||||
func (cmd *Commands) SendCTCPReplyf(target, ctcpType, format string, a ...interface{}) error {
|
// command, e.g. "FINGER", "TIME", "VERSION", etc.
|
||||||
return cmd.SendCTCPReply(target, ctcpType, fmt.Sprintf(format, a...))
|
func (cmd *Commands) SendCTCPReplyf(target, ctcpType, format string, a ...interface{}) {
|
||||||
|
cmd.SendCTCPReply(target, ctcpType, fmt.Sprintf(format, a...))
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendCTCPReply sends a CTCP response to target. Note that this method uses
|
// SendCTCPReply sends a CTCP response to target. Note that this method uses
|
||||||
// NOTICE specifically.
|
// NOTICE specifically.
|
||||||
func (cmd *Commands) SendCTCPReply(target, ctcpType, message string) error {
|
func (cmd *Commands) SendCTCPReply(target, ctcpType, message string) {
|
||||||
out := encodeCTCPRaw(ctcpType, message)
|
out := encodeCTCPRaw(ctcpType, message)
|
||||||
if out == "" {
|
if out == "" {
|
||||||
return errors.New("invalid CTCP")
|
panic(fmt.Sprintf("invalid CTCP: %s -> %s: %s", target, ctcpType, message))
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd.Notice(target, out)
|
cmd.Notice(target, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Message sends a PRIVMSG to target (either channel, service, or user).
|
// Message sends a PRIVMSG to target (either channel, service, or user).
|
||||||
func (cmd *Commands) Message(target, message string) error {
|
func (cmd *Commands) Message(target, message string) {
|
||||||
if !IsValidNick(target) && !IsValidChannel(target) {
|
cmd.c.Send(&Event{Command: PRIVMSG, Params: []string{target}, Trailing: message, EmptyTrailing: true})
|
||||||
return &ErrInvalidTarget{Target: target}
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.c.Send(&Event{Command: PRIVMSG, Params: []string{target}, Trailing: message})
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Messagef sends a formated PRIVMSG to target (either channel, service, or
|
// Messagef sends a formated PRIVMSG to target (either channel, service, or
|
||||||
// user).
|
// user).
|
||||||
func (cmd *Commands) Messagef(target, format string, a ...interface{}) error {
|
func (cmd *Commands) Messagef(target, format string, a ...interface{}) {
|
||||||
return cmd.Message(target, fmt.Sprintf(format, a...))
|
cmd.Message(target, fmt.Sprintf(format, a...))
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrInvalidSource is returned when a method needs to know the origin of an
|
// ErrInvalidSource is returned when a method needs to know the origin of an
|
||||||
@ -146,94 +120,95 @@ func (cmd *Commands) Messagef(target, format string, a ...interface{}) error {
|
|||||||
var ErrInvalidSource = errors.New("event has nil or invalid source address")
|
var ErrInvalidSource = errors.New("event has nil or invalid source address")
|
||||||
|
|
||||||
// Reply sends a reply to channel or user, based on where the supplied event
|
// Reply sends a reply to channel or user, based on where the supplied event
|
||||||
// originated from. See also ReplyTo().
|
// originated from. See also ReplyTo(). Panics if the incoming event has no
|
||||||
func (cmd *Commands) Reply(event Event, message string) error {
|
// source.
|
||||||
|
func (cmd *Commands) Reply(event Event, message string) {
|
||||||
if event.Source == nil {
|
if event.Source == nil {
|
||||||
return ErrInvalidSource
|
panic(ErrInvalidSource)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(event.Params) > 0 && IsValidChannel(event.Params[0]) {
|
if len(event.Params) > 0 && IsValidChannel(event.Params[0]) {
|
||||||
return cmd.Message(event.Params[0], message)
|
cmd.Message(event.Params[0], message)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd.Message(event.Source.Name, message)
|
cmd.Message(event.Source.Name, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replyf sends a reply to channel or user with a format string, based on
|
// Replyf sends a reply to channel or user with a format string, based on
|
||||||
// where the supplied event originated from. See also ReplyTof().
|
// where the supplied event originated from. See also ReplyTof(). Panics if
|
||||||
func (cmd *Commands) Replyf(event Event, format string, a ...interface{}) error {
|
// the incoming event has no source.
|
||||||
return cmd.Reply(event, fmt.Sprintf(format, a...))
|
func (cmd *Commands) Replyf(event Event, format string, a ...interface{}) {
|
||||||
|
cmd.Reply(event, fmt.Sprintf(format, a...))
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReplyTo sends a reply to a channel or user, based on where the supplied
|
// ReplyTo sends a reply to a channel or user, based on where the supplied
|
||||||
// event originated from. ReplyTo(), when originating from a channel will
|
// event originated from. ReplyTo(), when originating from a channel will
|
||||||
// default to replying with "<user>, <message>". See also Reply().
|
// default to replying with "<user>, <message>". See also Reply(). Panics if
|
||||||
func (cmd *Commands) ReplyTo(event Event, message string) error {
|
// the incoming event has no source.
|
||||||
|
func (cmd *Commands) ReplyTo(event Event, message string) {
|
||||||
if event.Source == nil {
|
if event.Source == nil {
|
||||||
return ErrInvalidSource
|
panic(ErrInvalidSource)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(event.Params) > 0 && IsValidChannel(event.Params[0]) {
|
if len(event.Params) > 0 && IsValidChannel(event.Params[0]) {
|
||||||
return cmd.Message(event.Params[0], event.Source.Name+", "+message)
|
cmd.Message(event.Params[0], event.Source.Name+", "+message)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd.Message(event.Source.Name, message)
|
cmd.Message(event.Source.Name, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReplyTof sends a reply to a channel or user with a format string, based
|
// ReplyTof sends a reply to a channel or user with a format string, based
|
||||||
// on where the supplied event originated from. ReplyTo(), when originating
|
// on where the supplied event originated from. ReplyTo(), when originating
|
||||||
// from a channel will default to replying with "<user>, <message>". See
|
// from a channel will default to replying with "<user>, <message>". See
|
||||||
// also Replyf().
|
// also Replyf(). Panics if the incoming event has no source.
|
||||||
func (cmd *Commands) ReplyTof(event Event, format string, a ...interface{}) error {
|
func (cmd *Commands) ReplyTof(event Event, format string, a ...interface{}) {
|
||||||
return cmd.ReplyTo(event, fmt.Sprintf(format, a...))
|
cmd.ReplyTo(event, fmt.Sprintf(format, a...))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Action sends a PRIVMSG ACTION (/me) to target (either channel, service,
|
// Action sends a PRIVMSG ACTION (/me) to target (either channel, service,
|
||||||
// or user).
|
// or user).
|
||||||
func (cmd *Commands) Action(target, message string) error {
|
func (cmd *Commands) Action(target, message string) {
|
||||||
if !IsValidNick(target) && !IsValidChannel(target) {
|
|
||||||
return &ErrInvalidTarget{Target: target}
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.c.Send(&Event{
|
cmd.c.Send(&Event{
|
||||||
Command: PRIVMSG,
|
Command: PRIVMSG,
|
||||||
Params: []string{target},
|
Params: []string{target},
|
||||||
Trailing: fmt.Sprintf("\001ACTION %s\001", message),
|
Trailing: fmt.Sprintf("\001ACTION %s\001", message),
|
||||||
})
|
})
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actionf sends a formated PRIVMSG ACTION (/me) to target (either channel,
|
// Actionf sends a formated PRIVMSG ACTION (/me) to target (either channel,
|
||||||
// service, or user).
|
// service, or user).
|
||||||
func (cmd *Commands) Actionf(target, format string, a ...interface{}) error {
|
func (cmd *Commands) Actionf(target, format string, a ...interface{}) {
|
||||||
return cmd.Action(target, fmt.Sprintf(format, a...))
|
cmd.Action(target, fmt.Sprintf(format, a...))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notice sends a NOTICE to target (either channel, service, or user).
|
// Notice sends a NOTICE to target (either channel, service, or user).
|
||||||
func (cmd *Commands) Notice(target, message string) error {
|
func (cmd *Commands) Notice(target, message string) {
|
||||||
if !IsValidNick(target) && !IsValidChannel(target) {
|
cmd.c.Send(&Event{Command: NOTICE, Params: []string{target}, Trailing: message, EmptyTrailing: true})
|
||||||
return &ErrInvalidTarget{Target: target}
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.c.Send(&Event{Command: NOTICE, Params: []string{target}, Trailing: message})
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Noticef sends a formated NOTICE to target (either channel, service, or
|
// Noticef sends a formated NOTICE to target (either channel, service, or
|
||||||
// user).
|
// user).
|
||||||
func (cmd *Commands) Noticef(target, format string, a ...interface{}) error {
|
func (cmd *Commands) Noticef(target, format string, a ...interface{}) {
|
||||||
return cmd.Notice(target, fmt.Sprintf(format, a...))
|
cmd.Notice(target, fmt.Sprintf(format, a...))
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendRaw sends a raw string back to the server, without carriage returns
|
// SendRaw sends a raw string (or multiple) to the server, without carriage
|
||||||
// or newlines.
|
// returns or newlines. Returns an error if one of the raw strings cannot be
|
||||||
func (cmd *Commands) SendRaw(raw string) error {
|
// properly parsed.
|
||||||
e := ParseEvent(raw)
|
func (cmd *Commands) SendRaw(raw ...string) error {
|
||||||
if e == nil {
|
var event *Event
|
||||||
return errors.New("invalid event: " + raw)
|
|
||||||
|
for i := 0; i < len(raw); i++ {
|
||||||
|
event = ParseEvent(raw[i])
|
||||||
|
if event == nil {
|
||||||
|
return errors.New("invalid event: " + raw[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.c.Send(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.c.Send(e)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,31 +221,26 @@ func (cmd *Commands) SendRawf(format string, a ...interface{}) error {
|
|||||||
// Topic sets the topic of channel to message. Does not verify the length
|
// Topic sets the topic of channel to message. Does not verify the length
|
||||||
// of the topic.
|
// of the topic.
|
||||||
func (cmd *Commands) Topic(channel, message string) {
|
func (cmd *Commands) Topic(channel, message string) {
|
||||||
cmd.c.Send(&Event{Command: TOPIC, Params: []string{channel}, Trailing: message})
|
cmd.c.Send(&Event{Command: TOPIC, Params: []string{channel}, Trailing: message, EmptyTrailing: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Who sends a WHO query to the server, which will attempt WHOX by default.
|
// Who sends a WHO query to the server, which will attempt WHOX by default.
|
||||||
// See http://faerion.sourceforge.net/doc/irc/whox.var for more details. This
|
// See http://faerion.sourceforge.net/doc/irc/whox.var for more details. This
|
||||||
// sends "%tcuhnr,2" per default. Do not use "1" as this will conflict with
|
// sends "%tcuhnr,2" per default. Do not use "1" as this will conflict with
|
||||||
// girc's builtin tracking functionality.
|
// girc's builtin tracking functionality.
|
||||||
func (cmd *Commands) Who(target string) error {
|
func (cmd *Commands) Who(users ...string) {
|
||||||
if !IsValidNick(target) && !IsValidChannel(target) && !IsValidUser(target) {
|
for i := 0; i < len(users); i++ {
|
||||||
return &ErrInvalidTarget{Target: target}
|
cmd.c.Send(&Event{Command: WHO, Params: []string{users[i], "%tcuhnr,2"}})
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.c.Send(&Event{Command: WHO, Params: []string{target, "%tcuhnr,2"}})
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Whois sends a WHOIS query to the server, targeted at a specific user.
|
// Whois sends a WHOIS query to the server, targeted at a specific user (or
|
||||||
// as WHOIS is a bit slower, you may want to use WHO for brief user info.
|
// set of users). As WHOIS is a bit slower, you may want to use WHO for brief
|
||||||
func (cmd *Commands) Whois(nick string) error {
|
// user info.
|
||||||
if !IsValidNick(nick) {
|
func (cmd *Commands) Whois(users ...string) {
|
||||||
return &ErrInvalidTarget{Target: nick}
|
for i := 0; i < len(users); i++ {
|
||||||
|
cmd.c.Send(&Event{Command: WHOIS, Params: []string{users[i]}})
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.c.Send(&Event{Command: WHOIS, Params: []string{nick}})
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ping sends a PING query to the server, with a specific identifier that
|
// Ping sends a PING query to the server, with a specific identifier that
|
||||||
@ -294,36 +264,19 @@ func (cmd *Commands) Oper(user, pass string) {
|
|||||||
// Kick sends a KICK query to the server, attempting to kick nick from
|
// Kick sends a KICK query to the server, attempting to kick nick from
|
||||||
// channel, with reason. If reason is blank, one will not be sent to the
|
// channel, with reason. If reason is blank, one will not be sent to the
|
||||||
// server.
|
// server.
|
||||||
func (cmd *Commands) Kick(channel, nick, reason string) error {
|
func (cmd *Commands) Kick(channel, user, reason string) {
|
||||||
if !IsValidChannel(channel) {
|
|
||||||
return &ErrInvalidTarget{Target: channel}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !IsValidNick(nick) {
|
|
||||||
return &ErrInvalidTarget{Target: nick}
|
|
||||||
}
|
|
||||||
|
|
||||||
if reason != "" {
|
if reason != "" {
|
||||||
cmd.c.Send(&Event{Command: KICK, Params: []string{channel, nick}, Trailing: reason})
|
cmd.c.Send(&Event{Command: KICK, Params: []string{channel, user}, Trailing: reason, EmptyTrailing: true})
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.c.Send(&Event{Command: KICK, Params: []string{channel, nick}})
|
cmd.c.Send(&Event{Command: KICK, Params: []string{channel, user}})
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invite sends a INVITE query to the server, to invite nick to channel.
|
// Invite sends a INVITE query to the server, to invite nick to channel.
|
||||||
func (cmd *Commands) Invite(channel, nick string) error {
|
func (cmd *Commands) Invite(channel string, users ...string) {
|
||||||
if !IsValidChannel(channel) {
|
for i := 0; i < len(users); i++ {
|
||||||
return &ErrInvalidTarget{Target: channel}
|
cmd.c.Send(&Event{Command: INVITE, Params: []string{users[i], channel}})
|
||||||
}
|
}
|
||||||
|
|
||||||
if !IsValidNick(nick) {
|
|
||||||
return &ErrInvalidTarget{Target: nick}
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.c.Send(&Event{Command: INVITE, Params: []string{nick, channel}})
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Away sends a AWAY query to the server, suggesting that the client is no
|
// Away sends a AWAY query to the server, suggesting that the client is no
|
||||||
@ -348,10 +301,10 @@ func (cmd *Commands) Back() {
|
|||||||
// Supports multiple channels at once, in hopes it will reduce extensive
|
// Supports multiple channels at once, in hopes it will reduce extensive
|
||||||
// LIST queries to the server. Supply no channels to run a list against the
|
// LIST queries to the server. Supply no channels to run a list against the
|
||||||
// entire server (warning, that may mean LOTS of channels!)
|
// entire server (warning, that may mean LOTS of channels!)
|
||||||
func (cmd *Commands) List(channels ...string) error {
|
func (cmd *Commands) List(channels ...string) {
|
||||||
if len(channels) == 0 {
|
if len(channels) == 0 {
|
||||||
cmd.c.Send(&Event{Command: LIST})
|
cmd.c.Send(&Event{Command: LIST})
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// We can LIST multiple channels at once, however we need to ensure that
|
// We can LIST multiple channels at once, however we need to ensure that
|
||||||
@ -361,10 +314,6 @@ func (cmd *Commands) List(channels ...string) error {
|
|||||||
var buffer string
|
var buffer string
|
||||||
|
|
||||||
for i := 0; i < len(channels); i++ {
|
for i := 0; i < len(channels); i++ {
|
||||||
if !IsValidChannel(channels[i]) {
|
|
||||||
return &ErrInvalidTarget{Target: channels[i]}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(buffer+","+channels[i]) > max {
|
if len(buffer+","+channels[i]) > max {
|
||||||
cmd.c.Send(&Event{Command: LIST, Params: []string{buffer}})
|
cmd.c.Send(&Event{Command: LIST, Params: []string{buffer}})
|
||||||
buffer = ""
|
buffer = ""
|
||||||
@ -379,20 +328,13 @@ func (cmd *Commands) List(channels ...string) error {
|
|||||||
|
|
||||||
if i == len(channels)-1 {
|
if i == len(channels)-1 {
|
||||||
cmd.c.Send(&Event{Command: LIST, Params: []string{buffer}})
|
cmd.c.Send(&Event{Command: LIST, Params: []string{buffer}})
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Whowas sends a WHOWAS query to the server. amount is the amount of results
|
// Whowas sends a WHOWAS query to the server. amount is the amount of results
|
||||||
// you want back.
|
// you want back.
|
||||||
func (cmd *Commands) Whowas(nick string, amount int) error {
|
func (cmd *Commands) Whowas(user string, amount int) {
|
||||||
if !IsValidNick(nick) {
|
cmd.c.Send(&Event{Command: WHOWAS, Params: []string{user, string(amount)}})
|
||||||
return &ErrInvalidTarget{Target: nick}
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.c.Send(&Event{Command: WHOWAS, Params: []string{nick, string(amount)}})
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
5
vendor/github.com/lrstanley/girc/format.go
generated
vendored
5
vendor/github.com/lrstanley/girc/format.go
generated
vendored
@ -233,6 +233,7 @@ func IsValidNick(nick string) bool {
|
|||||||
|
|
||||||
for i := 1; i < len(nick); i++ {
|
for i := 1; i < len(nick); i++ {
|
||||||
if (nick[i] < 0x41 || nick[i] > 0x7D) && (nick[i] < 0x30 || nick[i] > 0x39) && nick[i] != 0x2D {
|
if (nick[i] < 0x41 || nick[i] > 0x7D) && (nick[i] < 0x30 || nick[i] > 0x39) && nick[i] != 0x2D {
|
||||||
|
fmt.Println(nick[i], i, nick)
|
||||||
// a-z, A-Z, 0-9, -, and _\[]{}^|
|
// a-z, A-Z, 0-9, -, and _\[]{}^|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -291,7 +292,9 @@ func IsValidUser(name string) bool {
|
|||||||
// ToRFC1459 converts a string to the stripped down conversion within RFC
|
// ToRFC1459 converts a string to the stripped down conversion within RFC
|
||||||
// 1459. This will do things like replace an "A" with an "a", "[]" with "{}",
|
// 1459. This will do things like replace an "A" with an "a", "[]" with "{}",
|
||||||
// and so forth. Useful to compare two nicknames or channels.
|
// and so forth. Useful to compare two nicknames or channels.
|
||||||
func ToRFC1459(input string) (out string) {
|
func ToRFC1459(input string) string {
|
||||||
|
var out string
|
||||||
|
|
||||||
for i := 0; i < len(input); i++ {
|
for i := 0; i < len(input); i++ {
|
||||||
if input[i] >= 65 && input[i] <= 94 {
|
if input[i] >= 65 && input[i] <= 94 {
|
||||||
out += string(rune(input[i]) + 32)
|
out += string(rune(input[i]) + 32)
|
||||||
|
2
vendor/manifest
vendored
2
vendor/manifest
vendored
@ -282,7 +282,7 @@
|
|||||||
"importpath": "github.com/lrstanley/girc",
|
"importpath": "github.com/lrstanley/girc",
|
||||||
"repository": "https://github.com/lrstanley/girc",
|
"repository": "https://github.com/lrstanley/girc",
|
||||||
"vcs": "git",
|
"vcs": "git",
|
||||||
"revision": "055075db54ebd311be5946efb3f62502846089ff",
|
"revision": "e698f0468e166574e122130ffd2f579aba7e2abc",
|
||||||
"branch": "master",
|
"branch": "master",
|
||||||
"notests": true
|
"notests": true
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user