Skip to content

Commit

Permalink
Strip down dev docs until I find a way of keeping it up to date
Browse files Browse the repository at this point in the history
  • Loading branch information
3urobeat committed Oct 19, 2023
1 parent 1f061ac commit 3103105
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 1,025 deletions.
4 changes: 2 additions & 2 deletions docs/dev/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Welcome to the steam-comment-service-bot developer documentation!
[⬅️ Go back to the main page](../..#readme)

The developer documentation includes pages for every module and the functions exposed by it.
This should help you greatly figuring out how to implement parts of the bot into your plugin or when working on the project itself!
The developer documentation includes pages for every module and some useful information about it.
This should help you figuring out how to implement parts of the bot into your plugin or when working on the project itself!

It makes sense to first learn how this project works and is built before diving in further. The [introduction](./introduction.md) page should get you started quickly.

Expand Down
98 changes: 2 additions & 96 deletions docs/dev/bot/bot.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,99 +9,5 @@ The bot object itself handles events for this specific account (e.g. chat messag

 

## Table of Contents
- [Event Handlers](./events.md)
- [Data](#data)
- [Functions](#functions)

Please use your browser's search function <kbd>Ctrl</kbd>+<kbd>F</kbd> to find a specific function using its name on this page.

&nbsp;

## Data
The Bot object holds the following data:

### controller
Reference to the active [Controller](../controller/controller.md) object

## data
Reference to the active [DataManager](../dataManager/dataManager.md) object

## index
The login index of this bot account, matching the index of it in the logininfo object (and accounts.txt)
Warning: This index can change at runtime if accounts are reordered. To uniquely identify an account, use its accountName.

## status
[EStatus](/src/bot/EStatus.js) of this bot account. Indicates whether the bot account is online, offline, skipped, etc.

Default: `EStatus.OFFLINE`

## friendMessageBlock
Array of steamID64s to ignore in the friendMessage event handler. This is used by readChatMessage() to prevent duplicate responses.

## proxyIndex


## loginData
Object containing login related information for this bot account with the following properties:
- `logOnOptions` (Object) - Object containing the login information of this bot account
- `logOnTries` (number) - Amount of logOnTries used in the most recent login/relog attempt
- `waitingFor2FA` (boolean) - Set by [sessionHandler](../sessionHandler/sessionHandler.md)'s handle2FA helper to prevent login timeout from triggering when waiting for user input
- `proxyIndex` (Number) - Index of the proxy in the DataManager.[proxies](../dataManager/dataManager.md#proxies) array which this account uses to connect to Steam
- `proxy` (String) - The proxy URL behind the used proxyIndex

## sessionHandler
Reference to the active [sessionHandler](../sessionHandler/sessionHandler.md) object for this bot object.

## user
Reference to the active [SteamUser](https://github.com/DoctorMcKay/node-steam-user) object for this bot account.
This allows you to interact with Steam using this logged in Steam account.

## community
Reference to the active [SteamCommunity](https://github.com/DoctorMcKay/node-steamcommunity) object for this bot account.
This allows you to interact with the SteamCommunity using this logged in Steam account.

&nbsp;

## Functions
All private functions, except the constructor, are prefixed with an `_` underscore. They should not be called from external modules (e.g. plugins).

### (controller, index): void
- `controller` ([Controller](../controller/controller.md)) - Reference to the active controller object
- `index` (number) - The loginindex of this account in the logininfo object

Constructor - Initializes an object which represents a user steam account

&nbsp;

### _loginToSteam(): void
Calls SteamUser logOn() for this account. This will either trigger the SteamUser loggedOn or error event.

### checkMsgBlock(steamID64, message): boolean
- `steamID64` (object) - The steamID64 of the message sender
- `message` (string) - The message string provided by the steam-user friendMessage event

Checks if user is blocked, has an active cooldown for spamming or isn't a friend.
Returns a boolean, indicating whether the user is blocked or not.

### handleLoginTimeout(): void
Handles aborting a login attempt should an account get stuck to prevent the bot from softlocking (see issue #139).

### handleMissingGameLicenses(): void
Handles checking for missing game licenses, requests them and then starts playing.

### sendChatMessage(_this, resInfo, txt, retry, part?): void
- `_this` (object) - The Bot object context
- `resInfo` (CommandHandler.[resInfo](../commandHandler/commandHandler.md#resInfo)) - Object containing information passed to command by friendMessage event
- `txt` (string) - The text to send
- `retry` (boolean) - Internal: true if this message called itself again to send failure message
- `part` (number) - Internal: Index of which part to send for messages larger than 750 chars

Our commandHandler respondModule implementation - Sends a message to a Steam user

### readChatMessage(steamID64, timeout): Promise
- `steamID64` (string) - The steamID64 of the user to read a message from
- `timeout` (number) - Time in ms after which the Promise will be resolved if user does not respond. Pass 0 to disable (not recommended)

Waits for a Steam Chat message from this user to this account and resolves their message content. The "normal" friendMessage event handler will be blocked for this user.
Returns a Promise which will be resolved with a string on user response or `null` on timeout.
Every function and object property is documented with JsDocs in the implementation file.
Please check them out using your IntelliSense or by clicking the button in the top right corner of this page.
96 changes: 2 additions & 94 deletions docs/dev/commands/commandHandler.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,107 +12,15 @@ This adds support for running commands and receiving answers through the Steam C

&nbsp;

## Table Of Contents
- [Helpers](./helpers.md)
- [Data](#data)
- [Type Definitions](#typedefs)
- [Functions](#functions)

Please use your browser's search function <kbd>Ctrl</kbd>+<kbd>F</kbd> to find a specific function using its name on this page.

&nbsp;

## Data

### controller
Reference to the active [Controller](../controller/controller.md) object.

### data
Reference to the active [DataManager](../dataManager/dataManager.md) object.

### commands
Array of [Command](#command)s which are currently registered.
Every function and object property is documented with JsDocs in the implementation file.
Please check them out using your IntelliSense or by clicking the button in the top right corner of this page.

&nbsp;

## Typedefs
To improve IntelliSense support and provide detailed parameter documentation, the CommandHandler contains three type definitions:

### Command
Object representing a Command which is stored in the [commands](#commands) array.
It contains the following properties:
- `names` (string[]) - Collection of names/aliases which trigger this command
- `description` (string) - Description of what this command does
- `args` ([CommandArg](#CommandArg)[]) Array of objects containing information about each parameter supported by this command
- `ownersOnly` (boolean) - Set to true to only allow owners to use this command
- `run` (function(CommandHandler, Array, string, function(object, object, string): void, object, object): void) - Function that will be executed to run the command. Arguments: commandHandler, args, steamID64, respondModule, context, resInfo

### CommandArg
Object representing one argument (of many) supported by a [Command](#command) stored in the [commands](#commands) array.
It contains the following properties:
- `name` (string) - Name of this argument. Use common phrases like "ID" or "amount" if possible. If a specific word is expected, put the word inside quotation marks.
- `description` (string) - Description of this argument
- `type` (string) - Expected datatype of this argument. If read from a chat it will usually be "string"
- `isOptional` (boolean) - True if this argument is optional, false if it must be provided. Make sure to check for missing arguments and return an error if false.
- `ownersOnly` (boolean) - True if this argument is only allowed to be provided by owners set in the config. If the command itself is `ownersOnly`, set this property to `true` as well.

### resInfo
Object representing the default/commonly used content the resInfo object can/should contain.
The resInfo object is passed to every command and contains valuable information about the command handler which executes this command (plugins implementing other chat platforms need to implement their own command handler of course),
about the user who ran the command, which userIDs have owner rights, etc.
The commandHandler of e.g. a plugin can add more information to this object as they please. This can be useful to pass more information to their commands, through the commandHandler.

It contains the following properties:
- `cmdprefix` (string) Optional: Prefix your command execution handler uses. This will be used in response messages referencing commands. Default: !
- `userID` (string) - ID of the user who executed this command. Will be used for command default behavior (e.g. commenting on the requester's profile), to check for owner privileges, apply cooldowns and maybe your respondModule implementation for responding. Strongly advised to include.
- `ownerIDs` (string[]) - Optional: Can be provided to overwrite `config.ownerid` for owner privilege checks. Useful if you are implementing a different platform and so `userID` won't be a steamID64 (e.g. discord)
- `charLimit` (number) - Optional: Supported by the Steam Chat Message handler: Overwrites the default index from which response messages will be cut up into parts
- `cutChars` (string[]) - Optional: Custom chars to search after for cutting string in parts to overwrite cutStringsIntelligently's default: [" ", "\n", "\r"]
- `fromSteamChat` (boolean) - Optional: Set to true if your command handler is receiving messages from the Steam Chat and `userID` is therefore a `steamID64`. Will be used to enable command default behavior (e.g. commenting on the requester's profile)
- `prefix` (string) - Optional: Do not provide this argument, you'll receive it from commands: Steam Chat Message prefixes like /me. Can be ignored or translated to similar prefixes your platform might support

&nbsp;

## Functions
All private functions, except the constructor, are prefixed with an _ underscore. They should not be called from external modules (e.g. plugins).

### (controller): void
- `controller` ([Controller](../controller/controller.md)) - Reference to the active controller object

Constructor - Creates a new CommandHandler object. Is called by Controller on startup.

&nbsp;

### _importCoreCommands(): Promise
Internal:
Imports core commands on startup.

Returns a Promise which resolves when all core commands have been imported.

### registerCommand(command): boolean
- `command` ([Command](#command)) - The command object to register

Registers a new command during runtime. This is used by plugins to register commands which they are adding.

Returns `true` if the command was successfully registered, `false` otherwise.

### unregisterCommand(commandName): boolean
- `commandName` (string) - Name of the command to unregister

Unregisters a command at runtime which has one alias that matches the parameter.

Returns `true` if the command was successfully unregistered, `false` otherwise.

### runCommand(name, args, respondModule, context, resInfo): boolean
- `name` (string) - The name of the command.
- `args` (array) - Array of arguments that will be passed to the command.
- `respondModule` (function(object, object, string): void) - Function that will be called to respond to the user's request. Passes context, resInfo and txt as parameters.
- `context` (object) - The context (`this.`) of the object calling this command. Will be passed to respondModule() as first parameter to make working in this function easier.
- `resInfo` ([resInfo](#resInfo)) - Object containing additional information.

Finds a loaded command by name and runs it.

Returns `true` if the command was found, `false` otherwise.

### reloadCommands(): void
Reloads all core commands. Does NOT reload commands registered at runtime. Please consider reloading the pluginSystem as well.
Loading

0 comments on commit 3103105

Please sign in to comment.