Skip to content

Commit

Permalink
Latest Changes Massive Changes!
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximKing1 committed Feb 22, 2021
1 parent 369e814 commit 152c04a
Show file tree
Hide file tree
Showing 2 changed files with 287 additions and 204 deletions.
187 changes: 119 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ BLWebhooks fully supports external and discord.js internal sharding, make sure t

Please do remember this is in beta, before writing a negative review please open a issue first so we can have a chance to resolve the issue.

**NPM (recommended)**
## NPM (recommended)

```js
# Stable
npm i --save blwebhooks
Expand All @@ -42,7 +43,8 @@ npm i --save blwebhooks
npm i --save blwebhooks@nightly
```

**Yarn**
## Yarn

```js
# Stable
yarn add blwebhooks
Expand All @@ -53,24 +55,25 @@ yarn add blwebhooks@nightly

# Supported Libraries

| Name | Features |
| --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| Name | Features |
| ------------------------------------------------------ | ------------------------------------------ |
| [discord.js](https://www.npmjs.com/package/discord.js) | `DATABASE`, `EXPRESS`, `HOOKS`, `SECURITY` |
| [Eris](https://www.npmjs.com/package/eris) | `EXPRESS`, `HOOKS`, `SECURITY` |
| [Eris](https://www.npmjs.com/package/eris) | `EXPRESS`, `HOOKS`, `SECURITY` |

# Supported Lists

> top.gg<br>
> InfinityBotList<br>
> VoidBots<br>
> DiscordLabs<br>
> Botrix<br>
> Botrix - Coming Soon!<br>
> Blist<br>
> DiscordBots.co<br>
# Usage

**Import the lib via ES6 or commonJS modules**
### Import the lib via ES6 or commonJS modules

```js
// ES6
import * as blwebhooks from "blwebhooks";
Expand All @@ -79,68 +82,102 @@ const blwebhooks = require("blwebhooks");
```

### With discord.js

```js
const discord = require("discord.js");
const client = discord.Client();
const { WebhooksManager } = require("blwebhooks");

const voteClient = new WebhooksManager(client, 80);
const voteClient = new WebhooksManager(client, 80, {
database: "none", // mongoose or sqlite
string: "MongooseURL", // Only Use This If The Database Is Set To Mongoose
extra: {
extraLogging: false, // This will enable extraLogging {Debugging}
extraProtection: true, // Leave Enabled Unless Using Small Amount Of RAM
proxyTrust: false, // Enable this if your behind a proxy, Heroku,
},
});
client.voteManager = voteClient;
```

### With Eris

```js
const Eris = require("eris");

var bot = new Eris("BOT_TOKEN");
// Replace BOT_TOKEN with your bot account's token

