Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Added Top.gg Server Webhook Methods #23

Merged
merged 1 commit into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion assets/overlays.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"thuglife",
"balance",
"brilliance",
"bravery"
"bravery",
"wasted"
]
8 changes: 3 additions & 5 deletions docs/guide/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const WeebyAPI = require('weeby-js');
const weeby = new WeebyAPI('YOUR_TOKEN');

const image = await weeby.generators.oneImage({ type: '3000years', image: 'https://i.imgur.com/qgKvcQv.png' });
message.channel.send({files: [{ attachment: image }]}); // -> Image Buffer
return image; // -> Image Buffer
```

### Custom:
Expand All @@ -24,8 +24,6 @@ const WeebyAPI = require('weeby-js');
const weeby = new WeebyAPI('YOUR_TOKEN');

const image = await weeby.custom.greeting({ icon: 'https://i.imgur.com/qgKvcQv.png', background: 'https://i.imgur.com/ENbvdWD.png', greet: 'Welcome', name: 'Nate', message: 'Hello and Welcome!', greetHex: 'E881D1', messageHex: '76d6ff', circleHex: '6b6d75', nameHex: 'e889e0', font: 'riffic' });
message.channel.send({files: [{ attachment: image }]}); // -> Image Buffer
```

More Examples can be found in `/test/bot-v12.js`.
> NOTE: Bot Example is outdated and is strongly discouraged from production use.
return image; // -> Image Buffer
```
2 changes: 1 addition & 1 deletion docs/guide/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ WEEBY_TOKEN=<your token>

```js
const WeebyAPI = require('weeby-js');
require('dotenv').config();)
require('dotenv').config();

