@keiranlovett Good question, you’re on the right track. There are two message types you probably want to hook into: ChannelMessageSend
(this is the main one) and ChannelMessageUpdate
(only if your game clients use it).
In these hooks you should inspect the incoming message or send it to a profanity verification service, and either sanitise the text or reject the message.
I’m not sure which runtime you plan to use, but here’s an example of a Go runtime before hook that would reject bad messages.
// Inside your Go module's `InitModule` function.
if err := initializer.RegisterBeforeRt("ChannelMessageSend", func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, envelope *rtapi.Envelope) (*rtapi.Envelope, error) {
message := envelope.GetChannelMessageSend()
if strings.Contains(message.Content, "bad word") {
// Alternatively, to sanitise instead of reject:
// message.Content = strings.ReplaceAll(message.Content, "bad word", "****")
// Reject the message send:
return nil, runtime.NewError("profanity detected", 3)
}
return envelope, nil
}); err != nil {
return err
}