nimbotsdk/README.md

87 lines
2.4 KiB
Markdown
Raw Normal View History

2023-12-03 17:48:59 -05:00
# Nim Bot SDK
Nim wrapper for the [Matrix bot SDK](https://github.com/turt2live/matrix-bot-sdk).
2023-12-03 17:41:40 -05:00
2024-01-15 01:24:41 -05:00
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.
2023-12-14 16:54:11 -05:00
2024-01-15 01:24:41 -05:00
## 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:
2024-01-12 15:24:40 -05:00
2024-01-15 01:24:41 -05:00
- [Nim](https://nim-lang.org/)
2024-01-15 02:01:37 -05:00
- Nimble (comes with Nim compiler) (For tests)
- [Node.js](https://nodejs.org/) (For tests)
- [pnpm](https://pnpm.io/)
2024-01-15 01:24:41 -05:00
Clone the repository and download the SDK:
2024-01-12 15:24:40 -05:00
```sh
2024-01-15 01:24:41 -05:00
git clone https://git.inamatrix.xyz/array-in-a-matrix/nimbotsdk
cd nimbotsdk/src/ && pnpm install
2024-01-12 15:24:40 -05:00
```
2024-01-15 01:24:41 -05:00
### Tests
2024-01-12 15:24:40 -05:00
2024-02-07 11:59:50 -05:00
Procedures that have been checked to work are imported into `src/nimbotsdk.nim`.
2024-01-12 15:24:40 -05:00
2024-02-07 11:59:50 -05:00
Copy `credentials.nim.example` to `credentials.nim` and add the needed values before running tests.
2024-01-15 01:24:41 -05:00
Run tests:
```sh
nimble test
```
2023-12-14 16:54:11 -05:00
## Usage
2024-01-15 01:24:41 -05:00
### Project Setup
2023-12-14 16:54:11 -05:00
2024-01-15 01:24:41 -05:00
You will need the following installed:
2023-12-14 16:54:11 -05:00
2024-01-15 01:24:41 -05:00
- [Nim](https://nim-lang.org/)
- Nimble (comes with Nim compiler)
2024-01-15 02:01:37 -05:00
- [Node.js](https://nodejs.org/) (Not needed if you plan on running the code in the browser, this has not been tested yet.)
2024-01-15 01:24:41 -05:00
- NPM package manager ([pnpm](https://pnpm.io/), [yarn](https://yarnpkg.com/), [npm](https://www.npmjs.com/), etc.)
You can install this library using `nimble`:
2023-12-14 16:54:11 -05:00
2024-01-12 15:24:40 -05:00
```sh
2024-01-15 01:24:41 -05:00
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]
2024-01-12 15:24:40 -05:00
```
2024-01-15 01:24:41 -05:00
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:
2023-12-14 16:54:11 -05:00
2024-01-12 15:24:40 -05:00
```sh
2024-01-15 01:24:41 -05:00
# If using pnpm
pnpm add matrix-bot-sdk
#If using yarn
yarn add matrix-bot-sdk
#If using npm
npm install matrix-bot-sdk
2024-01-12 15:24:40 -05:00
```
2024-01-15 01:24:41 -05:00
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.