-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add release GitHub action and documentation (#39)
* Add release action * Add documentation * Finishing touches * Fix package.json
- Loading branch information
Showing
16 changed files
with
1,190 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Publish to NPM | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: 12 | ||
registry-url: https://registry.npmjs.org/ | ||
- run: npm publish --unsafe-perm | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.NPM_SECRET}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
dist/ | ||
|
||
docs/build | ||
# Logs | ||
logs | ||
*.log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
node_modules/ | ||
src/ | ||
docs/ | ||
logs/ | ||
*.log | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,229 @@ | ||
<a name="Api"></a> | ||
|
||
## Api | ||
Top.gg API Client for Posting stats or Fetching data | ||
|
||
**Kind**: global class | ||
**Link**: https://top.gg/api/docs | ||
|
||
* [Api](#Api) | ||
* [new Api(token, options)](#new_Api_new) | ||
* [.postStats(stats)](#Api+postStats) ⇒ <code>BotStats</code> | ||
* [.getStats(id)](#Api+getStats) ⇒ <code>BotStats</code> | ||
* [.getBot(id)](#Api+getBot) ⇒ <code>BotInfo</code> | ||
* [.getUser(id)](#Api+getUser) ⇒ <code>UserInfo</code> | ||
* [.getBots(query)](#Api+getBots) ⇒ <code>BotsResponse</code> | ||
* [.getVotes()](#Api+getVotes) ⇒ <code>Array.<ShortUser></code> | ||
* [.hasVoted(id)](#Api+hasVoted) ⇒ <code>Boolean</code> | ||
* [.isWeekend()](#Api+isWeekend) ⇒ <code>Boolean</code> | ||
|
||
<a name="new_Api_new"></a> | ||
|
||
### new Api(token, options) | ||
Create Top.gg API instance | ||
|
||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| token | <code>string</code> | Token or options | | ||
| options | <code>object</code> | API Options | | ||
|
||
**Example** | ||
```js | ||
const Topgg = require(`@top-gg/sdk`) | ||
|
||
const api = new Topgg.Api('Your top.gg token') | ||
``` | ||
<a name="Api+postStats"></a> | ||
|
||
### api.postStats(stats) ⇒ <code>BotStats</code> | ||
Post bot stats to Top.gg (Do not use if you supplied a client) | ||
|
||
**Kind**: instance method of [<code>Api</code>](#Api) | ||
**Returns**: <code>BotStats</code> - Passed object | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| stats | <code>Object</code> | Stats object | | ||
| stats.serverCount | <code>number</code> | Server count | | ||
| stats.shardCount | <code>number</code> | Shard count | | ||
| stats.shardId | <code>number</code> | Posting shard (useful for process sharding) | | ||
|
||
**Example** | ||
```js | ||
await client.postStats({ | ||
serverCount: 28199, | ||
shardCount: 1 | ||
}) | ||
``` | ||
<a name="Api+getStats"></a> | ||
|
||
### api.getStats(id) ⇒ <code>BotStats</code> | ||
Get a bots stats | ||
|
||
**Kind**: instance method of [<code>Api</code>](#Api) | ||
**Returns**: <code>BotStats</code> - Stats of bot requested | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| id | <code>Snowflake</code> | Bot ID | | ||
|
||
**Example** | ||
```js | ||
await client.getStats('461521980492087297') | ||
// => | ||
{ | ||
serverCount: 28199, | ||
shardCount 1, | ||
shards: [] | ||
} | ||
``` | ||
<a name="Api+getBot"></a> | ||
|
||
### api.getBot(id) ⇒ <code>BotInfo</code> | ||
Get bot info | ||
|
||
**Kind**: instance method of [<code>Api</code>](#Api) | ||
**Returns**: <code>BotInfo</code> - Info for bot | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| id | <code>Snowflake</code> | Bot ID | | ||
|
||
**Example** | ||
```js | ||
await client.getBot('461521980492087297') // returns bot info | ||
``` | ||
<a name="Api+getUser"></a> | ||
|
||
### api.getUser(id) ⇒ <code>UserInfo</code> | ||
Get user info | ||
|
||
**Kind**: instance method of [<code>Api</code>](#Api) | ||
**Returns**: <code>UserInfo</code> - Info for user | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| id | <code>Snowflake</code> | User ID | | ||
|
||
**Example** | ||
```js | ||
await client.getUser('205680187394752512') | ||
// => | ||
user.username // Xignotic | ||
``` | ||
<a name="Api+getBots"></a> | ||
|
||
### api.getBots(query) ⇒ <code>BotsResponse</code> | ||
Get a list of bots | ||
|
||
**Kind**: instance method of [<code>Api</code>](#Api) | ||
**Returns**: <code>BotsResponse</code> - Return response | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| query | <code>BotsQuery</code> | Bot Query | | ||
|
||
**Example** | ||
```js | ||
// Finding by properties | ||
await client.getBots({ | ||
search: { | ||
username: 'shiro', | ||
certifiedBot: true | ||
...any other bot object properties | ||
} | ||
}) | ||
// => | ||
{ | ||
results: [ | ||
{ | ||
id: '461521980492087297', | ||
username: 'Shiro', | ||
discriminator: '8764', | ||
lib: 'discord.js', | ||
...rest of bot object | ||
} | ||
...other shiro knockoffs B) | ||
], | ||
limit: 10, | ||
offset: 0, | ||
count: 1, | ||
total: 1 | ||
} | ||
// Restricting fields | ||
await client.getBots({ | ||
fields: ['id', 'username'] | ||
}) | ||
// => | ||
{ | ||
results: [ | ||
{ | ||
id: '461521980492087297', | ||
username: 'Shiro' | ||
}, | ||
{ | ||
id: '493716749342998541', | ||
username: 'Mimu' | ||
}, | ||
... | ||
], | ||
... | ||
} | ||
``` | ||
<a name="Api+getVotes"></a> | ||
|
||
### api.getVotes() ⇒ <code>Array.<ShortUser></code> | ||
Get users who've voted | ||
|
||
**Kind**: instance method of [<code>Api</code>](#Api) | ||
**Returns**: <code>Array.<ShortUser></code> - Array of users who've voted | ||
**Example** | ||
```js | ||
await client.getVotes() | ||
// => | ||
[ | ||
{ | ||
username: 'Xignotic', | ||
discriminator: '0001', | ||
id: '205680187394752512', | ||
avatar: '3b9335670c7213b3a2d4e990081900c7' | ||
}, | ||
{ | ||
username: 'iara', | ||
discriminator: '0001', | ||
id: '395526710101278721', | ||
avatar: '3d1477390b8d7c3cec717ac5c778f5f4' | ||
} | ||
...more | ||
] | ||
``` | ||
<a name="Api+hasVoted"></a> | ||
|
||
### api.hasVoted(id) ⇒ <code>Boolean</code> | ||
Get whether or not a user has voted | ||
|
||
**Kind**: instance method of [<code>Api</code>](#Api) | ||
**Returns**: <code>Boolean</code> - Whether the user has voted | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| id | <code>Snowflake</code> | User ID | | ||
|
||
**Example** | ||
```js | ||
await client.hasVoted('205680187394752512') | ||
// => true/false | ||
``` | ||
<a name="Api+isWeekend"></a> | ||
|
||
### api.isWeekend() ⇒ <code>Boolean</code> | ||
Whether or not the weekend multiplier is active | ||
|
||
**Kind**: instance method of [<code>Api</code>](#Api) | ||
**Returns**: <code>Boolean</code> - Whether the the multiplier is active | ||
**Example** | ||
```js | ||
await client.hasVoted() | ||
// => true/false | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<a name="Change Log"></a> | ||
|
||
# Change Log | ||
|
||
## 3.0.4 | ||
- Released official documentation page | ||
- Added GitHub actions to publish to npm on release | ||
|
||
## 3.0.3 | ||
- Fixed some webhook bugs | ||
- Improved a few typings | ||
|
||
## 3.0.2 | ||
Some day-one patches to README, 3.0.1 is a dud release | ||
|
||
## 3.0.0 | ||
A full rewrite of the package, here's some of the major changes: | ||
- The webhook and API interaction have been full separated, into two different classes, `Api` and `Webhook` | ||
- Auto-Posting is no longer natively supported in the package, instead you can use the officially *supported* [`topgg-autoposter`](https://npmjs.com/topgg-autoposter) package. | ||
- The webhook class is no longer ran off of events, instead acting as a middleware function that defines `req.vote` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Minimal makefile for Sphinx documentation | ||
# | ||
|
||
# You can set these variables from the command line. | ||
SPHINXOPTS = | ||
SPHINXBUILD = sphinx-build | ||
SOURCEDIR = ./ | ||
BUILDDIR = build | ||
|
||
# Put it first so that "make" without argument is like "make help". | ||
help: | ||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) | ||
|
||
.PHONY: help Makefile | ||
|
||
# Catch-all target: route all unknown targets to Sphinx using the new | ||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). | ||
%: Makefile | ||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<a name="Webhook"></a> | ||
|
||
## Webhook | ||
Top.gg Webhook | ||
|
||
**Kind**: global class | ||
|
||
* [Webhook](#Webhook) | ||
* [new Webhook(authorization)](#new_Webhook_new) | ||
* [.middleware()](#Webhook+middleware) | ||
|
||
<a name="new_Webhook_new"></a> | ||
|
||
### new Webhook(authorization) | ||
Create a new webhook client instance | ||
|
||
|
||
| Param | Description | | ||
| --- | --- | | ||
| authorization | Webhook authorization to verify requests | | ||
|
||
**Example** | ||
```js | ||
const express = require('express') | ||
const { Webhook } = require(`@top-gg/sdk`) | ||
|
||
const app = express() | ||
const wh = new Webhook('webhookauth123') | ||
|
||
app.post('/dblwebhook', wh.middleware(), (req, res) => { | ||
// req.vote is your vote object e.g | ||
console.log(req.vote.user) // => 321714991050784770 | ||
}) | ||
|
||
app.listen(80) | ||
|
||
// In this situation, your TopGG Webhook dashboard should look like | ||
// URL = http://your.server.ip:80/dblwebhook | ||
// Authorization: webhookauth123 | ||
``` | ||
<a name="Webhook+middleware"></a> | ||
|
||
### webhook.middleware() | ||
Middleware function to pass to express, sets req.vote to the payload | ||
|
||
**Kind**: instance method of [<code>Webhook</code>](#Webhook) | ||
**Example** | ||
```js | ||
app.post('/dblwebhook', wh.middleware(), (req, res) => { | ||
// req.vote is your payload e.g | ||
console.log(req.vote.user) // => 395526710101278721 | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
project = "Topgg Node SDK" | ||
author = "Top.gg" | ||
|
||
extensions = ["recommonmark", "sphinx_markdown_tables"] | ||
|
||
source_suffix = [".md", ".rst"] | ||
|
||
html_theme = "sphinx_rtd_theme" | ||
|
||
master_doc = "master" | ||
|
||
html_theme_options = { | ||
"collapse_navigation": True, | ||
"sticky_navigation": True, | ||
"includehidden": True | ||
} |
Oops, something went wrong.