module

PrivateParlorXT::Format

Inherits Tourmaline::Helpers

A general use module for formatting text and Tourmaline::MessageEntity

Instance methods

allow_text?(text : String) : Bool

Checks the content of the message text and determines if it should be relayed.

Returns true if the text is empty or permitted, false if the text has mathematical alphanumeric symbols, as they contain bold and italic characters.

Source
check_text(text : String, user : User, message : Tourmaline::Message, services : Services) : Bool

Checks the given text for invalid characters

Source
contact(contact : String | Nil, replies : Replies) : String | Nil

Format the given contact for blacklist contact replies

Source
escape_mdv2(text : String | Nil)

A simple wrapper for Tourmaline::Helpers.escape_md that defaults to escaping text according to Telegram's MarkdownV2

Source
flag_sign(name : String, entities : Array(Tourmaline::MessageEntity)) : Tuple(String, Array(Tourmaline::MessageEntity))

Format the flag sign header for tripcode messages when flag signs are enabled

Source
format_text(text : String, entities : Array(Tourmaline::MessageEntity), preformatted : Bool | Nil, services : Services) : Tuple(String, Array(Tourmaline::MessageEntity))

Removes formatting from the given text and entities

Source
generate_tripcode(tripkey : String, services : Services) : Tuple(String, String)

Generate a 2channel or secure 8chan style tripcode from a given string in the format name#pass.

Returns a named tuple containing the tripname and tripcode.

Using procedures based on code by Fredrick R. Brennan and Tinyboard Development Group

8chan secure tripcode: Copyright (c) 2010-2014 Tinyboard Development Group

github.com/ctrlcctrlv/infinity/blob/1535f2c976bdc503c12b5e92e605ee665e3239e7/inc/functions.php#L2755

2channel tripcode: Copyright (c) Fredrick R. Brennan, 2020

github.com/ctrlcctrlv/tripkeys/blob/33dcb519a8c08185aecba15eee9aa80760dddc87/doc/2ch_tripcode_annotated.pl

Source
get_arg(text : String | Nil) : String | Nil

Returns the argument following a given text, usually a command where the argument comes after the first whitespace

Source
get_args(text : String | Nil, count : Int) : Array(String) | Nil

Returns count number of args after a given text, usually a command where the command precedes the first whitespace.

Source
offset_entities(entities : Array(Tourmaline::MessageEntity), offset : Int32) : Array(Tourmaline::MessageEntity)

Add the given offset to the offset of each message entity

Source
prepend_pseudonym(text : String, entities : Array(Tourmaline::MessageEntity), user : User, message : Tourmaline::Message, services : Services) : Tuple(String | Nil, Array(Tourmaline::MessageEntity))

Prepend the user's tripcode to the message

Source
reason(reason : String | Nil, replies : Replies) : String | Nil

Format the reason for system message replies

Source
reason_log(reason : String | Nil, logs : Logs) : String | Nil

Format the reason for log messages

Source
remove_entities(entities : Array(Tourmaline::MessageEntity), strip_types : Array(String)) : Array(Tourmaline::MessageEntity)

Removes message entities if their types are found in strip_types

Source
reset_entities(entities : Array(Tourmaline::MessageEntity), amount : Int32) : Array(Tourmaline::MessageEntity)

Subtract the given amount from the offset of each message entity

Source
strip_format(text : String, entities : Array(Tourmaline::MessageEntity), strip_types : Array(String), linked_network : Hash(String, String)) : Tuple(String, Array(Tourmaline::MessageEntity))

Resturns text and message entities with formatting stripped, such as text_links and stripped entities, and formats network links

Source
substitute_message(msg : String, variables : Hash(String, String | Nil) = {"" => ""}) : String

Globally substitutes placeholders in message with the given variables

Source
substitute_reply(msg : String, variables : Hash(String, String | Nil) = {"" => ""}) : String

Globally substitutes placeholders in reply with the given variables Excapes placeholders according to MarkdownV2

Source
text_and_entities(message : Tourmaline::Message, user : User, services : Services) : Tuple(String | Nil, Array(Tourmaline::MessageEntity))

Gets the text and message entities from a given message

Source
time(time : Time | Nil, format : String) : String | Nil

Formats a given Time based on the given format

Source
time_span(time : Time::Span, locale : Locale) : String

Format a time span using localized time units

Source
tripcode_sign(name : String, tripcode : String, entities : Array(Tourmaline::MessageEntity)) : Tuple(String, Array(Tourmaline::MessageEntity))

Format the tripcode header for tripcode signs

Source
validate_text_and_entities(message : Tourmaline::Message, user : User, services : Services) : Tuple(String | Nil, Array(Tourmaline::MessageEntity))

Checks the text and entities from the given message for validity.

Used for signature commands where the text should not be formatted or given a tripcode header if pseudonymous mode is enabled

Source