abstract class PrivateParlorXT::Robot9000

Overview

A base class for ROBOT9000 implementations

ROBOT9000 is an algorithm by Randall Munroe designed to reduce noise in large chats and encourage original content.

ROBOT9000 will prevent users from repeating information that has already been posted before. When a user's post is considered unoriginal, the post will not be sent and the user will be cooldowned.

Subclasses of this type should use a Database to store and query unique texts and media IDs

Direct Known Subclasses

Defined in:

private-parlor-xt/robot9000/robot9000.cr

Instance Method Summary

Instance Method Detail

abstract def add_file_id(id : String) : Nil #

Stores the file id to be referenced later


[View source]
abstract def add_line(text : String) : Nil #

Stores the stripped line of text to be referenced later


[View source]
def allow_text?(text : String) : Bool #

Returns true if the given text has valid codepoints or is empty

Returns false if any character/codepoint in the given text is not found in valid_codepoints


[View source]
def check_forwards? : Bool | Nil #

Returns true if this module should check forwards for uniqueness

If true, this module should also check for unique text or media if check_text or check_media is toggled, respectively.

Returns false otherwise


[View source]
def check_media? : Bool | Nil #

Returns true if this module should check media (photos, audio, videos, etc.) for uniqueness

Returns false otherwise


[View source]
def check_text? : Bool | Nil #

Returns true if this module should check text for uniqueness

Returns false otherwise


[View source]
def cooldown : Int32 #

Returns the cooldown duration for unoriginal messages


[View source]
def media_file_id(message : Tourmaline::Message) : String | Nil #

Returns a String containing the unique file ID from the given message


[View source]
def remove_links(text : String, entities : Array(Tourmaline::MessageEntity)) : String #

Returns a String containing the given text with URLs removed


[View source]
def strip_text(text : String, entities : Array(Tourmaline::MessageEntity)) : String #

Returns a String containing the given text in lower case with the following elements removed:

  • Links/URLS
  • Commands
  • Usernames
  • Sequences of 3 or more repeating characters (digits can repeat)
  • Network links/Back links (i.e., ">>>/foo/")
  • Punctuation and the em-dash
  • Repeating spaces and newlines
  • Trailing and leading whitespace

[View source]
def unique_media(user : User, message : Tourmaline::Message, services : Services, file_id : String) : String | Nil #

Returns the file_id if the message's media is unique

Returns nil if the message's media is not unique, and cooldowns the sender if configured to do so


[View source]
def unique_message?(user : User, message : Tourmaline::Message, services : Services, text : String | Nil = nil) : Bool #

Checks the message for uniqueness and returns true if:

  • Message is preformatted (message already checked)
  • Message is a forward, but this Robot9000 is not configured to check forwards for uniqueness
  • No media file ID could be found when checking message media
  • Message is unique

Returns false if the message does not pass the text_check or the media_check; message is unoriginal

The unique text and/or file_id will be stored to flag future messages of the same kind as unoriginal


[View source]
def unique_text(user : User, message : Tourmaline::Message, services : Services, text : String) : String | Nil #

Returns the text if the message's text or caption is unique

Returns nil if the message's text or caption is not unique, and cooldowns the sender if configured to do so


[View source]
abstract def unoriginal_media?(id : String) : Bool | Nil #

Returns true if the given file id has been sent before Returns false otherwise


[View source]
def unoriginal_message(user : User, message : Tourmaline::Message, services : Services) : Nil #

Queues a message telling the user that the message was unoriginal, and cooldowns the user if configured to do so


[View source]
abstract def unoriginal_text?(text : String) : Bool | Nil #

Returns true if the given text has been sent before Returns false otherwise


[View source]
def warn_user? : Bool | Nil #

Returns true if this module should give the user a warning for unoriginal messages

If true, the unoriginal message cooldown should scale with user warnings

Returns false otherwise


[View source]