-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from wzhouwzhou/rewrite-2.0.0
Release 2.0.0
- Loading branch information
Showing
78 changed files
with
23,164 additions
and
157 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,153 @@ | ||
{ | ||
"extends": "eslint:recommended", | ||
"parserOptions": { | ||
"ecmaVersion": 2017 | ||
}, | ||
"env": { | ||
"es6": true, | ||
"node": true | ||
}, | ||
"overrides": [ | ||
{ "files": ["*.browser.js"], "env": { "browser": true } } | ||
], | ||
"rules": { | ||
"no-await-in-loop": "warn", | ||
"no-compare-neg-zero": "error", | ||
"no-extra-parens": ["warn", "all", { | ||
"nestedBinaryExpressions": false | ||
}], | ||
"no-template-curly-in-string": "error", | ||
"no-unsafe-negation": "error", | ||
"valid-jsdoc": ["error", { | ||
"requireReturn": false, | ||
"requireReturnDescription": false, | ||
"prefer": { | ||
"return": "return", | ||
"arg": "param" | ||
}, | ||
"preferType": { | ||
"String": "string", | ||
"Number": "number", | ||
"Boolean": "boolean", | ||
"Symbol": "symbol", | ||
"object": "Object", | ||
"function": "Function", | ||
"array": "Array", | ||
"date": "Date", | ||
"error": "Error", | ||
"null": "void" | ||
} | ||
}], | ||
|
||
"accessor-pairs": "warn", | ||
"array-callback-return": "error", | ||
"complexity": "warn", | ||
"consistent-return": "error", | ||
"curly": ["error", "multi-line", "consistent"], | ||
"dot-location": ["error", "property"], | ||
"dot-notation": "error", | ||
"eqeqeq": "error", | ||
"no-empty-function": "error", | ||
"no-floating-decimal": "error", | ||
"no-implied-eval": "error", | ||
"no-invalid-this": "error", | ||
"no-lone-blocks": "error", | ||
"no-multi-spaces": "error", | ||
"no-new-func": "error", | ||
"no-new-wrappers": "error", | ||
"no-new": "error", | ||
"no-octal-escape": "error", | ||
"no-return-assign": "error", | ||
"no-return-await": "error", | ||
"no-self-compare": "error", | ||
"no-sequences": "error", | ||
"no-throw-literal": "error", | ||
"no-unmodified-loop-condition": "error", | ||
"no-unused-expressions": "error", | ||
"no-useless-call": "error", | ||
"no-useless-concat": "error", | ||
"no-useless-escape": "error", | ||
"no-useless-return": "error", | ||
"no-void": "error", | ||
"no-warning-comments": "warn", | ||
"prefer-promise-reject-errors": "error", | ||
"require-await": "warn", | ||
"wrap-iife": "error", | ||
"yoda": "error", | ||
|
||
"no-label-var": "error", | ||
"no-shadow": "error", | ||
"no-undef-init": "error", | ||
|
||
"callback-return": "error", | ||
"handle-callback-err": "error", | ||
"no-mixed-requires": "error", | ||
"no-new-require": "error", | ||
"no-path-concat": "error", | ||
|
||
"array-bracket-spacing": "error", | ||
"block-spacing": "error", | ||
"brace-style": ["error", "1tbs", { "allowSingleLine": true }], | ||
"capitalized-comments": ["error", "always", { "ignoreConsecutiveComments": true }], | ||
"comma-dangle": ["error", "always-multiline"], | ||
"comma-spacing": "error", | ||
"comma-style": "error", | ||
"computed-property-spacing": "error", | ||
"consistent-this": ["error", "$this"], | ||
"eol-last": "error", | ||
"func-names": "error", | ||
"func-name-matching": "error", | ||
"func-style": ["error", "declaration", { "allowArrowFunctions": true }], | ||
"indent": ["error", 2, { "SwitchCase": 1 }], | ||
"key-spacing": "error", | ||
"keyword-spacing": "error", | ||
"max-depth": "error", | ||
"max-len": ["error", 120, 2], | ||
"max-nested-callbacks": ["error", { "max": 4 }], | ||
"max-statements-per-line": ["error", { "max": 2 }], | ||
"new-cap": "off", | ||
"newline-per-chained-call": ["error", { "ignoreChainWithDepth": 3 }], | ||
"no-array-constructor": "error", | ||
"no-inline-comments": "error", | ||
"no-lonely-if": "error", | ||
"no-mixed-operators": "error", | ||
"no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1, "maxBOF": 0 }], | ||
"no-new-object": "error", | ||
"no-spaced-func": "error", | ||
"no-trailing-spaces": "error", | ||
"no-unneeded-ternary": "error", | ||
"no-whitespace-before-property": "error", | ||
"nonblock-statement-body-position": "error", | ||
"object-curly-spacing": ["error", "always"], | ||
"operator-assignment": "error", | ||
"operator-linebreak": ["error", "after"], | ||
"padded-blocks": ["error", "never"], | ||
"quote-props": ["error", "as-needed"], | ||
"quotes": ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": true }], | ||
"semi-spacing": "error", | ||
"semi": "error", | ||
"space-before-blocks": "error", | ||
"space-before-function-paren": ["error", "never"], | ||
"space-in-parens": "error", | ||
"space-infix-ops": "error", | ||
"space-unary-ops": "error", | ||
"spaced-comment": "error", | ||
"template-tag-spacing": "error", | ||
"unicode-bom": "error", | ||
|
||
"arrow-body-style": "error", | ||
"arrow-parens": ["error", "as-needed"], | ||
"arrow-spacing": "error", | ||
"no-duplicate-imports": "error", | ||
"no-useless-computed-key": "error", | ||
"no-useless-constructor": "error", | ||
"prefer-arrow-callback": "error", | ||
"prefer-numeric-literals": "error", | ||
"prefer-rest-params": "error", | ||
"prefer-spread": "error", | ||
"prefer-template": "error", | ||
"rest-spread-spacing": "error", | ||
"template-curly-spacing": "error", | ||
"yield-star-spacing": "error" | ||
} | ||
} |
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,8 @@ | ||
# Contributing | ||
|
||
If you wish to contribute, feel free to fork the repository and submit a pull request. | ||
Make sure you have ESLint set up in your editor of choice so that obvious mistakes can be avoided. | ||
|
||
1. Fork & clone the repository | ||
2. Code something special! | ||
3. [Submit a pull request](https://github.com/wzhouwzhou/discordblacklist/compare) |
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 @@ | ||
|
||
**Please describe the problem you are having in detail:** | ||
|
||
|
||
**Include a reproducible code sample here, if possible:** | ||
```js | ||
|
||
``` | ||
|
||
**Further details:** | ||
|
||
- discordblacklist version: | ||
- Nodejs version: | ||
- Operating system: | ||
- Priority this issue should have – please be realistic and elaborate if possible: | ||
|
||
**If applicable, check the box by replace [ ] with [x]:** | ||
- [ ] I have also tested the issue on latest master, commit hash: |
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,13 @@ | ||
|
||
**Please describe the changes in this PR and why it should be merged:** | ||
|
||
|
||
**Check all that apply by replacing [ ] with [x]:** | ||
**Semantic versioning classification:** | ||
- [ ] This PR changes the package's interface (methods or parameters added) | ||
- [ ] This PR includes breaking changes (methods removed or renamed, parameters moved or removed, etc) | ||
- [ ] This PR **only** includes non-code changes, like changes to documentation, README, etc. | ||
|
||
**Make sure these are checked:** | ||
- [ ] I have verified that my linter works properly and fixed issues that my linter may have alerted me. | ||
- [ ] I have described all changes made in this PR. |
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,7 @@ | ||
language: node_js | ||
node_js: | ||
- "8" | ||
cache: | ||
directories: | ||
- node_modules | ||
install: npm install |
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,66 +1,141 @@ | ||
|
||
# discordblacklist | ||
## A nodejs package that facilitates getting banned Discord users from DiscordBans | ||
<div align="center"> | ||
<br /> | ||
<p> | ||
<a href="https://www.npmjs.com/package/discordblacklist"><img src="https://img.shields.io/npm/v/discordblacklist.svg" alt="NPM version" /></a> | ||
<a href="https://www.npmjs.com/package/discordblacklist"><img src="https://img.shields.io/npm/dt/discordblacklist.svg" alt="NPM downloads" /></a> | ||
<a href="https://travis-ci.org/wzhouwzhou/discordblacklist"><img src="https://travis-ci.org/wzhouwzhou/discordblacklist.svg" alt="Build Status" /></a> | ||
<a href="https://david-dm.org/wzhouwzhou/discordblacklist"><img src="https://img.shields.io/david/wzhouwzhou/discordblacklist.svg" alt="Dependencies" /></a> | ||
<a href="https://paypal.me/wzhouwzhou"><img src="https://img.shields.io/badge/donate-paypal-009cde.svg" alt="Paypal" /></a> | ||
</p> | ||
<p> | ||
<a href="https://nodei.co/npm/discordblacklist/"><img src="https://nodei.co/npm/discordblacklist.png?stars=true&downloads=true"></a> | ||
</p> | ||
</div> | ||
|
||
# Discordblacklist | ||
## The Featured Nodejs package that facilitates getting banned Discord users from DiscordBans. | ||
|
||
### Installing via NPM. | ||
|
||
```$ npm install discordblacklist``` | ||
```$ npm install --save discordblacklist``` | ||
|
||
or to use JSON only for stringifying/serializing (more info below) | ||
|
||
```$ npm install --save discordblacklist --no-optional``` | ||
|
||
**Note: Version 2.x API has changed from version 1.x to support DiscordBans v3 api. Version 2.x is not backwards compatible with version 1.x code. Package dependencies have also been updated so make sure you npm install properly.** | ||
|
||
The following contains documentation for discordblacklist 2.0.0, read the 1.0.7 (the latest 1.x) documentation [here](https://github.com/wzhouwzhou/discordblacklist/releases/tag/v1.0.7) | ||
|
||
|
||
### Quickstart: | ||
|
||
// Create the object (which autorefreshes the banlist every 120 minutes) | ||
const { Blacklist } = require('discordblacklist'); | ||
const token = 'My-token'; | ||
const blacklist = new Blacklist({ token, update: true }); | ||
|
||
// Update the blacklist. | ||
await blacklist.update(); | ||
|
||
// Someone's id to test | ||
const someID = '1234567890'; | ||
|
||
// Check if they are on the banlist - Returns either null or the BannedUser. | ||
let user = blacklist.lookup(someID); | ||
|
||
// Get the full list in string JSON form. Must be used after update() has completed | ||
const jsonified = blacklist.banstore.stringify(-1, true); | ||
console.log(jsonified); | ||
|
||
// If you installed optional dependencies (erlpack) use this. | ||
const bufferstring = blacklist.banstore.stringify(-1, false); | ||
console.log(bufferstring); | ||
|
||
// If you want an Array of BannedUser objects | ||
const array = blacklist.banstore.array(); | ||
|
||
// The first user on the banlist | ||
const banneduser = array[0]; | ||
const sameBanneduser = blacklist.banstore.get('1'); | ||
console.log(banneduser); | ||
|
||
### Setup and functions. | ||
**Creating the object:** | ||
|
||
const Blacklist = require('discordblacklist'), | ||
banlist = new Blacklist('token'); | ||
**Exports:** | ||
|
||
`require('discordblacklist')` will return an Object with several keys: Blacklist, Errors, BanStore, and Constants. | ||
|
||
The Blacklist class can be set with | ||
|
||
const { Blacklist } = require('discordblacklist'); | ||
|
||
There are several ways to create an object from it, here's the simplest: | ||
|
||
const apiToken = '12345'; // Replace with actual token | ||
const blacklist = new Blacklist(apiToken); | ||
|
||
Get a token [here](https://bans.discordlist.net/mytoken). | ||
<br></br> | ||
The object will try to update its banlist on creation, however you can update the list manually at any time. | ||
|
||
<br></br> | ||
**To update the ban list manually:** | ||
```banlist.update();``` | ||
To update the list Manually | ||
|
||
const newlist = await blacklist.update(); | ||
|
||
To get the list quickly without updating unless the internal cache was deleted blacklist.fetchBanlist(); | ||
|
||
const list = await blacklist.fetchBanlist(); | ||
|
||
list and newList will contain a <BanStore> object which is a collection of BannedUser objects mapped by their banID. BannedUser objects have an id (userid), tag (discord tag), banID, bannedFor (reason), prooflink. | ||
|
||
Used normally (i.e. caching enabled), BanStores will always be stored inside blacklist.banstore | ||
|
||
To strip any class data and just get them in pure object form just run <BannedUser>.serialize() or <BanStore>.serialize(), and to stringify them <BannedUser> or <BanStore>.stringify(). | ||
|
||
This returns a promise, and you can get the ban list from it with either the thenable or `banlist.list` or the thenable of `banlist.array()`. | ||
<br></br> | ||
**It is recommended you update your ban list every two hours** | ||
<br></br> | ||
You can have the blacklist autoupdate the list like so: | ||
<br></br> | ||
```const banlist = new Blacklist('token', true, 2*60); ``` | ||
<br></br> | ||
To specify your own auto-update interval, create your object like so: | ||
<br></br> | ||
`new Blacklist('token', true, minutes);` | ||
|
||
**Clearing and resetting your auto-updater** | ||
<br></br> | ||
To clear the autoupdater simply call ``banlist.stopUpdateTimer();``. To then set a new one do ``banlist.setUpdateTimer(minutes)``. | ||
You can have the blacklist autoupdate at the recommended time like so: | ||
|
||
const banlist = new Blacklist({ token: 'something', update: true }); | ||
|
||
to customise the timer length (180 minutes in this example): | ||
|
||
const banlist = new Blacklist({ token: 'something', update: 180 }); | ||
|
||
to be completely explicit: | ||
|
||
const banlist = new Blacklist({ | ||
token: 'something', | ||
update: { | ||
autoupdate: true, | ||
minutes: 180, | ||
} | ||
}); | ||
|
||
**Looking up users.** | ||
<br></br> | ||
```banlist.lookup("id")``` where id is the userid of the user you want to check. This returns a boolean depending on if the user is on the ban list. | ||
|
||
Convenience shortcut (only works after if banlist has been fetched and cached): | ||
|
||
blacklist.lookup('id'); | ||
|
||
'id' is the userid of the user you want to check. This returns either a BannedUser or null depending on if the user is on the ban list. | ||
|
||
**Clearing and resetting your auto-updater** | ||
|
||
To clear the autoupdater simply call ``banlist.stopUpdateTimer();``. To then set a new one do ``banlist.setUpdateTimer(minutes)`` where minutes is an number. | ||
|
||
**Changing token** | ||
<br></br> | ||
If for whatever reason you would like to switch tokens mid-execution, you can do that easily by calling | ||
```banlist.changeToken('newtoken');``` | ||
<br></br> | ||
|
||
### Summary example: | ||
If for whatever reason you would like to switch tokens, you can do that easily by calling. | ||
```banlist.changeToken('newtoken');``` | ||
|
||
//Create the object (which autorefreshes the banlist every 120 minutes) | ||
const Blacklist = require('discordblacklist'); | ||
let banlist = new Blacklist('token', true, 120); | ||
|
||
//Someone's id to test | ||
const someID = '1234567890'; | ||
This work is ©Copyright under the `GNU AFFERO GENERAL PUBLIC LICENSE Version 3`. See LICENSE for more details. | ||
|
||
//Check if they are on the banlist - Returns a true/false , or throws an error if an error occurred. | ||
let isOnTheBanList = banlist.lookup(someID); | ||
### Further Documentation: | ||
[https://wzhouwzhou.github.io/discordblacklist/](https://wzhouwzhou.github.io/discordblacklist/) | ||
|
||
//Get the full list in string form. Must be used after update() has completed | ||
console.log(banlist.list); | ||
Enjoy this package? Consider starring on [github](https://github.com/wzhouwzhou/discordblacklist) and checking out some of my other work: | ||
|
||
//Promise resolves the full list as an array. Can be called before update() is completed. Await will throw an error if an error occurred. | ||
console.log(await banlist.array()); | ||
[Youtube Search API](https://npmjs.com/ytsearcher) | ||
|
||
//Manually update the ban list: | ||
let theUpdatedList = await banlist.update(); | ||
[Chips Discord Bot](https://chipsbot.me/) |
Oops, something went wrong.