# antibot

> A simple auto-training spamfilter

Latest version **1.1.4** (published 2023-11-20) · ISC license · 0 weekly downloads

## Install

```sh
npm install antibot
pnpm add antibot
yarn add antibot
bun add antibot
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.4 |
| Published | 2023-11-20 |
| First published | 2023-09-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | thepicture |
| Maintainers | thepicture |
| Keywords | spam, filter, spamfilter, auto, training, bot |

## Links

- npm: https://www.npmjs.com/package/antibot
- Homepage: http://thepicture/spamfilter
- npm.io page: https://npm.io/package/antibot

## Recent versions

- 1.1.4 (latest) — 2023-11-20
- 1.1.3 — 2023-09-27
- 1.1.2 — 2023-09-26
- 1.1.1 — 2023-09-25
- 1.0.1 — 2023-09-24

## README

# antibot

```
A simple spamfilter with autotraining
```

## Install

```bash
npm i --save antibot
```

## Example

```js
const spamfilter = require("antibot");

const instance = spamfilter.create(["spam"], {
  onFiltered: (spam) =>
    spam.split(" ").flatMap((word) => [`_${word}_`, `-${word}-`]),
  skipOnFilteredOnInit: true,
});

const isSpam = instance.test("SPAM filter"); // true
const isSpamToo = instance.test("_FILTER_"); // true, because it trained from onFiltered call
```

## API

```js
const instance = instance.create();
```

Creates a new `Spamfilter` instance

```js
instance.test(content);
```

Returns `true` if spam detected, otherwise `false`.

By default will split words and lowercase them, banning those too. You might want to override the tactic with `onFiltered` second parameter of the `.create` method:

```js
const instance = spamfilter.create(["spam"], {
  onFiltered: (spam) =>
    spam.split(" ").flatMap((word) => [`_${word}_`, `-${word}-`]),
  skipOnFilteredOnInit: true,
});
```

`onFiltered` - function that predicts the new banned words derived from detected content

`skipOnFilteredOnInit` - the words passed in `.create()` method will not be transformed through `onFiltered` and leave intact

`onDetection` - overrides detection behavior

```js
const filter = spamfilter.create(["123"], {
  onDetection: (text, dict) => Object.keys(dict).length === text.length,
});

filter.test("3"); // true
```

```js
const tree = instance.explain();
```

Explains the reason of detection as a tree, e.g.

```js
{
  spam: {
    filter: {},
    test: {},
  },
  filter: {
    word: {},
  },
};
```

## Plugins

```js
const spamfilter = require("antibot");

class CustomPlugin extends spamfilter.Plugin {
  beforeFiltered(content: string) {
    // ... preprocessing returning string
    return content;
  }

  afterFiltered(contents: string[]) {
    // ... postprocessing returning string array
    return contents;
  }
}

const filter = spamfilter.create(...);

filter.inject(new CustomPlugin())
```

`beforeFiltered` fires before main intermediate processing as asserted in `Spamfilter` params `onFiltered`

`afterFiltered` fires after main intermediate processing as asserted in `Spamfilter` params `onFiltered`

`onDetection` of params takes precedence over `onDetection` of plugin(s)

## Predefined plugins

### Levenshtein

```js
const LevenshteinPlugin = require("antibot/plugins/LevenshteinPlugin");

const filter = spamfilter.create(["abcd"]);
filter.inject(new LevenshteinPlugin({ sensitivity: 1 }));

filter.test("abced");
```

### Nilsimsa

```js
const NilsimsaPlugin = require("antibot/plugins/NilsimsaPlugin");

const expected = true;

const filter = spamfilter.create(["1234 abcde"], {
  onFiltered: (exact) => [exact],
});
filter.inject(new NilsimsaPlugin({ from: 128, to: 128 }));

filter.test("1234 abcde");
```

## Test

```bash
npm test
```

---
_Source: https://npm.io/package/antibot · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
