This repository was archived by the owner on Jan 22, 2025. It is now read-only.
File tree 2 files changed +29
-2
lines changed
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 {
85
85
continue
86
86
}
87
87
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 ) {
90
97
// Ack any AckRequests so that kssh can determine whether it has fully connected
91
98
_ , err = kbc .SendMessageByConvID (msg .Message .ConvID , shared .GenerateAckResponse (messageBody ))
92
99
if err != nil {
Original file line number Diff line number Diff line change @@ -80,3 +80,23 @@ func IsAckRequest(msg string) bool {
80
80
func IsAckResponse (msg string ) bool {
81
81
return strings .HasPrefix (msg , "Ack--" )
82
82
}
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