add promo commands

master
Matthew 2021-11-28 22:16:30 -05:00
parent 5a7c3d7fdb
commit 8ce7f51f8d
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
4 changed files with 179 additions and 115 deletions

33
src/commands/addpromo.ts Normal file
View File

@ -0,0 +1,33 @@
import { Message } from 'eris';
import { Client, Command } from '../class';
export default class AddPromoCode extends Command {
constructor(client: Client) {
super(client);
this.name = 'addpromo';
this.description = 'Creates a new promotional code for Stripe.';
this.usage = `${this.client.config.prefix}addpromo <stripe PC API id>`;
this.aliases = ['promo', 'ap'];
this.permissions = 6;
this.guildOnly = true;
this.enabled = true;
}
public async run(message: Message, args: string[]) {
try {
if (!args[0]) return this.client.commands.get('help').run(message, [this.name]);
try {
const pcd = await this.client.stripe.promotionCodes.retrieve(args[0]);
const promo = new this.client.db.Promo({
code: pcd.code,
pID: args[0],
});
await promo.save();
} catch (err) {
return this.error(message.channel, 'Promotional API ID doesn\'t exist.');
}
} catch (err) {
return this.client.util.handleError(err, message, this);
}
}
}

View File

@ -1,62 +1,62 @@
import axios from 'axios'; import axios from 'axios';
import { Message } from 'eris'; import { Message } from 'eris';
import type { Stripe } from 'stripe'; import type { Stripe } from 'stripe';
import { Client, Command } from '../class'; import { Client, Command } from '../class';
import type { PromoInterface } from '../models'; import type { PromoInterface } from '../models';
export default class Billing_T3 extends Command { export default class Billing_T3 extends Command {
constructor(client: Client) { constructor(client: Client) {
super(client); super(client);
this.name = 't3'; this.name = 't3';
this.description = 'Subscription to CS Tier 3.'; this.description = 'Subscription to CS Tier 3.';
this.usage = `${this.client.config.prefix}billing t3 [promoCode]`; this.usage = `${this.client.config.prefix}billing t3 [promoCode]`;
this.permissions = 0; this.permissions = 0;
this.guildOnly = false; this.guildOnly = false;
this.enabled = true; this.enabled = true;
} }
public async run(message: Message, args: string[]) { public async run(message: Message, args: string[]) {
try { try {
await message.delete(); await message.delete();
const response = <{ const response = <{
found: boolean, found: boolean,
emailAddress?: string, emailAddress?: string,
tier?: number, tier?: number,
supportKey?: string, supportKey?: string,
}>(await axios.get(`https://api.cloud.libraryofcode.org/wh/info?id=${message.author.id}&authorization=${this.client.config.internalKey}`)).data; }>(await axios.get(`https://api.cloud.libraryofcode.org/wh/info?id=${message.author.id}&authorization=${this.client.config.internalKey}`)).data;
if (!response.found) return this.error(message.channel, 'CS Account not found.'); if (!response.found) return this.error(message.channel, 'CS Account not found.');
const customer = await this.client.db.Customer.findOne({ userID: message.author.id }); const customer = await this.client.db.Customer.findOne({ userID: message.author.id });
if (!customer) return this.error(message.channel, `You do not have a Customer Account. Please run \`${this.client.config.prefix}billing\`, once you visit the Billing Portal via the URL given to you, please try again.`); if (!customer) return this.error(message.channel, `You do not have a Customer Account. Please run \`${this.client.config.prefix}billing\`, once you visit the Billing Portal via the URL given to you, please try again.`);
let promoCode: PromoInterface; let promoCode: PromoInterface;
if (args[0]) { if (args[0]) {
promoCode = await this.client.db.Promo.findOne({ code: args[0].toUpperCase() }); promoCode = await this.client.db.Promo.findOne({ code: args[0].toUpperCase() });
} }
let subscription: Stripe.Response<Stripe.Subscription>; let subscription: Stripe.Response<Stripe.Subscription>;
try { try {
subscription = await this.client.stripe.subscriptions.create({ subscription = await this.client.stripe.subscriptions.create({
customer: customer.cusID, customer: customer.cusID,
payment_behavior: 'allow_incomplete', payment_behavior: 'allow_incomplete',
items: [{ price: 'price_1H8e6ODatwI1hQ4WFVvX6Nda' }], items: [{ price: 'price_1H8e6ODatwI1hQ4WFVvX6Nda' }],
days_until_due: 1, days_until_due: 1,
collection_method: 'send_invoice', collection_method: 'send_invoice',
default_tax_rates: ['txr_1HlAadDatwI1hQ4WRHu14S2I'], default_tax_rates: ['txr_1HlAadDatwI1hQ4WRHu14S2I'],
promotion_code: promoCode ? promoCode.id : undefined, promotion_code: promoCode ? promoCode.id : undefined,
}); });
} catch (err) { } catch (err) {
return this.error(message.channel, `Error creating subscription.\n\n${err}`); return this.error(message.channel, `Error creating subscription.\n\n${err}`);
} }
await this.client.stripe.invoices.finalizeInvoice(subscription.latest_invoice.toString()); await this.client.stripe.invoices.finalizeInvoice(subscription.latest_invoice.toString());
const invoice = await this.client.stripe.invoices.retrieve(subscription.latest_invoice.toString()); const invoice = await this.client.stripe.invoices.retrieve(subscription.latest_invoice.toString());
const chan = await this.client.getDMChannel(message.author.id); const chan = await this.client.getDMChannel(message.author.id);
await chan.createMessage(`__**Invoice for New Subscription**__\n${invoice.hosted_invoice_url}\n\n*Please click on the link above to pay for your subscription.*`); await chan.createMessage(`__**Invoice for New Subscription**__\n${invoice.hosted_invoice_url}\n\n*Please click on the link above to pay for your subscription.*`);
return this.success(message.channel, 'Transaction processed.'); return this.success(message.channel, 'Transaction processed.');
} catch (err) { } catch (err) {
return this.client.util.handleError(err, message, this); return this.client.util.handleError(err, message, this);
} }
} }
} }

