Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more cool commands! #28

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 13 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ declare module "quick.eco" {
BEG: number;
MONTHLY: number;
SEARCH: number;
SEARCHALT: number;
FISH: number;
HUNT: number;
DIG: number;
POSTMEME: number;
CULTIVATE: number; // Bonus
}

export interface Leaderboard {
Expand Down Expand Up @@ -118,6 +124,12 @@ declare module "quick.eco" {
public search(userID: string, guildID: string | false, amount: number, ops: TimeBasedRewardOptions): Promise<JobData>
public custom(userID: string, guildID: string | false, amount: number, ops: CustomRewardOptions): Promise<JobData>
public beg(userID: string, guildID: string | false, amount: number, ops: TimeBasedRewardOptions): Promise<JobData>
public fish(userID: string, guildID: string | false, amount: number, ops: TimeBasedRewardOptions): Promise<JobData>
public hunt(userID: string, guildID: string | false, amount: number, ops: TimeBasedRewardOptions): Promise<JobData>
public dig(userID: string, guildID: string | false, amount: number, ops: TimeBasedRewardOptions): Promise<JobData>
public postmeme(userID: string, guildID: string | false, amount: number, ops: TimeBasedRewardOptions): Promise<JobData>
public cultivate(userID: string, guildID: string | false, amount: number, ops: TimeBasedRewardOptions): Promise<JobData>
public searchalt(userID: string, guildID: string | false, amount: number, ops: TimeBasedRewardOptions): Promise<JobData>
public fetchMoney(userID: string, guildID: string | false): Promise<number>;
public reset(): Promise<boolean>;
private __checkManager(): void;
Expand All @@ -137,4 +149,4 @@ declare module "quick.eco" {
}

export const version: string;
}
}
168 changes: 168 additions & 0 deletions src/Eco.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,174 @@ class EconomyManager {
return { cooldown: false, time: null, amount: newAmount };
}

/**
* Fish reward
* @param {string} userID User id
* @param {string} guildID Guild id
* @param {number} amount Custom Amount
* @param {object} ops Options
* @param {number[]} [ops.range] Amount range
* @param {number} [ops.timeout] Timeout
* @returns {Promise<JobData>}
*/
async fish(userID, guildID = false, amount, ops = { range: [], timeout: 0 }) {
this.__checkManager();

if (!userID || typeof userID !== "string") throw new Error("User id was not provided!");
if (!amount) amount = Util.random(ops && ops.range[0] || 1, ops && ops.range[1] || 70);

const key = Util.makeKey(userID, guildID, "fish");
const cooldownRaw = await this._get(key);
const cooldown = Util.onCooldown(ops.timeout || Util.COOLDOWN.FISH, cooldownRaw ? cooldownRaw.data : 0);

if (cooldown) return { cooldown: true, time: Util.getCooldown(ops.timeout || Util.COOLDOWN.FISH, cooldownRaw ? cooldownRaw.data : 0) };

const newAmount = await this.addMoney(userID, guildID, amount);
await this._set(key, Date.now());

return { cooldown: false, time: null, amount: newAmount };
}

/**
* Hunt reward
* @param {string} userID User id
* @param {string} guildID Guild id
* @param {number} amount Custom Amount
* @param {object} ops Options
* @param {number[]} [ops.range] Amount range
* @param {number} [ops.timeout] Timeout
* @returns {Promise<JobData>}
*/
async hunt(userID, guildID = false, amount, ops = { range: [], timeout: 0 }) {
this.__checkManager();

if (!userID || typeof userID !== "string") throw new Error("User id was not provided!");
if (!amount) amount = Util.random(ops && ops.range[0] || 1, ops && ops.range[1] || 70);

const key = Util.makeKey(userID, guildID, "hunt");
const cooldownRaw = await this._get(key);
const cooldown = Util.onCooldown(ops.timeout || Util.COOLDOWN.HUNT, cooldownRaw ? cooldownRaw.data : 0);

if (cooldown) return { cooldown: true, time: Util.getCooldown(ops.timeout || Util.COOLDOWN.HUNT, cooldownRaw ? cooldownRaw.data : 0) };

const newAmount = await this.addMoney(userID, guildID, amount);
await this._set(key, Date.now());

return { cooldown: false, time: null, amount: newAmount };
}

/**
* Dig reward
* @param {string} userID User id
* @param {string} guildID Guild id
* @param {number} amount Custom Amount
* @param {object} ops Options
* @param {number[]} [ops.range] Amount range
* @param {number} [ops.timeout] Timeout
* @returns {Promise<JobData>}
*/
async dig(userID, guildID = false, amount, ops = { range: [], timeout: 0 }) {
this.__checkManager();

if (!userID || typeof userID !== "string") throw new Error("User id was not provided!");
if (!amount) amount = Util.random(ops && ops.range[0] || 1, ops && ops.range[1] || 70);

const key = Util.makeKey(userID, guildID, "dig");
const cooldownRaw = await this._get(key);
const cooldown = Util.onCooldown(ops.timeout || Util.COOLDOWN.DIG, cooldownRaw ? cooldownRaw.data : 0);

if (cooldown) return { cooldown: true, time: Util.getCooldown(ops.timeout || Util.COOLDOWN.DIG, cooldownRaw ? cooldownRaw.data : 0) };

const newAmount = await this.addMoney(userID, guildID, amount);
await this._set(key, Date.now());

return { cooldown: false, time: null, amount: newAmount };
}

