This repository was archived by the owner on Jan 22, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed
Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -85,8 +85,15 @@ func StartBot(conf config.Config) error {
8585 continue
8686 }
8787
88- if shared .IsAckRequest (messageBody ) {
89- log .Debug ("Responding to AckMessage" )
88+ if shared .IsPingRequest (messageBody , kbc .GetUsername ()) {
89+ // Respond to messages of the form `ping @botName` with `pong @senderName`
90+ log .Debug ("Responding to ping with pong" )
91+ _ , err = kbc .SendMessageByConvID (msg .Message .ConvID , fmt .Sprintf (shared .GeneratePingResponse (msg .Message .Sender .Username )))
92+ if err != nil {
93+ LogError (conf , kbc , msg , err )
94+ continue
95+ }
96+ } else if shared .IsAckRequest (messageBody ) {
9097 // Ack any AckRequests so that kssh can determine whether it has fully connected
9198 _ , err = kbc .SendMessageByConvID (msg .Message .ConvID , shared .GenerateAckResponse (messageBody ))
9299 if err != nil {
Original file line number Diff line number Diff line change @@ -80,3 +80,23 @@ func IsAckRequest(msg string) bool {
8080func IsAckResponse (msg string ) bool {
8181 return strings .HasPrefix (msg , "Ack--" )
8282}
83+
84+ // Generate a ping request message
85+ func GeneratePingRequest (botname string ) string {
86+ return fmt .Sprintf ("ping @%s" , botname )
87+ }
88+
89+ // Returns whether the given message is a ping request
90+ func IsPingRequest (msg , botUsername string ) bool {
91+ return strings .TrimSpace (msg ) == fmt .Sprintf ("ping @%s" , botUsername )
92+ }
93+
94+ // Generate a ping response message
95+ func GeneratePingResponse (botname string ) string {
96+ return fmt .Sprintf ("pong @%s" , botname )
97+ }
98+
99+ // Returns whether the given message is a ping response
100+ func IsPingResponse (msg , localUsername string ) bool {
101+ return strings .TrimSpace (msg ) == fmt .Sprintf ("pong @%s" , localUsername )
102+ }
You can’t perform that action at this time.
0 commit comments