Skip to content

Commit

Permalink
feat: fix the fucking heroku issue once and for all
Browse files Browse the repository at this point in the history
  • Loading branch information
eternal committed Feb 20, 2021
1 parent f507cd7 commit 87ce783
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { Util: djsUtil } = require('discord.js');

async function init() {
// Requires
const Constants = require('./lib/Constants');
const Webhook = require('./lib/Webhook');
const Logger = require('./lib/Logger');
Expand All @@ -9,6 +10,7 @@ async function init() {
const chalk = require('chalk');
const phin = require('phin');

// Call dotenv to recognize env vars
require('dotenv').config();

console.log(chalk.green(`
Expand All @@ -34,32 +36,38 @@ async function init() {
╙╙▀▀▀▓▓▓▓▀▀▀╙╙
`));

// Define globals
global.active = [];
global.webhook = null;
global.constants = Constants;
global.util = Util;
global.logger = new Logger({ debug: false });
global.pSourceId = null;
global.paymentSourceId = null;

// Try to parse settings
try {
global.settings = JSON.parse(process.env.settings);
} catch {
return logger.critical(constants.invalidConfig);
}

// Define settings with defaults
global.settings = djsUtil.mergeDefault(constants.defaultSettings, settings);

if (!settings.mode) return logger.critical(constants.noMode);
if (!Object.keys(modes).includes(settings.mode)) return logger.critical(constants.invalidMode);

// Init selected mode
await modes[settings.mode]();

if (!active.length) return logger.critical(constants.invalidTokens);

// Counters
let guildCount = active
.map((s) => s.guilds.cache.size)
.reduce((a, b) => a + b, 0);

// Get payment method
let res = await phin({
url: constants.paymentSourceURL,
method: 'GET',
Expand All @@ -73,11 +81,12 @@ async function init() {
if (!res.body || res.body?.length === 0) {
logger.warn(constants.noPaymentMethod);
} else if (res.body[0]) {
global.pSourceId = res.body[0].id;
global.paymentSourceId = res.body[0].id;
} else {
logger.warn(constants.paymentMethodFail(res.body));
}

// Init webhook
if (settings.webhook?.url) {
const webhookToken = /[^/]*$/.exec(settings.webhook.url)[0];
const webhookId = settings.webhook.url.replace(/^.*\/(?=[^\/]*\/[^\/]*$)|\/[^\/]*$/g, '');
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Nitro.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = class Sniper {
'Authorization': settings.tokens.main,
'User-Agent': constants.userAgent
},
data: `{"channel_id":${msg.channel.id},"payment_source_id":${pSourceId}}`
data: `{"channel_id":${msg.channel.id},"payment_source_id":${paymentSourceId}}`
}, (err, res) => {
// Handle response
let time = `${new Date() - start}ms`;
Expand Down

0 comments on commit 87ce783

Please sign in to comment.