module PrivateParlorXT::Format

Overview

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

Included Modules

Extended Modules

Defined in:

private-parlor-xt/format.cr

Instance Method Summary

Instance Method Detail

def 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.


[View source]
def check_text(text : String, user : User, message : Tourmaline::Message, services : Services) : Bool #

Checks the given text for invalid characters


[View source]
def contact(contact : String | Nil, replies : Replies) : String | Nil #

Format the given contact for blacklist contact replies


[View source]
def escape_mdv2(text : String | Nil) #

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


[View source]
def 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


[View source]
def 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


[View source]
def 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


[View source]
def 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


[View source]
def 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.


[View source]
def offset_entities(entities : Array(Tourmaline::MessageEntity), offset : Int32) : Array(Tourmaline::MessageEntity) #

Add the given offset to the offset of each message entity


[View source]
def 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


[View source]
def reason(reason : String | Nil, replies : Replies) : String | Nil #

Format the reason for system message replies


[View source]
def reason_log(reason : String | Nil, logs : Logs) : String | Nil #

Format the reason for log messages


[View source]
def remove_entities(entities : Array(Tourmaline::MessageEntity), strip_types : Array(String)) : Array(Tourmaline::MessageEntity) #

Removes message entities if their types are found in strip_types


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

Replaces appends links contained in text link entities to the end of the given text


[View source]
def reset_entities(entities : Array(Tourmaline::MessageEntity), amount : Int32) : Array(Tourmaline::MessageEntity) #

Subtract the given amount from the offset of each message entity


[View source]
def 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


[View source]
def substitute_message(msg : String, variables : Hash(String, String | Nil) = {"" => ""}) : String #

Globally substitutes placeholders in message with the given variables


[View source]
def substitute_reply(msg : String, variables : Hash(String, String | Nil) = {"" => ""}) : String #

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


[View source]
def 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


[View source]
def time(time : Time | Nil, format : String) : String | Nil #

Formats a given Time based on the given format


[View source]
def time_span(time : Time::Span, locale : Locale) : String #

Format a time span using localized time units


[View source]
def tripcode_sign(name : String, tripcode : String, entities : Array(Tourmaline::MessageEntity)) : Tuple(String, Array(Tourmaline::MessageEntity)) #

Format the tripcode header for tripcode signs


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

Returns a text link message entities corresponding to the network links in text, linking to their respective chats


[View source]
def 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


[View source]