abstract class PrivateParlorXT::User
- PrivateParlorXT::User
- Reference
- Object
Overview
A reprentation of a Telegram user.
All users require an ID, which is obtained from the Telegram user (Tourmaline::User
).
This ID should be unique and stored as a UserID
.
Database
implementations should have their own User
type that inherits
from this class and is modified to work with the given implementation.
Direct Known Subclasses
Defined in:
private-parlor-xt/user.crConstructors
-
.new(id : UserID, username : String | Nil = nil, realname : String = "", rank : Int32 = 0, joined : Time = Time.utc, left : Time | Nil = nil, last_active : Time = Time.utc, cooldown_until : Time | Nil = nil, blacklist_reason : String | Nil = nil, warnings : Int32 = 0, warn_expiry : Time | Nil = nil, karma : Int32 = 0, hide_karma : Bool | Nil = false, debug_enabled : Bool | Nil = false, tripcode : String | Nil = nil)
Creates an instance of
User
.
Instance Method Summary
-
#blacklist(reason : String | Nil) : Nil
Set the user's
#rank
to -10 (blacklisted), sets the#left
value, and updates the#blacklist_reason
-
#blacklist_reason : String | Nil
Returns the reason why the user was blacklisted, or
nil
if a reason does not exist -
#blacklisted? : Bool
Returns
true
if rank is -10; user is blacklisted. -
#can_chat?(limit : Time::Span) : Bool
Returns
true
if user is joined, not in cooldown, not blacklisted, and not limited; user can chat -
#can_chat? : Bool
Returns
true
if user is joined, not in cooldown, and not blacklisted; user can chat -
#can_use_command? : Bool
Returns
true
if user is joined and not blacklisted; user can use commands -
#cooldown(base : Int32) : Time::Span
Gives the user an exponentially increasing cooldown from the given base value and current number of
#warnings
-
#cooldown(time : Time::Span) : Time::Span
Gives the user a cooldown based on the given
Time::Span
-
#cooldown_until : Time | Nil
Returns the
Time
until which the user is in cooldown, ornil
if the user is not cooldowned -
#debug_enabled : Bool | Nil
Returns true if the suer has debug mode enabled,
false
otherwise - #decrement_karma(amount : Int32 = 1) : Nil
-
#formatted_name : String
Get the formatted name of the user.
-
#hide_karma : Bool | Nil
Returns true if the user has karma notifications disabled,
false
otherwise -
#id : UserID
Returns the user's ID
- #increment_karma(amount : Int32 = 1) : Nil
-
#joined : Time
Returns the
Time
the user joined the chat -
#karma : Int32
Returns the user's current amount of karma
-
#last_active : Time
Returns the
Time
the user was last active (i.e., the last time a message was sent or a command was used) -
#left : Time | Nil
Returns the
Time
the user left the chat, ornil
if the user has not left -
#left? : Bool
Returns
true
if left is notnil
; user has left the chat. -
#obfuscated_id : String
Generate an obfuscated ID for the user, used for log messages and commands like
InfoCommand
-
#obfuscated_karma : Int32
Get the user's obfuscated
#karma
-
#rank : Int32
Returns the user's current rank value
-
#realname : String
Returns the user's full name
-
#rejoin : Nil
Set
#left
tonil
, meaning that the User has joined the chat. -
#remove_cooldown(override : Bool = false) : Bool
Removes a cooldown from a user if it has expired.
-
#remove_warning(amount : Int32, warn_lifespan : Time::Span) : Nil
Removes the given amount of
#warnings
from a user -
#set_active : Nil
Set
#last_active
to the current time -
#set_left : Nil
Set
#left
to the current time -
#set_rank(rank : Int32) : Nil
Set
#rank
to the given value -
#set_tripcode(tripcode : String) : Nil
Set
#tripcode
to the given value -
#to_a : Array(UserID | String | Int32 | Time | Bool | Nil)
Returns an array with all the values in
User
. -
#toggle_debug : Nil
Switches user's
#debug_enabled
toggle -
#toggle_karma : Nil
Switches user's
#hide_karma
notifications toggle -
#tripcode : String | Nil
Returns a
String
containing the user's tripcode name and password for generating tripcodes, ornil
if the user has no tripcode set - #update_names(username : String | Nil, fullname : String) : Nil
-
#username : String | Nil
Returns the user's unformatted username, or
nil
if it does not exist -
#warn(lifespan : Int32) : Nil
Increments the user's
#warnings
and sets the#warn_expiry
to the current time plus the lifespan of a warning -
#warn_expiry : Time | Nil
Returns the
Time
when one of the#warnings
will expire, ornil
if such a time does not exit -
#warnings : Int32
Returns the number of warnings the user has
Constructor Detail
Creates an instance of User
.
Arguments:
#id
: unique UserID
identifier for this user
#username
: username of this user; can be nil
#realname
: full name (first name + last name) of the user
#rank
: rank of this user, corresponding to either -10 (blacklisted) or one of the configurable ranks
#joined
: date and time the user joined the chat
#left
: date and time the user left the chat; if nil
, the user is still in the chat
#last_active
: date and time the user last sent a message or used a command
#cooldown_until
: date and time for until which the user cannot send messages; if nil
, the user is not in cooldown
#blacklist_reason
: described reason for blacklisting the user (seeBlacklistCommand
) ; set to nil
by default
#warnings
: number of warnings the user received from WarnCommand
or DeleteCommand
; cooldown times are based off of this value
#warn_expiry
: date and time in which one of the #warnings
will be removed; if nil
, user has no #warnings
to remove
#karma
: points the user acquired from upvotes, or lost from downvotes and warnings (see UpvoteHandler
, DownvoteHandler
)
#hide_karma
: toggle for receiving karma notifications (see ToggleKarmaCommand
); if true
, the user will not receive karma notifications
#debug_enabled
: toggle for debug mode (see ToggleDebugCommand
); if true
, the user will receive a copy of their sent message that everyone else received
#tripcode
: a name and password pairing used for generating pseudononyms attached to the user's message; if nil, user has no tripcode
Instance Method Detail
Set the user's #rank
to -10 (blacklisted), sets the #left
value, and updates the #blacklist_reason
Returns the reason why the user was blacklisted, or nil
if a reason does not exist
Returns true
if rank is -10; user is blacklisted.
Returns false
otherwise.
Returns true
if user is joined, not in cooldown, not blacklisted, and not limited; user can chat
Returns false
otherwise.
Returns true
if user is joined, not in cooldown, and not blacklisted; user can chat
Returns false
otherwise.
Returns true
if user is joined and not blacklisted; user can use commands
Returns false
otherwise.
Gives the user an exponentially increasing cooldown from the given base value and current number of #warnings
Gives the user a cooldown based on the given Time::Span
Returns the Time
until which the user is in cooldown, or nil
if the user is not cooldowned
Decrement the user's #karma
by a given amount (1 by default)
On arithmetic overflow, sets user's #karma
to the minimum Int32
value
Get the formatted name of the user.
If the user has a #username
, returns it with the '@' prepended to it
Otherwise, returns the #realname
Returns true if the user has karma notifications disabled, false
otherwise
Increment the user's #karma
by a given amount (1 by default)
On arithmetic overflow, sets user's #karma
to the maximum Int32
value
Returns the Time
the user was last active (i.e., the last time a message was sent or a command was used)
Returns true
if left is not nil
; user has left the chat.
Returns false
otherwise.
Generate an obfuscated ID for the user, used for log messages and commands like InfoCommand
Removes a cooldown from a user if it has expired.
Returns true
if the cooldown can be expired, false
otherwise
Removes the given amount of #warnings
from a user
If the user still has #warnings
after the removal, reset the #warn_expiry
to a later time based on warn_lifespan
Returns an array with all the values in User
. Intended for database query arguments.
Returns a String
containing the user's tripcode name and password for generating tripcodes, or nil
if the user has no tripcode set
Increments the user's #warnings
and sets the #warn_expiry
to the current time plus the lifespan of a warning