ChatRoom
open class ChatRoom: NSObject
A ChatRoom represents a Stack Exchange chat room.
-
A type of event from the chat room.
See moreDeclaration
Swift
public enum ChatEvent: Int -
The host the bot is running on.
See moreDeclaration
Swift
public enum Host: Int -
The Client to use.
Declaration
Swift
open let client: Client -
The ID of this room.
Declaration
Swift
open let roomID: Int -
The Host of this room.
Declaration
Swift
open let host: Host -
The list of known users.
Declaration
Swift
open var userDB = [ChatUser]() -
The fkey used to authorize actions in chat.
Declaration
Swift
open var fkey: String! -
The closure to run when a message is posted or edited.
Declaration
Swift
open var messageHandler: (ChatMessage, Bool) -> () = {message, isEdit in} -
Runs a closure when a message is posted or edited.
Declaration
Swift
open func onMessage(_ handler: @escaping (ChatMessage, Bool) -> ()) -
Whether the bot is currently in the chat room.
Declaration
Swift
open private(set) var inRoom = false -
Messages that are waiting to be posted & their completion handlers.
Declaration
Swift
open var messageQueue = [(String, ((Int?) -> Void)?)]() -
Custom per-room persistent storage. Must be serializable by JSONSerialization!
Declaration
Swift
open var info: [String:Any] = [:]
-
Looks up a user by ID. If the user is not in the database, they are added.
Declaration
Swift
open func userWithID(_ id: Int) -> ChatUser -
Looks up a user by name. The user must already exist in the database!
Declaration
Swift
open func userNamed(_ name: String) -> [ChatUser] -
Loads the user database from disk.
Declaration
Swift
open func loadUserDB(filename: String? = nil) throwsParameters
filenameThe filename to load the user databse from. The default value is
users_roomID_host.json, for exampleusers_11347_stackoverflow.com.jsonfor SOBotics. -
Saves the user database to disk.
Declaration
Swift
open func saveUserDB(filename: String? = nil) throwsParameters
filenameThe filename to save the user databse to. The default value is
users_roomID_host.json, for exampleusers_11347_stackoverflow.com.jsonfor SOBotics. -
Posts a message to the ChatRoom.
- paramter message: The content of the message to post, in Markdown.
Declaration
Swift
open func postMessage(_ message: String, completion: ((Int?) -> Void)? = nil)Parameters
completionThe completion handler to call when the message is posted. The message ID will be passed to the completion handler.
-
Replies to a ChatMessage.
- paramter reply: The content of the message to post, in Markdown.
Declaration
Swift
open func postReply(_ reply: String, to: ChatMessage, completion: ((Int?) -> Void)? = nil)Parameters
toThe ChatMessage to reply to.
completionThe completion handler to call when the message is posted. The message ID will be passed to the completion handler.
-
Joins the chat room.
Declaration
Swift
open func join() throws -
Leaves the chat room.
Declaration
Swift
open func leave() -
The errors which can be caused while the bot joins the room.
See moreDeclaration
Swift
public enum RoomJoinError: Error -
An error which happened while the bot was processing a chat event.
See moreDeclaration
Swift
public enum EventError: Error
ChatRoom Class Reference