mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-11-03 08:14:28 -05:00
Fixed .bank take, added .bank seize alias. Added .bank award
This commit is contained in:
@@ -75,7 +75,21 @@ public partial class Gambling
|
|||||||
|
|
||||||
private async Task BankTakeInternalAsync(long amount, ulong userId)
|
private async Task BankTakeInternalAsync(long amount, ulong userId)
|
||||||
{
|
{
|
||||||
if (await _bank.WithdrawAsync(userId, amount))
|
if (await _bank.TakeAsync(userId, amount))
|
||||||
|
{
|
||||||
|
await ReplyErrorLocalizedAsync(strs.take_fail(N(amount),
|
||||||
|
_client.GetUser(userId)?.ToString()
|
||||||
|
?? userId.ToString(),
|
||||||
|
CurrencySign));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await ctx.OkAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task BankAwardInternalAsync(long amount, ulong userId)
|
||||||
|
{
|
||||||
|
if (await _bank.AwardAsync(userId, amount))
|
||||||
{
|
{
|
||||||
await ReplyErrorLocalizedAsync(strs.take_fail(N(amount),
|
await ReplyErrorLocalizedAsync(strs.take_fail(N(amount),
|
||||||
_client.GetUser(userId)?.ToString()
|
_client.GetUser(userId)?.ToString()
|
||||||
@@ -89,7 +103,7 @@ public partial class Gambling
|
|||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
[OwnerOnly]
|
[OwnerOnly]
|
||||||
[Priority(-1)]
|
[Priority(1)]
|
||||||
public async Task BankTake(long amount, [Leftover] IUser user)
|
public async Task BankTake(long amount, [Leftover] IUser user)
|
||||||
=> await BankTakeInternalAsync(amount, user.Id);
|
=> await BankTakeInternalAsync(amount, user.Id);
|
||||||
|
|
||||||
@@ -98,5 +112,10 @@ public partial class Gambling
|
|||||||
[Priority(0)]
|
[Priority(0)]
|
||||||
public async Task BankTake(long amount, ulong userId)
|
public async Task BankTake(long amount, ulong userId)
|
||||||
=> await BankTakeInternalAsync(amount, userId);
|
=> await BankTakeInternalAsync(amount, userId);
|
||||||
|
|
||||||
|
[Cmd]
|
||||||
|
[OwnerOnly]
|
||||||
|
public async Task BankAward(long amount, [Leftover] IUser user)
|
||||||
|
=> await BankAwardInternalAsync(amount, user.Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,6 +15,48 @@ public sealed class BankService : IBankService, INService
|
|||||||
_db = db;
|
_db = db;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<bool> AwardAsync(ulong userId, long amount)
|
||||||
|
{
|
||||||
|
if (amount <= 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(amount));
|
||||||
|
|
||||||
|
await using var ctx = _db.GetDbContext();
|
||||||
|
await ctx.BankUsers
|
||||||
|
.ToLinqToDBTable()
|
||||||
|
.InsertOrUpdateAsync(() => new()
|
||||||
|
{
|
||||||
|
UserId = userId,
|
||||||
|
Balance = amount
|
||||||
|
},
|
||||||
|
(old) => new()
|
||||||
|
{
|
||||||
|
Balance = old.Balance + amount
|
||||||
|
},
|
||||||
|
() => new()
|
||||||
|
{
|
||||||
|
UserId = userId
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> TakeAsync(ulong userId, long amount)
|
||||||
|
{
|
||||||
|
if (amount <= 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(amount));
|
||||||
|
|
||||||
|
await using var ctx = _db.GetDbContext();
|
||||||
|
var rows = await ctx.BankUsers
|
||||||
|
.ToLinqToDBTable()
|
||||||
|
.Where(x => x.UserId == userId && x.Balance >= amount)
|
||||||
|
.UpdateAsync((old) => new()
|
||||||
|
{
|
||||||
|
Balance = old.Balance - amount
|
||||||
|
});
|
||||||
|
|
||||||
|
return rows > 0;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<bool> DepositAsync(ulong userId, long amount)
|
public async Task<bool> DepositAsync(ulong userId, long amount)
|
||||||
{
|
{
|
||||||
if (amount <= 0)
|
if (amount <= 0)
|
||||||
|
|||||||
@@ -5,4 +5,6 @@ public interface IBankService
|
|||||||
Task<bool> DepositAsync(ulong userId, long amount);
|
Task<bool> DepositAsync(ulong userId, long amount);
|
||||||
Task<bool> WithdrawAsync(ulong userId, long amount);
|
Task<bool> WithdrawAsync(ulong userId, long amount);
|
||||||
Task<long> GetBalanceAsync(ulong userId);
|
Task<long> GetBalanceAsync(ulong userId);
|
||||||
|
Task<bool> AwardAsync(ulong userId, long amount);
|
||||||
|
Task<bool> TakeAsync(ulong userId, long amount);
|
||||||
}
|
}
|
||||||
@@ -374,6 +374,7 @@ award:
|
|||||||
- award
|
- award
|
||||||
take:
|
take:
|
||||||
- take
|
- take
|
||||||
|
- seize
|
||||||
betroll:
|
betroll:
|
||||||
- betroll
|
- betroll
|
||||||
- br
|
- br
|
||||||
@@ -1323,6 +1324,9 @@ bankbalance:
|
|||||||
- bal
|
- bal
|
||||||
banktake:
|
banktake:
|
||||||
- take
|
- take
|
||||||
|
- seize
|
||||||
|
bankaward:
|
||||||
|
- award
|
||||||
# Patron
|
# Patron
|
||||||
patron:
|
patron:
|
||||||
- patron
|
- patron
|
||||||
|
|||||||
@@ -2238,9 +2238,13 @@ bankbalance:
|
|||||||
args:
|
args:
|
||||||
- ""
|
- ""
|
||||||
banktake:
|
banktake:
|
||||||
desc: "Takes the specified from a user's bank"
|
desc: "Takes the specified amount of currency from a user's bank"
|
||||||
args:
|
args:
|
||||||
- "500 @MoniLaunder"
|
- "500 @MoniLaunder"
|
||||||
|
bankaward:
|
||||||
|
desc: "Award the specified amount of currency to a user's bank"
|
||||||
|
args:
|
||||||
|
- "99999 @Bestie"
|
||||||
patron:
|
patron:
|
||||||
desc: "Check your patronage status and command usage quota. Bot owners can check targeted user's patronage status."
|
desc: "Check your patronage status and command usage quota. Bot owners can check targeted user's patronage status."
|
||||||
args:
|
args:
|
||||||
|
|||||||
Reference in New Issue
Block a user