nimbotsdk/README.md
2024-02-07 11:59:50 -05:00

87 lines
2.4 KiB
Markdown

# Nim Bot SDK
Nim wrapper for the [Matrix bot SDK](https://github.com/turt2live/matrix-bot-sdk).
This library aims to take TypeScript functions, classes and whatever else that is needed from the [Matrix bot SDK](https://github.com/turt2live/matrix-bot-sdk) and expose them to Nim code with a JavaScript target.
## Development
Nim files inside `src/nimbotsdk/` are named after the original TypeScript file they wrap (`MatrixAuth.nim` warps `MatrixAuth.d.ts`). `matrixTypes.nim` defines the object types used throughout the entire library.
### Development Setup
To start developing, make sure you have the needed dependencies installed:
- [Nim](https://nim-lang.org/)
- Nimble (comes with Nim compiler) (For tests)
- [Node.js](https://nodejs.org/) (For tests)
- [pnpm](https://pnpm.io/)
Clone the repository and download the SDK:
```sh
git clone https://git.inamatrix.xyz/array-in-a-matrix/nimbotsdk
cd nimbotsdk/src/ && pnpm install
```
### Tests
Procedures that have been checked to work are imported into `src/nimbotsdk.nim`.
Copy `credentials.nim.example` to `credentials.nim` and add the needed values before running tests.
Run tests:
```sh
nimble test
```
## Usage
### Project Setup
You will need the following installed:
- [Nim](https://nim-lang.org/)
- Nimble (comes with Nim compiler)
- [Node.js](https://nodejs.org/) (Not needed if you plan on running the code in the browser, this has not been tested yet.)
- NPM package manager ([pnpm](https://pnpm.io/), [yarn](https://yarnpkg.com/), [npm](https://www.npmjs.com/), etc.)
You can install this library using `nimble`:
```sh
nimble install https://git.inamatrix.xyz/array-in-a-matrix/nimbotsdk
```
Now you will be able to import and use it in your Nim code:
```nim
# imports everything
import nimbotsdk
# imports only select modules
import nimbotsdk/[matrixTypes, MatrixClient]
```
You can compile your Nim code without downloading the NPM module but it will not work. To deal with this, download the [Matrix bot SDK](https://github.com/turt2live/matrix-bot-sdk) if you haven't already:
```sh
# If using pnpm
pnpm add matrix-bot-sdk
#If using yarn
yarn add matrix-bot-sdk
#If using npm
npm install matrix-bot-sdk
```
Now you can run your compiled Nim code or compile and run directly:
```sh
nim js printToken.nim && node printToken.js
nim js -r printToken.nim
```
There are code examples inside the `examples/` directory.