Console¶
-
class
console.Console(database, rname, router, log=None)[source]¶ Each instance of the console corresponds to a single user session. The console handles user-command interaction.
- Variables
user – TinyDB user document for the currently logged in user, if any.
rname – The name used by the router for this console.
router – The Router instance, which handles interfacing between the server backend and the user consoles.
-
__init__(database, rname, router, log=None)[source]¶ Console Initializer
- Parameters
database – The DatabaseManager instance to use.
rname – The name used by the router for this console.
router – The Router instance, which handles interfacing between the server backend and the user consoles.
log – Alternative logging facility, if set.
-
broadcast(message)[source]¶ Broadcast Message
Send a message to all users connected to consoles.
- Parameters
message – The message to send.
- Returns
True
-
broadcast_room(message)[source]¶ Broadcast Message to Room
Send a message to all users who are in the same room as the user connected to this console.
- Parameters
message – The message to send.
- Returns
True
-
command(line, show_command=True)[source]¶ Command Handler
Parse and execute a command line, discerning which arguments are part of the command name and which arguments should be passed to the command.
- Parameters
line – The command line to parse.
show_command – Whether or not to echo the command being executed in the console.
- Returns
Command result or None.
-
help(line)[source]¶ Help Handler
Retrieve the help for a category or command.
- Parameters
line – The help line to parse.
- Returns
True if succeeded, False if failed.
-
msg(message, _nbsp=False)[source]¶ Send Message
Send a message to the user connected to this console.
- Parameters
message – The message to send.
_nbsp – Will insert non-breakable spaces for formatting on the websocket frontend.
- Returns
True
-
usage(line)[source]¶ Usage Handler
Retrieve just the usage string for a command.
- Parameters
line – The help line to parse.
- Returns
True if succeeded, False if failed.
-
user_by_name(username)[source]¶ Get a user by their name.
It is necessary to modify user records through the console before updating the database, if they are logged in. Otherwise their database record will be overwritten next time something is changed in their console record. If the user is logged in, return their console record. Otherwise, return their record directly from the database.
- Returns
Console or Database User Document, or None
-
user_by_nick(nickname)[source]¶ Get a user by their nickname.
It is necessary to modify user records through the console before updating the database, if they are logged in. Otherwise their database record will be overwritten next time something is changed in their console record. If the user is logged in, return their console record. Otherwise, return their record directly from the database.
- Returns
Console or Database User Document, or None