bot.on("ready", () => { // When the bot is ready
console.log("Ready!"); // Log "Ready!"

bot.on("ready", () => {
// When the bot is ready
console.log("Ready!"); // Log "Ready!"
});

const { WebhooksManager } = require("blwebhooks");

const voteClient = new WebhooksManager(bot, 80);
const voteClient = new WebhooksManager(bot, 80, {
database: "none", // mongoose or sqlite
string: "MongooseURL", // Only Use This If The Database Is Set To Mongoose
extra: {
extraLogging: false, // This will enable extraLogging {Debugging}
extraProtection: true, // Leave Enabled Unless Using Small Amount Of RAM
proxyTrust: false, // Enable this if your behind a proxy, Heroku,
},
});
bot.voteManager = voteClient;

bot.connect(); // Get the bot to connect to Discord
```

**Vote's Storage**
```js
// The DB can be set to either mongo, sqlite
// Only set the string if using the mongoose db
voteClient.setStroage(DB, String);

// MongooseDB Example (recommended)
voteClient.setStroage("mongo", "mongodb://localhost/my_database");
### Vote Storage

// SQLITE Example
voteClient.setStroage("sqlite");
```js
// Set the vote storage in the voteClient
const voteClient = new WebhooksManager(client, 80, {
database: "mongoose", // mongoose or sqlite
string: "mongooseDB-URL",
extra: {
extraLogging: false,
extraProtection: true,
proxyTrust: false,
},
});
```

For usage on pulling data see the [Database Vote](#database-vote) Section.

**Turn On Sharding Support**
```js
voteClient.shardedClient(true);
```
### Extended Security

**Turn On Extended Security**
```js
// This will enable bruteforce protection for module, once enabled
// it will start the protection also using more CPU.
voteClient.extraProtection(true);
// You can enable this via the voteClient
const voteClient = new WebhooksManager(client, 80, {
database: "mongoose",
string: "mongooseDB-URL",
extra: {
extraLogging: false,
extraProtection: true, // Enable this here
proxyTrust: false,
},
});
```

**Turn On Proxy Trust**
### Proxy Trust

```js
// Enable this option is you use this behind a proxy like
// Heroku services etc
voteClient.proxyTrust(true);
// Enable this in the voteClient
const voteClient = new WebhooksManager(client, 80, {
database: "mongoose",
string: "mongooseDB-URL",
extra: {
extraLogging: false,
extraProtection: true,
proxyTrust: true, // Enable it here
},
});
```

**Emit Test Vote Events**
### Test Events

```js
// Emit a test event to test your Voted Event
voteClient.testVote(userID, botID);
Expand All @@ -149,126 +186,138 @@ voteClient.testVote(userID, botID);
# Vote Hooks

**TopGG Vote Hooks:**

```js
// This will listen to votes from top.gg, the url is the end not
// including the / and auth is the webhook auth. You can enable and
// disable using true or false at the end
client.voteManager.topggVoteHook(url, auth, true);

// This code will run after a new vote was received from top.gg
client.on('topgg-voted', async function (userID, botID, type) {
console.log(userID)
})
client.on("topgg-voted", async function (userID, botID, type) {
console.log(userID);
});
```

**InfinityBotList Vote Hooks:**

```js
// This will listen to votes from InfinityBotList, the url is the end not
// including the / and auth is the webhook auth. You can enable and
// disable using true or false at the end
client.voteManager.IBLVoteHook(url, auth, true);

// This code will run after a new vote was received from InfinityBotList
client.on('IBL-voted', async function (userID, botID, type) {
console.log(userID)
})
client.on("IBL-voted", async function (userID, botID, type) {
console.log(userID);
});
```

**VoidBots Vote Hooks:**

```js
// This will listen to votes from VoidBots, the url is the end not
// including the / and auth is the webhook auth. You can enable and
// disable using true or false at the end
client.voteManager.VoidBotsVoteHook(url, auth, true);

// This code will run after a new vote was received from VoidBots
client.on('VB-voted', async function (userID, botID) {
console.log(userID + " Voted For " + botID)
})
client.on("VB-voted", async function (userID, botID) {
console.log(userID + " Voted For " + botID);
});
```

**DiscordLabs Vote Hooks:**

```js
// This will listen to votes from DiscordLabs, the url is the end not
// including the / and auth is the webhook auth. You can enable and
// disable using true or false at the end
client.voteManager.DiscordLabsVoteHook(url, auth, true);

// This code will run after a new vote was received from DiscordLabs
client.on('DL-voted', async function (userID, botID, wasTest) {
console.log(`${userID} Voted For ${botID}. Was Test: ${wasTest}`)
})
client.on("DL-voted", async function (userID, botID, wasTest) {
console.log(`${userID} Voted For ${botID}. Was Test: ${wasTest}`);
});
```

**Botrix Vote Hooks:**

```js
// This will listen to votes from Botrix, the url is the end not
// including the / and auth is the webhook auth. You can enable and
// disable using true or false at the end
client.voteManager.BotrixVoteHook(url, auth, true);

// This code will run after a new vote was received from Botrix
client.on('BTR-voted', async function (userID, botID) {
console.log(`${userID} Voted For ${botID}.`)
})
client.on("BTR-voted", async function (userID, botID) {
console.log(`${userID} Voted For ${botID}.`);
});
```

**BList Vote Hooks:**

```js
// This will listen to votes from BList, the url is the end not
// including the / and auth is the webhook auth. You can enable and
// disable using true or false at the end
client.voteManager.BListVoteHook(url, auth, true);

// This code will run after a new vote was received from BList
client.on('BLT-voted', async function (userID, botID) {
console.log(`${userID} Voted.`)
})
client.on("BLT-voted", async function (userID, botID) {
console.log(`${userID} Voted.`);
});
```

**DiscordBots.co Vote Hooks:**

```js
// This will listen to votes from BList, the url is the end not
// including the / and auth is the webhook auth. You can enable and
// disable using true or false at the end
client.voteManager.DBCVoteHook(url, auth, true);

// This code will run after a new vote was received from BList
client.on('DBC-voted', async function (userID, botID) {
console.log(`${userID} Voted.`)
})
client.on("DBC-voted", async function (userID, botID) {
console.log(`${userID} Voted.`);
});
```

# Events

**Global Voted Event**

```js
// This will run after any vote has been received, use this if you don't want seprate events for each list
client.on('vote', async function (userID, botID, List) {
console.log(`${userID} Voted For ${botID} on ${List}`)
})
client.on("vote", async function (userID, botID, List) {
console.log(`${userID} Voted For ${botID} on ${List}`);
});
```

**Vote Expired Event**

```js
// This will run after the vote expires, this will be different for each list
client.on('vote-expired', async function (userID, botID, List) {
console.log(userID)
})
client.on("vote-expired", async function (userID, botID, List) {
console.log(userID);
});
```

**Error Event**

```js
// This code will run in the event of a error, normally it will just console.log the error but you can add custom error events here
client.on('webhookError', async function (error) {
console.log(userID)
})
client.on("webhookError", async function (error) {
console.log(userID);
});
```

# Vote Database

The vote Database feature will save the total votes a User had made for your bot / server, it will add all the vote in a database and the methods below show you how to set it up and pull data.

**discord.js example**

```js
// The DB can be set to either mongo, sqlite
// Only set the string if using the mongoose db
Expand All @@ -282,10 +331,12 @@ voteClient.setStroage("sqlite");
```

**Pulling User Votes**

```js
voteClient.getVotes(userID, option);
```
*Options:*<br>

_Options:_<br>

- `daily` - Get Daily Votes<br>
- `weekly` - Get Weekly Votes<br>
Expand Down
Loading

0 comments on commit 152c04a

Please sign in to comment.