Skip to content

Commit

Permalink
ESLint + new api url + events + postEvent -> custom
Browse files Browse the repository at this point in the history
  • Loading branch information
DEVTomatoCake committed Dec 16, 2023
1 parent 9f1a585 commit c0a9a6d
Show file tree
Hide file tree
Showing 8 changed files with 1,813 additions and 3,268 deletions.
87 changes: 77 additions & 10 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"node": true,
"es2022": true
},
"ignorePatterns": ["util/temp.js", "befehle/eval.js"],
"plugins": ["unicorn", "sonarjs"],
"ignorePatterns": ["index.test.js"],
"rules": {
"array-bracket-spacing": 2,
"array-callback-return": 2,
Expand All @@ -23,12 +24,12 @@
"key-spacing": 2,
"keyword-spacing": 2,
"max-statements-per-line": 2,
"max-len": [2, { "code": 500 }],
"new-cap": 2,
"max-len": [2, { "code": 250 }],
"new-parens": 2,
"no-array-constructor": 2,
"no-compare-neg-zero": 2,
"no-const-assign": 2,
"no-constructor-return": 2,
"no-dupe-args": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
Expand Down Expand Up @@ -60,7 +61,7 @@
"no-unreachable": 1,
"no-unreachable-loop": 2,
"no-unsafe-finally": 2,
"no-unused-vars": [2, { "argsIgnorePattern": "args|next", "varsIgnorePattern": "updateSlashcommands" }],
"no-unused-vars": 2,
"no-useless-computed-key": 2,
"no-useless-rename": 2,
"no-useless-escape": 2,
Expand All @@ -72,6 +73,7 @@
"no-useless-backreference": 2,
"no-useless-catch": 2,
"no-unneeded-ternary": 2,
"no-undef": [2, { "typeof": true }],
"no-undef-init": 2,
"no-useless-constructor": 2,
"no-redeclare": 2,
Expand All @@ -83,9 +85,8 @@
"no-unsafe-optional-chaining": 2,
"no-unmodified-loop-condition": 2,
"no-promise-executor-return": 2,
"no-warning-comments": 2,
"no-new": 2,
"no-var": 1,
"no-warning-comments": 1,
"no-var": 2,
"no-new-func": 2,
"no-new-wrappers": 2,
"no-multi-str": 2,
Expand All @@ -97,14 +98,80 @@
"no-irregular-whitespace": [2, { "skipRegExps": true }],
"no-constant-condition": 2,
"no-undefined": 2,
"no-confusing-arrow": 2,
"no-lone-blocks": 2,
"no-whitespace-before-property": 2,
"object-shorthand": 2,
"prefer-arrow-callback": 2,
"prefer-const": 1,
"prefer-const": 2,
"quotes": [2, "double", { "allowTemplateLiterals": false, "avoidEscape": true }],
"use-isnan": 2,
"valid-typeof": 2
"valid-typeof": 2,

"unicorn/empty-brace-spaces": 2,
"unicorn/error-message": 2,
"unicorn/new-for-builtins": 2,
"unicorn/consistent-destructuring": 2,
"unicorn/consistent-function-scoping": 2,
"unicorn/no-array-method-this-argument": 2,
"unicorn/no-lonely-if": 2,
"unicorn/no-instanceof-array": 2,
"unicorn/no-nested-ternary": 2,
"unicorn/no-new-buffer": 2,
"unicorn/no-console-spaces": 2,
"unicorn/no-for-loop": 2,
"unicorn/no-useless-undefined": 2,
"unicorn/no-zero-fractions": 2,
"unicorn/no-unreadable-iife": 2,
"unicorn/no-unnecessary-await": 2,
"unicorn/no-unreadable-array-destructuring": 2,
"unicorn/no-useless-switch-case": 2,
"unicorn/no-typeof-undefined": 2,
"unicorn/no-useless-fallback-in-spread": 2,
"unicorn/no-useless-length-check": 2,
"unicorn/no-useless-spread": 2,
"unicorn/no-useless-promise-resolve-reject": 2,
"unicorn/prefer-array-find": 2,
"unicorn/prefer-array-index-of": 2,
"unicorn/prefer-includes": 2,
"unicorn/prefer-logical-operator-over-ternary": 2,
"unicorn/prefer-date-now": 2,
"unicorn/prefer-default-parameters": 2,
"unicorn/prefer-array-some": 2,
"unicorn/prefer-blob-reading-methods": 2,
"unicorn/prefer-at": 2,
"unicorn/prefer-optional-catch-binding": 2,
"unicorn/prefer-regexp-test": 2,
"unicorn/prefer-set-has": 2,
"unicorn/prefer-set-size": 2,
"unicorn/prefer-negative-index": 2,
"unicorn/prefer-node-protocol": 2,
"unicorn/prefer-prototype-methods": 2,
"unicorn/prefer-string-trim-start-end": 2,
"unicorn/prefer-string-starts-ends-with": 2,
"unicorn/require-array-join-separator": 2,
"unicorn/require-number-to-fixed-digits-argument": 2,
"unicorn/switch-case-braces": [2, "avoid"],
"unicorn/text-encoding-identifier-case": 2,

"sonarjs/no-extra-arguments": 2,
"sonarjs/no-empty-collection": 2,
"sonarjs/no-element-overwrite": 2,
"sonarjs/no-use-of-empty-return-value": 2,
"sonarjs/no-all-duplicated-branches": 2,
"sonarjs/no-ignored-return": 2,
"sonarjs/no-identical-expressions": 2,
"sonarjs/no-one-iteration-loop": 2,
"sonarjs/non-existent-operator": 2,
"sonarjs/no-redundant-boolean": 2,
"sonarjs/no-unused-collection": 2,
"sonarjs/prefer-immediate-return": 2,
"sonarjs/no-inverted-boolean-check": 2,
"sonarjs/no-redundant-jump": 2,
"sonarjs/no-same-line-conditional": 2,
"sonarjs/prefer-object-literal": 2,
"sonarjs/no-collection-size-mischeck": 2,
"sonarjs/prefer-while": 2,
"sonarjs/no-gratuitous-expressions": 2,
"sonarjs/no-duplicated-branches": 2
}
}
8 changes: 4 additions & 4 deletions .github/workflows/eslint.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
name: ESLint
name: Run ESLint

