swearfilter

package module
v0.0.0-...-1ff372c Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2020 License: MIT Imports: 5 Imported by: 0

README

gofuckyourself

GoDoc Go Report Card cover.run

A sanitization-based swear filter for Go.

Installing

go get github.com/JoshuaDoes/gofuckyourself

Example

package main

import (
	"fmt"

	swearfilter "github.com/JoshuaDoes/gofuckyourself"
)

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 gofuckyourself is released under the MIT License. See LICENSE for more details.

Donations

All donations are appreciated and help me stay awake at night to work on this more. Even if it's not much, it helps a lot in the long run!

Donate

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
	EnableSpacedBypass              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)

	//A list of words to check against the filters
	BadWords []string
}

SwearFilter contains settings for the swear filter

func NewSwearFilter

func NewSwearFilter(enableSpacedBypass bool, uhohwords ...string) (filter *SwearFilter)

NewSwearFilter returns an initialized SwearFilter struct to check messages against

func (*SwearFilter) Add

func (filter *SwearFilter) Add(badWords ...string)

Add appends the given word to the uhohwords list

func (*SwearFilter) Check

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

Check will return any words that trip an enabled swear filter, an error if any, or nothing if you've removed all the words for some reason

Jump to

Keyboard shortcuts

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