swearfilter

package module
v0.0.0-...-c7e8d20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2020 License: MIT Imports: 5 Imported by: 0

README

filch

Profanity filter forked from this one

GoDoc Go Report Card cover.run

A sanitization-based swear filter for Go.

Installing

go get github.com/cheddartv/filch

Example

package main

import (
	"fmt"

	swearfilter "github.com/cheddartv/filch"
)

var message = "This is a fûçking message with shitty swear words."
var swears = []string{"fuck", "shit"}

func main() {
	filter := swearfilter.New(false, false, false, false, false, swears...)
	swearFound, swearsFound, err := filter.Check(message)
	fmt.Println("Swear found: ", swearFound)
	fmt.Println("Swears tripped: ", swearsFound)
	fmt.Println("Error: ", err)
}
Output
> go run main.go
Swear found:  true
Swears tripped:  [fuck shit]
Error:  <nil>

License

The source code for filch is released under the MIT License. See LICENSE for more details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SwearFilter

type SwearFilter struct {
	//Options to tell the swear filter how to operate
	DisableNormalize                bool //Disables normalization of alphabetic characters if set to true (ex: à -> a)
	DisableSpacedTab                bool //Disables converting tabs to singular spaces (ex: [tab][tab] -> [space][space])
	DisableMultiWhitespaceStripping bool //Disables stripping down multiple whitespaces (ex: hello[space][space]world -> hello[space]world)
	DisableZeroWidthStripping       bool //Disables stripping zero-width spaces
	DisableSpacedBypass             bool //Disables testing for spaced bypasses (if hell is in filter, look for occurrences of h and detect only alphabetic characters that follow; ex: h[space]e[space]l[space]l[space] -> hell)

	BlacklistedWords []string //A list of words to blacklist
}

SwearFilter contains settings for the swear filter

func New

func New(disableNormalize, disableSpacedTab, disableMutliWhitespaceStripping, disableZeroWidthStripping, disableSpacedBypass bool, words ...string) (filter *SwearFilter)

New returns an initialized SwearFilter struct to check messages against

func (*SwearFilter) Check

func (filter *SwearFilter) Check(message string) (bool, []string, error)

Check checks if a message contains blacklisted words and returns whether or not it does, a list of blacklisted words if so, and any errors returned by external packages

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL