mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
- Updated editorconfig rules to hopefully look a bit nicer.
- Removed configureawait(false) from everywhere as it doesnt' do anything in a console app and just makes the code look ugly - Started using .WhenAll extension instead of Task.WhenAll to make it look nicer when chaining methods
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#nullable disable
|
||||
#nullable disable
|
||||
using NadekoBot.Modules.Gambling.Common;
|
||||
using NadekoBot.Modules.Gambling.Common.AnimalRacing;
|
||||
using NadekoBot.Modules.Gambling.Services;
|
||||
@@ -112,15 +112,13 @@ public partial class Gambling
|
||||
var msg = raceMessage;
|
||||
|
||||
if (msg is null)
|
||||
raceMessage = await SendConfirmAsync(text)
|
||||
.ConfigureAwait(false);
|
||||
raceMessage = await SendConfirmAsync(text);
|
||||
else
|
||||
await msg.ModifyAsync(x => x.Embed = _eb.Create()
|
||||
.WithTitle(GetText(strs.animal_race))
|
||||
.WithDescription(text)
|
||||
.WithOkColor()
|
||||
.Build())
|
||||
.ConfigureAwait(false);
|
||||
.Build());
|
||||
}
|
||||
|
||||
private Task Ar_OnStartingFailed(AnimalRace race)
|
||||
@@ -133,18 +131,17 @@ public partial class Gambling
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task JoinRace(ShmartNumber amount = default)
|
||||
{
|
||||
if (!await CheckBetOptional(amount).ConfigureAwait(false))
|
||||
if (!await CheckBetOptional(amount))
|
||||
return;
|
||||
|
||||
if (!_service.AnimalRaces.TryGetValue(ctx.Guild.Id, out var ar))
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.race_not_exist).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.race_not_exist);
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
var user = await ar.JoinRace(ctx.User.Id, ctx.User.ToString(), amount)
|
||||
.ConfigureAwait(false);
|
||||
var user = await ar.JoinRace(ctx.User.Id, ctx.User.ToString(), amount);
|
||||
if (amount > 0)
|
||||
await SendConfirmAsync(GetText(strs.animal_race_join_bet(ctx.User.Mention, user.Animal.Icon, amount + CurrencySign)));
|
||||
else
|
||||
@@ -164,8 +161,7 @@ public partial class Gambling
|
||||
}
|
||||
catch (AnimalRaceFullException)
|
||||
{
|
||||
await SendConfirmAsync(GetText(strs.animal_race), GetText(strs.animal_race_full))
|
||||
.ConfigureAwait(false);
|
||||
await SendConfirmAsync(GetText(strs.animal_race), GetText(strs.animal_race_full));
|
||||
}
|
||||
catch (NotEnoughFundsException)
|
||||
{
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#nullable disable
|
||||
#nullable disable
|
||||
using NadekoBot.Modules.Gambling.Common;
|
||||
using NadekoBot.Modules.Gambling.Common.Blackjack;
|
||||
using NadekoBot.Modules.Gambling.Services;
|
||||
@@ -31,14 +31,14 @@ public partial class Gambling
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task BlackJack(ShmartNumber amount)
|
||||
{
|
||||
if (!await CheckBetMandatory(amount).ConfigureAwait(false))
|
||||
if (!await CheckBetMandatory(amount))
|
||||
return;
|
||||
|
||||
var newBj = new Blackjack(_cs, _db);
|
||||
Blackjack bj;
|
||||
if (newBj == (bj = _service.Games.GetOrAdd(ctx.Channel.Id, newBj)))
|
||||
{
|
||||
if (!await bj.Join(ctx.User, amount).ConfigureAwait(false))
|
||||
if (!await bj.Join(ctx.User, amount))
|
||||
{
|
||||
_service.Games.TryRemove(ctx.Channel.Id, out _);
|
||||
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
|
||||
@@ -48,19 +48,19 @@ public partial class Gambling
|
||||
bj.GameEnded += Bj_GameEnded;
|
||||
bj.Start();
|
||||
|
||||
await ReplyConfirmLocalizedAsync(strs.bj_created).ConfigureAwait(false);
|
||||
await ReplyConfirmLocalizedAsync(strs.bj_created);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (await bj.Join(ctx.User, amount).ConfigureAwait(false))
|
||||
await ReplyConfirmLocalizedAsync(strs.bj_joined).ConfigureAwait(false);
|
||||
if (await bj.Join(ctx.User, amount))
|
||||
await ReplyConfirmLocalizedAsync(strs.bj_joined);
|
||||
else
|
||||
{
|
||||
Log.Information($"{ctx.User} can't join a blackjack game as it's in " + bj.State.ToString() + " state already.");
|
||||
}
|
||||
}
|
||||
|
||||
await ctx.Message.DeleteAsync().ConfigureAwait(false);
|
||||
await ctx.Message.DeleteAsync();
|
||||
}
|
||||
|
||||
private Task Bj_GameEnded(Blackjack arg)
|
||||
@@ -129,7 +129,7 @@ public partial class Gambling
|
||||
full = "💰 " + full;
|
||||
embed.AddField(full, cStr);
|
||||
}
|
||||
_msg = await ctx.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||
_msg = await ctx.Channel.EmbedAsync(embed);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -167,18 +167,18 @@ public partial class Gambling
|
||||
return;
|
||||
|
||||
if (a == BjAction.Hit)
|
||||
await bj.Hit(ctx.User).ConfigureAwait(false);
|
||||
await bj.Hit(ctx.User);
|
||||
else if (a == BjAction.Stand)
|
||||
await bj.Stand(ctx.User).ConfigureAwait(false);
|
||||
await bj.Stand(ctx.User);
|
||||
else if (a == BjAction.Double)
|
||||
{
|
||||
if (!await bj.Double(ctx.User).ConfigureAwait(false))
|
||||
if (!await bj.Double(ctx.User))
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
|
||||
}
|
||||
}
|
||||
|
||||
await ctx.Message.DeleteAsync().ConfigureAwait(false);
|
||||
await ctx.Message.DeleteAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#nullable disable
|
||||
#nullable disable
|
||||
using NadekoBot.Modules.Gambling.Common.AnimalRacing.Exceptions;
|
||||
using NadekoBot.Modules.Games.Common;
|
||||
|
||||
@@ -45,15 +45,15 @@ public sealed class AnimalRace : IDisposable
|
||||
{
|
||||
var _t = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(_options.StartTime * 1000).ConfigureAwait(false);
|
||||
await Task.Delay(_options.StartTime * 1000);
|
||||
|
||||
await _locker.WaitAsync().ConfigureAwait(false);
|
||||
await _locker.WaitAsync();
|
||||
try
|
||||
{
|
||||
if (CurrentPhase != Phase.WaitingForPlayers)
|
||||
return;
|
||||
|
||||
await Start().ConfigureAwait(false);
|
||||
await Start();
|
||||
}
|
||||
finally { _locker.Release(); }
|
||||
});
|
||||
@@ -66,7 +66,7 @@ public sealed class AnimalRace : IDisposable
|
||||
|
||||
var user = new AnimalRacingUser(userName, userId, bet);
|
||||
|
||||
await _locker.WaitAsync().ConfigureAwait(false);
|
||||
await _locker.WaitAsync();
|
||||
try
|
||||
{
|
||||
if (_users.Count == MaxUsers)
|
||||
@@ -75,7 +75,7 @@ public sealed class AnimalRace : IDisposable
|
||||
if (CurrentPhase != Phase.WaitingForPlayers)
|
||||
throw new AlreadyStartedException();
|
||||
|
||||
if (!await _currency.RemoveAsync(userId, "BetRace", bet).ConfigureAwait(false))
|
||||
if (!await _currency.RemoveAsync(userId, "BetRace", bet))
|
||||
throw new NotEnoughFundsException();
|
||||
|
||||
if (_users.Contains(user))
|
||||
@@ -86,7 +86,7 @@ public sealed class AnimalRace : IDisposable
|
||||
_users.Add(user);
|
||||
|
||||
if (_animalsQueue.Count == 0) //start if no more spots left
|
||||
await Start().ConfigureAwait(false);
|
||||
await Start();
|
||||
|
||||
return user;
|
||||
}
|
||||
@@ -101,7 +101,7 @@ public sealed class AnimalRace : IDisposable
|
||||
foreach (var user in _users)
|
||||
{
|
||||
if (user.Bet > 0)
|
||||
await _currency.AddAsync(user.UserId, "Race refund", user.Bet).ConfigureAwait(false);
|
||||
await _currency.AddAsync(user.UserId, "Race refund", user.Bet);
|
||||
}
|
||||
|
||||
var _sf = OnStartingFailed?.Invoke(this);
|
||||
@@ -128,12 +128,11 @@ public sealed class AnimalRace : IDisposable
|
||||
FinishedUsers.AddRange(finished);
|
||||
|
||||
var _ignore = OnStateUpdate?.Invoke(this);
|
||||
await Task.Delay(2500).ConfigureAwait(false);
|
||||
await Task.Delay(2500);
|
||||
}
|
||||
|
||||
if (FinishedUsers[0].Bet > 0)
|
||||
await _currency.AddAsync(FinishedUsers[0].UserId, "Won a Race", FinishedUsers[0].Bet * (_users.Count - 1))
|
||||
.ConfigureAwait(false);
|
||||
await _currency.AddAsync(FinishedUsers[0].UserId, "Won a Race", FinishedUsers[0].Bet * (_users.Count - 1));
|
||||
|
||||
var _ended = OnEnded?.Invoke(this);
|
||||
});
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#nullable disable
|
||||
#nullable disable
|
||||
namespace NadekoBot.Modules.Gambling.Common.Blackjack;
|
||||
|
||||
public class Blackjack
|
||||
@@ -44,8 +44,8 @@ public class Blackjack
|
||||
try
|
||||
{
|
||||
//wait for players to join
|
||||
await Task.Delay(20000).ConfigureAwait(false);
|
||||
await locker.WaitAsync().ConfigureAwait(false);
|
||||
await Task.Delay(20000);
|
||||
await locker.WaitAsync();
|
||||
try
|
||||
{
|
||||
State = GameState.Playing;
|
||||
@@ -54,7 +54,7 @@ public class Blackjack
|
||||
{
|
||||
locker.Release();
|
||||
}
|
||||
await PrintState().ConfigureAwait(false);
|
||||
await PrintState();
|
||||
//if no users joined the game, end it
|
||||
if (!Players.Any())
|
||||
{
|
||||
@@ -78,15 +78,15 @@ public class Blackjack
|
||||
while (!usr.Done)
|
||||
{
|
||||
Log.Information($"Waiting for {usr.DiscordUser}'s move");
|
||||
await PromptUserMove(usr).ConfigureAwait(false);
|
||||
await PromptUserMove(usr);
|
||||
}
|
||||
}
|
||||
await PrintState().ConfigureAwait(false);
|
||||
await PrintState();
|
||||
State = GameState.Ended;
|
||||
await Task.Delay(2500).ConfigureAwait(false);
|
||||
await Task.Delay(2500);
|
||||
Log.Information("Dealer moves");
|
||||
await DealerMoves().ConfigureAwait(false);
|
||||
await PrintState().ConfigureAwait(false);
|
||||
await DealerMoves();
|
||||
await PrintState();
|
||||
var _ = GameEnded?.Invoke(this);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -102,13 +102,13 @@ public class Blackjack
|
||||
var pause = Task.Delay(20000); //10 seconds to decide
|
||||
CurrentUser = usr;
|
||||
_currentUserMove = new();
|
||||
await PrintState().ConfigureAwait(false);
|
||||
await PrintState();
|
||||
// either wait for the user to make an action and
|
||||
// if he doesn't - stand
|
||||
var finished = await Task.WhenAny(pause, _currentUserMove.Task).ConfigureAwait(false);
|
||||
var finished = await Task.WhenAny(pause, _currentUserMove.Task);
|
||||
if (finished == pause)
|
||||
{
|
||||
await Stand(usr).ConfigureAwait(false);
|
||||
await Stand(usr);
|
||||
}
|
||||
CurrentUser = null;
|
||||
_currentUserMove = null;
|
||||
@@ -116,7 +116,7 @@ public class Blackjack
|
||||
|
||||
public async Task<bool> Join(IUser user, long bet)
|
||||
{
|
||||
await locker.WaitAsync().ConfigureAwait(false);
|
||||
await locker.WaitAsync();
|
||||
try
|
||||
{
|
||||
if (State != GameState.Starting)
|
||||
@@ -125,7 +125,7 @@ public class Blackjack
|
||||
if (Players.Count >= 5)
|
||||
return false;
|
||||
|
||||
if (!await _cs.RemoveAsync(user, "BlackJack-gamble", bet, gamble: true).ConfigureAwait(false))
|
||||
if (!await _cs.RemoveAsync(user, "BlackJack-gamble", bet, gamble: true))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -145,14 +145,14 @@ public class Blackjack
|
||||
var cu = CurrentUser;
|
||||
|
||||
if (cu != null && cu.DiscordUser == u)
|
||||
return await Stand(cu).ConfigureAwait(false);
|
||||
return await Stand(cu);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task<bool> Stand(User u)
|
||||
{
|
||||
await locker.WaitAsync().ConfigureAwait(false);
|
||||
await locker.WaitAsync();
|
||||
try
|
||||
{
|
||||
if (State != GameState.Playing)
|
||||
@@ -229,7 +229,7 @@ public class Blackjack
|
||||
{
|
||||
if (usr.State is User.UserState.Won or User.UserState.Blackjack)
|
||||
{
|
||||
await _cs.AddAsync(usr.DiscordUser.Id, "BlackJack-win", usr.Bet * 2, gamble: true).ConfigureAwait(false);
|
||||
await _cs.AddAsync(usr.DiscordUser.Id, "BlackJack-win", usr.Bet * 2, gamble: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -239,14 +239,14 @@ public class Blackjack
|
||||
var cu = CurrentUser;
|
||||
|
||||
if (cu != null && cu.DiscordUser == u)
|
||||
return await Double(cu).ConfigureAwait(false);
|
||||
return await Double(cu);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task<bool> Double(User u)
|
||||
{
|
||||
await locker.WaitAsync().ConfigureAwait(false);
|
||||
await locker.WaitAsync();
|
||||
try
|
||||
{
|
||||
if (State != GameState.Playing)
|
||||
@@ -255,7 +255,7 @@ public class Blackjack
|
||||
if (CurrentUser != u)
|
||||
return false;
|
||||
|
||||
if (!await _cs.RemoveAsync(u.DiscordUser.Id, "Blackjack-double", u.Bet).ConfigureAwait(false))
|
||||
if (!await _cs.RemoveAsync(u.DiscordUser.Id, "Blackjack-double", u.Bet))
|
||||
return false;
|
||||
|
||||
u.Bet *= 2;
|
||||
@@ -292,14 +292,14 @@ public class Blackjack
|
||||
var cu = CurrentUser;
|
||||
|
||||
if (cu != null && cu.DiscordUser == u)
|
||||
return await Hit(cu).ConfigureAwait(false);
|
||||
return await Hit(cu);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task<bool> Hit(User u)
|
||||
{
|
||||
await locker.WaitAsync().ConfigureAwait(false);
|
||||
await locker.WaitAsync();
|
||||
try
|
||||
{
|
||||
if (State != GameState.Playing)
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#nullable disable
|
||||
#nullable disable
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
||||
namespace NadekoBot.Modules.Gambling.Common.Events;
|
||||
@@ -78,14 +78,14 @@ public class GameStatusEvent : ICurrencyEvent
|
||||
await _cs.AddBulkAsync(toAward,
|
||||
toAward.Select(x => "GameStatus Event"),
|
||||
toAward.Select(x => _amount),
|
||||
gamble: true).ConfigureAwait(false);
|
||||
gamble: true);
|
||||
|
||||
if (_isPotLimited)
|
||||
{
|
||||
await _msg.ModifyAsync(m =>
|
||||
{
|
||||
m.Embed = GetEmbed(PotSize).Build();
|
||||
}, new() { RetryMode = RetryMode.AlwaysRetry }).ConfigureAwait(false);
|
||||
}, new() { RetryMode = RetryMode.AlwaysRetry });
|
||||
}
|
||||
|
||||
Log.Information("Awarded {0} users {1} currency.{2}",
|
||||
@@ -107,8 +107,8 @@ public class GameStatusEvent : ICurrencyEvent
|
||||
|
||||
public async Task StartEvent()
|
||||
{
|
||||
_msg = await _channel.EmbedAsync(GetEmbed(_opts.PotSize)).ConfigureAwait(false);
|
||||
await _client.SetGameAsync(_code).ConfigureAwait(false);
|
||||
_msg = await _channel.EmbedAsync(GetEmbed(_opts.PotSize));
|
||||
await _client.SetGameAsync(_code);
|
||||
_client.MessageDeleted += OnMessageDeleted;
|
||||
_client.MessageReceived += HandleMessage;
|
||||
_t.Change(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2));
|
||||
@@ -121,7 +121,7 @@ public class GameStatusEvent : ICurrencyEvent
|
||||
{
|
||||
if (msg.Id == _msg.Id)
|
||||
{
|
||||
await StopEvent().ConfigureAwait(false);
|
||||
await StopEvent();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#nullable disable
|
||||
#nullable disable
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
||||
namespace NadekoBot.Modules.Gambling.Common.Events;
|
||||
@@ -74,14 +74,14 @@ public class ReactionEvent : ICurrencyEvent
|
||||
await _cs.AddBulkAsync(toAward,
|
||||
toAward.Select(x => "Reaction Event"),
|
||||
toAward.Select(x => _amount),
|
||||
gamble: true).ConfigureAwait(false);
|
||||
gamble: true);
|
||||
|
||||
if (_isPotLimited)
|
||||
{
|
||||
await _msg.ModifyAsync(m =>
|
||||
{
|
||||
m.Embed = GetEmbed(PotSize).Build();
|
||||
}, new() { RetryMode = RetryMode.AlwaysRetry }).ConfigureAwait(false);
|
||||
}, new() { RetryMode = RetryMode.AlwaysRetry });
|
||||
}
|
||||
|
||||
Log.Information("Awarded {0} users {1} currency.{2}",
|
||||
@@ -110,8 +110,8 @@ public class ReactionEvent : ICurrencyEvent
|
||||
{
|
||||
_emote = new Emoji(_config.Currency.Sign);
|
||||
}
|
||||
_msg = await _channel.EmbedAsync(GetEmbed(_opts.PotSize)).ConfigureAwait(false);
|
||||
await _msg.AddReactionAsync(_emote).ConfigureAwait(false);
|
||||
_msg = await _channel.EmbedAsync(GetEmbed(_opts.PotSize));
|
||||
await _msg.AddReactionAsync(_emote);
|
||||
_client.MessageDeleted += OnMessageDeleted;
|
||||
_client.ReactionAdded += HandleReaction;
|
||||
_t.Change(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2));
|
||||
@@ -124,7 +124,7 @@ public class ReactionEvent : ICurrencyEvent
|
||||
{
|
||||
if (msg.Id == _msg.Id)
|
||||
{
|
||||
await StopEvent().ConfigureAwait(false);
|
||||
await StopEvent();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#nullable disable
|
||||
#nullable disable
|
||||
namespace NadekoBot.Modules.Gambling.Common;
|
||||
|
||||
public class RollDuelGame
|
||||
@@ -47,13 +47,13 @@ public class RollDuelGame
|
||||
|
||||
_timeoutTimer = new(async delegate
|
||||
{
|
||||
await _locker.WaitAsync().ConfigureAwait(false);
|
||||
await _locker.WaitAsync();
|
||||
try
|
||||
{
|
||||
if (CurrentState != State.Waiting)
|
||||
return;
|
||||
CurrentState = State.Ended;
|
||||
await (OnEnded?.Invoke(this, Reason.Timeout)).ConfigureAwait(false);
|
||||
await (OnEnded?.Invoke(this, Reason.Timeout));
|
||||
}
|
||||
catch { }
|
||||
finally
|
||||
@@ -65,7 +65,7 @@ public class RollDuelGame
|
||||
|
||||
public async Task StartGame()
|
||||
{
|
||||
await _locker.WaitAsync().ConfigureAwait(false);
|
||||
await _locker.WaitAsync();
|
||||
try
|
||||
{
|
||||
if (CurrentState != State.Waiting)
|
||||
@@ -78,16 +78,16 @@ public class RollDuelGame
|
||||
_locker.Release();
|
||||
}
|
||||
|
||||
if(!await _cs.RemoveAsync(P1, "Roll Duel", Amount).ConfigureAwait(false))
|
||||
if(!await _cs.RemoveAsync(P1, "Roll Duel", Amount))
|
||||
{
|
||||
await (OnEnded?.Invoke(this, Reason.NoFunds)).ConfigureAwait(false);
|
||||
await (OnEnded?.Invoke(this, Reason.NoFunds));
|
||||
CurrentState = State.Ended;
|
||||
return;
|
||||
}
|
||||
if(!await _cs.RemoveAsync(P2, "Roll Duel", Amount).ConfigureAwait(false))
|
||||
if(!await _cs.RemoveAsync(P2, "Roll Duel", Amount))
|
||||
{
|
||||
await _cs.AddAsync(P1, "Roll Duel - refund", Amount).ConfigureAwait(false);
|
||||
await (OnEnded?.Invoke(this, Reason.NoFunds)).ConfigureAwait(false);
|
||||
await _cs.AddAsync(P1, "Roll Duel - refund", Amount);
|
||||
await (OnEnded?.Invoke(this, Reason.NoFunds));
|
||||
CurrentState = State.Ended;
|
||||
return;
|
||||
}
|
||||
@@ -109,20 +109,18 @@ public class RollDuelGame
|
||||
Winner = P2;
|
||||
}
|
||||
var won = (long)(Amount * 2 * 0.98f);
|
||||
await _cs.AddAsync(Winner, "Roll Duel win", won)
|
||||
.ConfigureAwait(false);
|
||||
await _cs.AddAsync(Winner, "Roll Duel win", won);
|
||||
|
||||
await _cs.AddAsync(_botId, "Roll Duel fee", (Amount * 2) - won)
|
||||
.ConfigureAwait(false);
|
||||
await _cs.AddAsync(_botId, "Roll Duel fee", (Amount * 2) - won);
|
||||
}
|
||||
try { await (OnGameTick?.Invoke(this)).ConfigureAwait(false); } catch { }
|
||||
await Task.Delay(2500).ConfigureAwait(false);
|
||||
try { await (OnGameTick?.Invoke(this)); } catch { }
|
||||
await Task.Delay(2500);
|
||||
if (n1 != n2)
|
||||
break;
|
||||
}
|
||||
while (true);
|
||||
CurrentState = State.Ended;
|
||||
await (OnEnded?.Invoke(this, Reason.Normal)).ConfigureAwait(false);
|
||||
await (OnEnded?.Invoke(this, Reason.Normal));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#nullable disable
|
||||
#nullable disable
|
||||
namespace NadekoBot.Modules.Gambling.Common.WheelOfFortune;
|
||||
|
||||
public class WheelOfFortuneGame
|
||||
@@ -31,7 +31,7 @@ public class WheelOfFortuneGame
|
||||
var amount = (long)(_bet * _config.WheelOfFortune.Multipliers[result]);
|
||||
|
||||
if (amount > 0)
|
||||
await _cs.AddAsync(_userId, "Wheel Of Fortune - won", amount, gamble: true).ConfigureAwait(false);
|
||||
await _cs.AddAsync(_userId, "Wheel Of Fortune - won", amount, gamble: true);
|
||||
|
||||
return new()
|
||||
{
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#nullable disable
|
||||
#nullable disable
|
||||
using CommandLine;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
@@ -88,15 +88,15 @@ public sealed class Connect4Game : IDisposable
|
||||
return;
|
||||
var _ = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(15000).ConfigureAwait(false);
|
||||
await _locker.WaitAsync().ConfigureAwait(false);
|
||||
await Task.Delay(15000);
|
||||
await _locker.WaitAsync();
|
||||
try
|
||||
{
|
||||
if (_players[1] is null)
|
||||
{
|
||||
var __ = OnGameFailedToStart?.Invoke(this);
|
||||
CurrentPhase = Phase.Ended;
|
||||
await _cs.AddAsync(_players[0].Value.UserId, "Connect4-refund", _options.Bet, true).ConfigureAwait(false);
|
||||
await _cs.AddAsync(_players[0].Value.UserId, "Connect4-refund", _options.Bet, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -106,7 +106,7 @@ public sealed class Connect4Game : IDisposable
|
||||
|
||||
public async Task<bool> Join(ulong userId, string userName, int bet)
|
||||
{
|
||||
await _locker.WaitAsync().ConfigureAwait(false);
|
||||
await _locker.WaitAsync();
|
||||
try
|
||||
{
|
||||
if (CurrentPhase != Phase.Joining) //can't join if its not a joining phase
|
||||
@@ -118,7 +118,7 @@ public sealed class Connect4Game : IDisposable
|
||||
if (bet != _options.Bet) // can't join if bet amount is not the same
|
||||
return false;
|
||||
|
||||
if (!await _cs.RemoveAsync(userId, "Connect4-bet", bet, true).ConfigureAwait(false)) // user doesn't have enough money to gamble
|
||||
if (!await _cs.RemoveAsync(userId, "Connect4-bet", bet, true)) // user doesn't have enough money to gamble
|
||||
return false;
|
||||
|
||||
if (_rng.Next(0, 2) == 0) //rolling from 0-1, if number is 0, join as first player
|
||||
@@ -132,7 +132,7 @@ public sealed class Connect4Game : IDisposable
|
||||
CurrentPhase = Phase.P1Move; //start the game
|
||||
_playerTimeoutTimer = new(async state =>
|
||||
{
|
||||
await _locker.WaitAsync().ConfigureAwait(false);
|
||||
await _locker.WaitAsync();
|
||||
try
|
||||
{
|
||||
EndGame(Result.OtherPlayerWon, OtherPlayer.UserId);
|
||||
@@ -148,7 +148,7 @@ public sealed class Connect4Game : IDisposable
|
||||
|
||||
public async Task<bool> Input(ulong userId, int inputCol)
|
||||
{
|
||||
await _locker.WaitAsync().ConfigureAwait(false);
|
||||
await _locker.WaitAsync();
|
||||
try
|
||||
{
|
||||
inputCol -= 1;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#nullable disable
|
||||
#nullable disable
|
||||
using NadekoBot.Modules.Gambling.Common;
|
||||
using NadekoBot.Modules.Gambling.Common.Connect4;
|
||||
using NadekoBot.Modules.Gambling.Services;
|
||||
@@ -28,7 +28,7 @@ public partial class Gambling
|
||||
public async Task Connect4(params string[] args)
|
||||
{
|
||||
var (options, _) = OptionsParser.ParseFrom(new Connect4Game.Options(), args);
|
||||
if (!await CheckBetOptional(options.Bet).ConfigureAwait(false))
|
||||
if (!await CheckBetOptional(options.Bet))
|
||||
return;
|
||||
|
||||
var newGame = new Connect4Game(ctx.User.Id, ctx.User.ToString(), options, _cs);
|
||||
@@ -40,13 +40,13 @@ public partial class Gambling
|
||||
|
||||
newGame.Dispose();
|
||||
//means game already exists, try to join
|
||||
var joined = await game.Join(ctx.User.Id, ctx.User.ToString(), options.Bet).ConfigureAwait(false);
|
||||
var joined = await game.Join(ctx.User.Id, ctx.User.ToString(), options.Bet);
|
||||
return;
|
||||
}
|
||||
|
||||
if (options.Bet > 0)
|
||||
{
|
||||
if (!await _cs.RemoveAsync(ctx.User.Id, "Connect4-bet", options.Bet, true).ConfigureAwait(false))
|
||||
if (!await _cs.RemoveAsync(ctx.User.Id, "Connect4-bet", options.Bet, true))
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
|
||||
_service.Connect4Games.TryRemove(ctx.Channel.Id, out _);
|
||||
@@ -63,7 +63,7 @@ public partial class Gambling
|
||||
game.Initialize();
|
||||
if (options.Bet == 0)
|
||||
{
|
||||
await ReplyConfirmLocalizedAsync(strs.connect4_created).ConfigureAwait(false);
|
||||
await ReplyConfirmLocalizedAsync(strs.connect4_created);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -80,11 +80,11 @@ public partial class Gambling
|
||||
var success = false;
|
||||
if (int.TryParse(arg.Content, out var col))
|
||||
{
|
||||
success = await game.Input(arg.Author.Id, col).ConfigureAwait(false);
|
||||
success = await game.Input(arg.Author.Id, col);
|
||||
}
|
||||
|
||||
if (success)
|
||||
try { await arg.DeleteAsync().ConfigureAwait(false); } catch { }
|
||||
try { await arg.DeleteAsync(); } catch { }
|
||||
else
|
||||
{
|
||||
if (game.CurrentPhase is Connect4Game.Phase.Joining or Connect4Game.Phase.Ended)
|
||||
@@ -93,7 +93,7 @@ public partial class Gambling
|
||||
}
|
||||
RepostCounter++;
|
||||
if (RepostCounter == 0)
|
||||
try { msg = await ctx.Channel.SendMessageAsync("", embed: (Embed)msg.Embeds.First()).ConfigureAwait(false); } catch { }
|
||||
try { msg = await ctx.Channel.SendMessageAsync("", embed: (Embed)msg.Embeds.First()); } catch { }
|
||||
}
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
@@ -160,9 +160,9 @@ public partial class Gambling
|
||||
|
||||
|
||||
if (msg is null)
|
||||
msg = await ctx.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||
msg = await ctx.Channel.EmbedAsync(embed);
|
||||
else
|
||||
await msg.ModifyAsync(x => x.Embed = embed.Build()).ConfigureAwait(false);
|
||||
await msg.ModifyAsync(x => x.Embed = embed.Build());
|
||||
}
|
||||
|
||||
private string GetGameStateText(Connect4Game game)
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#nullable disable
|
||||
#nullable disable
|
||||
using NadekoBot.Modules.Gambling.Services;
|
||||
using NadekoBot.Modules.Gambling.Common.Events;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
@@ -28,7 +28,7 @@ public partial class Gambling
|
||||
opts,
|
||||
GetEmbed))
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.start_event_fail).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.start_event_fail);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#nullable disable
|
||||
#nullable disable
|
||||
using NadekoBot.Modules.Gambling.Services;
|
||||
using NadekoBot.Modules.Gambling.Common;
|
||||
|
||||
@@ -25,15 +25,14 @@ public partial class Gambling
|
||||
[Priority(1)]
|
||||
public async Task RaffleCur(ShmartNumber amount, bool mixed = false)
|
||||
{
|
||||
if (!await CheckBetMandatory(amount).ConfigureAwait(false))
|
||||
if (!await CheckBetMandatory(amount))
|
||||
return;
|
||||
async Task OnEnded(IUser arg, long won)
|
||||
{
|
||||
await SendConfirmAsync(GetText(strs.rafflecur_ended(CurrencyName, Format.Bold(arg.ToString()), won + CurrencySign)));
|
||||
}
|
||||
var res = await _service.JoinOrCreateGame(ctx.Channel.Id,
|
||||
ctx.User, amount, mixed, OnEnded)
|
||||
.ConfigureAwait(false);
|
||||
ctx.User, amount, mixed, OnEnded);
|
||||
|
||||
if (res.Item1 != null)
|
||||
{
|
||||
@@ -44,7 +43,7 @@ public partial class Gambling
|
||||
else
|
||||
{
|
||||
if (res.Item2 == CurrencyRaffleService.JoinErrorType.AlreadyJoinedOrInvalidAmount)
|
||||
await ReplyErrorLocalizedAsync(strs.rafflecur_already_joined).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.rafflecur_already_joined);
|
||||
else if (res.Item2 == CurrencyRaffleService.JoinErrorType.NotEnoughCurrency)
|
||||
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
|
||||
}
|
||||
|
@@ -41,23 +41,23 @@ public partial class Gambling
|
||||
[NadekoCommand, Aliases]
|
||||
[Priority(1)]
|
||||
public async Task Roll(int num)
|
||||
=> await InternalRoll(num, true).ConfigureAwait(false);
|
||||
=> await InternalRoll(num, true);
|
||||
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[Priority(1)]
|
||||
public async Task Rolluo(int num = 1)
|
||||
=> await InternalRoll(num, false).ConfigureAwait(false);
|
||||
=> await InternalRoll(num, false);
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[Priority(0)]
|
||||
public async Task Roll(string arg)
|
||||
=> await InternallDndRoll(arg, true).ConfigureAwait(false);
|
||||
=> await InternallDndRoll(arg, true);
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[Priority(0)]
|
||||
public async Task Rolluo(string arg)
|
||||
=> await InternallDndRoll(arg, false).ConfigureAwait(false);
|
||||
=> await InternallDndRoll(arg, false);
|
||||
|
||||
private async Task InternalRoll(int num, bool ordered)
|
||||
{
|
||||
@@ -132,7 +132,7 @@ public partial class Gambling
|
||||
.WithDescription(ctx.User.Mention + " " + GetText(strs.dice_rolled_num(Format.Bold(n1.ToString()))))
|
||||
.AddField(Format.Bold("Result"), string.Join(" ", rolls.Select(c => Format.Code($"[{c}]"))));
|
||||
|
||||
await ctx.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||
await ctx.Channel.EmbedAsync(embed);
|
||||
}
|
||||
else if ((match = dndRegex.Match(arg)).Length != 0)
|
||||
{
|
||||
@@ -160,7 +160,7 @@ public partial class Gambling
|
||||
Format.Code(x.ToString()))))
|
||||
.AddField(Format.Bold("Sum"),
|
||||
sum + " + " + add + " - " + sub + " = " + (sum + add - sub));
|
||||
await ctx.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||
await ctx.Channel.EmbedAsync(embed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -177,7 +177,7 @@ public partial class Gambling
|
||||
.ToArray();
|
||||
if (arr[0] > arr[1])
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.second_larger_than_first).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.second_larger_than_first);
|
||||
return;
|
||||
}
|
||||
rolled = new NadekoRandom().Next(arr[0], arr[1] + 1);
|
||||
@@ -187,7 +187,7 @@ public partial class Gambling
|
||||
rolled = new NadekoRandom().Next(0, int.Parse(range) + 1);
|
||||
}
|
||||
|
||||
await ReplyConfirmLocalizedAsync(strs.dice_rolled(Format.Bold(rolled.ToString()))).ConfigureAwait(false);
|
||||
await ReplyConfirmLocalizedAsync(strs.dice_rolled(Format.Bold(rolled.ToString())));
|
||||
}
|
||||
|
||||
private Image<Rgba32> GetDice(int num)
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#nullable disable
|
||||
#nullable disable
|
||||
using NadekoBot.Modules.Gambling.Common;
|
||||
using Image = SixLabors.ImageSharp.Image;
|
||||
using SixLabors.ImageSharp;
|
||||
@@ -31,7 +31,7 @@ public partial class Gambling
|
||||
{
|
||||
try
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.no_more_cards).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.no_more_cards);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -69,10 +69,10 @@ public partial class Gambling
|
||||
if (num > 10)
|
||||
num = 10;
|
||||
|
||||
var (ImageStream, ToSend) = await InternalDraw(num, ctx.Guild.Id).ConfigureAwait(false);
|
||||
var (ImageStream, ToSend) = await InternalDraw(num, ctx.Guild.Id);
|
||||
await using (ImageStream)
|
||||
{
|
||||
await ctx.Channel.SendFileAsync(ImageStream, num + " cards.jpg", ToSend).ConfigureAwait(false);
|
||||
await ctx.Channel.SendFileAsync(ImageStream, num + " cards.jpg", ToSend);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,10 +84,10 @@ public partial class Gambling
|
||||
if (num > 10)
|
||||
num = 10;
|
||||
|
||||
var (ImageStream, ToSend) = await InternalDraw(num).ConfigureAwait(false);
|
||||
var (ImageStream, ToSend) = await InternalDraw(num);
|
||||
await using (ImageStream)
|
||||
{
|
||||
await ctx.Channel.SendFileAsync(ImageStream, num + " cards.jpg", ToSend).ConfigureAwait(false);
|
||||
await ctx.Channel.SendFileAsync(ImageStream, num + " cards.jpg", ToSend);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ public partial class Gambling
|
||||
return c;
|
||||
});
|
||||
|
||||
await ReplyConfirmLocalizedAsync(strs.deck_reshuffled).ConfigureAwait(false);
|
||||
await ReplyConfirmLocalizedAsync(strs.deck_reshuffled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -60,7 +60,7 @@ public partial class Gambling
|
||||
: Format.Bold(ctx.User.ToString()) + " " + GetText(strs.flipped(headCount > 0
|
||||
? Format.Bold(GetText(strs.heads))
|
||||
: Format.Bold(GetText(strs.tails))));
|
||||
await ctx.Channel.SendFileAsync(stream, $"{count} coins.{format.FileExtensions.First()}", msg).ConfigureAwait(false);
|
||||
await ctx.Channel.SendFileAsync(stream, $"{count} coins.{format.FileExtensions.First()}", msg);
|
||||
}
|
||||
|
||||
public enum BetFlipGuess
|
||||
@@ -76,10 +76,10 @@ public partial class Gambling
|
||||
[NadekoCommand, Aliases]
|
||||
public async Task Betflip(ShmartNumber amount, BetFlipGuess guess)
|
||||
{
|
||||
if (!await CheckBetMandatory(amount).ConfigureAwait(false) || amount == 1)
|
||||
if (!await CheckBetMandatory(amount) || amount == 1)
|
||||
return;
|
||||
|
||||
var removed = await _cs.RemoveAsync(ctx.User, "Betflip Gamble", amount, false, gamble: true).ConfigureAwait(false);
|
||||
var removed = await _cs.RemoveAsync(ctx.User, "Betflip Gamble", amount, false, gamble: true);
|
||||
if (!removed)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
|
||||
@@ -104,7 +104,7 @@ public partial class Gambling
|
||||
{
|
||||
var toWin = (long)(amount * _config.BetFlip.Multiplier);
|
||||
str = Format.Bold(ctx.User.ToString()) + " " + GetText(strs.flip_guess(toWin + CurrencySign));
|
||||
await _cs.AddAsync(ctx.User, "Betflip Gamble", toWin, false, gamble: true).ConfigureAwait(false);
|
||||
await _cs.AddAsync(ctx.User, "Betflip Gamble", toWin, false, gamble: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -114,7 +114,7 @@ public partial class Gambling
|
||||
await ctx.Channel.EmbedAsync(_eb.Create()
|
||||
.WithDescription(str)
|
||||
.WithOkColor()
|
||||
.WithImageUrl(imageToSend.ToString())).ConfigureAwait(false);
|
||||
.WithImageUrl(imageToSend.ToString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -68,7 +68,7 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
.AddField(GetText(strs.total), ((BigInteger)(ec.Cash + ec.Planted + ec.Waifus)).ToString("N", Culture) + CurrencySign)
|
||||
.WithOkColor();
|
||||
// ec.Cash already contains ec.Bot as it's the total of all values in the CurrencyAmount column of the DiscordUser table
|
||||
await ctx.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||
await ctx.Channel.EmbedAsync(embed);
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
@@ -78,18 +78,18 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
var period = _config.Timely.Cooldown;
|
||||
if (val <= 0 || period <= 0)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.timely_none).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.timely_none);
|
||||
return;
|
||||
}
|
||||
|
||||
TimeSpan? rem;
|
||||
if ((rem = _cache.AddTimelyClaim(ctx.User.Id, period)) != null)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.timely_already_claimed(rem?.ToString(@"dd\d\ hh\h\ mm\m\ ss\s"))).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.timely_already_claimed(rem?.ToString(@"dd\d\ hh\h\ mm\m\ ss\s")));
|
||||
return;
|
||||
}
|
||||
|
||||
await _cs.AddAsync(ctx.User.Id, "Timely claim", val).ConfigureAwait(false);
|
||||
await _cs.AddAsync(ctx.User.Id, "Timely claim", val);
|
||||
|
||||
await ReplyConfirmLocalizedAsync(strs.timely(n(val), period));
|
||||
}
|
||||
@@ -99,7 +99,7 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
public async Task TimelyReset()
|
||||
{
|
||||
_cache.RemoveAllTimelyClaims();
|
||||
await ReplyConfirmLocalizedAsync(strs.timely_reset).ConfigureAwait(false);
|
||||
await ReplyConfirmLocalizedAsync(strs.timely_reset);
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
@@ -116,9 +116,9 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
});
|
||||
|
||||
if (amount == 0)
|
||||
await ReplyConfirmLocalizedAsync(strs.timely_set_none).ConfigureAwait(false);
|
||||
await ReplyConfirmLocalizedAsync(strs.timely_set_none);
|
||||
else
|
||||
await ReplyConfirmLocalizedAsync(strs.timely_set(Format.Bold(n(amount)), Format.Bold(period.ToString()))).ConfigureAwait(false);
|
||||
await ReplyConfirmLocalizedAsync(strs.timely_set(Format.Bold(n(amount)), Format.Bold(period.ToString())));
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
@@ -127,14 +127,14 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
{
|
||||
role ??= ctx.Guild.EveryoneRole;
|
||||
|
||||
var members = (await role.GetMembersAsync().ConfigureAwait(false)).Where(u => u.Status != UserStatus.Offline);
|
||||
var members = (await role.GetMembersAsync()).Where(u => u.Status != UserStatus.Offline);
|
||||
var membersArray = members as IUser[] ?? members.ToArray();
|
||||
if (membersArray.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var usr = membersArray[new NadekoRandom().Next(0, membersArray.Length)];
|
||||
await SendConfirmAsync("🎟 " + GetText(strs.raffled_user), $"**{usr.Username}#{usr.Discriminator}**", footer: $"ID: {usr.Id}").ConfigureAwait(false);
|
||||
await SendConfirmAsync("🎟 " + GetText(strs.raffled_user), $"**{usr.Username}#{usr.Discriminator}**", footer: $"ID: {usr.Id}");
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
@@ -143,14 +143,14 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
{
|
||||
role ??= ctx.Guild.EveryoneRole;
|
||||
|
||||
var members = await role.GetMembersAsync().ConfigureAwait(false);
|
||||
var members = await role.GetMembersAsync();
|
||||
var membersArray = members as IUser[] ?? members.ToArray();
|
||||
if (membersArray.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var usr = membersArray[new NadekoRandom().Next(0, membersArray.Length)];
|
||||
await SendConfirmAsync("🎟 " + GetText(strs.raffled_user), $"**{usr.Username}#{usr.Discriminator}**", footer: $"ID: {usr.Id}").ConfigureAwait(false);
|
||||
await SendConfirmAsync("🎟 " + GetText(strs.raffled_user), $"**{usr.Username}#{usr.Discriminator}**", footer: $"ID: {usr.Id}");
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
@@ -196,7 +196,7 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
|
||||
embed.WithDescription(desc);
|
||||
embed.WithFooter(GetText(strs.page(page + 1)));
|
||||
await ctx.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||
await ctx.Channel.EmbedAsync(embed);
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
@@ -219,13 +219,13 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
{
|
||||
if (amount <= 0 || ctx.User.Id == receiver.Id || receiver.IsBot)
|
||||
return;
|
||||
var success = await _cs.RemoveAsync((IGuildUser)ctx.User, $"Gift to {receiver.Username} ({receiver.Id}).", amount, false).ConfigureAwait(false);
|
||||
var success = await _cs.RemoveAsync((IGuildUser)ctx.User, $"Gift to {receiver.Username} ({receiver.Id}).", amount, false);
|
||||
if (!success)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
|
||||
return;
|
||||
}
|
||||
await _cs.AddAsync(receiver, $"Gift from {ctx.User.Username} ({ctx.User.Id}) - {msg}.", amount, true).ConfigureAwait(false);
|
||||
await _cs.AddAsync(receiver, $"Gift from {ctx.User.Username} ({ctx.User.Id}) - {msg}.", amount, true);
|
||||
await ReplyConfirmLocalizedAsync(strs.gifted(n(amount), Format.Bold(receiver.ToString())));
|
||||
}
|
||||
|
||||
@@ -261,14 +261,14 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
|
||||
if(usr is null)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.user_not_found).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.user_not_found);
|
||||
return;
|
||||
}
|
||||
|
||||
await _cs.AddAsync(usr,
|
||||
$"Awarded by bot owner. ({ctx.User.Username}/{ctx.User.Id}) {msg ?? ""}",
|
||||
amount,
|
||||
gamble: ctx.Client.CurrentUser.Id != usrId).ConfigureAwait(false);
|
||||
gamble: ctx.Client.CurrentUser.Id != usrId);
|
||||
await ReplyConfirmLocalizedAsync(strs.awarded(n(amount), $"<@{usrId}>"));
|
||||
}
|
||||
|
||||
@@ -278,15 +278,14 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
[Priority(3)]
|
||||
public async Task Award(long amount, [Leftover] IRole role)
|
||||
{
|
||||
var users = (await ctx.Guild.GetUsersAsync().ConfigureAwait(false))
|
||||
var users = (await ctx.Guild.GetUsersAsync())
|
||||
.Where(u => u.GetRoles().Contains(role))
|
||||
.ToList();
|
||||
|
||||
await _cs.AddBulkAsync(users.Select(x => x.Id),
|
||||
users.Select(x => $"Awarded by bot owner to **{role.Name}** role. ({ctx.User.Username}/{ctx.User.Id})"),
|
||||
users.Select(x => amount),
|
||||
gamble: true)
|
||||
.ConfigureAwait(false);
|
||||
gamble: true);
|
||||
|
||||
await ReplyConfirmLocalizedAsync(strs.mass_award(
|
||||
n(amount),
|
||||
@@ -305,8 +304,7 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
await _cs.RemoveBulkAsync(users.Select(x => x.Id),
|
||||
users.Select(x => $"Taken by bot owner from **{role.Name}** role. ({ctx.User.Username}/{ctx.User.Id})"),
|
||||
users.Select(x => amount),
|
||||
gamble: true)
|
||||
.ConfigureAwait(false);
|
||||
gamble: true);
|
||||
|
||||
await ReplyConfirmLocalizedAsync(strs.mass_take(
|
||||
n(amount),
|
||||
@@ -324,8 +322,8 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
return;
|
||||
|
||||
if (await _cs.RemoveAsync(user, $"Taken by bot owner.({ctx.User.Username}/{ctx.User.Id})", amount,
|
||||
gamble: ctx.Client.CurrentUser.Id != user.Id).ConfigureAwait(false))
|
||||
await ReplyConfirmLocalizedAsync(strs.take(n(amount), Format.Bold(user.ToString()))).ConfigureAwait(false);
|
||||
gamble: ctx.Client.CurrentUser.Id != user.Id))
|
||||
await ReplyConfirmLocalizedAsync(strs.take(n(amount), Format.Bold(user.ToString())));
|
||||
else
|
||||
await ReplyErrorLocalizedAsync(strs.take_fail(n(amount), Format.Bold(user.ToString()), CurrencySign));
|
||||
}
|
||||
@@ -339,7 +337,7 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
return;
|
||||
|
||||
if (await _cs.RemoveAsync(usrId, $"Taken by bot owner.({ctx.User.Username}/{ctx.User.Id})", amount,
|
||||
gamble: ctx.Client.CurrentUser.Id != usrId).ConfigureAwait(false))
|
||||
gamble: ctx.Client.CurrentUser.Id != usrId))
|
||||
await ReplyConfirmLocalizedAsync(strs.take(n(amount), $"<@{usrId}>"));
|
||||
else
|
||||
await ReplyErrorLocalizedAsync(strs.take_fail(n(amount), Format.Code(usrId.ToString()), CurrencySign));
|
||||
@@ -358,7 +356,7 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
//if it gets removed, means challenge is accepted
|
||||
if (_service.Duels.TryRemove((ctx.User.Id, u.Id), out var game))
|
||||
{
|
||||
await game.StartGame().ConfigureAwait(false);
|
||||
await game.StartGame();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,11 +382,11 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
{
|
||||
if (other.Amount != amount)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.roll_duel_already_challenged).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.roll_duel_already_challenged);
|
||||
}
|
||||
else
|
||||
{
|
||||
await RollDuel(u).ConfigureAwait(false);
|
||||
await RollDuel(u);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -414,15 +412,14 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
|
||||
if (rdMsg is null)
|
||||
{
|
||||
rdMsg = await ctx.Channel.EmbedAsync(embed)
|
||||
.ConfigureAwait(false);
|
||||
rdMsg = await ctx.Channel.EmbedAsync(embed);
|
||||
}
|
||||
else
|
||||
{
|
||||
await rdMsg.ModifyAsync(x =>
|
||||
{
|
||||
x.Embed = embed.Build();
|
||||
}).ConfigureAwait(false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -439,16 +436,15 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
|
||||
embed = embed.WithDescription(description);
|
||||
|
||||
await rdMsg.ModifyAsync(x => x.Embed = embed.Build())
|
||||
.ConfigureAwait(false);
|
||||
await rdMsg.ModifyAsync(x => x.Embed = embed.Build());
|
||||
}
|
||||
else if (reason == RollDuelGame.Reason.Timeout)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.roll_duel_timeout).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.roll_duel_timeout);
|
||||
}
|
||||
else if (reason == RollDuelGame.Reason.NoFunds)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.roll_duel_no_funds).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.roll_duel_no_funds);
|
||||
}
|
||||
}
|
||||
finally
|
||||
@@ -460,10 +456,10 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
|
||||
private async Task InternallBetroll(long amount)
|
||||
{
|
||||
if (!await CheckBetMandatory(amount).ConfigureAwait(false))
|
||||
if (!await CheckBetMandatory(amount))
|
||||
return;
|
||||
|
||||
if (!await _cs.RemoveAsync(ctx.User, "Betroll Gamble", amount, false, gamble: true).ConfigureAwait(false))
|
||||
if (!await _cs.RemoveAsync(ctx.User, "Betroll Gamble", amount, false, gamble: true))
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
|
||||
return;
|
||||
@@ -482,14 +478,14 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
n(win),
|
||||
result.Threshold + (result.Roll == 100 ? " 👑" : "")));
|
||||
await _cs.AddAsync(ctx.User, "Betroll Gamble",
|
||||
win, false, gamble: true).ConfigureAwait(false);
|
||||
win, false, gamble: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
str += GetText(strs.better_luck);
|
||||
}
|
||||
|
||||
await SendConfirmAsync(str).ConfigureAwait(false);
|
||||
await SendConfirmAsync(str);
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
@@ -528,8 +524,8 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
cleanRichest = uow.DiscordUser.GetTopRichest(_client.CurrentUser.Id, 10_000);
|
||||
}
|
||||
|
||||
await ctx.Channel.TriggerTypingAsync().ConfigureAwait(false);
|
||||
await _tracker.EnsureUsersDownloadedAsync(ctx.Guild).ConfigureAwait(false);
|
||||
await ctx.Channel.TriggerTypingAsync();
|
||||
await _tracker.EnsureUsersDownloadedAsync(ctx.Guild);
|
||||
|
||||
var sg = (SocketGuild)ctx.Guild;
|
||||
cleanRichest = cleanRichest.Where(x => sg.GetUser(x.UserId) != null)
|
||||
@@ -600,7 +596,7 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
public async Task Rps(RpsPick pick, ShmartNumber amount = default)
|
||||
{
|
||||
long oldAmount = amount;
|
||||
if (!await CheckBetOptional(amount).ConfigureAwait(false) || amount == 1)
|
||||
if (!await CheckBetOptional(amount) || amount == 1)
|
||||
return;
|
||||
|
||||
string getRpsPick(RpsPick p)
|
||||
@@ -622,7 +618,7 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
if (amount > 0)
|
||||
{
|
||||
if (!await _cs.RemoveAsync(ctx.User.Id,
|
||||
"Rps-bet", amount, gamble: true).ConfigureAwait(false))
|
||||
"Rps-bet", amount, gamble: true))
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
|
||||
return;
|
||||
@@ -633,7 +629,7 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
if (pick == nadekoPick)
|
||||
{
|
||||
await _cs.AddAsync(ctx.User.Id,
|
||||
"Rps-draw", amount, gamble: true).ConfigureAwait(false);
|
||||
"Rps-draw", amount, gamble: true);
|
||||
embed.WithOkColor();
|
||||
msg = GetText(strs.rps_draw(getRpsPick(pick)));
|
||||
}
|
||||
@@ -643,7 +639,7 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
{
|
||||
amount = (long)(amount * base._config.BetFlip.Multiplier);
|
||||
await _cs.AddAsync(ctx.User.Id,
|
||||
"Rps-win", amount, gamble: true).ConfigureAwait(false);
|
||||
"Rps-win", amount, gamble: true);
|
||||
embed.WithOkColor();
|
||||
embed.AddField(GetText(strs.won), n(amount));
|
||||
msg = GetText(strs.rps_win(ctx.User.Mention, getRpsPick(pick), getRpsPick(nadekoPick)));
|
||||
@@ -658,6 +654,6 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
embed
|
||||
.WithDescription(msg);
|
||||
|
||||
await ctx.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||
await ctx.Channel.EmbedAsync(embed);
|
||||
}
|
||||
}
|
||||
|
@@ -37,7 +37,7 @@ public partial class Gambling
|
||||
try
|
||||
{
|
||||
logService.AddDeleteIgnore(ctx.Message.Id);
|
||||
await ctx.Message.DeleteAsync().ConfigureAwait(false);
|
||||
await ctx.Message.DeleteAsync();
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
@@ -58,7 +58,7 @@ public partial class Gambling
|
||||
if (((SocketGuild)ctx.Guild).CurrentUser.GuildPermissions.ManageMessages)
|
||||
{
|
||||
logService.AddDeleteIgnore(ctx.Message.Id);
|
||||
await ctx.Message.DeleteAsync().ConfigureAwait(false);
|
||||
await ctx.Message.DeleteAsync();
|
||||
}
|
||||
|
||||
var success = await _service.PlantAsync(ctx.Guild.Id, ctx.Channel, ctx.User.Id, ctx.User.ToString(), amount, pass);
|
||||
@@ -79,11 +79,11 @@ public partial class Gambling
|
||||
var enabled = _service.ToggleCurrencyGeneration(ctx.Guild.Id, ctx.Channel.Id);
|
||||
if (enabled)
|
||||
{
|
||||
await ReplyConfirmLocalizedAsync(strs.curgen_enabled).ConfigureAwait(false);
|
||||
await ReplyConfirmLocalizedAsync(strs.curgen_enabled);
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyConfirmLocalizedAsync(strs.curgen_disabled).ConfigureAwait(false);
|
||||
await ReplyConfirmLocalizedAsync(strs.curgen_disabled);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#nullable disable
|
||||
#nullable disable
|
||||
using NadekoBot.Modules.Gambling.Common.Events;
|
||||
using NadekoBot.Modules.Gambling.Common;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
@@ -52,7 +52,7 @@ public class CurrencyEventsService : INService
|
||||
try
|
||||
{
|
||||
ce.OnEnded += OnEventEnded;
|
||||
await ce.StartEvent().ConfigureAwait(false);
|
||||
await ce.StartEvent();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#nullable disable
|
||||
#nullable disable
|
||||
using NadekoBot.Modules.Gambling.Common;
|
||||
|
||||
namespace NadekoBot.Modules.Gambling.Services;
|
||||
@@ -24,7 +24,7 @@ public class CurrencyRaffleService : INService
|
||||
|
||||
public async Task<(CurrencyRaffleGame, JoinErrorType?)> JoinOrCreateGame(ulong channelId, IUser user, long amount, bool mixed, Func<IUser, long, Task> onEnded)
|
||||
{
|
||||
await _locker.WaitAsync().ConfigureAwait(false);
|
||||
await _locker.WaitAsync();
|
||||
try
|
||||
{
|
||||
var newGame = false;
|
||||
@@ -39,7 +39,7 @@ public class CurrencyRaffleService : INService
|
||||
|
||||
//remove money, and stop the game if this
|
||||
// user created it and doesn't have the money
|
||||
if (!await _cs.RemoveAsync(user.Id, "Currency Raffle Join", amount).ConfigureAwait(false))
|
||||
if (!await _cs.RemoveAsync(user.Id, "Currency Raffle Join", amount))
|
||||
{
|
||||
if (newGame)
|
||||
Games.Remove(channelId);
|
||||
@@ -48,22 +48,22 @@ public class CurrencyRaffleService : INService
|
||||
|
||||
if (!crg.AddUser(user, amount))
|
||||
{
|
||||
await _cs.AddAsync(user.Id, "Curency Raffle Refund", amount).ConfigureAwait(false);
|
||||
await _cs.AddAsync(user.Id, "Curency Raffle Refund", amount);
|
||||
return (null, JoinErrorType.AlreadyJoinedOrInvalidAmount);
|
||||
}
|
||||
if (newGame)
|
||||
{
|
||||
var _t = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(60000).ConfigureAwait(false);
|
||||
await _locker.WaitAsync().ConfigureAwait(false);
|
||||
await Task.Delay(60000);
|
||||
await _locker.WaitAsync();
|
||||
try
|
||||
{
|
||||
var winner = crg.GetWinner();
|
||||
var won = crg.Users.Sum(x => x.Amount);
|
||||
|
||||
await _cs.AddAsync(winner.DiscordUser.Id, "Currency Raffle Win",
|
||||
won).ConfigureAwait(false);
|
||||
won);
|
||||
Games.Remove(channelId, out _);
|
||||
var oe = onEnded(winner.DiscordUser, won);
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#nullable disable
|
||||
#nullable disable
|
||||
using NadekoBot.Common.Configs;
|
||||
using NadekoBot.Modules.Gambling.Common;
|
||||
|
||||
@@ -50,7 +50,7 @@ public sealed class GamblingConfigService : ConfigServiceBase<GamblingConfig>
|
||||
|
||||
public void Migrate()
|
||||
{
|
||||
if (_data.Version < 2)
|
||||
if (data.Version < 2)
|
||||
{
|
||||
ModifyConfig(c =>
|
||||
{
|
||||
@@ -59,7 +59,7 @@ public sealed class GamblingConfigService : ConfigServiceBase<GamblingConfig>
|
||||
});
|
||||
}
|
||||
|
||||
if (_data.Version < 3)
|
||||
if (data.Version < 3)
|
||||
{
|
||||
ModifyConfig(c =>
|
||||
{
|
||||
@@ -68,7 +68,7 @@ public sealed class GamblingConfigService : ConfigServiceBase<GamblingConfig>
|
||||
});
|
||||
}
|
||||
|
||||
if (_data.Version < 4)
|
||||
if (data.Version < 4)
|
||||
{
|
||||
ModifyConfig(c =>
|
||||
{
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#nullable disable
|
||||
#nullable disable
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using SixLabors.Fonts;
|
||||
@@ -203,7 +203,7 @@ public class PlantPickService : INService
|
||||
IUserMessage sent;
|
||||
await using (var stream = GetRandomCurrencyImage(pw, out var ext))
|
||||
{
|
||||
sent = await channel.SendFileAsync(stream, $"currency_image.{ext}", toSend).ConfigureAwait(false);
|
||||
sent = await channel.SendFileAsync(stream, $"currency_image.{ext}", toSend);
|
||||
}
|
||||
|
||||
await AddPlantToDatabase(channel.GuildId,
|
||||
@@ -211,7 +211,7 @@ public class PlantPickService : INService
|
||||
_client.CurrentUser.Id,
|
||||
sent.Id,
|
||||
dropAmount,
|
||||
pw).ConfigureAwait(false);
|
||||
pw);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -302,7 +302,7 @@ public class PlantPickService : INService
|
||||
//get the image
|
||||
await using var stream = GetRandomCurrencyImage(pass, out var ext);
|
||||
// send it
|
||||
var msg = await ch.SendFileAsync(stream, $"img.{ext}", msgToSend).ConfigureAwait(false);
|
||||
var msg = await ch.SendFileAsync(stream, $"img.{ext}", msgToSend);
|
||||
// return sent message's id (in order to be able to delete it when it's picked)
|
||||
return msg.Id;
|
||||
}
|
||||
@@ -325,7 +325,7 @@ public class PlantPickService : INService
|
||||
if (await _cs.RemoveAsync(uid, "Planted currency", amount, gamble: false))
|
||||
{
|
||||
// try to send the message with the currency image
|
||||
var msgId = await SendPlantMessageAsync(gid, ch, user, amount, pass).ConfigureAwait(false);
|
||||
var msgId = await SendPlantMessageAsync(gid, ch, user, amount, pass);
|
||||
if (msgId is null)
|
||||
{
|
||||
// if it fails it will return null, if it returns null, refund
|
||||
@@ -333,7 +333,7 @@ public class PlantPickService : INService
|
||||
return false;
|
||||
}
|
||||
// if it doesn't fail, put the plant in the database for other people to pick
|
||||
await AddPlantToDatabase(gid, ch.Id, uid, msgId.Value, amount, pass).ConfigureAwait(false);
|
||||
await AddPlantToDatabase(gid, ch.Id, uid, msgId.Value, amount, pass);
|
||||
return true;
|
||||
}
|
||||
// if user doesn't have enough currency, fail
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#nullable disable
|
||||
#nullable disable
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NadekoBot.Common.Collections;
|
||||
using NadekoBot.Modules.Gambling.Common;
|
||||
@@ -95,7 +95,7 @@ public partial class Gambling
|
||||
|
||||
if (entry is null)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.shop_item_not_found).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.shop_item_not_found);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -106,33 +106,33 @@ public partial class Gambling
|
||||
|
||||
if (role is null)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.shop_role_not_found).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.shop_role_not_found);
|
||||
return;
|
||||
}
|
||||
|
||||
if (guser.RoleIds.Any(id => id == role.Id))
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.shop_role_already_bought).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.shop_role_already_bought);
|
||||
return;
|
||||
}
|
||||
|
||||
if (await _cs.RemoveAsync(ctx.User.Id, $"Shop purchase - {entry.Type}", entry.Price).ConfigureAwait(false))
|
||||
if (await _cs.RemoveAsync(ctx.User.Id, $"Shop purchase - {entry.Type}", entry.Price))
|
||||
{
|
||||
try
|
||||
{
|
||||
await guser.AddRoleAsync(role).ConfigureAwait(false);
|
||||
await guser.AddRoleAsync(role);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warning(ex, "Error adding shop role");
|
||||
await _cs.AddAsync(ctx.User.Id, $"Shop error refund", entry.Price).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.shop_role_purchase_error).ConfigureAwait(false);
|
||||
await _cs.AddAsync(ctx.User.Id, $"Shop error refund", entry.Price);
|
||||
await ReplyErrorLocalizedAsync(strs.shop_role_purchase_error);
|
||||
return;
|
||||
}
|
||||
var profit = GetProfitAmount(entry.Price);
|
||||
await _cs.AddAsync(entry.AuthorId, $"Shop sell item - {entry.Type}", profit).ConfigureAwait(false);
|
||||
await _cs.AddAsync(ctx.Client.CurrentUser.Id, $"Shop sell item - cut", entry.Price - profit).ConfigureAwait(false);
|
||||
await ReplyConfirmLocalizedAsync(strs.shop_role_purchase(Format.Bold(role.Name))).ConfigureAwait(false);
|
||||
await _cs.AddAsync(entry.AuthorId, $"Shop sell item - {entry.Type}", profit);
|
||||
await _cs.AddAsync(ctx.Client.CurrentUser.Id, $"Shop sell item - cut", entry.Price - profit);
|
||||
await ReplyConfirmLocalizedAsync(strs.shop_role_purchase(Format.Bold(role.Name)));
|
||||
return;
|
||||
}
|
||||
else
|
||||
@@ -145,13 +145,13 @@ public partial class Gambling
|
||||
{
|
||||
if (entry.Items.Count == 0)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.out_of_stock).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.out_of_stock);
|
||||
return;
|
||||
}
|
||||
|
||||
var item = entry.Items.ToArray()[new NadekoRandom().Next(0, entry.Items.Count)];
|
||||
|
||||
if (await _cs.RemoveAsync(ctx.User.Id, $"Shop purchase - {entry.Type}", entry.Price).ConfigureAwait(false))
|
||||
if (await _cs.RemoveAsync(ctx.User.Id, $"Shop purchase - {entry.Type}", entry.Price))
|
||||
{
|
||||
await using (var uow = _db.GetDbContext())
|
||||
{
|
||||
@@ -165,18 +165,17 @@ public partial class Gambling
|
||||
.WithTitle(GetText(strs.shop_purchase(ctx.Guild.Name)))
|
||||
.AddField(GetText(strs.item), item.Text, false)
|
||||
.AddField(GetText(strs.price), entry.Price.ToString(), true)
|
||||
.AddField(GetText(strs.name), entry.Name, true))
|
||||
.ConfigureAwait(false);
|
||||
.AddField(GetText(strs.name), entry.Name, true));
|
||||
|
||||
await _cs.AddAsync(entry.AuthorId,
|
||||
$"Shop sell item - {entry.Name}",
|
||||
GetProfitAmount(entry.Price)).ConfigureAwait(false);
|
||||
GetProfitAmount(entry.Price));
|
||||
}
|
||||
catch
|
||||
{
|
||||
await _cs.AddAsync(ctx.User.Id,
|
||||
$"Shop error refund - {entry.Name}",
|
||||
entry.Price).ConfigureAwait(false);
|
||||
entry.Price);
|
||||
await using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigsForId(ctx.Guild.Id,
|
||||
@@ -191,10 +190,10 @@ public partial class Gambling
|
||||
}
|
||||
}
|
||||
}
|
||||
await ReplyErrorLocalizedAsync(strs.shop_buy_error).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.shop_buy_error);
|
||||
return;
|
||||
}
|
||||
await ReplyConfirmLocalizedAsync(strs.shop_item_purchase).ConfigureAwait(false);
|
||||
await ReplyConfirmLocalizedAsync(strs.shop_item_purchase);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -238,7 +237,7 @@ public partial class Gambling
|
||||
uow.SaveChanges();
|
||||
}
|
||||
await ctx.Channel.EmbedAsync(EntryToEmbed(entry)
|
||||
.WithTitle(GetText(strs.shop_item_add))).ConfigureAwait(false);
|
||||
.WithTitle(GetText(strs.shop_item_add)));
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
@@ -270,7 +269,7 @@ public partial class Gambling
|
||||
}
|
||||
|
||||
await ctx.Channel.EmbedAsync(EntryToEmbed(entry)
|
||||
.WithTitle(GetText(strs.shop_item_add))).ConfigureAwait(false);
|
||||
.WithTitle(GetText(strs.shop_item_add)));
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
@@ -303,13 +302,13 @@ public partial class Gambling
|
||||
}
|
||||
}
|
||||
if (entry is null)
|
||||
await ReplyErrorLocalizedAsync(strs.shop_item_not_found).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.shop_item_not_found);
|
||||
else if (!rightType)
|
||||
await ReplyErrorLocalizedAsync(strs.shop_item_wrong_type).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.shop_item_wrong_type);
|
||||
else if (added == false)
|
||||
await ReplyErrorLocalizedAsync(strs.shop_list_item_not_unique).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.shop_list_item_not_unique);
|
||||
else
|
||||
await ReplyConfirmLocalizedAsync(strs.shop_list_item_added).ConfigureAwait(false);
|
||||
await ReplyConfirmLocalizedAsync(strs.shop_list_item_added);
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
@@ -338,10 +337,10 @@ public partial class Gambling
|
||||
}
|
||||
|
||||
if (removed is null)
|
||||
await ReplyErrorLocalizedAsync(strs.shop_item_not_found).ConfigureAwait(false);
|
||||
await ReplyErrorLocalizedAsync(strs.shop_item_not_found);
|
||||
else
|
||||
await ctx.Channel.EmbedAsync(EntryToEmbed(removed)
|
||||
.WithTitle(GetText(strs.shop_item_rm))).ConfigureAwait(false);
|
||||
.WithTitle(GetText(strs.shop_item_rm)));
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#nullable disable
|
||||
#nullable disable
|
||||
using System.Text;
|
||||
using NadekoBot.Db.Models;
|
||||
using NadekoBot.Modules.Gambling.Services;
|
||||
@@ -106,7 +106,7 @@ public partial class Gambling
|
||||
.AddField("Paid Out", paid.ToString(), true)
|
||||
.WithFooter($"Payout Rate: {paid * 1.0 / bet * 100:f4}%");
|
||||
|
||||
await ctx.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||
await ctx.Channel.EmbedAsync(embed);
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
@@ -134,7 +134,7 @@ public partial class Gambling
|
||||
payout += key * dict[key];
|
||||
}
|
||||
await SendConfirmAsync("Slot Test Results", sb.ToString(),
|
||||
footer: $"Total Bet: {tests} | Payout: {payout} | {payout * 1.0f / tests * 100}%").ConfigureAwait(false);
|
||||
footer: $"Total Bet: {tests} | Payout: {payout} | {payout * 1.0f / tests * 100}%");
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
@@ -145,10 +145,10 @@ public partial class Gambling
|
||||
|
||||
try
|
||||
{
|
||||
if (!await CheckBetMandatory(amount).ConfigureAwait(false))
|
||||
if (!await CheckBetMandatory(amount))
|
||||
return;
|
||||
|
||||
await ctx.Channel.TriggerTypingAsync().ConfigureAwait(false);
|
||||
await ctx.Channel.TriggerTypingAsync();
|
||||
|
||||
var result = await _service.SlotAsync(ctx.User.Id, amount);
|
||||
|
||||
@@ -239,7 +239,7 @@ public partial class Gambling
|
||||
{
|
||||
await ctx.Channel.SendFileAsync(imgStream,
|
||||
filename: "result.png",
|
||||
text: Format.Bold(ctx.User.ToString()) + " " + msg).ConfigureAwait(false);
|
||||
text: Format.Bold(ctx.User.ToString()) + " " + msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -247,7 +247,7 @@ public partial class Gambling
|
||||
{
|
||||
var _ = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(1000).ConfigureAwait(false);
|
||||
await Task.Delay(1000);
|
||||
_runningUsers.Remove(ctx.User.Id);
|
||||
});
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#nullable disable
|
||||
#nullable disable
|
||||
using Wof = NadekoBot.Modules.Gambling.Common.WheelOfFortune.WheelOfFortuneGame;
|
||||
using NadekoBot.Modules.Gambling.Services;
|
||||
using NadekoBot.Modules.Gambling.Common;
|
||||
@@ -33,16 +33,16 @@ public partial class Gambling
|
||||
[NadekoCommand, Aliases]
|
||||
public async Task WheelOfFortune(ShmartNumber amount)
|
||||
{
|
||||
if (!await CheckBetMandatory(amount).ConfigureAwait(false))
|
||||
if (!await CheckBetMandatory(amount))
|
||||
return;
|
||||
|
||||
if (!await _cs.RemoveAsync(ctx.User.Id, "Wheel Of Fortune - bet", amount, gamble: true).ConfigureAwait(false))
|
||||
if (!await _cs.RemoveAsync(ctx.User.Id, "Wheel Of Fortune - bet", amount, gamble: true))
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
|
||||
return;
|
||||
}
|
||||
|
||||
var result = await _service.WheelOfFortuneSpinAsync(ctx.User.Id, amount).ConfigureAwait(false);
|
||||
var result = await _service.WheelOfFortuneSpinAsync(ctx.User.Id, amount);
|
||||
|
||||
var wofMultipliers = _config.WheelOfFortune.Multipliers;
|
||||
await SendConfirmAsync(
|
||||
@@ -52,7 +52,7 @@ public partial class Gambling
|
||||
|
||||
『{wofMultipliers[2]}』 {_emojis[result.Index]} 『{wofMultipliers[6]}』
|
||||
|
||||
『{wofMultipliers[3]}』 『{wofMultipliers[4]}』 『{wofMultipliers[5]}』")).ConfigureAwait(false);
|
||||
『{wofMultipliers[3]}』 『{wofMultipliers[4]}』 『{wofMultipliers[5]}』"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user