on:
push:
branches: [ master ]
pull_request:

jobs:
lint:
name: ESLint
runs-on: ubuntu-latest
steps:
- name: "☁️ checkout repository"
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: "🔧 setup node"
uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
cache: "npm"

- name: "🔍 lint code"
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
name: Run tests
name: Run Jest tests

on:
push:
pull_request:

jobs:
test:
name: Run jest
name: Tests
runs-on: ubuntu-latest
steps:
- name: "☁️ checkout repository"
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: "🔧 setup node"
uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
cache: "npm"

- name: "🔍 run tests"
Expand Down
51 changes: 32 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# DisStat-npm
The official npm package for [DisStat](https://disstat.numselli.xyz)
The official npm package for [DisStat](https://disstat.pages.dev) -
DisStat itself is [open source](https://github.com/DisStat/DisStat) btw!

You can find the public api and example responses on https://disstat.numselli.xyz/docs,
if you dont want to use an api wrapper.

## ⚠️ Warning: This package is still in development and may not work as expected.
DisStat itself is still in development too, so expect breaking changes while we're not fully released.
You can find the public HTTP api docs on https://disstat.pages.dev/docs if you dont want to use an api wrapper.

# Installation
```bash
Expand All @@ -17,16 +14,17 @@ npm i disstat
const DisStat = require("disstat")

/*
* @param {string} apiKey - Your api key, found at the bot page
* @param {string} bot - Your bot's user id OR a discord.js based bot client.
* If a client is provided, the package will automatically post server and user count to DisStat.
* @param {string} apiKey - Your api key, found in your dashboard on https://disstat.pages.dev/me
* @param {string|Discord.Client} bot - Your bot's user id OR a discord.js based bot client.
*
* If a client is provided, the package will automatically post server and user count to DisStat ("autoposting").
* Note that the client has to be ready, so if you're using a client there, put this into it's ready event.
*/
const disstat = new DisStat("DS-apikey123", "685166801394335819")
const disstat = new DisStat("DS-apikey123", client)

/*
* Gets data from your bot or someone else's (public) bot.
* Gets data from your bot or someone else public bot.
* @param {string} botId? - The bot's id
* @returns {Promise<Object>} - The bot's data
*/
Expand All @@ -35,27 +33,42 @@ console.log(botData)

/*
* Posts your bots data to DisStat.
* @param {Object} data - The data to post
* Warning: You shouldn't use this when autoposting.
*
* @param {Object} data - The data to post:
* @param {number} data.servers - The amount of servers your bot is in, e.g. client.guilds.cache.size
* @param {number} data.users - The amount of users your bot can see, e.g. client.users.cache.size
* @param {number} data.shards - The amount of shards your bot is using, e.g. client.shard.count
* @param {boolean} returnStats? - Whether to return the stats after posting, default false
* @returns {Promise<Object>} - The stats after posting, if returnStats is true
*/
const newBotData = await disstat.postData({ servers: 42, users: 100, shards: 1 }, true)
const newBotData = await disstat.postData({ servers: 42, users: 100, shards: 1 })
console.log(newBotData)

/*
* Posts a command to DisStat.
* You shouldn't post user generated commands like custom commands to protect user privacy.
* You also should exclude the prefix and command arguments from the command.
*
* @param {string} command - The command to post
* @param {string} userId? - The user's id
* @param {string} guildId? - The guild's id
* @param {Boolean} force? - Whether to force the command to be posted instantly IF autoposting is enabled,
* defaults to false, causing a delay from up to 90 seconds.
*/
disstat.postCommand("help", "581146486646243339")
disstat.postCommand("info")
disstat.postCommand("help", "581146486646243339", "1081089799324180490")

/*
* Posts an event to DisStat.
* @param {string} command - The command to post
* @param {string} userId? - The user's id
* Posts data for a custom graph to DisStat.
* Note that using a not used type here creates the custom graph on DisStat if you have enough unused graph slots.
*
* @param {string} type - The type of event to post
* @param {string|Number} value1? - First custom value (e.g. an event name like "interactionCreate")
* @param {string|Number} value2? - Second custom value (e.g. a user ID)
* @param {string|Number} value3? - Third custom value (e.g. a guild ID)
*/
disstat.postEvent("interactionCreate", "581146486646243339")
disstat.postCustom("events", "interactionCreate")

if (message.content.includes("<@" + bot.user.id + ">")) {
disstat.postCustom("ping")
}
```
Loading

0 comments on commit c0a9a6d

Please sign in to comment.