Skip to content
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,5 @@ groupSettings.json
node_modules/
.env
*.log
database.json
backups/
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion phantom-bot/commands/battle.js → commands/battle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
name: 'battle',
description: 'Engage in dragon battles.',
async execute(context) {
const { args, activeBattles, from, reply, sender, msg, getPlayer, BATTLE_ENVIRONMENTS, generateBattleImage, sock, getEffectiveness, dragons, PLAYER_XP_GAIN, getGuild, updateGuild, GUILD_TIERS, getRank, updatePlayer: updateContextPlayer, handleDungeonProgression, activeBeast, XP_PER_LEVEL, XP_GAIN_MULTIPLIER, activeWildEncounters } = context;
const { args, activeBattles, from, reply, sender, msg, getPlayer, BATTLE_ENVIRONMENTS, generateBattleImage, sock, getEffectiveness, dragons, PLAYER_XP_GAIN, getGuild, updateGuild, GUILD_TIERS, getRank, updatePlayer, handleDungeonProgression, activeBeast, XP_PER_LEVEL, XP_GAIN_MULTIPLIER, activeWildEncounters } = context;
const battle = activeBattles[from];
const subCommand = args[0]?.toLowerCase();

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion phantom-bot/commands/buy.js → commands/buy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
name: 'buy',
description: 'Buys an item from the shop.',
async execute(context) {
const { args, player, savePlayer, reply, shop } = context;
const { args, player, reply, shop } = context;
const itemKey = args[0]?.toLowerCase();
if (!itemKey || !shop[itemKey]) return reply('Invalid item.');
const item = shop[itemKey];
Expand Down
15 changes: 8 additions & 7 deletions phantom-bot/commands/buypack.js → commands/buypack.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ module.exports = {
name: 'buypack',
description: 'Buy a pack of 3 random cards for 300 gold.',
async execute(context) {
const { player, savePlayer, reply, CARD_PACK_COST, CARD_PACK_SIZE } = context;
const { player, reply, config, sock, from } = context;
const { cardPackCost, cardPackSize } = config.economy;

if (player.gold < CARD_PACK_COST) {
return reply(`You need ${CARD_PACK_COST} gold to buy a card pack, but you only have ${player.gold}.`);
if (player.gold < cardPackCost) {
return reply(`You need ${cardPackCost} gold to buy a card pack, but you only have ${player.gold}.`);
}

try {
// Deduct cost first
player.gold -= CARD_PACK_COST;
player.gold -= cardPackCost;

let receivedCards = [];
let cardFetchPromises = [];

for (let i = 0; i < CARD_PACK_SIZE; i++) {
for (let i = 0; i < cardPackSize; i++) {
cardFetchPromises.push(axios.get('https://aurora-api-ten.vercel.app/card/random'));
}

Expand All @@ -43,7 +44,7 @@ module.exports = {

require('../database/index').saveDb();

let message = `You spent ${CARD_PACK_COST} wallet and received a card pack containing:\n\n`;
let message = `You spent ${cardPackCost} gold and received a card pack containing:\n\n`;
receivedCards.forEach(card => {
message += `- *${card.name}* (Tier: ${card.tier})\n`;
});
Expand All @@ -58,7 +59,7 @@ module.exports = {
} catch (error) {
console.error('Error buying card pack:', error);
// Refund the player if the API call fails
player.gold += CARD_PACK_COST;
player.gold += cardPackCost;
require('../database/index').saveDb();
reply('There was an error trying to buy a card pack. Your gold has been refunded.');
}
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion phantom-bot/commands/catch.js → commands/catch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
name: 'catch',
description: 'Catch the spawned wild dragon.',
async execute(context) {
const { activeWildEncounters, from, sender, reply, player, args, savePlayer, activeBattles } = context;
const { activeWildEncounters, from, sender, reply, player, args, activeBattles } = context;
const wildEncounter = activeWildEncounters[from];
if (!wildEncounter) return reply('There is no wild dragon to catch.');

Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions phantom-bot/commands/choose.js → commands/choose.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module.exports = {
name: 'choose',
description: 'Choose your starter dragon.',
async execute(context) {
const { sock, from, msg, player, savePlayer, args, dragons, STARTER_DRAGON_IDS } = context;
const { sock, from, msg, player, args, dragons, config } = context;
const starterDragonIds = config.gameplay.starterDragonIds;

if (!player.adventureStarted) {
return sock.sendMessage(from, { text: 'You need to start your adventure first! Use `%start-hunt`.' }, { quoted: msg });
Expand All @@ -13,7 +14,7 @@ module.exports = {
}

const chosenId = parseInt(args[0]);
if (isNaN(chosenId) || !STARTER_DRAGON_IDS.includes(chosenId)) {
if (isNaN(chosenId) || !starterDragonIds.includes(chosenId)) {
return sock.sendMessage(from, { text: 'That is not a valid starter dragon ID. Please choose from the list provided.' }, { quoted: msg });
}

Expand Down
2 changes: 1 addition & 1 deletion phantom-bot/commands/claim.js → commands/claim.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
name: 'claim',
description: 'Claims a spawned card.',
async execute(context) {
const { from, player, savePlayer, reply, activeCardSpawns } = context;
const { from, player, reply, activeCardSpawns } = context;

const cardToClaim = activeCardSpawns[from];

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion phantom-bot/commands/deposit.js → commands/deposit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
name: 'deposit',
description: 'Deposits gold into your bank.',
async execute(context) {
const { args, player, savePlayer, reply } = context;
const { args, player, reply } = context;
const amount = parseInt(args[0]);
if (isNaN(amount) || amount <= 0) return reply('Invalid amount.');

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion phantom-bot/commands/eval.js → commands/eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
description: 'Executes JavaScript code (Owner only).',
async execute(context) {
// Making all context variables available to eval
const { args, reply, hasRole, sock, msg, from, sender, player, savePlayer, commandName, ...restOfContext } = context;
const { args, reply, hasRole, sock, msg, from, sender, player, commandName, ...restOfContext } = context;

if (!hasRole('owner')) {
return reply('❌ You are not authorized to use this command.');
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions phantom-bot/commands/givecard.js → commands/givecard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ module.exports = {
name: 'givecard',
description: 'Give a card to another player.',
async execute(context) {
const { args, msg, player, savePlayer, reply, getPlayer, updatePlayer } = context;
const { args, msg, player, reply, getPlayer, updatePlayer } = context;

const location = args[0]?.toLowerCase();
let location = args[0]?.toLowerCase();
const cardIndex = parseInt(args[1]) - 1;
const mentionedJid = msg.message?.extendedTextMessage?.contextInfo?.mentionedJid?.[0];

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
name: 'movetodeck',
description: 'Moves a card from your holder to your deck.',
async execute(context) {
const { args, player, savePlayer, reply } = context;
const { args, player, reply } = context;
const holderIndex = parseInt(args[0]) - 1;

if (isNaN(holderIndex)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
name: 'movetoholder',
description: 'Moves a card from your deck to your holder.',
async execute(context) {
const { args, player, savePlayer, reply } = context;
const { args, player, reply } = context;
const deckIndex = parseInt(args[0]) - 1;

if (isNaN(deckIndex)) {
Expand Down
2 changes: 1 addition & 1 deletion phantom-bot/commands/nickname.js → commands/nickname.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
name: 'nickname',
description: 'Give your dragon a nickname.',
async execute(context) {
const { args, player, savePlayer, reply } = context;
const { args, player, reply } = context;
const dragonIndex = parseInt(args[0]) - 1;
const newName = args.slice(1).join(' ');

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion phantom-bot/commands/re-roll.js → commands/re-roll.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = {
name: 're-roll',
description: "Re-roll a dragon's moves (owner/mod only).",
async execute(context) {
const { args, player, savePlayer, reply, hasRole, dragons } = context;
const { args, player, reply, hasRole, dragons } = context;

if (!hasRole('mod')) {
return reply('You do not have permission to use this command.');
Expand Down
2 changes: 1 addition & 1 deletion phantom-bot/commands/remove.js → commands/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
name: 'remove',
description: 'Remove a move from your dragon.',
async execute(context) {
const { args, player, savePlayer, reply } = context;
const { args, player, reply } = context;
const moveName = args.join(' ').toLowerCase();
if (!moveName) return reply('Please specify the name of the move to remove.');

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
name: 'sendtoden',
description: 'Move a party dragon to den.',
async execute(context) {
const { args, player, savePlayer, reply } = context;
const { args, player, reply } = context;
const index = parseInt(args[0]) - 1;
if (isNaN(index) || index < 0 || index >= player.party.length) {
return reply('Invalid party dragon index.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
name: 'sendtoparty',
description: 'Move a den dragon to party (max 6).',
async execute(context) {
const { args, player, savePlayer, reply } = context;
const { args, player, reply } = context;
if (player.party.length >= 6) return reply('Your party is full (max 6 dragons).');
const index = parseInt(args[0]) - 1;
if (isNaN(index) || index < 0 || index >= player.den.length) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 4 additions & 2 deletions phantom-bot/commands/slot.js → commands/slot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
name: 'slot',
description: 'Gamble your gold in the slot machine.',
async execute(context) {
const { from, getGroupSettings, args, player, savePlayer, reply, sock, msg } = context;
const { from, getGroupSettings, args, player, reply, sock, msg } = context;

if (from.endsWith('@g.us')) {
const groupSettings = getGroupSettings(from);
Expand All @@ -28,6 +28,9 @@ module.exports = {
return reply('Not enough gold to slot.');
}

// Deduct bet amount immediately
player.gold -= amount;

await sock.sendMessage(from, { text: `*🎰 Spinning the slots for ${amount} gold...*` }, { quoted: msg });

const symbols = ['🍒', '🍋', '🍊', '🍇', '🔔', '💎'];
Expand Down Expand Up @@ -62,7 +65,6 @@ module.exports = {
player.gold += win;
resultText += message;
} else {
player.gold -= amount;
resultText += `😢 Bad luck! You lost ${amount} gold.`;
}

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion phantom-bot/commands/spawn.js → commands/spawn.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
name: 'spawn',
description: 'Spawns a wild dragon.',
async execute(context) {
const { wildSpawnsEnabled, activeWildEncounters, from, player, cooldowns, savePlayer, reply, dragons, sender, sock } = context;
const { wildSpawnsEnabled, activeWildEncounters, from, player, cooldowns, reply, dragons, sender, sock } = context;
if (!wildSpawnsEnabled.enabled) return reply('Wild spawns are currently disabled.');
if (activeWildEncounters[from]) return reply('A wild dragon has already spawned in this chat.');

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions phantom-bot/commands/start-hunt.js → commands/start-hunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ module.exports = {
name: 'start-hunt',
description: 'Start your adventure and choose a dragon.',
async execute(context) {
const { sock, from, msg, player, savePlayer, dragons, STARTER_DRAGON_IDS } = context;
const { sock, from, msg, player, dragons, config } = context;
const starterDragonIds = config.gameplay.starterDragonIds;

if (player.party && player.party.length > 0) {
return sock.sendMessage(from, { text: 'You have already begun your adventure! Use `%party` to see your dragons.' }, { quoted: msg });
}

const starterDragons = STARTER_DRAGON_IDS.map(id => dragons.find(d => d.id === id));
const starterDragons = starterDragonIds.map(id => dragons.find(d => d.id === id));

let message = `*Welcome, Dragonbound! Your saga begins now.*\n\n`;
message += `A path unfolds before you, and with it, a choice. Six young dragons await a partner to raise them. Choose wisely, as this creature will be your first companion in a world of myth and magic.\n\n`;
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ module.exports = {
const restOfArgs = args.slice(1);

switch (subCommand) {
case 'create':
case 'create': {
const tournamentName = restOfArgs.join(' ');
if (!tournamentName) {
return reply('Please provide a name for the tournament.');
}
await reply(`Tournament "${tournamentName}" created!`);
break;
}
case 'join':
await reply('You have joined the tournament!');
break;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion phantom-bot/commands/train.js → commands/train.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
name: 'train',
description: 'Train your dragons.',
async execute(context) {
const { player, cooldowns, reply, savePlayer } = context;
const { player, cooldowns, reply } = context;
const now = Date.now();
const lastTrain = player.cooldowns.train || 0;
if (now - lastTrain < cooldowns.train) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion phantom-bot/commands/withdraw.js → commands/withdraw.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
name: 'withdraw',
description: 'Withdraws gold from your bank.',
async execute(context) {
const { args, player, savePlayer, reply } = context;
const { args, player, reply } = context;
const amount = parseInt(args[0]);
if (isNaN(amount) || amount <= 0) return reply('Invalid amount.');

Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions phantom-bot/config/index.js → config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ module.exports = {
cardPackSize: parseInt(process.env.CARD_PACK_SIZE) || 3,
guildCreateCost: parseInt(process.env.GUILD_CREATE_COST) || 10000,
maxBet: parseInt(process.env.MAX_BET) || 1000000
},
gameplay: {
starterDragonIds: (process.env.STARTER_DRAGON_IDS || '1,2,3,4,5,6').split(',').map(id => parseInt(id.trim()))
}
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const globals = require("globals");
const js = require("@eslint/js");

module.exports = [
js.configs.recommended,
{
languageOptions: {
ecmaVersion: 2022,
sourceType: "commonjs",
globals: {
...globals.node,
...globals.commonjs,
global: "writable"
},
},
rules: {
"no-unused-vars": "warn",
"no-undef": "error",
"no-console": "off"
}
}
];
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading