Overview
The Chat module consists of two main classes:- ChatRooms: Public and private chat room management
- PrivateChat: Private messaging between users
ChatRooms Class
Initialization
Room Management
join_room()
Joins a chat room.str
required
Name of the room to join
bool
default:"False"
Whether this is a private room
leave_room()
Leaves a chat room.str
required
Name of the room to leave
get_joined_rooms()
Returns list of currently joined rooms.list
List of room names currently joined
is_joined()
Checks if currently in a room.bool
True if currently in the room
Message Methods
send_message()
Sends a message to a chat room.str
required
Name of the room
str
required
Message text to send
send_me_action()
Sends an action message (like “/me” in IRC).str
required
Name of the room
str
required
Action text to send
Room Information
get_room_users()
Returns users in a room.str
required
Name of the room
list
List of usernames in the room
get_user_stats()
Returns statistics for a user in a room.dict
Dictionary with “avgspeed”, “files”, “dirs” keys
get_user_status()
Returns a user’s status in a room.int
Status code: 0=offline, 1=away, 2=online
Room List
request_room_list()
Requests list of available rooms from server.get_room_list()
Returns cached list of available rooms.list
List of tuples: (room_name, num_users)
Tickers
set_ticker()
Sets your ticker message in a room.str
required
Name of the room
str
required
Ticker text to display
get_tickers()
Returns ticker messages in a room.dict
Dictionary mapping usernames to ticker messages
PrivateChat Class
Initialization
Messaging
send_message()
Sends a private message to a user.str
required
Username to send message to
str
required
Message text
send_me_action()
Sends an action message privately.str
required
Username to send to
str
required
Action text
Conversation Management
get_users()
Returns list of users you have private conversations with.list
List of usernames
get_messages()
Returns message history with a user.str
required
Username to get messages for
list
List of message dictionaries
clear_messages()
Clears message history with a user.Events
The Chat module emits events for incoming messages and room activity:Complete Example
Chat Commands
Many chat applications support special commands:Best Practices
- Join relevant rooms to find content and connect with users
- Use tickers to advertise your shares
- Be respectful and follow room rules
- Handle incoming messages asynchronously to avoid blocking
- Store message history for conversation context
- Implement rate limiting to avoid flooding
- Use private messages for one-on-one conversations
- Monitor room lists to discover active communities