Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #111 from TMWare/dev
Browse files Browse the repository at this point in the history
chore(deps): upgrade all dependencies
  • Loading branch information
TMUniversal authored Apr 21, 2021
2 parents cec59a8 + 27b5f4b commit b94a5f2
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 204 deletions.
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,26 @@
"peerDependencies": {},
"dependencies": {
"@tmware/jitsuyo": "^1.5.1",
"@tmware/variable-parser": "^1.1.3",
"@tmware/variable-parser": "^1.1.4",
"axios": "0.21.1",
"discord-akairo": "^8.1.0",
"discord.js": "^12.5.3"
},
"devDependencies": {
"@commitlint/cli": "^12.1.1",
"@commitlint/config-conventional": "^12.1.1",
"@tmuniversal/ts": "^1.1.2",
"@tmuniversal/ts": "^1.2.1",
"@tmware/eslint-config": "^1.1.2",
"@tmware/eslint-config-typescript": "^1.0.5",
"@tmware/eslint-config-typescript": "^1.0.7",
"@tmware/semantic-release-npm-github-publish": "^1.4.2",
"@types/node": "^14.14.37",
"@types/node": "^14.14.41",
"@types/ws": "^7.4.1",
"cz-conventional-changelog": "3.3.0",
"eslint": "^7.23.0",
"eslint": "^7.24.0",
"husky": "^6.0.0",
"rimraf": "^3.0.2",
"semantic-release": "^17.4.2"
"semantic-release": "^17.4.2",
"typescript": "^4.2.4"
},
"config": {
"commitizen": {
Expand Down
23 changes: 12 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use strict'

import Util from '@tmware/jitsuyo'
import VariableParser from '@tmware/variable-parser'
import VariableParser, { VariableParserData } from '@tmware/variable-parser'
import Axios from 'axios'
import { AkairoClient } from 'discord-akairo'
import { ActivityOptions, Client as DJSClient, Presence } from 'discord.js'
Expand All @@ -18,13 +18,13 @@ const defaultStatuses: ActivityOptions[] = [
export type DiscordClient = AkairoClient | DJSClient

export default class StatusUpdater {
private readonly client: DiscordClient
private readonly parser: VariableParser
private readonly client!: DiscordClient
private readonly parser!: VariableParser
public statusUrl?: string
private _statuses: ActivityOptions[]
private isReady: boolean
private _statuses!: ActivityOptions[]
private isReady!: boolean
// eslint-disable-next-line no-undef
private timer: NodeJS.Timeout | false
private timer!: NodeJS.Timeout | false
/**
* A status updater that can pull from the internet
* @param {DiscordClient} client discord.js (extending) client
Expand Down Expand Up @@ -160,7 +160,7 @@ export default class StatusUpdater {
* @example
* updateParserData({ someName: "something" })
*/
public updateParserData (data): Object {
public updateParserData (data: VariableParserData): Object {
return this.parser.updateData(data)
}

Expand Down Expand Up @@ -195,22 +195,23 @@ export default class StatusUpdater {
* @returns {Promise<Presence>}
*/
public async updateStatus (activity?: ActivityOptions, shardId?: number): Promise<Presence> {
if (!this.client.user) throw new Error('cannot update status of undefined client user')
this._updateParserData()
const $activity = this.getSafeActivity(activity) || this._chooseActivity()
const $activity = activity ? this.getSafeActivity(activity) : this._chooseActivity()
if (shardId) $activity.shardID = shardId
return await this.client.user.setActivity($activity)
}

private _chooseActivity (): ActivityOptions {
return this.getSafeActivity(Util.arrayHelper.pickRandom(this.statuses))
return this.getSafeActivity(Util.arrayHelper.pickRandom(this.statuses) as ActivityOptions)
}

private getSafeActivity (info: ActivityOptions): ActivityOptions {
if (!info) return
return {
...info,
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
type: info.type || 'PLAYING',
name: this.parser.parse(info.name) || 'a game'
name: info.name ? this.parser.parse(info.name) : 'a game'
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"extends": "@tmuniversal/ts/config",
"compilerOptions": {
"outDir": "./dist",
"declaration": false,
"sourceMap": false,
"inlineSources": false,
"inlineSourceMap": false
},
Expand Down
Loading

0 comments on commit b94a5f2

Please sign in to comment.