const weeby = new WeebyAPI(process.env.WEEBY_TOKEN);
```
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "weeby-js",
"version": "2.0.0",
"version": "2.0.1",
"description": "JavaScript Wrapper for Weeby API",
"main": "src/index.js",
"scripts": {
Expand All @@ -27,12 +27,12 @@
"homepage": "https://js.weebyapi.xyz/",
"devDependencies": {
"@discordjs/docgen": "^0.11.0",
"common-tags": "^1.8.0",
"common-tags": "^1.8.2",
"dotenv": "^16.0.0",
"eslint": "^8.9.0",
"eslint": "^8.11.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.0.0",
"typescript": "^4.5.5"
"typescript": "^4.6.2"
},
"dependencies": {
"chalk": "^4.1.2",
Expand Down
41 changes: 41 additions & 0 deletions src/lib/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,30 @@ class Utility {
}
}

/**
* Checks if a user has voted for a server on Top.gg
* @param {TopGGServerVoteCheckerOptions} options - The options you want to use.
* @returns {Promise<TopGGServerVoteCheckerOptions>}
*/
async topGGServerVoteChecker({ serverID, userID }) {
if (typeof serverID !== 'string') throw new Error(`${chalk.magenta('Weeby-JS')} ${chalk.gray('»')} ${chalk.yellow('The Server ID parameter is not a string.')}`);
if (!serverID) throw new Error(`${chalk.magenta('Weeby-JS')} ${chalk.gray('»')} ${chalk.yellow('Server ID parameter is missing. You will need to provide a valid Bot ID.')}`);
if (typeof userID !== 'string') throw new Error(`${chalk.magenta('Weeby-JS')} ${chalk.gray('»')} ${chalk.yellow('The User ID parameter is not a string.')}`);
if (!userID) throw new Error(`${chalk.magenta('Weeby-JS')} ${chalk.gray('»')} ${chalk.yellow('User ID parameter is missing. You will need to provide a valid User ID.')}`);

try {
const { body } = await get(`${this.baseURL}/webhook/topgg/server/votecheck`)
.query({ serverid: serverID, userid: userID })
.set('Authorization', `Bearer ${this.token}`)
.set('User-Agent', `Weeby-JS by NTM Development » v${version}`);

return body;
}
catch (e) {
throw new Error(`${chalk.magenta('Weeby-JS')} ${chalk.gray('»')} ${chalk.yellow(`Could not find that User's vote information for Server ID: ${serverID}. Make sure the User ID and Server ID is correct, or the user should vote first.`)}`);
}
}

/**
* Converts the provided currency to a different currency.
* @param {CurrencyConverterOptions} options - The options you want to use.
Expand Down Expand Up @@ -132,6 +156,12 @@ module.exports = Utility;
* @property {string} userID - The ID of the user you want to check.
*/

/**
* @typedef {Object} TopGGServerVoteCheckerOptions - The options for the TopGGServerVoteChecker.
* @property {string} serverID - The ID of the server you want to check.
* @property {string} userID - The ID of the user you want to check.
*/

/**
* @typedef {Object} TopGGVoteCheckerResponse - The response from the Top.gg Vote Checker method.
* @property {string} userID - The ID of the user.
Expand All @@ -143,6 +173,17 @@ module.exports = Utility;
* @property {boolean} isWeekend - Whether the user voted on a weekend or not.
*/

/**
* @typedef {Object} TopGGServerVoteCheckerResponse - The response from the Top.gg Server Vote Checker method.
* @property {string} userID - The ID of the user.
* @property {string} serverID - The ID of the server.
* @property {number} dateVoted - The date the user voted (Unix Timestamp)
* @property {number} currentVoteExpiry - The current expiry of the vote (12 Hours - Unix Timestamp)
* @property {number} timesVoted - The amount of times the user has voted lifetime for the bot.
* @property {boolean} hasVoted - Whether the user has voted or not.
* @property {boolean} isWeekend - Whether the user voted on a weekend or not.
*/

/**
* @typedef {Object} TranslateOptions - The options for the Translate method.
* @property {string} from - A valid ISO language code. Refer to this: http://www.lingoes.net/en/translator/langcode.htm
Expand Down
59 changes: 58 additions & 1 deletion typings/lib/utility.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ declare class Utility {
* @returns {Promise<TopGGVoteCheckerResponse>}
*/
topGGVoteChecker({ botID, userID }: TopGGVoteCheckerOptions): Promise<TopGGVoteCheckerResponse>;
/**
* Converts the provided currency to a different currency.
* @param {CurrencyConverterOptions} options - The options you want to use.
* @returns {Promise<CurrencyConverterResponse>}
*/
/**
* Checks if a user has voted for a server on Top.gg
* @param {TopGGServerVoteCheckerOptions} options - The options you want to use.
* @returns {Promise<TopGGServerVoteCheckerResponse>}
*/
topGGServerVoteChecker({ serverID, userID }: TopGGServerVoteCheckerOptions): Promise<TopGGServerVoteCheckerResponse>;
/**
* Converts the provided currency to a different currency.
* @param {CurrencyConverterOptions} options - The options you want to use.
Expand All @@ -42,7 +53,7 @@ declare class Utility {
weather({ location, degreeType }?: WeatherOptions): Promise<WeatherResponse>;
}
declare namespace Utility {
export { TopGGVoteCheckerOptions, TopGGVoteCheckerResponse, TranslateOptions, TranslateResponse, CurrencyConverterOptions, CurrencyConverterResponse, WeatherOptions, WeatherResponse };
export { TopGGVoteCheckerOptions, TopGGVoteCheckerResponse, TopGGServerVoteCheckerOptions, TopGGServerVoteCheckerResponse, TranslateOptions, TranslateResponse, CurrencyConverterOptions, CurrencyConverterResponse, WeatherOptions, WeatherResponse };
}
/**
* - The options for the TopGGVoteChecker.
Expand All @@ -57,6 +68,19 @@ type TopGGVoteCheckerOptions = {
*/
userID: string;
};
/**
* - The options for the TopGGServerVoteChecker.
*/
type TopGGServerVoteCheckerOptions = {
/**
* - The ID of the server you want to check.
*/
serverID: string;
/**
* - The ID of the user you want to check.
*/
userID: string;
};
/**
* - The response from the Top.gg Vote Checker method.
*/
Expand Down Expand Up @@ -90,6 +114,39 @@ type TopGGVoteCheckerResponse = {
*/
isWeekend: boolean;
};
/**
* - The response from the Top.gg Vote Checker method.
*/
type TopGGServerVoteCheckerResponse = {
/**
* - The ID of the user.
*/
userID: string;
/**
* - The ID of the server.
*/
serverID: string;
/**
* - The date the user voted (Unix Timestamp)
*/
dateVoted: number;
/**
* - The current expiry of the vote (12 Hours - Unix Timestamp)
*/
currentVoteExpiry: number;
/**
* - The amount of times the user has voted lifetime for the bot.
*/
timesVoted: number;
/**
* - Whether the user has voted or not.
*/
hasVoted: boolean;
/**
* - Whether the user voted on a weekend or not.
*/
isWeekend: boolean;
};
/**
* - The options for the Currency Converter.
*/
Expand Down