snooker 0.1.0

Snooker is a pure-Rust implementation of Jonathan Snook's spam detection algorithm for blog comments
Documentation
  • Coverage
  • 81.25%
    13 out of 16 items documented1 out of 4 items with examples
  • Size
  • Source code size: 26.51 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.31 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 17s Average build duration of successful builds.
  • all releases: 17s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • elliotekj/snooker
    6 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • elliotekj

Snooker - Lightweight spam detection for blog comments

Crates.io Docs License

This crate provides a pure-Rust implementation of Jonathan Snook's spam detection algorithm for blog comments.

As described in the afore-linked post, it works on a points system. Points are awarded and deducted based on a variety of rules. If a comments final score is greater than or equal to 1, the comment is considered valid. If the comments final score is 0 then it's considered to be worth of moderating. If the comments final score is below 0 then it's considered to be spam. Each comment starts with a score of 0.

Installation

If you're using Cargo, just add Snooker to your Cargo.toml:

[dependencies]
snooker = "0.1.0"

Example

Snooker gives the example comment below a score of -10 based off of the following patterns:

  • The body has less that 2 links in it: +2 points
  • The body is more that 20 characters long but contains 1 link: +1 point
  • The link in the body contains one keyword considered spammy ("free"): -1 point
  • The body contains one phrase considered spammy ("limited time only"): -1 point
  • The body starts with a word considered spammy when it's the first word of the comment ("nice"): -10 points
  • The author field doesn't contain http:// or https://: +0 points (unchanged)
  • The url field contains a keyword considered spammy ("free"): -1 point
  • None of the URLs use a TLD considered spammy: +0 points (unchanged)
  • None of the URLs are longer that 30 characters: +0 points (unchanged)
  • No consonant groups were found: +0 points (unchanged)
  • No data was provided about the comments previously submitted with this email address: +0 points (unchanged)
use snooker::{Comment, Snooker, Status};

let comment = Comment {
    author: Some("Johnny B. Goode".to_string()),
    url: Some("http://my-free-ebook.com".to_string()),
    body: String::from("
        <p>Nice post! Check out our free (for a limited time only) eBook
        <a href=\"http://my-free-ebook.com\">here</a> that's totally relevant</p>
    "),
    previously_accepted_for_email: None,
    previously_rejected_for_email: None,
    previous_comment_bodies: None,
};

let snooker_result = Snooker::new(comment);
assert_eq!(snooker_result.score, -10);
assert_eq!(snooker_result.status, Status::Spam);

License

Snooker is released under the MIT LICENSE.

About

This crate was written by Elliot Jackson.