Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/keybaseca/bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,15 @@ func StartBot(conf config.Config) error {
continue
}

if shared.IsAckRequest(messageBody) {
log.Debug("Responding to AckMessage")
if shared.IsPingRequest(messageBody, kbc.GetUsername()) {
// Respond to messages of the form `ping @botName` with `pong @senderName`
log.Debug("Responding to ping with pong")
_, err = kbc.SendMessageByConvID(msg.Message.ConvID, fmt.Sprintf(shared.GeneratePingResponse(msg.Message.Sender.Username)))
if err != nil {
LogError(conf, kbc, msg, err)
continue
}
} else if shared.IsAckRequest(messageBody) {
// Ack any AckRequests so that kssh can determine whether it has fully connected
_, err = kbc.SendMessageByConvID(msg.Message.ConvID, shared.GenerateAckResponse(messageBody))
if err != nil {
Expand Down
20 changes: 20 additions & 0 deletions src/shared/chat_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,23 @@ func IsAckRequest(msg string) bool {
func IsAckResponse(msg string) bool {
return strings.HasPrefix(msg, "Ack--")
}

// Generate a ping request message
func GeneratePingRequest(botname string) string {
return fmt.Sprintf("ping @%s", botname)
}

// Returns whether the given message is a ping request
func IsPingRequest(msg, botUsername string) bool {
return strings.TrimSpace(msg) == fmt.Sprintf("ping @%s", botUsername)
}

// Generate a ping response message
func GeneratePingResponse(botname string) string {
return fmt.Sprintf("pong @%s", botname)
}

// Returns whether the given message is a ping response
func IsPingResponse(msg, localUsername string) bool {
return strings.TrimSpace(msg) == fmt.Sprintf("pong @%s", localUsername)
}