/**
* Postmeme reward
* @param {string} userID User id
* @param {string} guildID Guild id
* @param {number} amount Custom Amount
* @param {object} ops Options
* @param {number[]} [ops.range] Amount range
* @param {number} [ops.timeout] Timeout
* @returns {Promise<JobData>}
*/
async postmeme(userID, guildID = false, amount, ops = { range: [], timeout: 0 }) {
this.__checkManager();

if (!userID || typeof userID !== "string") throw new Error("User id was not provided!");
if (!amount) amount = Util.random(ops && ops.range[0] || 1, ops && ops.range[1] || 70);

const key = Util.makeKey(userID, guildID, "postmeme");
const cooldownRaw = await this._get(key);
const cooldown = Util.onCooldown(ops.timeout || Util.COOLDOWN.POSTMEME, cooldownRaw ? cooldownRaw.data : 0);

if (cooldown) return { cooldown: true, time: Util.getCooldown(ops.timeout || Util.COOLDOWN.POSTMEME, cooldownRaw ? cooldownRaw.data : 0) };

const newAmount = await this.addMoney(userID, guildID, amount);
await this._set(key, Date.now());

return { cooldown: false, time: null, amount: newAmount };
}

/**
* Cultivate reward
* @param {string} userID User id
* @param {string} guildID Guild id
* @param {number} amount Custom Amount
* @param {object} ops Options
* @param {number[]} [ops.range] Amount range
* @param {number} [ops.timeout] Timeout
* @returns {Promise<JobData>}
*/
async cultivate(userID, guildID = false, amount, ops = { range: [], timeout: 0 }) {
this.__checkManager();

if (!userID || typeof userID !== "string") throw new Error("User id was not provided!");
if (!amount) amount = Util.random(ops && ops.range[0] || 1, ops && ops.range[1] || 70);

const key = Util.makeKey(userID, guildID, "cultivate");
const cooldownRaw = await this._get(key);
const cooldown = Util.onCooldown(ops.timeout || Util.COOLDOWN.CULTIVATE, cooldownRaw ? cooldownRaw.data : 0);

if (cooldown) return { cooldown: true, time: Util.getCooldown(ops.timeout || Util.COOLDOWN.CULTIVATE, cooldownRaw ? cooldownRaw.data : 0) };

const newAmount = await this.addMoney(userID, guildID, amount);
await this._set(key, Date.now());

return { cooldown: false, time: null, amount: newAmount };
}

/**
* Searchalt reward
* @param {string} userID User id
* @param {string} guildID Guild id
* @param {number} amount Custom Amount
* @param {object} ops Options
* @param {number[]} [ops.range] Amount range
* @param {number} [ops.timeout] Timeout
* @returns {Promise<JobData>}
*/
async searchalt(userID, guildID = false, amount, ops = { range: [], timeout: 0 }) {
this.__checkManager();

if (!userID || typeof userID !== "string") throw new Error("User id was not provided!");
if (!amount) amount = Util.random(ops.range[0] || 1, ops.range[1] || 70);

const key = Util.makeKey(userID, guildID, "searchalt");
const cooldownRaw = await this._get(key);
const cooldown = Util.onCooldown(ops.timeout || Util.COOLDOWN.SEARCHALT, cooldownRaw ? cooldownRaw.data : 0);
if (cooldown) return { cooldown: true, time: Util.getCooldown(ops.timeout || Util.COOLDOWN.SEARCHALT, cooldownRaw ? cooldownRaw.data : 0) };

const newAmount = await this.addMoney(userID, guildID, amount);
await this._set(key, Date.now());

return { cooldown: false, time: null, amount: newAmount };
}




/**
Expand Down
16 changes: 14 additions & 2 deletions src/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ class Util {
* @property {number} BEG Cooldown for beg
* @property {number} MONTHLY Cooldown for monthly
* @property {number} SEARCH Cooldown for search
* @property {number} SEARCHALT Cooldown for search alternative
* @property {number} FISH Cooldown for fish
* @property {number} HUNT Cooldown for hunt
* @property {number} DIG Cooldown for dig
* @property {number} POSTMEME Cooldown for postmeme
* @property {number} CULTIVATE Cooldown for cultivate
*/

/**
Expand All @@ -148,7 +154,13 @@ class Util {
WORK: 2700000,
BEG: 60000,
MONTHLY: 2628000000,
SEARCH: 300000
SEARCH: 300000,
SEARCHALT: 45000,
FISH: 50000,
HUNT: 45000,
DIG: 30000,
POSTMEME: 60000,
CULTIVATE: 55000 // Bonus
};
}

Expand Down Expand Up @@ -218,4 +230,4 @@ class Util {
}
};

module.exports = Util;
module.exports = Util;