Skip to content

Economy Connector

M3rcena edited this page Nov 1, 2026 · 1 revision

🪙 Weky <-> Economy Cross-Package Connector

The @m3rcena/weky minigames suite seamlessly integrates with @m3rcena/eco to bring real-stakes gaming into your Discord server. Games directly influence players' cash balances, credit scores, streaks, and net worth!


⚡ Key Capabilities

  • 💰 Automated Game Rewards: Victorious players automatically receive cash rewards in their @m3rcena/eco wallet.
  • 🛑 Defeat Penalties: Optional entry fees or loss penalties for high-stakes games.
  • 📈 Score-Based Payouts: Solo arcade games (2048, Snake, Fast Type, etc.) calculate coin payouts proportional to final score.
  • 🔥 Win Streak Multipliers: Players on consecutive winning streaks earn bonus coin multipliers.
  • ⚔️ PvP Wagers & Bets: Two players challenge each other, both escrow an agreed bet amount, and the winner takes the pot (with optional house fee).
  • 🏆 Tournament Prize Pools: Champion and runner-up cash prizes disbursed when brackets conclude.

🔌 Connecting Weky to Eco

Connecting the two engines takes a single line of code:

import { Client } from "discord.js";
import { WekyManager } from "@m3rcena/weky";
import { EcoManager } from "@m3rcena/eco";

const client = new Client({ intents: [/* ... */] });
const eco = new EcoManager({ database: "sqlite" });
const weky = new WekyManager(client, { database: "sqlite" });

// Initialize the connector from Weky...
export const connector = weky.connectEco(eco, {
  defaultWinReward: 50,       // 50 coins awarded on victory
  defaultLossPenalty: 0,      // No penalty on defeat
  defaultDrawReward: 10,      // 10 coins on draw/tie
  defaultScoreMultiplier: 0.05, // Solo score multiplier (1000 pts = 50 coins)
  maxScoreReward: 500,        // Score cap
  streakBonus: 10,            // +10 bonus coins per active win streak count
  tournamentChampionPrize: 500, // Tournament champion prize
  wagerHouseFee: 5,           // 5% house fee deducted from PvP pots
});

// ...Or initialize from Eco!
// export const connector = eco.connectWeky(weky, { /* options */ });

🎲 PvP Wagers (Coin Bets)

Allow players to put their coins on the line in PvP minigames (Tic-Tac-Toe, Fight RPG, Rock Paper Scissors, etc.):

// Slash command: /bet-duel @opponent 100
const wagerRes = await connector.createWager({
  wagerId: interaction.channelId, // Or match ID
  player1Id: interaction.user.id,
  player2Id: opponent.id,
  amount: 100, // 100 coins each = 200 pot
  game: "fight",
  guildId: interaction.guildId,
});

if (!wagerRes.success) {
  return interaction.reply({
    content: `❌ Could not start wager: ${wagerRes.reason}`,
    ephemeral: true,
  });
}

// Start the game!
await weky.createFight({
  context: interaction,
  opponent: opponent,
});
// When the game finishes, Weky automatically detects the winner,
// resolves the wager, deducts the 5% house fee, and deposits the pot into the winner's wallet!

🛠️ Configuration Options

Option Type Default Description
defaultWinReward number 50 Flat coins awarded upon winning any minigame.
defaultLossPenalty number 0 Flat coins deducted upon defeat.
defaultDrawReward number 10 Flat coins awarded upon a tie/draw.
defaultScoreMultiplier number 0.05 Coins awarded per point in solo games (e.g. 2048, Snake).
maxScoreReward number 500 Maximum coins a single solo game can award from score.
streakBonus number 5 Bonus coins per consecutive win streak count.
tournamentChampionPrize number 500 Cash prize awarded to tournament winners.
tournamentRunnerUpPrize number 200 Cash prize awarded to 2nd place in tournaments.
wagerHouseFee number 0 Percentage (0-100) taken from PvP wager pots as a house tax.
autoReward boolean true Whether to automatically listen for gameOver and tournamentEnd events.
games Record<string, GameRewardRule> {} Per-game overrides for any of the above settings.

📡 Connector Event Telemetry

The connector is an EventEmitter providing audit logs and broadcast hooks:

connector.on("reward", (result) => {
  console.log(`[Eco] ${result.userId} earned +${result.amount} coins in ${result.game} (${result.reason})`);
});

connector.on("penalty", (result) => {
  console.log(`[Eco] ${result.userId} lost ${result.amount} coins in ${result.game}`);
});

connector.on("wagerResolved", ({ wager, winnerId, payout, houseFee }) => {
  console.log(`[Eco] ${winnerId} won wager ${wager.id}: +${payout} coins (${houseFee} tax)`);
});

connector.on("tournamentReward", (result) => {
  console.log(`[Eco] Tournament Champion ${result.userId} awarded +${result.amount} coins!`);
});

Clone this wiki locally