Skip to content

Commit 171f349

Browse files
committed
New features and fixes
1 parent 6623197 commit 171f349

File tree

12 files changed

+41
-78
lines changed

12 files changed

+41
-78
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@ Easy AutoPosting via the [top.gg sdk](https://npmjs.com/package/@top-gg/sdk)
44
# How to
55
It's really really simple! All you gotta do is:
66
```js
7-
const AutoPoster = require('topgg-autoposter')
7+
const { AutoPoster } = require('topgg-autoposter')
88

9-
const ap = AutoPoster('topggtoken', client) // your discord.js or eris client
9+
const poster = AutoPoster('topggtoken', client) // your discord.js or eris client
1010

1111
// optional
12-
ap.on('posted', () => { // ran when succesfully posted
13-
console.log('Posted stats to top.gg')
12+
poster.on('posted', (stats) => { // ran when succesfully posted
13+
console.log(`Posted stats to Top.gg | ${stats.serverCount} servers`)
1414
})
1515
```
16+
*You can also do poster.on('error', (err) => { ... }) and this will stop errors from being logged and left for you to handle*
17+
1618
And that's it!
1719

1820
It will begin to post your server count, and shard count every 30 minutes.
1921

2022
This even work on individual Discord.JS shards that are process separated.
2123

22-
If you would like to do specific clients, `AutoPoster.DJSPoster` & `AutoPoster.ErisPoster` & `AutoPoster.DJSSharderPoster` with the same parameters!
24+
If you would like to do specific clients, `DJSPoster` & `ErisPoster` & `DJSSharderPoster` & `RosePoster` are all exported classes!
2325

2426
## Traditional Discord.JS Sharding:
2527

index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

package-lock.json

Lines changed: 6 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "topgg-autoposter",
3-
"version": "1.2.0",
3+
"version": "2.0.0",
44
"description": "Auto-Poster for Top.gg",
5-
"main": "index.js",
5+
"main": "dist/index.js",
66
"scripts": {
77
"test": "node ./tests/test.js",
88
"build": "tsc",
@@ -24,6 +24,7 @@
2424
"eris": "latest"
2525
},
2626
"dependencies": {
27+
"@jpbberry/typed-emitter": "^1.0.1",
2728
"@top-gg/sdk": "^3.0.9",
2829
"typescript": "^4.2.3"
2930
},

src/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import DJSPoster from './structs/DJSPoster'
2-
import ErisPoster from './structs/ErisPoster'
3-
import DJSSharderPoster from './structs/DJSSharderPoster'
4-
import RosePoster from './structs/RosePoster'
1+
import { DJSPoster } from './structs/DJSPoster'
2+
import { ErisPoster } from './structs/ErisPoster'
3+
import { DJSSharderPoster } from './structs/DJSSharderPoster'
4+
import { RosePoster } from './structs/RosePoster'
55

66
import { BasePoster } from './structs/BasePoster'
77

@@ -17,7 +17,7 @@ import { PosterOptions } from './typings'
1717
*
1818
* AutoPoster('topggtoken', client) // that's it!
1919
*/
20-
function AutoPoster (token: string, client: any, options?: PosterOptions): BasePoster {
20+
export function AutoPoster (token: string, client: any, options?: PosterOptions): BasePoster {
2121
if (!token) throw new Error('Top.gg token is missing')
2222
if (!client) throw new Error('Client is missing')
2323
let DiscordJS
@@ -43,9 +43,9 @@ function AutoPoster (token: string, client: any, options?: PosterOptions): BaseP
4343
throw new Error('Unsupported client')
4444
}
4545

46-
AutoPoster.DJSPoster = DJSPoster
47-
AutoPoster.ErisPoster = ErisPoster
48-
AutoPoster.DJSSharderPost = DJSSharderPoster
49-
AutoPoster.RosePoster = RosePoster
46+
export { DJSPoster } from './structs/DJSPoster'
47+
export { ErisPoster } from './structs/ErisPoster'
48+
export { DJSSharderPoster } from './structs/DJSSharderPoster'
49+
export { RosePoster } from './structs/RosePoster'
5050

51-
export default AutoPoster
51+
export default AutoPoster

src/structs/BasePoster.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { EventEmitter } from 'events'
21
import { Api } from '@top-gg/sdk'
2+
import { EventEmitter } from '@jpbberry/typed-emitter'
33

44
import { BotStats } from '@top-gg/sdk/dist/typings'
55

@@ -11,12 +11,10 @@ export interface BasePosterInterface {
1111
waitForReady: (fn: () => void) => void
1212
}
1313

14-
export interface BasePoster {
15-
on(event: 'posted', listener: (stats) => void)
16-
on(event: 'error', listener: (Error) => void)
17-
}
18-
19-
export class BasePoster extends EventEmitter {
14+
export class BasePoster extends EventEmitter<{
15+
posted: BotStats,
16+
error: Error
17+
}> {
2018
private options: PosterOptions
2119
private binds: BasePosterInterface
2220
private api: Api
@@ -89,6 +87,9 @@ export class BasePoster extends EventEmitter {
8987
public async post () {
9088
this.api.postStats(await this.binds.getStats())
9189
.then((data) => this.emit('posted', data))
92-
.catch((err) => "error" in this._events ? this.emit("error", err) : console.error(err))
90+
.catch((err) => this.eventNames().includes('error')
91+
? this.emit('error', err)
92+
: console.error(err)
93+
)
9394
}
9495
}

src/structs/DJSPoster.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Client } from 'discord.js'
99
/**
1010
* Auto-Poster For Discord.JS
1111
*/
12-
export default class DJSPoster extends BasePoster implements BasePosterInterface {
12+
export class DJSPoster extends BasePoster implements BasePosterInterface {
1313
private client: Client
1414

1515
/**

src/structs/DJSSharderPoster.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { PosterOptions } from '../typings'
99
/**
1010
* Auto-Poster For Discord.JS ShardingManager
1111
*/
12-
export default class DJSSharderPoster extends BasePoster implements BasePosterInterface {
12+
export class DJSSharderPoster extends BasePoster implements BasePosterInterface {
1313
private client: ShardingManager
1414

1515
/**

src/structs/ErisPoster.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { PosterOptions } from '../typings'
99
/**
1010
* Auto-Poster For Eris
1111
*/
12-
export default class ErisPoster extends BasePoster implements BasePosterInterface {
12+
export class ErisPoster extends BasePoster implements BasePosterInterface {
1313
private client: Client
1414

1515
/**

src/structs/RosePoster.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { PosterOptions } from '../typings'
99
/**
1010
* Auto-Poster For Discord-Rose
1111
*/
12-
export default class RosePoster extends BasePoster implements BasePosterInterface {
12+
export class RosePoster extends BasePoster implements BasePosterInterface {
1313
private client: Master
1414

1515
/**

0 commit comments

Comments
 (0)