Skip to content

Commit

Permalink
fix: only reply to CTCP message if it's not a reply message itself (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
heavyjoost authored Aug 23, 2024
1 parent d46f28e commit 80555f2
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion ctcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (c *CTCP) call(client *Client, event *CTCPEvent) {
}

// Send a ERRMSG reply, if we know who sent it.
if event.Source != nil && IsValidNick(event.Source.ID()) {
if !event.Reply && event.Source != nil && IsValidNick(event.Source.ID()) {
client.Cmd.SendCTCPReply(event.Source.ID(), CTCP_ERRMSG, "that is an unknown CTCP query")
}
return
Expand Down Expand Up @@ -263,6 +263,10 @@ func handleCTCPPong(client *Client, ctcp CTCPEvent) {
// as the os type (darwin, linux, windows, etc) and architecture type (x86,
// arm, etc).
func handleCTCPVersion(client *Client, ctcp CTCPEvent) {
if ctcp.Reply {
return
}

if client.Config.Version != "" {
client.Cmd.SendCTCPReply(ctcp.Source.ID(), CTCP_VERSION, client.Config.Version)
return
Expand All @@ -277,18 +281,30 @@ func handleCTCPVersion(client *Client, ctcp CTCPEvent) {

// handleCTCPSource replies with the public git location of this library.
func handleCTCPSource(client *Client, ctcp CTCPEvent) {
if ctcp.Reply {
return
}

client.Cmd.SendCTCPReply(ctcp.Source.ID(), CTCP_SOURCE, "https://github.com/lrstanley/girc")
}

// handleCTCPTime replies with a RFC 1123 (Z) formatted version of Go's
// local time.
func handleCTCPTime(client *Client, ctcp CTCPEvent) {
if ctcp.Reply {
return
}

client.Cmd.SendCTCPReply(ctcp.Source.ID(), CTCP_TIME, ":"+time.Now().Format(time.RFC1123Z))
}

// handleCTCPFinger replies with the realname and idle time of the user. This
// is obsoleted by improvements to the IRC protocol, however still supported.
func handleCTCPFinger(client *Client, ctcp CTCPEvent) {
if ctcp.Reply {
return
}

client.conn.mu.RLock()
active := client.conn.lastActive
client.conn.mu.RUnlock()
Expand Down

0 comments on commit 80555f2

Please sign in to comment.