Class: Client
index.Client
Hierarchy
-
TypedEventEmitter
<ClientEvents
,this
>↳
Client
Constructors
constructor
• new Client(name
, commandPrefixes?
, options?
): Client
Creates a new msgroom client.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
name | string | undefined | The username to use. |
commandPrefixes | string | RegExp | (string | RegExp )[] | [] | List of prefixes to be used for commands. Set this to an empty string to disable the command system. |
options | Partial <ClientOptions > | {} | Extra options. |
Returns
Overrides
(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).constructor
Defined in
Properties
#ID
• Private
Optional
#ID: string
Defined in
#name
• Private
#name: string
Defined in
#sessionID
• Private
Optional
#sessionID: string
Defined in
apikey
• Optional
apikey: string
Defined in
authOptions
• authOptions: undefined
| Omit
<Partial
<{ apikey?
: string
; bot?
: boolean
; loginkey?
: string
; staff?
: string
; user
: string
}>, "bot"
| "user"
| "apikey"
>
Cannot be changed after connecting.
Defined in
blockBots
• blockBots: boolean
Defined in
blockSelf
• blockSelf: boolean
Defined in
blockedIDs
• blockedIDs: Set
<string
>
Defined in
blockedSessionIDs
• blockedSessionIDs: Set
<string
>
Defined in
bot
• bot: boolean
Defined in
commands
• commands: CommandMap
= {}
Defined in
erroredFiles
• erroredFiles: Set
<string
>
Defined in
helpCommandLimit
• helpCommandLimit: number
Defined in
helpSuffix
• helpSuffix: string
Defined in
mainPrefix
• mainPrefix: string
| RegExp
Defined in
prefixes
• prefixes: Set
<string
| RegExp
>
Defined in
printErrors
• printErrors: boolean
Defined in
server
• server: string
Defined in
socket
• Optional
socket: MsgroomSocket
Defined in
socketIOOptions
• socketIOOptions: undefined
| Partial
<ManagerOptions
& SocketOptions
>
Cannot be changed after connecting.
Defined in
unescapeMessages
• unescapeMessages: boolean
Defined in
users
• users: Record
<string
, User
> = {}
Defined in
welcomeMessage
• Optional
welcomeMessage: string
Deprecated
This option has been removed. As a general rule, bots should not send messages if the user doesn't explicitly ask for them.
Defined in
Accessors
ID
• get
ID(): string
The user's ID.
Returns
string
Throws
A NotConnectedError when you haven't connected yet.
Defined in
name
• get
name(): string
The user's name. You can change it by reassigning this variable. Do note that changing it is done using an asynchronous operation, meaning the change won't be reflected immediately.
Returns
string
Throws
A NotConnectedError when you haven't connected yet.
Defined in
• set
name(name
): void
Parameters
Name | Type |
---|---|
name | string |
Returns
void
Defined in
sessionID
• get
sessionID(): string
The user's session ID.
Returns
string
Throws
A NotConnectedError when you haven't connected yet.
Defined in
Methods
addListener
▸ addListener<E
>(event
, listener
): Client
Type parameters
Name | Type |
---|---|
E | extends keyof ClientEvents |
Parameters
Name | Type |
---|---|
event | E |
listener | ClientEvents [E ] |
Returns
Inherited from
(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).addListener
Defined in
node_modules/typed-emitter/index.d.ts:22
adminAction
▸ adminAction(...args
): void
Triggers an admin action. The way it works is by passing an array of arguments, similar to how commands work. We currently have no idea what these commands could be because only msgroom staff know the list of commands.
Parameters
Name | Type | Description |
---|---|---|
...args | string [] | The arguments to pass to the admin-action event. |
Returns
void
Throws
A NotConnectedError when you haven't connected yet.
Defined in
connect
▸ connect(): Promise
<void
>
Connect to a msgroom server.
Returns
Promise
<void
>
A promise which resolves when the connection has successfully been established.
Throws
An AuthError when the server won't let you in.
Defined in
disconnect
▸ disconnect(): void
Disconnects from the server if connected.
Returns
void
Defined in
emit
▸ emit<E
>(event
, ...args
): boolean
Type parameters
Name | Type |
---|---|
E | extends keyof ClientEvents |
Parameters
Name | Type |
---|---|
event | E |
...args | Parameters <ClientEvents [E ]> |
Returns
boolean
Inherited from
(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).emit
Defined in
node_modules/typed-emitter/index.d.ts:32
eventNames
▸ eventNames(): (string
| symbol
)[]
Returns
(string
| symbol
)[]
Inherited from
(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).eventNames
Defined in
node_modules/typed-emitter/index.d.ts:34
getCommand
▸ getCommand(commandAndArguments
): Promise
<undefined
| [CommandWithName
, string
[]]>
Gets a command from its call.
Parameters
Name | Type | Description |
---|---|---|
commandAndArguments | string [] | The split arguments which also have the command in it. |
Returns
Promise
<undefined
| [CommandWithName
, string
[]]>
A promise which resolves to the command and its arguments, or undefined if none was found.
Defined in
getMaxListeners
▸ getMaxListeners(): number
Returns
number
Inherited from
(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).getMaxListeners
Defined in
node_modules/typed-emitter/index.d.ts:39
isBlocked
▸ isBlocked(userID
, userSessionID?
, blockBots?
): boolean
Checks whether the specified user is blocked.
Parameters
Name | Type | Description |
---|---|---|
userID | string | A user's ID or an object with an ID, sessionID, and/or blockBots property. |
userSessionID? | string | A user's session ID. |
blockBots? | boolean | Whether to block bots too. Defaults to the blockBots option. |
Returns
boolean
A boolean value indicating whether the user is blocked.
Example
client.isBlocked("user-id-here", "session-id-here");
client.isBlocked({
ID: "user-id-here", // you can leave any of these out
sessionID: "session-id-here",
blockBots: true,
});
client.isBlocked("bad-user-id", "some session id"); // false
client.blockedIDs.add("bad-user-id");
client.isBlocked("bad-user-id", "some session id"); // true
Defined in
▸ isBlocked(userIDOrObject
): boolean
Parameters
Name | Type |
---|---|
userIDOrObject | Object |
userIDOrObject.ID? | string |
userIDOrObject.blockBots? | boolean |
userIDOrObject.sessionID? | string |
Returns
boolean
Defined in
isBot
▸ isBot(sessionID
): boolean
Parameters
Name | Type |
---|---|
sessionID | string |
Returns
boolean
Defined in
listenerCount
▸ listenerCount<E
>(event
): number
Type parameters
Name | Type |
---|---|
E | extends keyof ClientEvents |
Parameters
Name | Type |
---|---|
event | E |
Returns
number
Inherited from
(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).listenerCount
Defined in
node_modules/typed-emitter/index.d.ts:37
listeners
▸ listeners<E
>(event
): ClientEvents
[E
][]
Type parameters
Name | Type |
---|---|
E | extends keyof ClientEvents |
Parameters
Name | Type |
---|---|
event | E |
Returns
ClientEvents
[E
][]
Inherited from
(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).listeners
Defined in
node_modules/typed-emitter/index.d.ts:36
loadDirectory
▸ loadDirectory(directory
): Promise
<void
>
Loads modules from a directory recursively. Any errors thrown anywhere in the process will be caught and logged to the console.
Parameters
Name | Type | Description |
---|---|---|
directory | string | URL | The directory to get the modules from. |
Returns
Promise
<void
>
A promise which resolves once the modules have been loaded.
Defined in
loadModule
▸ loadModule(file
): Promise
<void
>
Loads a module. Any errors thrown anywhere in the process will be caught and logged to the console.
Parameters
Name | Type | Description |
---|---|---|
file | string | URL | The module to load. |
Returns
Promise
<void
>
A promise which resolves once the module has been loaded.
Defined in
off
▸ off<E
>(event
, listener
): Client
Type parameters
Name | Type |
---|---|
E | extends keyof ClientEvents |
Parameters
Name | Type |
---|---|
event | E |
listener | ClientEvents [E ] |
Returns
Inherited from
(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).off
Defined in
node_modules/typed-emitter/index.d.ts:28
on
▸ on<E
>(event
, listener
): Client
Type parameters
Name | Type |
---|---|
E | extends keyof ClientEvents |
Parameters
Name | Type |
---|---|
event | E |
listener | ClientEvents [E ] |
Returns
Inherited from
(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).on
Defined in
node_modules/typed-emitter/index.d.ts:23
once
▸ once<E
>(event
, listener
): Client
Type parameters
Name | Type |
---|---|
E | extends keyof ClientEvents |
Parameters
Name | Type |
---|---|
event | E |
listener | ClientEvents [E ] |
Returns
Inherited from
(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).once
Defined in
node_modules/typed-emitter/index.d.ts:24
parseCommandCall
▸ parseCommandCall(commandCall
): string
[]
Parameters
Name | Type |
---|---|
commandCall | string |
Returns
string
[]
Defined in
prependListener
▸ prependListener<E
>(event
, listener
): Client
Type parameters
Name | Type |
---|---|
E | extends keyof ClientEvents |
Parameters
Name | Type |
---|---|
event | E |
listener | ClientEvents [E ] |
Returns
Inherited from
(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).prependListener
Defined in
node_modules/typed-emitter/index.d.ts:25
prependOnceListener
▸ prependOnceListener<E
>(event
, listener
): Client
Type parameters
Name | Type |
---|---|
E | extends keyof ClientEvents |
Parameters
Name | Type |
---|---|
event | E |
listener | ClientEvents [E ] |
Returns
Inherited from
(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).prependOnceListener
Defined in
node_modules/typed-emitter/index.d.ts:26
processCommands
▸ processCommands(context
): Promise
<void
>
Processes a message to check for command calls.
Parameters
Name | Type | Description |
---|---|---|
context | CommandContext | The context which will be passed to command handlers. |
Returns
Promise
<void
>
A promise which resolves when the associated command (if there is one) has been called.
Defined in
rawListeners
▸ rawListeners<E
>(event
): ClientEvents
[E
][]
Type parameters
Name | Type |
---|---|
E | extends keyof ClientEvents |
Parameters
Name | Type |
---|---|
event | E |
Returns
ClientEvents
[E
][]
Inherited from
(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).rawListeners
Defined in
node_modules/typed-emitter/index.d.ts:35
removeAllListeners
▸ removeAllListeners<E
>(event?
): Client
Type parameters
Name | Type |
---|---|
E | extends keyof ClientEvents |
Parameters
Name | Type |
---|---|
event? | E |
Returns
Inherited from
(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).removeAllListeners
Defined in
node_modules/typed-emitter/index.d.ts:29
removeListener
▸ removeListener<E
>(event
, listener
): Client
Type parameters
Name | Type |
---|---|
E | extends keyof ClientEvents |
Parameters
Name | Type |
---|---|
event | E |
listener | ClientEvents [E ] |
Returns
Inherited from
(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).removeListener
Defined in
node_modules/typed-emitter/index.d.ts:30
runCommand
▸ runCommand(command
, commandHandlerArguments
, context
): Promise
<void
>
Runs a command.
Parameters
Name | Type | Description |
---|---|---|
command | CommandWithName | The command to run. |
commandHandlerArguments | string [] | The arguments to pass to the command's handler. |
context | CommandContext | The context in which the command was triggered. |
Returns
Promise
<void
>
A promise which resolves when the command has been ran.
Defined in
sendMessage
▸ sendMessage(...messages
): void
Sends a message. (The character limit is 2048.) All arguments will be joined together with a space before being sent. Anything that is not a string will be converted to one, but this does not mean that it is a good practice to do so.
Parameters
Name | Type | Description |
---|---|---|
...messages | string [] | The message to send. |
Returns
void
Throws
A NotConnectedError when you haven't connected yet.
Defined in
setMaxListeners
▸ setMaxListeners(maxListeners
): Client
Parameters
Name | Type |
---|---|
maxListeners | number |
Returns
Inherited from
(EventEmitter as unknown as new () => TypedEmitter.default<ClientEvents>).setMaxListeners
Defined in
node_modules/typed-emitter/index.d.ts:40
validateNickname
▸ validateNickname(name
, onJoin?
): void
Validates a nickname. A nickname should be 1-16 characters.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
name | string | undefined | The nickname to validate. |
onJoin | boolean | false | Whether the nickname is passed to the auth event, which checks for a length of 18 characters. |
Returns
void
Throws
An Error when the criteria has not been met.
Defined in
walkCommandOrMap
▸ walkCommandOrMap(commandOrMap
, walkFunction
, fullCommand?
): void
Walks a commandMap or a command's subcommands recursively.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
commandOrMap | Command | CommandMap | undefined | The command or commandMap to walk. |
walkFunction | WalkFunction | undefined | The function that will be called with every command. |
fullCommand | string [] | [] | The full path to the current command or commandMap being walked. (Used when walking, you probably don't need this). |
Returns
void
Throws
An Error when fullCommand is empty when commandOrMap is a command.