Skip to content

Commit 308dfc2

Browse files
committed
Vault command progress
1 parent f57009c commit 308dfc2

File tree

7 files changed

+225
-50
lines changed

7 files changed

+225
-50
lines changed

discord/bot/cogs/commands/econ.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -494,42 +494,42 @@ async def inventory_farming(self, ctx: Ctx, user: discord.User | discord.Member
494494
async def vault_deposit(self, ctx: Ctx, emerald_blocks: str):
495495
"""Deposits the given amount of emerald blocks into the vault"""
496496

497-
db_user = await self.db.fetch_user(ctx.author.id)
497+
# db_user = await self.db.fetch_user(ctx.author.id)
498498

499-
if db_user.emeralds < 9:
500-
await ctx.reply_embed(ctx.l.econ.dep.poor_loser)
501-
return
499+
# if db_user.emeralds < 9:
500+
# await ctx.reply_embed(ctx.l.econ.dep.poor_loser)
501+
# return
502502

503+
amount: int | Literal["Max"]
503504
if emerald_blocks.lower() in ("all", "max"):
504-
amount = db_user.vault_max - db_user.vault_balance
505-
506-
if amount * 9 > db_user.emeralds:
507-
amount = math.floor(db_user.emeralds / 9)
505+
amount = "Max"
508506
else:
509507
try:
510508
amount = int(emerald_blocks)
511509
except ValueError:
512510
await ctx.reply_embed(ctx.l.econ.use_a_number_stupid)
513511
return
514512

515-
if amount * 9 > db_user.emeralds:
516-
await ctx.reply_embed(ctx.l.econ.dep.stupid_3)
517-
return
513+
# if amount * 9 > db_user.emeralds:
514+
# await ctx.reply_embed(ctx.l.econ.dep.stupid_3)
515+
# return
518516

519-
if amount < 1:
520-
if emerald_blocks.lower() in ("all", "max"):
521-
await ctx.reply_embed(ctx.l.econ.dep.stupid_2)
522-
else:
523-
await ctx.reply_embed(ctx.l.econ.dep.stupid_1)
517+
# if amount < 1:
518+
# if emerald_blocks.lower() in ("all", "max"):
519+
# await ctx.reply_embed(ctx.l.econ.dep.stupid_2)
520+
# else:
521+
# await ctx.reply_embed(ctx.l.econ.dep.stupid_1)
524522

525-
return
523+
# return
526524

527-
if amount > db_user.vault_max - db_user.vault_balance:
528-
await ctx.reply_embed(ctx.l.econ.dep.stupid_2)
529-
return
525+
# if amount > db_user.vault_max - db_user.vault_balance:
526+
# await ctx.reply_embed(ctx.l.econ.dep.stupid_2)
527+
# return
528+
529+
# await self.db.balance_sub(ctx.author.id, amount * 9)
530+
# await self.db.set_vault(ctx.author.id, db_user.vault_balance + amount, db_user.vault_max)
530531

531-
await self.db.balance_sub(ctx.author.id, amount * 9)
532-
await self.db.set_vault(ctx.author.id, db_user.vault_balance + amount, db_user.vault_max)
532+
await self.karen.commands.vault.deposit(ctx.k.user.id, blocks=amount)
533533

534534
await ctx.reply_embed(
535535
ctx.l.econ.dep.deposited.format(
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class KarenGameError(Exception):
2+
def __init__(self, message: str) -> None:
3+
super().__init__(message)
4+
5+
self.message = message
6+
7+
8+
class UserDoesNotExistError(KarenGameError):
9+
def __init__(self) -> None:
10+
super().__init__("User does not exist")
11+
12+
13+
class UserLockCannotBeAcquiredError(KarenGameError):
14+
def __init__(self, lock: str) -> None:
15+
super().__init__(f"User lock {lock!r} cannot be acquired")
16+
17+
18+
class NotEnoughEmeraldsError(KarenGameError):
19+
def __init__(self) -> None:
20+
super().__init__("User does not have enough emeralds")

discord/bot/services/karen/resources/command_executions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,5 @@ async def preflight(self, **kwargs: Unpack[CommandExecutionPreflightRequest]) ->
5757
)
5858
data = await response.read()
5959

60+
print(data)
6061
return CommandExecutionPreflightResponse.model_validate_json(data)

discord/bot/services/karen/resources/commands/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import aiohttp
44

55
from bot.services.karen.client import KarenResourceBase
6-
from bot.services.karen.resources.commands.profile import ProfileCommandResource
76

87

98
class CommandsResourceGroup(KarenResourceBase):
@@ -12,4 +11,8 @@ class CommandsResourceGroup(KarenResourceBase):
1211
def __init__(self, http: aiohttp.ClientSession):
1312
super().__init__(http)
1413

14+
from .profile import ProfileCommandResource
15+
from .vault import VaultCommandResource
16+
1517
self.profile = ProfileCommandResource(http)
18+
self.vault = VaultCommandResource(http)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from typing import ClassVar, Literal
2+
3+
import aiohttp
4+
5+
from bot.services.karen.client import KarenResourceBase
6+
from bot.utils.urls import url_join
7+
8+
9+
class VaultCommandResource(KarenResourceBase):
10+
BASE_URL: ClassVar[str] = "/commands/vault/"
11+
12+
def __init__(self, http: aiohttp.ClientSession):
13+
super().__init__(http)
14+
15+
async def deposit(self, user_id: str, *, blocks: int | Literal["Max"]) -> None:
16+
await self._http.post(
17+
url_join(self.BASE_URL, user_id, "deposit"),
18+
json={
19+
"blocks": blocks,
20+
},
21+
allow_redirects=False,
22+
)
23+
24+
async def withdraw(self, user_id: str, *, blocks: int | Literal["Max"]) -> None:
25+
await self._http.post(
26+
url_join(self.BASE_URL, user_id, "withdraw"),
27+
json={
28+
"blocks": blocks,
29+
},
30+
allow_redirects=False,
31+
)

karen/src/routes/command_executions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct CommandExecutionPreflightResponse {
3535

3636
#[derive(Debug, Serialize)]
3737
#[cfg_attr(test, derive(Deserialize))]
38-
#[serde(tag = "error_type", content = "error")]
38+
#[serde(tag = "error_type")]
3939
enum PreflightErrorResponse {
4040
CommandOnCooldown { until: DateTime<Utc> },
4141
}

0 commit comments

Comments
 (0)