feat(arabot): add bonus to daily rewards

This commit is contained in:
smyalygames 2023-03-04 01:28:34 +00:00
parent 45c07dbb11
commit 12b8f7016e
3 changed files with 47 additions and 4 deletions

View File

@ -19,10 +19,16 @@
import { Command, RegisterBehavior } from '@sapphire/framework';
import { Time } from '@sapphire/time-utilities';
import type { User, Guild, Message } from 'discord.js';
import type {
User,
Guild,
GuildMember,
Message,
} from 'discord.js';
import { updateUser } from '#utils/database/dbExistingUser';
import { daily, getLastDaily } from '#utils/database/economy';
import { EmbedBuilder } from 'discord.js';
import IDs from '#utils/ids';
export class DailyCommand extends Command {
public constructor(context: Command.Context, options: Command.Options) {
@ -116,18 +122,26 @@ export class DailyCommand extends Command {
return info;
}
// Give bonus for the user
const bonus = await this.giveBonus(member);
await updateUser(member);
const [db] = await Promise.all([daily(user.id, amount)]);
const [db] = await Promise.all([daily(user.id, amount + bonus)]);
const balance = db.Balance?.balance;
const embed = new EmbedBuilder()
.setColor('#00ff7d')
.setAuthor({ name: 'Daily Reward', iconURL: `${user.displayAvatarURL()}` })
.addFields(
{ name: 'Collected', value: `${amount} ARA` },
.addFields({ name: 'Collected', value: `${amount} ARA`, inline: bonus > 0 });
if (bonus > 0) {
embed.addFields(
{ name: 'Bonus', value: `${bonus} ARA`, inline: true },
{ name: '\u200B', value: 'Thank you for contributing to ARA! :D' },
);
}
if (balance !== undefined) {
embed.setFooter({ text: `New Balance: ${balance}` });
@ -137,4 +151,31 @@ export class DailyCommand extends Command {
info.embeds.push(embed);
return info;
}
private async giveBonus(member: GuildMember) {
let bonus = 0;
const amount = [
{ role: member.roles.premiumSubscriberRole?.id, amount: 5 },
{ role: IDs.roles.staff.coordinator, amount: 2 },
{ role: IDs.roles.staff.moderator, amount: 2 },
{ role: IDs.roles.staff.trialModerator, amount: 2 },
{ role: IDs.roles.staff.restricted, amount: 1 },
{ role: IDs.roles.staff.verifier, amount: 2 },
{ role: IDs.roles.staff.trialVerifier, amount: 2 },
{ role: IDs.roles.staff.developer, amount: 2 },
{ role: IDs.roles.staff.mentor, amount: 2 },
{ role: IDs.roles.stageHost, amount: 1 },
];
member.roles.cache.forEach((role) => {
amount.forEach((check) => {
if (role.id === check.role) {
bonus += check.amount;
}
});
});
return bonus;
}
}

View File

@ -64,6 +64,7 @@ const devIDs = {
trialVerifier: '999431675123597405',
mentor: '999431675140382801',
diversity: '999431675123597410',
developer: '792089759338070048',
},
stageHost: '999431675123597411',
patron: '999431675098447935',

View File

@ -67,6 +67,7 @@ let IDs = {
trialVerifier: '982635638010572850',
mentor: '802752882831130624',
diversity: '965482239913762826',
developer: '792089759338070048',
},
stageHost: '854893757593419786',
patron: '765370219207852055',