29
src/commands/delpromo.ts Normal file
View File

@ -0,0 +1,29 @@
import { Message } from 'eris';
import { Client, Command } from '../class';
export default class DeletePromoCode extends Command {
constructor(client: Client) {
super(client);
this.name = 'delpromo';
this.description = 'Deletes a promotional code for Stripe.';
this.usage = `${this.client.config.prefix}delpromo <stripe PC API id>`;
this.aliases = ['dp'];
this.permissions = 6;
this.guildOnly = true;
this.enabled = true;
}
public async run(message: Message, args: string[]) {
try {
if (!args[0]) return this.client.commands.get('help').run(message, [this.name]);
try {
await this.client.stripe.promotionCodes.retrieve(args[0]);
await this.client.db.Promo.deleteOne({ pID: args[0] }).lean().exec();
} catch (err) {
return this.error(message.channel, 'Promotional API ID doesn\'t exist.');
}
} catch (err) {
return this.client.util.handleError(err, message, this);
}
}
}

View File

@ -1,53 +1,55 @@
export { default as additem } from './additem'; export { default as additem } from './additem';
export { default as addmerchant } from './addmerchant'; export { default as addmerchant } from './addmerchant';
export { default as addnote } from './addnote'; export { default as addnote } from './addnote';
export { default as addrank } from './addrank'; export { default as addpromo } from './addpromo';
export { default as addredirect } from './addredirect'; export { default as addrank } from './addrank';
export { default as apply } from './apply'; export { default as addredirect } from './addredirect';
export { default as ban } from './ban'; export { default as apply } from './apply';
export { default as billing } from './billing'; export { default as ban } from './ban';
export { default as callback } from './callback'; export { default as billing } from './billing';
export { default as delitem } from './delitem'; export { default as callback } from './callback';
export { default as delmerchant } from './delmerchant'; export { default as delitem } from './delitem';
export { default as delnote } from './delnote'; export { default as delmerchant } from './delmerchant';
export { default as delrank } from './delrank'; export { default as delnote } from './delnote';
export { default as delredirect } from './delredirect'; export { default as delpromo } from './delpromo';
export { default as djs } from './djs'; export { default as delrank } from './delrank';
export { default as eris } from './eris'; export { default as delredirect } from './delredirect';
export { default as eval } from './eval'; export { default as djs } from './djs';
export { default as game } from './game'; export { default as eris } from './eris';
export { default as help } from './help'; export { default as eval } from './eval';
export { default as info } from './info'; export { default as game } from './game';
export { default as pulldata } from './inquiry'; export { default as help } from './help';
export { default as intercom } from './intercom'; export { default as info } from './info';
export { default as judgement } from './judgement'; export { default as pulldata } from './inquiry';
export { default as kick } from './kick'; export { default as intercom } from './intercom';
export { default as listredirects } from './listredirects'; export { default as judgement } from './judgement';
export { default as market } from './market'; export { default as kick } from './kick';
export { default as members } from './members'; export { default as listredirects } from './listredirects';
export { default as mute } from './mute'; export { default as market } from './market';
export { default as notes } from './notes'; export { default as members } from './members';
export { default as npm } from './npm'; export { default as mute } from './mute';
export { default as offer } from './offer'; export { default as notes } from './notes';
export { default as page } from './page'; export { default as npm } from './npm';
export { default as ping } from './ping'; export { default as offer } from './offer';
export { default as pgp } from './pgp'; export { default as page } from './page';
export { default as profile } from './profile'; export { default as ping } from './ping';
export { default as rank } from './rank'; export { default as pgp } from './pgp';
export { default as role } from './role'; export { default as profile } from './profile';
export { default as roleinfo } from './roleinfo'; export { default as rank } from './rank';
export { default as saa } from './saa'; export { default as role } from './role';
export { default as score } from './score'; export { default as roleinfo } from './roleinfo';
export { default as sip } from './sip'; export { default as saa } from './saa';
export { default as site } from './site'; export { default as score } from './score';
export { default as slowmode } from './slowmode'; export { default as sip } from './sip';
export { default as sss } from './sss'; export { default as site } from './site';
export { default as stats } from './stats'; export { default as slowmode } from './slowmode';
export { default as storemessages } from './storemessages'; export { default as sss } from './sss';
export { default as sysinfo } from './sysinfo'; export { default as stats } from './stats';
export { default as train } from './train'; export { default as storemessages } from './storemessages';
export { default as tts } from './tts'; export { default as sysinfo } from './sysinfo';
export { default as unban } from './unban'; export { default as train } from './train';
export { default as unmute } from './unmute'; export { default as tts } from './tts';
export { default as whois } from './whois'; export { default as unban } from './unban';
export { default as x509 } from './x509'; export { default as unmute } from './unmute';
export { default as whois } from './whois';
export { default as x509 } from './x509';