add helper function to remove the bot name from messages
This commit is contained in:
parent
1c8f8fe2b0
commit
09ba1cade3
@ -55,6 +55,12 @@ func ToMe(user, message string) bool {
|
||||
return strings.Contains(message, u)
|
||||
}
|
||||
|
||||
// RemoveName removes the friendly name from a given message
|
||||
func RemoveName(user, message string) string {
|
||||
n := NameRE.ReplaceAllString(user, "$1")
|
||||
return strings.ReplaceAll(message, n + ": ", "")
|
||||
}
|
||||
|
||||
// HTTPRequest has the bits for making http requests
|
||||
type HTTPRequest struct {
|
||||
Client http.Client
|
||||
|
@ -20,6 +20,14 @@ func TestPluginsNameRE(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPluginsRemoveName(t *testing.T) {
|
||||
expected := "this is for you"
|
||||
n := RemoveName("mctest", fmt.Sprintf("mctest: %s", expected))
|
||||
if n != expected {
|
||||
t.Errorf("Expected %q; got %q\n", expected, n)
|
||||
}
|
||||
}
|
||||
|
||||
type testResp struct {
|
||||
Name string `json:"test"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user