Skip to content

Commit 2fb2243

Browse files
committed
feat(libraries): add documentation for Lua SDK
Add documentation for the community maintained Top.gg Lua SDK.
1 parent 624141c commit 2fb2243

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

content/libraries/lua.mdx

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
name: Lua
3+
description: A community maintained Top.gg Lua library
4+
---
5+
6+
## Links
7+
8+
[GitHub](https://github.com/top-gg/lua-sdk)
9+
10+
## Installation
11+
12+
You need to install the `git` CLI (Command Line Interface) and add it to the `PATH`.
13+
14+
You can check GitHub's Git Guides on [installation of the Git CLI](https://github.com/git-guides/install-git).
15+
16+
After installing the Git CLI, you can clone the GitHub repository listed [here](#links) by using:
17+
18+
```bash
19+
$ git clone https://github.com/top-gg/lua-sdk
20+
```
21+
22+
After cloning the GitHub repository, you should put the directory of the cloned GitHub repository in the root direcrory of your project's directory and require the library by using the following segment of code:
23+
24+
```lua
25+
package.path = './?/init.lua' .. package.path;
26+
local topgg = require('topgg');
27+
```
28+
29+
## Dependencies
30+
31+
This library requires all 3 of the following dependencies to work properly:
32+
33+
1. `creationix/coro-http@3.2.0`
34+
2. `luvit/json`
35+
3. `luvit/secure-socket`
36+
37+
## Usage
38+
39+
For full usage and documentation of the library, please refer to the GithHub repository listed [here](#links).
40+
41+
## Posting stats
42+
43+
```lua
44+
local topgg = require('topgg');
45+
local Api = topgg.Api:init('your-top.gg-token-goes-here');
46+
47+
local postStats = coroutine.create(function()
48+
local stats = Api:postStats({
49+
serverCount = -- Your server count goes here (e.g. client.guilds.__len())
50+
});
51+
52+
print(stats);
53+
end);
54+
55+
coroutine.resume(postStats);
56+
```
57+
58+
## Auto-posting
59+
60+
```lua
61+
local topgg = require('topgg');
62+
63+
local autoPoster = coroutine.create(function()
64+
topgg.Autoposter:init('your-top.gg-token-goes-here', yourClientGoesHere);
65+
topgg.Autoposter:on('posted', function()
66+
print('Top.gg stats posted!');
67+
end);
68+
end);
69+
70+
coroutine.resume(autoPoster);
71+
```
72+

0 commit comments

Comments
 (0)