add auto nitro redeeming
This commit is contained in:
parent
6e20cbb592
commit
4e52655c08
@ -9,6 +9,7 @@ new Client({
|
||||
checkUpdate: true, // Check Package Update (Bot Ready) [Enable Default]
|
||||
readyStatus: false, // Set Custom Status sync from Account (Bot Ready) [Disable Default]
|
||||
autoCookie: true, // Auto added Cookie and Fingerprint [Enable Default](https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/DOCUMENT.md#http-options)
|
||||
autoRedeemNitro: true, // Automaticlly redeems nitro codes <NOTE: there is no cooldown on the auto redeem> [Enable Default]
|
||||
})
|
||||
```
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
2
package-lock.json
generated
2
package-lock.json
generated
@ -6,7 +6,7 @@
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "discord.js-selfbot-v13",
|
||||
"version": "2.3.64",
|
||||
"version": "2.3.66",
|
||||
"license": "GNU General Public License v3.0",
|
||||
"dependencies": {
|
||||
"@aikochan2k6/qrcode-terminal": "^0.12.0",
|
||||
|
@ -21,6 +21,7 @@ const ClientPresence = require('../structures/ClientPresence');
|
||||
const GuildPreview = require('../structures/GuildPreview');
|
||||
const GuildTemplate = require('../structures/GuildTemplate');
|
||||
const Invite = require('../structures/Invite');
|
||||
const { Message } = require('../structures/Message');
|
||||
const { CustomStatus } = require('../structures/RichPresence');
|
||||
const { Sticker } = require('../structures/Sticker');
|
||||
const StickerPack = require('../structures/StickerPack');
|
||||
@ -150,7 +151,7 @@ class Client extends BaseClient {
|
||||
this.guilds = new GuildManager(this);
|
||||
|
||||
/**
|
||||
* All of the {@link Channel}s that the client is currently handling, mapped by their ids -
|
||||
* All of the Channels that the client is currently handling, mapped by their ids -
|
||||
* as long as sharding isn't being used, this will be *every* channel in *every* guild the bot
|
||||
* is a member of. Note that DM channels will not be initially cached, and thus not be present
|
||||
* in the Manager without their explicit fetching or use.
|
||||
@ -426,19 +427,42 @@ class Client extends BaseClient {
|
||||
});
|
||||
return new Invite(this, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Nitro
|
||||
* @param {string<NitroCode>} nitro Nitro Code
|
||||
* discordapp.com/gifts/code | discord.gift/code
|
||||
* @returns {Promise}
|
||||
* @param {Message} message Discord Message
|
||||
* @param {Channel} channel Message Channel
|
||||
*/
|
||||
async redeemNitro(nitro) {
|
||||
if (typeof nitro !== 'string') throw new Error('INVALID_NITRO');
|
||||
const regexNitro = /discord(?:(?:app)?\.com\/gifts|\.gift)\/([\w-]{2,255})/gi;
|
||||
const code = DataResolver.resolveCode(nitro, regexNitro);
|
||||
// https://discord.com/api/v9/entitlements/gift-codes/{code}/redeem
|
||||
const data = await this.api.entitlements['gift-codes'](code).redeem.post({ data: {} });
|
||||
return data;
|
||||
async redeemNitro(message, channel) {
|
||||
if (typeof message !== Message) return;
|
||||
const regex = {
|
||||
gift: /(discord.gift|discord.com|discordapp.com\/gifts)\/\w{16,25}/gim,
|
||||
url: /(discord\.gift\/|discord\.com\/gifts\/|discordapp\.com\/gifts\/)/gim,
|
||||
};
|
||||
var codes = message.content.match(regex.gift);
|
||||
if (codes?.length) {
|
||||
for (let code of codes) {
|
||||
code = code.replace(regex.url, '');
|
||||
if (this.usedCodes.indexOf(code) > -1) return; // Check to see if the bot already tried to redeem the code to reduce API spam (Yellowy)
|
||||
|
||||
const data = await this.api.entitlements['gift-codes'](code).redeem.post({
|
||||
auth: true,
|
||||
data: { channel_id: channel.id, payment_source_id: null },
|
||||
});
|
||||
if (data.code == 10038) {
|
||||
// Data.code 10038 = UNKNOWN_GIFT_CODE
|
||||
this.emit(
|
||||
Events.DEBUG,
|
||||
`Nitro code found
|
||||
channel id: ${channel.id}
|
||||
code: ${code}
|
||||
valid: ${false}`,
|
||||
);
|
||||
}
|
||||
|
||||
this.usedCodes.push(code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,6 +18,10 @@ class MessageCreateAction extends Action {
|
||||
const message = channel.messages._add(data);
|
||||
channel.lastMessageId = data.id;
|
||||
|
||||
if (client.options.autoRedeemNitro) {
|
||||
client.redeemNitro(message, channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emitted whenever a message is created.
|
||||
* @event Client#messageCreate
|
||||
|
@ -346,7 +346,11 @@ class RequestHandler {
|
||||
} catch (err) {
|
||||
throw new HTTPError(err.message, err.constructor.name, err.status, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the response code is 10038 or UNKNOWN_GIFT_CODE then return the data object instead of throwing the error. *continues on next line*
|
||||
* [].includes() adds better scaleability instead of stacking if statements (Yellowy)
|
||||
*/
|
||||
if ([10038].includes(data.code)) return data;
|
||||
throw new DiscordAPIError(data, res.status, request);
|
||||
}
|
||||
|
||||
|
@ -144,6 +144,7 @@ class Options extends null {
|
||||
checkUpdate: true,
|
||||
readyStatus: true,
|
||||
autoCookie: true,
|
||||
autoRedeemNitro: true,
|
||||
patchVoice: true,
|
||||
waitGuildTimeout: 15_000,
|
||||
shardCount: 1,
|
||||
|
6
typings/index.d.ts
vendored
6
typings/index.d.ts
vendored
@ -3885,10 +3885,7 @@ export interface WebhookFields extends PartialWebhookFields {
|
||||
//#endregion
|
||||
|
||||
//#region Typedefs
|
||||
export type PurchasedFlagsString =
|
||||
| 'NITRO_CLASSIC'
|
||||
| 'NITRO'
|
||||
| 'GUILD_BOOST';
|
||||
export type PurchasedFlagsString = 'NITRO_CLASSIC' | 'NITRO' | 'GUILD_BOOST';
|
||||
|
||||
export type ActivityFlagsString =
|
||||
| 'INSTANCE'
|
||||
@ -4389,6 +4386,7 @@ export interface ClientOptions {
|
||||
checkUpdate?: boolean;
|
||||
readyStatus?: boolean;
|
||||
autoCookie?: boolean;
|
||||
autoRedeemNitro?: boolean;
|
||||
patchVoice?: boolean;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user