spam

package
v0.0.0-...-41aa9aa Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLinkSpamKickUser = errors.New(
		`<strong>Spam Detected:</strong> ` +
			`You have pasted the same URL link to too many different people in a row, and this has been flagged as spam.<br><br>` +
			`You will now be kicked from the chat room. You may refresh and log back in, however, if you continue to spam this ` +
			`link one more time, you <strong>will be temporarily banned from the chat room.</strong>`,
	)
	ErrLinkSpamBanUser = errors.New(
		`<strong>Spam Detected:</strong> ` +
			`You recently were kicked from the chat room because you had already pasted this link to too many different people. ` +
			`You were warned that spamming this link one more time would result in a temporary ban from the chat room.<br><br>` +
			`<strong>You are now (temporarily) banned from the chat room.</strong>`,
	)
)

Sentinel errors returned from LinkSpamMan.Check().

View Source
var HyperlinkRegexp = regexp.MustCompile(`(?:http[s]?:\/\/.)?(?:www\.)?[-a-zA-Z0-9@%._\+~#=]{2,256}\.[a-z]{2,6}\b(?:[-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)`)

Functions

func Hash

func Hash(input []byte) string

Hash a byte array as SHA256 and returns the hex string.

Types

type LinkSpam

type LinkSpam struct {
	Username  string
	URL       string
	SentTo    map[string]struct{} // Usernames they have sent it to
	FirstSent time.Time           // time of the first link
	LastSent  time.Time           // time of the most recently sent link
	Lock      sync.RWMutex
	Kicked    bool // user was kicked once for this spam
}

LinkSpam holds info about possibly spammy hyperlinks that Username has sent to multiple others over Direct Messages, to detect e.g. somebody spamming a link to their off-site video conference to everybody on chat while hiding from moderators and public channels.

type LinkSpamMap

type LinkSpamMap map[string]UserLinkMap

LinkSpamMap keeps track of link spamming behavior per username.

It is a map of usernames to their recent history of hyperlinks sent to other usernames over DMs. The intention is to detect when one user is spamming (copy/pasting) the same hyperlink to many many people over DMs, e.g., if they are trying to take the whole chat room away to a competing video conference and they are sending the link by DM to everybody on chat in order to hide from the moderators by not using the public channels.

var (
	LinkSpamManager LinkSpamMap
)

LinkSpamManager is the singleton global instance variable that checks and tracks link spam sent by users on chat. It is initialized at server startup and provides an API surface area to ping and test for spammy behavior from users.

func (LinkSpamMap) Check

func (m LinkSpamMap) Check(sourceUsername, targetUsername, message string) error

Check if the current user has been spamming a link to too many people over DMs.

This function will parse the message for any hyperlinks, and upsert/ping the sourceUsername's spam detection struct.

If the user has pasted the same hyperlink into too many different DM threads, this function may return one of two sentinel errors:

- ErrLinkSpamKickUser if the user should be kicked from the room. - ErrLinkSpamBanUser if the user should be banned from the room.

The first time they trip the spam limit they are to be kicked, but if they rejoin the chat and (still within the spam duration window), paste the same link to yet another recipient they will be banned temporarily from chat.

type UserLinkMap

type UserLinkMap map[string]*LinkSpam

UserLinkMap connects usernames to the set of distinct links they have sent.

It is a map of the URL hash to the LinkSpam data struct.

Jump to

Keyboard shortcuts

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