module Format

Included Modules

Extended Modules

Defined in:

privateparlor/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 false if the text has mathematical alphanumeric symbols, as they contain bold and italic characters.


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

[View source]
def format_contact_reply(contact : String | Nil, locale : Locale) : String | Nil #

[View source]
def format_cooldown_until(expiration : Time | Nil, locale : Locale) : String #

[View source]
def format_help(user : Database::User, ranks : Hash(Int32, Rank), locale : Locale) : String #

Returns a message containing the commands the user can use.


[View source]
def format_karma_loading_bar(percentage : Float32, locale : Locale) : String #

Formats a loading bar for the /karmainfo command


[View source]
def format_karma_say(signature : String) : String #

Returns a bolded signature (as terveisin) showing the karma level of the user that sent this message.


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

Parses new MOTD for HTML formatting and returns the MOTD in HTML without the command and whitespace that follows it

Returns an empty string if no whitespace or command argument could be found.


[View source]
def format_private_channel_forward(name : String, id : Int64, msid : Int64 | Nil) : String #

Removes the "-100" prefix for private channels


[View source]
def format_private_user_forward(name : String) : String #

[View source]
def format_pseudonymous_message(text : String | Nil, tripkey : String, salt : String) : String #

[View source]
def format_reason_log(reason : String | Nil, locale : Locale) : String | Nil #

[View source]
def format_reason_reply(reason : String | Nil, locale : Locale) : String | Nil #

[View source]
def format_smiley(warnings : Int32, smileys : Array(String)) : String #

Returns a smiley based on the number of given warnings


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

Formats a timestamp according to the locale settings


[View source]
def format_timespan(cmp : Time::Span, time_units : Array(String)) : String #

Formats a timespan, so the duration is marked by its largest unit ("20m", "3h", "5d", etc)


[View source]
def format_tripcode_reply(tripcode : String | Nil, locale : Locale) : String #

[View source]
def format_tripcode_sign(name : String, tripcode : String) : String #

[View source]
def format_user_forward(name : String, id : Int64) : String #

[View source]
def format_user_reveal(id : Int64, name : String, locale : Locale) : String #

Returns a link to a given user's account, for reveal messages


[View source]
def format_user_say(signature : String) : String #

Returns a bolded signature showing which type of user sent this message.


[View source]
def format_user_sign(id : Int64, name : String) : String #

Returns a link to the given user's account.


[View source]
def format_username_forward(name : String, username : String | Nil, msid : Int64 | Nil = nil) : String #

For bots or public channels


[View source]
def format_version : String #

Returns a message containing the program version and a link to its Git repo.

Feel free to edit this if you fork the code.


[View source]
def format_warn_expiry(expiration : Time | Nil, locale : Locale) : String | Nil #

[View source]
def generate_tripcode(tripkey : String, salt : String | Nil) : Tuple(String, String) #

Generate a 8chan or Secretlounge-ng style tripcode from a given string in the format name#pass.

Returns a named tuple containing the tripname and tripcode.


[View source]
def get_arg(msg : String | Nil) : String | Nil #

Returns arguments found after a command from a message text.


[View source]
def get_args(msg : String | Nil, count : Int) : Array(String) | Nil #

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

[View source]
def regular_forward?(text : String | Nil, entities : Array(Tourmaline::MessageEntity)) : Bool | Nil #

Checks the text and entities for a forwarded message to determine if it was relayed as a regular message

Returns true if the forward message was relayed regularly, nil otherwise


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

Strips message entities if they're found in entity_types


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

Takes the URL found in an inline link and appends it to the message text.


[View source]
def replace_network_links(text : String, linked_network : Hash(String, String)) : String #

Embeds any occurence of a >>>/chat/ link with a link to that chat.


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

Strips HTML format from a message and escapes formatting found in MessageEntities. If the message has MessageEntities, replaces any inline links and removes entities found in entity_types.


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

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

Globally substitutes placeholders in message with the given variables


[View source]