from __future__ import annotations import asyncio import datetime from collections.abc import Awaitable, Callable import discord from discord import app_commands import economy import strings as S def register_economy_income_commands( tree: app_commands.CommandTree, bot: discord.Client, coin: Callable[[int], str], cd_ts: Callable[[datetime.timedelta], str], check_cmd_rate: Callable[[discord.Interaction], Awaitable[bool]], maybe_remind: Callable[[int, str], Awaitable[None]], award_exp: Callable[[discord.Interaction, int], Awaitable[None]], ) -> None: @tree.command(name="daily", description=S.CMD["daily"]) async def cmd_daily(interaction: discord.Interaction): res = await economy.do_daily(interaction.user.id) if not res["ok"]: if res["reason"] == "banned": await interaction.response.send_message(S.MSG_BANNED, ephemeral=True) elif res["reason"] == "cooldown": await interaction.response.send_message( S.CD_MSG["daily"].format(ts=cd_ts(res["remaining"])), ephemeral=True, ) return streak = res["streak"] streak_str = f"đŸ”„ {streak}p" + ( " (+200%)" if res["streak_mult"] >= 3.0 else " (+100%)" if res["streak_mult"] >= 2.0 else " (+50%)" if res["streak_mult"] >= 1.5 else "" ) lines = [S.DAILY_UI["earned"].format(earned=coin(res["earned"]))] if res["interest"]: lines.append(S.DAILY_UI["interest"].format(interest=coin(res["interest"]))) if res["vip"]: lines.append(S.DAILY_UI["vip"]) lines.append(S.DAILY_UI["footer"].format(streak_str=streak_str, balance=coin(res["balance"]))) embed = discord.Embed(title=S.TITLE["daily"], description="\n".join(lines), color=0xF4C430) await interaction.response.send_message(embed=embed) asyncio.create_task(maybe_remind(interaction.user.id, "daily")) asyncio.create_task(award_exp(interaction, economy.EXP_REWARDS["daily"])) @tree.command(name="work", description=S.CMD["work"]) async def cmd_work(interaction: discord.Interaction): if await check_cmd_rate(interaction): return res = await economy.do_work(interaction.user.id) if not res["ok"]: if res["reason"] == "banned": await interaction.response.send_message(S.MSG_BANNED, ephemeral=True) elif res["reason"] == "cooldown": await interaction.response.send_message( S.CD_MSG["work"].format(ts=cd_ts(res["remaining"])), ephemeral=True, ) elif res["reason"] == "jailed": await interaction.response.send_message( S.CD_MSG["jailed"].format(ts=cd_ts(res["remaining"])), ephemeral=True, ) return desc = S.WORK_UI["desc"].format(job=res["job"], earned=coin(res["earned"])) if res["lucky"]: desc += S.WORK_UI["redbull"] if res["hiir"]: desc += S.WORK_UI["hiir"] if res["laud"]: desc += S.WORK_UI["laud"] desc += S.WORK_UI["balance"].format(balance=coin(res["balance"])) embed = discord.Embed(title=S.TITLE["work"], description=desc, color=0x57F287) await interaction.response.send_message(embed=embed) asyncio.create_task(maybe_remind(interaction.user.id, "work")) asyncio.create_task(award_exp(interaction, economy.EXP_REWARDS["work"])) @tree.command(name="beg", description=S.CMD["beg"]) async def cmd_beg(interaction: discord.Interaction): if await check_cmd_rate(interaction): return res = await economy.do_beg(interaction.user.id) if not res["ok"]: if res["reason"] == "banned": await interaction.response.send_message(S.MSG_BANNED, ephemeral=True) elif res["reason"] == "cooldown": await interaction.response.send_message( S.CD_MSG["beg"].format(ts=cd_ts(res["remaining"])), ephemeral=True, ) return if res["jailed"]: title = "🔒 " + S.TITLE["beg"] color = 0xE67E22 else: title = S.TITLE["beg"] color = 0x99AAB5 beg_lines = [S.BEG_UI["desc"].format(text=res["text"], earned=coin(res["earned"]))] if res["klaviatuur"]: beg_lines.append(S.BEG_UI["klaviatuur"]) beg_lines.append(S.BEG_UI["balance"].format(balance=coin(res["balance"]))) embed = discord.Embed(title=title, description="\n".join(beg_lines), color=color) await interaction.response.send_message(embed=embed) asyncio.create_task(maybe_remind(interaction.user.id, "beg")) asyncio.create_task(award_exp(interaction, economy.EXP_REWARDS["beg"])) @tree.command(name="crime", description=S.CMD["crime"]) async def cmd_crime(interaction: discord.Interaction): if await check_cmd_rate(interaction): return res = await economy.do_crime(interaction.user.id) if not res["ok"]: if res["reason"] == "banned": await interaction.response.send_message(S.MSG_BANNED, ephemeral=True) elif res["reason"] == "cooldown": await interaction.response.send_message( S.CD_MSG["crime"].format(ts=cd_ts(res["remaining"])), ephemeral=True, ) elif res["reason"] == "jailed": await interaction.response.send_message( S.CD_MSG["jailed"].format(ts=cd_ts(res["remaining"])), ephemeral=True, ) return if res["success"]: crime_lines = [S.CRIME_UI["win_desc"].format(text=res["text"], earned=coin(res["earned"]))] if res["mikrofon"]: crime_lines.append(S.CRIME_UI["mikrofon"].lstrip("\n")) crime_lines.append(S.CRIME_UI["balance"].lstrip("\n").format(balance=coin(res["balance"]))) embed = discord.Embed( title=S.TITLE["crime_win"], description="\n".join(crime_lines), color=0x57F287, ) else: jail_part = ( S.CRIME_UI["fail_jailed"].format(ts=cd_ts(economy.JAIL_DURATION)) if res.get("jailed") else S.CRIME_UI["fail_shield"] ) embed = discord.Embed( title=S.TITLE["crime_fail"], description=S.CRIME_UI["fail_base"].format(text=res["text"], fine=coin(res["fine"])) + jail_part + S.CRIME_UI["balance"].format(balance=coin(res["balance"])), color=0xED4245, ) await interaction.response.send_message(embed=embed) asyncio.create_task(maybe_remind(interaction.user.id, "crime")) if res["success"]: asyncio.create_task(award_exp(interaction, economy.EXP_REWARDS["crime_win"])) @tree.command(name="rob", description=S.CMD["rob"]) async def cmd_rob(interaction: discord.Interaction, sihtmĂ€rk: discord.Member): if await check_cmd_rate(interaction): return if sihtmĂ€rk.id == interaction.user.id: await interaction.response.send_message(S.ERR["rob_self"], ephemeral=True) return if sihtmĂ€rk.bot and (bot.user is None or sihtmĂ€rk.id != bot.user.id): await interaction.response.send_message(S.ERR["rob_bot"], ephemeral=True) return if bot.user and sihtmĂ€rk.id == bot.user.id: await interaction.response.send_message(S.ERR["rob_house_blocked"], ephemeral=True) return res = await economy.do_rob(interaction.user.id, sihtmĂ€rk.id) if not res["ok"]: if res["reason"] == "banned": await interaction.response.send_message(S.MSG_BANNED, ephemeral=True) elif res["reason"] == "cooldown": await interaction.response.send_message( S.CD_MSG["rob"].format(ts=cd_ts(res["remaining"])), ephemeral=True, ) elif res["reason"] == "jailed": await interaction.response.send_message( S.CD_MSG["jailed"].format(ts=cd_ts(res["remaining"])), ephemeral=True, ) elif res["reason"] == "broke": await interaction.response.send_message( S.ERR["rob_too_poor"].format(name=sihtmĂ€rk.display_name), ephemeral=True, ) elif res["reason"] == "target_jailed": await interaction.response.send_message( S.ERR["rob_target_jailed"].format(name=sihtmĂ€rk.display_name), ephemeral=True, ) return if res["success"]: if res.get("jackpot"): desc = S.ROB_UI["jackpot_desc"].format(stolen=coin(res["stolen"]), balance=coin(res["balance"])) color = 0xF4C430 else: desc = S.ROB_UI["win_desc"].format( stolen=coin(res["stolen"]), name=sihtmĂ€rk.display_name, balance=coin(res["balance"]), ) color = 0x57F287 embed = discord.Embed(title=S.TITLE["rob_win"], description=desc, color=color) elif res["reason"] == "valvur": embed = discord.Embed( title=S.TITLE["rob_anticheat"], description=S.ROB_UI["anticheat_desc"].format( name=sihtmĂ€rk.display_name, fine=coin(res["fine"]), ), color=0xED4245, ) target_data = await economy.get_user(sihtmĂ€rk.id) if "anticheat" not in target_data.get("items", []): try: await sihtmĂ€rk.send(S.ROB_UI["anticheat_worn"]) except discord.Forbidden: pass else: embed = discord.Embed( title=S.TITLE["rob_fail"], description=S.ROB_UI["fail_desc"].format( fine=coin(res["fine"]), balance=coin(res["balance"]), ), color=0xED4245, ) await interaction.response.send_message(embed=embed) asyncio.create_task(maybe_remind(interaction.user.id, "rob")) if res["success"]: asyncio.create_task(award_exp(interaction, economy.EXP_REWARDS["rob_win"])) try: await sihtmĂ€rk.send( S.ROB_UI["victim_dm"].format( robber=interaction.user.display_name, stolen=coin(res["stolen"]), ) ) except discord.Forbidden: pass