Part2 of the response system rework

This commit is contained in:
Kwoth
2024-04-29 01:13:45 +00:00
parent 4bab94b329
commit d28c7b500d
128 changed files with 2723 additions and 2289 deletions

View File

@@ -41,7 +41,9 @@ public partial class Gambling
var ar = new AnimalRace(options, _cs, _gamesConf.Data.RaceAnimals.Shuffle());
if (!_service.AnimalRaces.TryAdd(ctx.Guild.Id, ar))
return SendErrorAsync(GetText(strs.animal_race), GetText(strs.animal_race_already_started));
return Response()
.Error(GetText(strs.animal_race), GetText(strs.animal_race_already_started))
.SendAsync();
ar.Initialize();
@@ -71,15 +73,19 @@ public partial class Gambling
var winner = race.FinishedUsers[0];
if (race.FinishedUsers[0].Bet > 0)
{
return SendConfirmAsync(GetText(strs.animal_race),
GetText(strs.animal_race_won_money(Format.Bold(winner.Username),
winner.Animal.Icon,
(race.FinishedUsers[0].Bet * (race.Users.Count - 1)) + CurrencySign)));
return Response()
.Confirm(GetText(strs.animal_race),
GetText(strs.animal_race_won_money(Format.Bold(winner.Username),
winner.Animal.Icon,
(race.FinishedUsers[0].Bet * (race.Users.Count - 1)) + CurrencySign)))
.SendAsync();
}
ar.Dispose();
return SendConfirmAsync(GetText(strs.animal_race),
GetText(strs.animal_race_won(Format.Bold(winner.Username), winner.Animal.Icon)));
return Response()
.Confirm(GetText(strs.animal_race),
GetText(strs.animal_race_won(Format.Bold(winner.Username), winner.Animal.Icon)))
.SendAsync();
}
ar.OnStartingFailed += Ar_OnStartingFailed;
@@ -88,17 +94,21 @@ public partial class Gambling
ar.OnStarted += Ar_OnStarted;
_client.MessageReceived += ClientMessageReceived;
return SendConfirmAsync(GetText(strs.animal_race),
GetText(strs.animal_race_starting(options.StartTime)),
footer: GetText(strs.animal_race_join_instr(prefix)));
return Response()
.Confirm(GetText(strs.animal_race),
GetText(strs.animal_race_starting(options.StartTime)),
footer: GetText(strs.animal_race_join_instr(prefix)))
.SendAsync();
}
private Task Ar_OnStarted(AnimalRace race)
{
if (race.Users.Count == race.MaxUsers)
return SendConfirmAsync(GetText(strs.animal_race), GetText(strs.animal_race_full));
return SendConfirmAsync(GetText(strs.animal_race),
GetText(strs.animal_race_starting_with_x(race.Users.Count)));
return Response().Confirm(GetText(strs.animal_race), GetText(strs.animal_race_full)).SendAsync();
return Response()
.Confirm(GetText(strs.animal_race),
GetText(strs.animal_race_starting_with_x(race.Users.Count)))
.SendAsync();
}
private async Task Ar_OnStateUpdate(AnimalRace race)
@@ -115,10 +125,10 @@ public partial class Gambling
var msg = raceMessage;
if (msg is null)
raceMessage = await SendConfirmAsync(text);
raceMessage = await Response().Confirm(text).SendAsync();
else
{
await msg.ModifyAsync(x => x.Embed = _eb.Create()
await msg.ModifyAsync(x => x.Embed = new EmbedBuilder()
.WithTitle(GetText(strs.animal_race))
.WithDescription(text)
.WithOkColor()
@@ -130,7 +140,7 @@ public partial class Gambling
{
_service.AnimalRaces.TryRemove(ctx.Guild.Id, out _);
race.Dispose();
return ReplyErrorLocalizedAsync(strs.animal_race_failed);
return Response().Error(strs.animal_race_failed).SendAsync();
}
[Cmd]
@@ -142,7 +152,7 @@ public partial class Gambling
if (!_service.AnimalRaces.TryGetValue(ctx.Guild.Id, out var ar))
{
await ReplyErrorLocalizedAsync(strs.race_not_exist);
await Response().Error(strs.race_not_exist).SendAsync();
return;
}
@@ -151,12 +161,16 @@ public partial class Gambling
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)));
await Response()
.Confirm(GetText(strs.animal_race_join_bet(ctx.User.Mention,
user.Animal.Icon,
amount + CurrencySign)))
.SendAsync();
}
else
await SendConfirmAsync(GetText(strs.animal_race_join(ctx.User.Mention, user.Animal.Icon)));
await Response()
.Confirm(GetText(strs.animal_race_join(ctx.User.Mention, user.Animal.Icon)))
.SendAsync();
}
catch (ArgumentOutOfRangeException)
{
@@ -172,11 +186,11 @@ public partial class Gambling
}
catch (AnimalRaceFullException)
{
await SendConfirmAsync(GetText(strs.animal_race), GetText(strs.animal_race_full));
await Response().Confirm(GetText(strs.animal_race), GetText(strs.animal_race_full)).SendAsync();
}
catch (NotEnoughFundsException)
{
await SendErrorAsync(GetText(strs.not_enough(CurrencySign)));
await Response().Error(GetText(strs.not_enough(CurrencySign))).SendAsync();
}
}
}

View File

@@ -30,11 +30,11 @@ public partial class Gambling
if (await _bank.DepositAsync(ctx.User.Id, amount))
{
await ReplyConfirmLocalizedAsync(strs.bank_deposited(N(amount)));
await Response().Confirm(strs.bank_deposited(N(amount))).SendAsync();
}
else
{
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
await Response().Error(strs.not_enough(CurrencySign)).SendAsync();
}
}
@@ -46,11 +46,11 @@ public partial class Gambling
if (await _bank.WithdrawAsync(ctx.User.Id, amount))
{
await ReplyConfirmLocalizedAsync(strs.bank_withdrew(N(amount)));
await Response().Confirm(strs.bank_withdrew(N(amount))).SendAsync();
}
else
{
await ReplyErrorLocalizedAsync(strs.bank_withdraw_insuff(CurrencySign));
await Response().Error(strs.bank_withdraw_insuff(CurrencySign)).SendAsync();
}
}
@@ -59,7 +59,7 @@ public partial class Gambling
{
var bal = await _bank.GetBalanceAsync(ctx.User.Id);
var eb = _eb.Create(ctx)
var eb = new EmbedBuilder()
.WithOkColor()
.WithDescription(GetText(strs.bank_balance(N(bal))));
@@ -70,7 +70,7 @@ public partial class Gambling
}
catch
{
await ReplyErrorLocalizedAsync(strs.cant_dm);
await Response().Error(strs.cant_dm).SendAsync();
}
}
@@ -82,10 +82,10 @@ public partial class Gambling
return;
}
await ReplyErrorLocalizedAsync(strs.take_fail(N(amount),
await Response().Error(strs.take_fail(N(amount),
_client.GetUser(userId)?.ToString()
?? userId.ToString(),
CurrencySign));
CurrencySign)).SendAsync();
}
private async Task BankAwardInternalAsync(long amount, ulong userId)

View File

@@ -42,7 +42,7 @@ public partial class Gambling
if (!await bj.Join(ctx.User, amount))
{
_service.Games.TryRemove(ctx.Channel.Id, out _);
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
await Response().Error(strs.not_enough(CurrencySign)).SendAsync();
return;
}
@@ -50,12 +50,12 @@ public partial class Gambling
bj.GameEnded += Bj_GameEnded;
bj.Start();
await ReplyConfirmLocalizedAsync(strs.bj_created);
await Response().Confirm(strs.bj_created).SendAsync();
}
else
{
if (await bj.Join(ctx.User, amount))
await ReplyConfirmLocalizedAsync(strs.bj_joined);
await Response().Confirm(strs.bj_joined).SendAsync();
else
{
Log.Information("{User} can't join a blackjack game as it's in {BlackjackState} state already",
@@ -95,7 +95,7 @@ public partial class Gambling
var cStr = string.Concat(c.Select(x => x[..^1] + " "));
cStr += "\n" + string.Concat(c.Select(x => x.Last() + " "));
var embed = _eb.Create()
var embed = new EmbedBuilder()
.WithOkColor()
.WithTitle("BlackJack")
.AddField($"{dealerIcon} Dealer's Hand | Value: {bj.Dealer.GetHandValue()}", cStr);
@@ -128,7 +128,7 @@ public partial class Gambling
embed.AddField(full, cStr);
}
msg = await EmbedAsync(embed);
msg = await Response().Embed(embed).SendAsync();
}
catch
{
@@ -174,7 +174,7 @@ public partial class Gambling
else if (a == BjAction.Double)
{
if (!await bj.Double(ctx.User))
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
await Response().Error(strs.not_enough(CurrencySign)).SendAsync();
}
await ctx.Message.DeleteAsync();

View File

@@ -68,7 +68,7 @@ public partial class Gambling
{
if (!await _cs.RemoveAsync(ctx.User.Id, options.Bet, new("connect4", "bet")))
{
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
await Response().Error(strs.not_enough(CurrencySign)).SendAsync();
_service.Connect4Games.TryRemove(ctx.Channel.Id, out _);
game.Dispose();
return;
@@ -82,9 +82,9 @@ public partial class Gambling
game.Initialize();
if (options.Bet == 0)
await ReplyConfirmLocalizedAsync(strs.connect4_created);
await Response().Confirm(strs.connect4_created).SendAsync();
else
await ReplyErrorLocalizedAsync(strs.connect4_created_bet(N(options.Bet)));
await Response().Error(strs.connect4_created_bet(N(options.Bet))).SendAsync();
Task ClientMessageReceived(SocketMessage arg)
{
@@ -125,7 +125,7 @@ public partial class Gambling
toDispose.Dispose();
}
return ErrorLocalizedAsync(strs.connect4_failed_to_start);
return Response().Error(strs.connect4_failed_to_start).SendAsync();
}
Task GameOnGameEnded(Connect4Game arg, Connect4Game.Result result)
@@ -150,7 +150,7 @@ public partial class Gambling
else
title = GetText(strs.connect4_draw);
return msg.ModifyAsync(x => x.Embed = _eb.Create()
return msg.ModifyAsync(x => x.Embed = new EmbedBuilder()
.WithTitle(title)
.WithDescription(GetGameStateText(game))
.WithOkColor()
@@ -160,14 +160,14 @@ public partial class Gambling
private async Task Game_OnGameStateUpdated(Connect4Game game)
{
var embed = _eb.Create()
var embed = new EmbedBuilder()
.WithTitle($"{game.CurrentPlayer.Username} vs {game.OtherPlayer.Username}")
.WithDescription(GetGameStateText(game))
.WithOkColor();
if (msg is null)
msg = await EmbedAsync(embed);
msg = await Response().Embed(embed).SendAsync();
else
await msg.ModifyAsync(x => x.Embed = embed.Build());
}
@@ -198,6 +198,7 @@ public partial class Gambling
for (var i = 0; i < Connect4Game.NUMBER_OF_COLUMNS; i++)
sb.Append(_numbers[i]);
return sb.ToString();
}
}

View File

@@ -38,7 +38,7 @@ public partial class Gambling
var fileName = $"dice.{format.FileExtensions.First()}";
var eb = _eb.Create(ctx)
var eb = new EmbedBuilder()
.WithOkColor()
.WithAuthor(ctx.User)
.AddField(GetText(strs.roll2), gen)
@@ -74,7 +74,7 @@ public partial class Gambling
{
if (num is < 1 or > 30)
{
await ReplyErrorLocalizedAsync(strs.dice_invalid_number(1, 30));
await Response().Error(strs.dice_invalid_number(1, 30)).SendAsync();
return;
}
@@ -115,7 +115,7 @@ public partial class Gambling
d.Dispose();
var imageName = $"dice.{format.FileExtensions.First()}";
var eb = _eb.Create(ctx)
var eb = new EmbedBuilder()
.WithOkColor()
.WithAuthor(ctx.User)
.AddField(GetText(strs.rolls), values.Select(x => Format.Code(x.ToString())).Join(' '), true)
@@ -141,14 +141,14 @@ public partial class Gambling
for (var i = 0; i < n1; i++)
rolls.Add(_fateRolls[rng.Next(0, _fateRolls.Length)]);
var embed = _eb.Create()
var embed = new EmbedBuilder()
.WithOkColor()
.WithAuthor(ctx.User)
.WithDescription(GetText(strs.dice_rolled_num(Format.Bold(n1.ToString()))))
.AddField(Format.Bold("Result"),
string.Join(" ", rolls.Select(c => Format.Code($"[{c}]"))));
await EmbedAsync(embed);
await Response().Embed(embed).SendAsync();
}
else if ((match = _dndRegex.Match(arg)).Length != 0)
{
@@ -170,7 +170,7 @@ public partial class Gambling
arr[i] = rng.Next(1, n2 + 1);
var sum = arr.Sum();
var embed = _eb.Create()
var embed = new EmbedBuilder()
.WithOkColor()
.WithAuthor(ctx.User)
.WithDescription(GetText(strs.dice_rolled_num(n1 + $"`1 - {n2}`")))
@@ -180,7 +180,7 @@ public partial class Gambling
=> Format.Code(x.ToString()))))
.AddField(Format.Bold("Sum"),
sum + " + " + add + " - " + sub + " = " + (sum + add - sub));
await EmbedAsync(embed);
await Response().Embed(embed).SendAsync();
}
}
}
@@ -194,7 +194,7 @@ public partial class Gambling
var arr = range.Split('-').Take(2).Select(int.Parse).ToArray();
if (arr[0] > arr[1])
{
await ReplyErrorLocalizedAsync(strs.second_larger_than_first);
await Response().Error(strs.second_larger_than_first).SendAsync();
return;
}
@@ -203,7 +203,7 @@ public partial class Gambling
else
rolled = new NadekoRandom().Next(0, int.Parse(range) + 1);
await ReplyConfirmLocalizedAsync(strs.dice_rolled(Format.Bold(rolled.ToString())));
await Response().Confirm(strs.dice_rolled(Format.Bold(rolled.ToString()))).SendAsync();
}
private async Task<Image<Rgba32>> GetDiceAsync(int num)

View File

@@ -34,7 +34,7 @@ public partial class Gambling
{
try
{
await ReplyErrorLocalizedAsync(strs.no_more_cards);
await Response().Error(strs.no_more_cards).SendAsync();
}
catch
{
@@ -55,7 +55,7 @@ public partial class Gambling
foreach (var i in images)
i.Dispose();
var eb = _eb.Create(ctx)
var eb = new EmbedBuilder()
.WithOkColor();
var toSend = string.Empty;
@@ -131,7 +131,7 @@ public partial class Gambling
return c;
});
await ReplyConfirmLocalizedAsync(strs.deck_reshuffled);
await Response().Confirm(strs.deck_reshuffled).SendAsync();
}
[Cmd]
@@ -156,11 +156,11 @@ public partial class Gambling
if (!res.TryPickT0(out var result, out _))
{
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
await Response().Error(strs.not_enough(CurrencySign)).SendAsync();
return;
}
var eb = _eb.Create(ctx)
var eb = new EmbedBuilder()
.WithOkColor()
.WithAuthor(ctx.User)
.WithDescription(result.Card.GetEmoji())

View File

@@ -24,18 +24,18 @@ public partial class Gambling
{
var (opts, _) = OptionsParser.ParseFrom(new EventOptions(), options);
if (!await _service.TryCreateEventAsync(ctx.Guild.Id, ctx.Channel.Id, ev, opts, GetEmbed))
await ReplyErrorLocalizedAsync(strs.start_event_fail);
await Response().Error(strs.start_event_fail).SendAsync();
}
private IEmbedBuilder GetEmbed(CurrencyEvent.Type type, EventOptions opts, long currentPot)
private EmbedBuilder GetEmbed(CurrencyEvent.Type type, EventOptions opts, long currentPot)
=> type switch
{
CurrencyEvent.Type.Reaction => _eb.Create()
CurrencyEvent.Type.Reaction => new EmbedBuilder()
.WithOkColor()
.WithTitle(GetText(strs.event_title(type.ToString())))
.WithDescription(GetReactionDescription(opts.Amount, currentPot))
.WithFooter(GetText(strs.event_duration_footer(opts.Hours))),
CurrencyEvent.Type.GameStatus => _eb.Create()
CurrencyEvent.Type.GameStatus => new EmbedBuilder()
.WithOkColor()
.WithTitle(GetText(strs.event_title(type.ToString())))
.WithDescription(GetGameStatusDescription(opts.Amount, currentPot))

View File

@@ -25,7 +25,7 @@ public class CurrencyEventsService : INService
ulong channelId,
CurrencyEvent.Type type,
EventOptions opts,
Func<CurrencyEvent.Type, EventOptions, long, IEmbedBuilder> embed)
Func<CurrencyEvent.Type, EventOptions, long, EmbedBuilder> embed)
{
var g = _client.GetGuild(guildId);
if (g?.GetChannel(channelId) is not ITextChannel ch)

View File

@@ -16,7 +16,7 @@ public class GameStatusEvent : ICurrencyEvent
private readonly ICurrencyService _cs;
private readonly long _amount;
private readonly Func<CurrencyEvent.Type, EventOptions, long, IEmbedBuilder> _embedFunc;
private readonly Func<CurrencyEvent.Type, EventOptions, long, EmbedBuilder> _embedFunc;
private readonly bool _isPotLimited;
private readonly ITextChannel _channel;
private readonly ConcurrentHashSet<ulong> _awardedUsers = new();
@@ -43,7 +43,7 @@ public class GameStatusEvent : ICurrencyEvent
SocketGuild g,
ITextChannel ch,
EventOptions opt,
Func<CurrencyEvent.Type, EventOptions, long, IEmbedBuilder> embedFunc)
Func<CurrencyEvent.Type, EventOptions, long, EmbedBuilder> embedFunc)
{
_client = client;
_guild = g;
@@ -113,7 +113,7 @@ public class GameStatusEvent : ICurrencyEvent
_t.Change(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2));
}
private IEmbedBuilder GetEmbed(long pot)
private EmbedBuilder GetEmbed(long pot)
=> _embedFunc(CurrencyEvent.Type.GameStatus, _opts, pot);
private async Task OnMessageDeleted(Cacheable<IMessage, ulong> message, Cacheable<IMessageChannel, ulong> cacheable)

View File

@@ -16,7 +16,7 @@ public class ReactionEvent : ICurrencyEvent
private readonly ICurrencyService _cs;
private readonly long _amount;
private readonly Func<CurrencyEvent.Type, EventOptions, long, IEmbedBuilder> _embedFunc;
private readonly Func<CurrencyEvent.Type, EventOptions, long, EmbedBuilder> _embedFunc;
private readonly bool _isPotLimited;
private readonly ITextChannel _channel;
private readonly ConcurrentHashSet<ulong> _awardedUsers = new();
@@ -38,7 +38,7 @@ public class ReactionEvent : ICurrencyEvent
ITextChannel ch,
EventOptions opt,
GamblingConfig config,
Func<CurrencyEvent.Type, EventOptions, long, IEmbedBuilder> embedFunc)
Func<CurrencyEvent.Type, EventOptions, long, EmbedBuilder> embedFunc)
{
_client = client;
_guild = g;
@@ -109,7 +109,7 @@ public class ReactionEvent : ICurrencyEvent
_t.Change(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2));
}
private IEmbedBuilder GetEmbed(long pot)
private EmbedBuilder GetEmbed(long pot)
=> _embedFunc(CurrencyEvent.Type.Reaction, _opts, pot);
private async Task OnMessageDeleted(Cacheable<IMessage, ulong> message, Cacheable<IMessageChannel, ulong> cacheable)

View File

@@ -45,7 +45,7 @@ public partial class Gambling
{
if (count is > 10 or < 1)
{
await ReplyErrorLocalizedAsync(strs.flip_invalid(10));
await Response().Error(strs.flip_invalid(10)).SendAsync();
return;
}
@@ -84,7 +84,7 @@ public partial class Gambling
? Format.Bold(GetText(strs.heads))
: Format.Bold(GetText(strs.tails))));
var eb = _eb.Create(ctx)
var eb = new EmbedBuilder()
.WithOkColor()
.WithAuthor(ctx.User)
.WithDescription(msg)
@@ -104,7 +104,7 @@ public partial class Gambling
var res = await _service.BetFlipAsync(ctx.User.Id, amount, (byte)guess);
if (!res.TryPickT0(out var result, out _))
{
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
await Response().Error(strs.not_enough(CurrencySign)).SendAsync();
return;
}
@@ -130,11 +130,11 @@ public partial class Gambling
str = Format.Bold(GetText(strs.better_luck));
}
await EmbedAsync(_eb.Create()
await Response().Embed(new EmbedBuilder()
.WithAuthor(ctx.User)
.WithDescription(str)
.WithOkColor()
.WithImageUrl(imageToSend.ToString()));
.WithImageUrl(imageToSend.ToString())).SendAsync();
}
}
}

View File

@@ -73,18 +73,18 @@ public partial class Gambling : GamblingModule<GamblingService>
{
var stats = await _gamblingTxTracker.GetAllAsync();
var eb = _eb.Create(ctx)
.WithOkColor();
var eb = new EmbedBuilder()
.WithOkColor();
var str = "` Feature `` Bet ``Paid Out`` RoI `\n";
str += "――――――――――――――――――――\n";
foreach (var stat in stats)
{
var perc = (stat.PaidOut / stat.Bet).ToString("P2", Culture);
str += $"`{stat.Feature.PadBoth(9)}`" +
$"`{stat.Bet.ToString("N0").PadLeft(8, '')}`" +
$"`{stat.PaidOut.ToString("N0").PadLeft(8, '')}`" +
$"`{perc.PadLeft(6, '')}`\n";
str += $"`{stat.Feature.PadBoth(9)}`"
+ $"`{stat.Bet.ToString("N0").PadLeft(8, '')}`"
+ $"`{stat.PaidOut.ToString("N0").PadLeft(8, '')}`"
+ $"`{perc.PadLeft(6, '')}`\n";
}
var bet = stats.Sum(x => x.Bet);
@@ -95,14 +95,14 @@ public partial class Gambling : GamblingModule<GamblingService>
var tPerc = (paidOut / bet).ToString("P2", Culture);
str += "――――――――――――――――――――\n";
str += $"` {("TOTAL").PadBoth(7)}` " +
$"**{N(bet).PadLeft(8, '')}**" +
$"**{N(paidOut).PadLeft(8, '')}**" +
$"`{tPerc.PadLeft(6, '')}`";
str += $"` {("TOTAL").PadBoth(7)}` "
+ $"**{N(bet).PadLeft(8, '')}**"
+ $"**{N(paidOut).PadLeft(8, '')}**"
+ $"`{tPerc.PadLeft(6, '')}`";
eb.WithDescription(str);
await EmbedAsync(eb);
await Response().Embed(eb).SendAsync();
}
[Cmd]
@@ -118,19 +118,19 @@ public partial class Gambling : GamblingModule<GamblingService>
}
// [21:03] Bob Page: Kinda remids me of US economy
var embed = _eb.Create()
.WithTitle(GetText(strs.economy_state))
.AddField(GetText(strs.currency_owned), N(ec.Cash - ec.Bot))
.AddField(GetText(strs.currency_one_percent), (onePercent * 100).ToString("F2") + "%")
.AddField(GetText(strs.currency_planted), N(ec.Planted))
.AddField(GetText(strs.owned_waifus_total), N(ec.Waifus))
.AddField(GetText(strs.bot_currency), N(ec.Bot))
.AddField(GetText(strs.bank_accounts), N(ec.Bank))
.AddField(GetText(strs.total), N(ec.Cash + ec.Planted + ec.Waifus + ec.Bank))
.WithOkColor();
var embed = new EmbedBuilder()
.WithTitle(GetText(strs.economy_state))
.AddField(GetText(strs.currency_owned), N(ec.Cash - ec.Bot))
.AddField(GetText(strs.currency_one_percent), (onePercent * 100).ToString("F2") + "%")
.AddField(GetText(strs.currency_planted), N(ec.Planted))
.AddField(GetText(strs.owned_waifus_total), N(ec.Waifus))
.AddField(GetText(strs.bot_currency), N(ec.Bot))
.AddField(GetText(strs.bank_accounts), N(ec.Bank))
.AddField(GetText(strs.total), N(ec.Cash + ec.Planted + ec.Waifus + ec.Bank))
.WithOkColor();
// ec.Cash already contains ec.Bot as it's the total of all values in the CurrencyAmount column of the DiscordUser table
await EmbedAsync(embed);
await Response().Embed(embed).SendAsync();
}
private static readonly FeatureLimitKey _timelyKey = new FeatureLimitKey()
@@ -153,7 +153,7 @@ public partial class Gambling : GamblingModule<GamblingService>
await smc.RespondConfirmAsync(_eb, GetText(strs.remind_timely(tt)), ephemeral: true);
}
private NadekoInteraction CreateRemindMeInteraction(int period)
{
return _inter
@@ -174,10 +174,10 @@ public partial class Gambling : GamblingModule<GamblingService>
var period = Config.Timely.Cooldown;
if (val <= 0 || period <= 0)
{
await ReplyErrorLocalizedAsync(strs.timely_none);
await Response().Error(strs.timely_none).SendAsync();
return;
}
var inter = CreateRemindMeInteraction(period);
if (await _service.ClaimTimelyAsync(ctx.User.Id, period) is { } rem)
@@ -187,10 +187,10 @@ public partial class Gambling : GamblingModule<GamblingService>
{
inter = null;
}
var now = DateTime.UtcNow;
var relativeTag = TimestampTag.FromDateTime(now.Add(rem), TimestampTagStyles.Relative);
await ReplyPendingLocalizedAsync(strs.timely_already_claimed(relativeTag), inter);
await Response().Pending(strs.timely_already_claimed(relativeTag)).Interaction(inter).SendAsync();
return;
}
@@ -200,15 +200,15 @@ public partial class Gambling : GamblingModule<GamblingService>
await _cs.AddAsync(ctx.User.Id, val, new("timely", "claim"));
await ReplyConfirmLocalizedAsync(strs.timely(N(val), period), inter);
await Response().Confirm(strs.timely(N(val), period)).Interaction(inter).SendAsync();
}
[Cmd]
[OwnerOnly]
public async Task TimelyReset()
{
await _service.RemoveAllTimelyClaimsAsync();
await ReplyConfirmLocalizedAsync(strs.timely_reset);
await Response().Confirm(strs.timely_reset).SendAsync();
}
[Cmd]
@@ -228,11 +228,13 @@ public partial class Gambling : GamblingModule<GamblingService>
if (amount == 0)
{
await ReplyConfirmLocalizedAsync(strs.timely_set_none);
await Response().Confirm(strs.timely_set_none).SendAsync();
}
else
{
await ReplyConfirmLocalizedAsync(strs.timely_set(Format.Bold(N(amount)), Format.Bold(period.ToString())));
await Response()
.Confirm(strs.timely_set(Format.Bold(N(amount)), Format.Bold(period.ToString())))
.SendAsync();
}
}
@@ -250,9 +252,11 @@ public partial class Gambling : GamblingModule<GamblingService>
}
var usr = membersArray[new NadekoRandom().Next(0, membersArray.Length)];
await SendConfirmAsync("🎟 " + GetText(strs.raffled_user),
$"**{usr.Username}**",
footer: $"ID: {usr.Id}");
await Response()
.Confirm("🎟 " + GetText(strs.raffled_user),
$"**{usr.Username}**",
footer: $"ID: {usr.Id}")
.SendAsync();
}
[Cmd]
@@ -269,9 +273,11 @@ public partial class Gambling : GamblingModule<GamblingService>
}
var usr = membersArray[new NadekoRandom().Next(0, membersArray.Length)];
await SendConfirmAsync("🎟 " + GetText(strs.raffled_user),
$"**{usr.Username}**",
footer: $"ID: {usr.Id}");
await Response()
.Confirm("🎟 " + GetText(strs.raffled_user),
$"**{usr.Username}**",
footer: $"ID: {usr.Id}")
.SendAsync();
}
[Cmd]
@@ -304,10 +310,10 @@ public partial class Gambling : GamblingModule<GamblingService>
trs = await uow.Set<CurrencyTransaction>().GetPageFor(userId, page);
}
var embed = _eb.Create()
.WithTitle(GetText(strs.transactions(((SocketGuild)ctx.Guild)?.GetUser(userId)?.ToString()
?? $"{userId}")))
.WithOkColor();
var embed = new EmbedBuilder()
.WithTitle(GetText(strs.transactions(((SocketGuild)ctx.Guild)?.GetUser(userId)?.ToString()
?? $"{userId}")))
.WithOkColor();
var sb = new StringBuilder();
foreach (var tr in trs)
@@ -331,7 +337,7 @@ public partial class Gambling : GamblingModule<GamblingService>
embed.WithDescription(sb.ToString());
embed.WithFooter(GetText(strs.page(page + 1)));
await EmbedAsync(embed);
await Response().Embed(embed).SendAsync();
}
private static string GetFormattedCurtrDate(CurrencyTransaction ct)
@@ -343,17 +349,18 @@ public partial class Gambling : GamblingModule<GamblingService>
int intId = id;
await using var uow = _db.GetDbContext();
var tr = await uow.Set<CurrencyTransaction>().ToLinqToDBTable()
.Where(x => x.Id == intId && x.UserId == ctx.User.Id)
.FirstOrDefaultAsync();
var tr = await uow.Set<CurrencyTransaction>()
.ToLinqToDBTable()
.Where(x => x.Id == intId && x.UserId == ctx.User.Id)
.FirstOrDefaultAsync();
if (tr is null)
{
await ReplyErrorLocalizedAsync(strs.not_found);
await Response().Error(strs.not_found).SendAsync();
return;
}
var eb = _eb.Create(ctx).WithOkColor();
var eb = new EmbedBuilder().WithOkColor();
eb.WithAuthor(ctx.User);
eb.WithTitle(GetText(strs.transaction));
@@ -374,7 +381,7 @@ public partial class Gambling : GamblingModule<GamblingService>
eb.WithFooter(GetFormattedCurtrDate(tr));
await EmbedAsync(eb);
await Response().Embed(eb).SendAsync();
}
private string GetHumanReadableTransaction(string type, string subType, ulong? maybeUserId)
@@ -398,7 +405,7 @@ public partial class Gambling : GamblingModule<GamblingService>
public async Task Cash(ulong userId)
{
var cur = await GetBalanceStringAsync(userId);
await ReplyConfirmLocalizedAsync(strs.has(Format.Code(userId.ToString()), cur));
await Response().Confirm(strs.has(Format.Code(userId.ToString()), cur)).SendAsync();
}
private async Task BankAction(SocketMessageComponent smc, object _)
@@ -406,9 +413,9 @@ public partial class Gambling : GamblingModule<GamblingService>
var balance = await _bank.GetBalanceAsync(ctx.User.Id);
await N(balance)
.Pipe(strs.bank_balance)
.Pipe(GetText)
.Pipe(text => smc.RespondConfirmAsync(_eb, text, ephemeral: true));
.Pipe(strs.bank_balance)
.Pipe(GetText)
.Pipe(text => smc.RespondConfirmAsync(_eb, text, ephemeral: true));
}
private NadekoInteraction CreateCashInteraction()
@@ -429,18 +436,24 @@ public partial class Gambling : GamblingModule<GamblingService>
? CreateCashInteraction()
: null;
await ConfirmLocalizedAsync(
user.ToString()
.Pipe(Format.Bold)
.With(cur)
.Pipe(strs.has),
inter);
await Response()
.Confirm(
user.ToString()
.Pipe(Format.Bold)
.With(cur)
.Pipe(strs.has))
.Interaction(inter)
.SendAsync();
}
[Cmd]
[RequireContext(ContextType.Guild)]
[Priority(0)]
public async Task Give([OverrideTypeReader(typeof(BalanceTypeReader))] long amount, IGuildUser receiver, [Leftover] string msg)
public async Task Give(
[OverrideTypeReader(typeof(BalanceTypeReader))]
long amount,
IGuildUser receiver,
[Leftover] string msg)
{
if (amount <= 0 || ctx.User.Id == receiver.Id || receiver.IsBot)
{
@@ -449,11 +462,11 @@ public partial class Gambling : GamblingModule<GamblingService>
if (!await _cs.TransferAsync(_eb, ctx.User, receiver, amount, msg, N(amount)))
{
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
await Response().Error(strs.not_enough(CurrencySign)).SendAsync();
return;
}
await ReplyConfirmLocalizedAsync(strs.gifted(N(amount), Format.Bold(receiver.ToString())));
await Response().Confirm(strs.gifted(N(amount), Format.Bold(receiver.ToString()))).SendAsync();
}
[Cmd]
@@ -490,12 +503,12 @@ public partial class Gambling : GamblingModule<GamblingService>
if (usr is null)
{
await ReplyErrorLocalizedAsync(strs.user_not_found);
await Response().Error(strs.user_not_found).SendAsync();
return;
}
await _cs.AddAsync(usr.Id, amount, new("award", ctx.User.ToString()!, msg, ctx.User.Id));
await ReplyConfirmLocalizedAsync(strs.awarded(N(amount), $"<@{usrId}>"));
await Response().Confirm(strs.awarded(N(amount), $"<@{usrId}>")).SendAsync();
}
[Cmd]
@@ -510,9 +523,11 @@ public partial class Gambling : GamblingModule<GamblingService>
amount,
new("award", ctx.User.ToString()!, role.Name, ctx.User.Id));
await ReplyConfirmLocalizedAsync(strs.mass_award(N(amount),
Format.Bold(users.Count.ToString()),
Format.Bold(role.Name)));
await Response()
.Confirm(strs.mass_award(N(amount),
Format.Bold(users.Count.ToString()),
Format.Bold(role.Name)))
.SendAsync();
}
[Cmd]
@@ -527,9 +542,11 @@ public partial class Gambling : GamblingModule<GamblingService>
amount,
new("take", ctx.User.ToString()!, null, ctx.User.Id));
await ReplyConfirmLocalizedAsync(strs.mass_take(N(amount),
Format.Bold(users.Count.ToString()),
Format.Bold(role.Name)));
await Response()
.Confirm(strs.mass_take(N(amount),
Format.Bold(users.Count.ToString()),
Format.Bold(role.Name)))
.SendAsync();
}
[Cmd]
@@ -547,11 +564,11 @@ public partial class Gambling : GamblingModule<GamblingService>
if (await _cs.RemoveAsync(user.Id, amount, extra))
{
await ReplyConfirmLocalizedAsync(strs.take(N(amount), Format.Bold(user.ToString())));
await Response().Confirm(strs.take(N(amount), Format.Bold(user.ToString()))).SendAsync();
}
else
{
await ReplyErrorLocalizedAsync(strs.take_fail(N(amount), Format.Bold(user.ToString()), CurrencySign));
await Response().Error(strs.take_fail(N(amount), Format.Bold(user.ToString()), CurrencySign)).SendAsync();
}
}
@@ -568,11 +585,11 @@ public partial class Gambling : GamblingModule<GamblingService>
if (await _cs.RemoveAsync(usrId, amount, extra))
{
await ReplyConfirmLocalizedAsync(strs.take(N(amount), $"<@{usrId}>"));
await Response().Confirm(strs.take(N(amount), $"<@{usrId}>")).SendAsync();
}
else
{
await ReplyErrorLocalizedAsync(strs.take_fail(N(amount), Format.Code(usrId.ToString()), CurrencySign));
await Response().Error(strs.take_fail(N(amount), Format.Code(usrId.ToString()), CurrencySign)).SendAsync();
}
}
@@ -607,7 +624,7 @@ public partial class Gambling : GamblingModule<GamblingService>
return;
}
var embed = _eb.Create().WithOkColor().WithTitle(GetText(strs.roll_duel));
var embed = new EmbedBuilder().WithOkColor().WithTitle(GetText(strs.roll_duel));
var description = string.Empty;
@@ -617,7 +634,7 @@ public partial class Gambling : GamblingModule<GamblingService>
{
if (other.Amount != amount)
{
await ReplyErrorLocalizedAsync(strs.roll_duel_already_challenged);
await Response().Error(strs.roll_duel_already_challenged).SendAsync();
}
else
{
@@ -632,9 +649,11 @@ public partial class Gambling : GamblingModule<GamblingService>
game.OnGameTick += GameOnGameTick;
game.OnEnded += GameOnEnded;
await ReplyConfirmLocalizedAsync(strs.roll_duel_challenge(Format.Bold(ctx.User.ToString()),
Format.Bold(u.ToString()),
Format.Bold(N(amount))));
await Response()
.Confirm(strs.roll_duel_challenge(Format.Bold(ctx.User.ToString()),
Format.Bold(u.ToString()),
Format.Bold(N(amount))))
.SendAsync();
}
async Task GameOnGameTick(RollDuelGame arg)
@@ -648,7 +667,7 @@ public partial class Gambling : GamblingModule<GamblingService>
if (rdMsg is null)
{
rdMsg = await ctx.Channel.EmbedAsync(embed);
rdMsg = await Response().Embed(embed).SendAsync();
}
else
{
@@ -671,11 +690,11 @@ public partial class Gambling : GamblingModule<GamblingService>
}
else if (reason == RollDuelGame.Reason.Timeout)
{
await ReplyErrorLocalizedAsync(strs.roll_duel_timeout);
await Response().Error(strs.roll_duel_timeout).SendAsync();
}
else if (reason == RollDuelGame.Reason.NoFunds)
{
await ReplyErrorLocalizedAsync(strs.roll_duel_no_funds);
await Response().Error(strs.roll_duel_no_funds).SendAsync();
}
}
finally
@@ -696,7 +715,7 @@ public partial class Gambling : GamblingModule<GamblingService>
var maybeResult = await _gs.BetRollAsync(ctx.User.Id, amount);
if (!maybeResult.TryPickT0(out var result, out _))
{
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
await Response().Error(strs.not_enough(CurrencySign)).SendAsync();
return;
}
@@ -712,13 +731,13 @@ public partial class Gambling : GamblingModule<GamblingService>
str = GetText(strs.better_luck);
}
var eb = _eb.Create(ctx)
.WithAuthor(ctx.User)
.WithDescription(Format.Bold(str))
.AddField(GetText(strs.roll2), result.Roll.ToString(CultureInfo.InvariantCulture))
.WithOkColor();
var eb = new EmbedBuilder()
.WithAuthor(ctx.User)
.WithDescription(Format.Bold(str))
.AddField(GetText(strs.roll2), result.Roll.ToString(CultureInfo.InvariantCulture))
.WithOkColor();
await ctx.Channel.EmbedAsync(eb);
await Response().Embed(eb).SendAsync();
}
[Cmd]
@@ -768,7 +787,7 @@ public partial class Gambling : GamblingModule<GamblingService>
await ctx.SendPaginatedConfirmAsync(page,
async curPage =>
{
var embed = _eb.Create().WithOkColor().WithTitle(CurrencySign + " " + GetText(strs.leaderboard));
var embed = new EmbedBuilder().WithOkColor().WithTitle(CurrencySign + " " + GetText(strs.leaderboard));
List<DiscordUser> toSend;
if (!opts.Clean)
@@ -838,11 +857,11 @@ public partial class Gambling : GamblingModule<GamblingService>
if (!res.TryPickT0(out var result, out _))
{
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
await Response().Error(strs.not_enough(CurrencySign)).SendAsync();
return;
}
var embed = _eb.Create();
var embed = new EmbedBuilder();
string msg;
if (result.Result == RpsResultType.Draw)
@@ -869,7 +888,7 @@ public partial class Gambling : GamblingModule<GamblingService>
.WithOkColor()
.WithDescription(msg);
await ctx.Channel.EmbedAsync(embed);
await Response().Embed(embed).SendAsync();
}
private static readonly ImmutableArray<string> _emojis =
@@ -884,7 +903,7 @@ public partial class Gambling : GamblingModule<GamblingService>
var res = await _gs.LulaAsync(ctx.User.Id, amount);
if (!res.TryPickT0(out var result, out _))
{
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
await Response().Error(strs.not_enough(CurrencySign)).SendAsync();
return;
}
@@ -903,15 +922,15 @@ public partial class Gambling : GamblingModule<GamblingService>
sb.AppendLine();
}
var eb = _eb.Create(ctx)
.WithOkColor()
.WithDescription(sb.ToString())
.AddField(GetText(strs.multiplier), $"{result.Multiplier:0.##}x", true)
.AddField(GetText(strs.won), $"{(long)result.Won}", true)
.WithAuthor(ctx.User);
var eb = new EmbedBuilder()
.WithOkColor()
.WithDescription(sb.ToString())
.AddField(GetText(strs.multiplier), $"{result.Multiplier:0.##}x", true)
.AddField(GetText(strs.won), $"{(long)result.Won}", true)
.WithAuthor(ctx.User);
await ctx.Channel.EmbedAsync(eb);
await Response().Embed(eb).SendAsync();
}
@@ -935,8 +954,8 @@ public partial class Gambling : GamblingModule<GamblingService>
var values = Enum.GetValues<GambleTestTarget>()
.Select(x => $"`{x}`")
.Join(", ");
await SendConfirmAsync(GetText(strs.available_tests), values);
await Response().Confirm(GetText(strs.available_tests), values).SendAsync();
}
[Cmd]
@@ -1006,8 +1025,10 @@ public partial class Gambling : GamblingModule<GamblingService>
sb.AppendLine($"Longest win streak: `{maxW}`");
sb.AppendLine($"Longest lose streak: `{maxL}`");
await SendConfirmAsync(GetText(strs.test_results_for(target)),
sb.ToString(),
footer: $"Total Bet: {tests} | Payout: {payout:F0} | {payout * 1.0M / tests * 100}%");
await Response()
.Confirm(GetText(strs.test_results_for(target)),
sb.ToString(),
footer: $"Total Bet: {tests} | Payout: {payout:F0} | {payout * 1.0M / tests * 100}%")
.SendAsync();
}
}

View File

@@ -26,13 +26,13 @@ public abstract class GamblingModule<TService> : NadekoModule<TService>
return false;
if (amount < Config.MinBet)
{
await ReplyErrorLocalizedAsync(strs.min_bet_limit(Format.Bold(Config.MinBet.ToString()) + CurrencySign));
await Response().Error(strs.min_bet_limit(Format.Bold(Config.MinBet.ToString()) + CurrencySign)).SendAsync();
return false;
}
if (Config.MaxBet > 0 && amount > Config.MaxBet)
{
await ReplyErrorLocalizedAsync(strs.max_bet_limit(Format.Bold(Config.MaxBet.ToString()) + CurrencySign));
await Response().Error(strs.max_bet_limit(Format.Bold(Config.MaxBet.ToString()) + CurrencySign)).SendAsync();
return false;
}

View File

@@ -27,7 +27,7 @@ public partial class Gambling
if (picked > 0)
{
var msg = await ReplyConfirmLocalizedAsync(strs.picked(N(picked)));
var msg = await Response().Confirm(strs.picked(N(picked))).SendAsync();
msg.DeleteAfter(10);
}
@@ -66,7 +66,7 @@ public partial class Gambling
pass);
if (!success)
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
await Response().Error(strs.not_enough(CurrencySign)).SendAsync();
}
[Cmd]
@@ -79,9 +79,9 @@ public partial class Gambling
{
var enabled = _service.ToggleCurrencyGeneration(ctx.Guild.Id, ctx.Channel.Id);
if (enabled)
await ReplyConfirmLocalizedAsync(strs.curgen_enabled);
await Response().Confirm(strs.curgen_enabled).SendAsync();
else
await ReplyConfirmLocalizedAsync(strs.curgen_disabled);
await Response().Confirm(strs.curgen_disabled).SendAsync();
}
[Cmd]
@@ -100,9 +100,9 @@ public partial class Gambling
var items = enabledIn.Skip(page * 9).Take(9).ToList();
if (!items.Any())
return _eb.Create().WithErrorColor().WithDescription("-");
return new EmbedBuilder().WithErrorColor().WithDescription("-");
return items.Aggregate(_eb.Create().WithOkColor(),
return items.Aggregate(new EmbedBuilder().WithOkColor(),
(eb, i) => eb.AddField(i.GuildId.ToString(), i.ChannelId));
},
enabledIn.Count(),

View File

@@ -32,25 +32,29 @@ public partial class Gambling
async Task OnEnded(IUser arg, long won)
{
await SendConfirmAsync(GetText(strs.rafflecur_ended(CurrencyName,
Format.Bold(arg.ToString()),
won + CurrencySign)));
await Response()
.Confirm(GetText(strs.rafflecur_ended(CurrencyName,
Format.Bold(arg.ToString()),
won + CurrencySign)))
.SendAsync();
}
var res = await _service.JoinOrCreateGame(ctx.Channel.Id, ctx.User, amount, mixed, OnEnded);
if (res.Item1 is not null)
{
await SendConfirmAsync(GetText(strs.rafflecur(res.Item1.GameType.ToString())),
string.Join("\n", res.Item1.Users.Select(x => $"{x.DiscordUser} ({N(x.Amount)})")),
footer: GetText(strs.rafflecur_joined(ctx.User.ToString())));
await Response()
.Confirm(GetText(strs.rafflecur(res.Item1.GameType.ToString())),
string.Join("\n", res.Item1.Users.Select(x => $"{x.DiscordUser} ({N(x.Amount)})")),
footer: GetText(strs.rafflecur_joined(ctx.User.ToString())))
.SendAsync();
}
else
{
if (res.Item2 == CurrencyRaffleService.JoinErrorType.AlreadyJoinedOrInvalidAmount)
await ReplyErrorLocalizedAsync(strs.rafflecur_already_joined);
await Response().Error(strs.rafflecur_already_joined).SendAsync();
else if (res.Item2 == CurrencyRaffleService.JoinErrorType.NotEnoughCurrency)
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
await Response().Error(strs.not_enough(CurrencySign)).SendAsync();
}
}
}

View File

@@ -54,8 +54,8 @@ public partial class Gambling
var theseEntries = entries.Skip(curPage * 9).Take(9).ToArray();
if (!theseEntries.Any())
return _eb.Create().WithErrorColor().WithDescription(GetText(strs.shop_none));
var embed = _eb.Create().WithOkColor().WithTitle(GetText(strs.shop));
return new EmbedBuilder().WithErrorColor().WithDescription(GetText(strs.shop_none));
var embed = new EmbedBuilder().WithOkColor().WithTitle(GetText(strs.shop));
for (var i = 0; i < theseEntries.Length; i++)
{
@@ -100,7 +100,7 @@ public partial class Gambling
if (entry is null)
{
await ReplyErrorLocalizedAsync(strs.shop_item_not_found);
await Response().Error(strs.shop_item_not_found).SendAsync();
return;
}
@@ -109,14 +109,14 @@ public partial class Gambling
var role = ctx.Guild.GetRole(reqRoleId);
if (role is null)
{
await ReplyErrorLocalizedAsync(strs.shop_item_req_role_not_found);
await Response().Error(strs.shop_item_req_role_not_found).SendAsync();
return;
}
var guser = (IGuildUser)ctx.User;
if (!guser.RoleIds.Contains(reqRoleId))
{
await ReplyErrorLocalizedAsync(strs.shop_item_req_role_unfulfilled(Format.Bold(role.ToString())));
await Response().Error(strs.shop_item_req_role_unfulfilled(Format.Bold(role.ToString()))).SendAsync();
return;
}
}
@@ -128,13 +128,13 @@ public partial class Gambling
if (role is null)
{
await ReplyErrorLocalizedAsync(strs.shop_role_not_found);
await Response().Error(strs.shop_role_not_found).SendAsync();
return;
}
if (guser.RoleIds.Any(id => id == role.Id))
{
await ReplyErrorLocalizedAsync(strs.shop_role_already_bought);
await Response().Error(strs.shop_role_already_bought).SendAsync();
return;
}
@@ -148,18 +148,18 @@ public partial class Gambling
{
Log.Warning(ex, "Error adding shop role");
await _cs.AddAsync(ctx.User.Id, entry.Price, new("shop", "error-refund"));
await ReplyErrorLocalizedAsync(strs.shop_role_purchase_error);
await Response().Error(strs.shop_role_purchase_error).SendAsync();
return;
}
var profit = GetProfitAmount(entry.Price);
await _cs.AddAsync(entry.AuthorId, profit, new("shop", "sell", $"Shop sell item - {entry.Type}"));
await _cs.AddAsync(ctx.Client.CurrentUser.Id, entry.Price - profit, new("shop", "cut"));
await ReplyConfirmLocalizedAsync(strs.shop_role_purchase(Format.Bold(role.Name)));
await Response().Confirm(strs.shop_role_purchase(Format.Bold(role.Name))).SendAsync();
return;
}
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
await Response().Error(strs.not_enough(CurrencySign)).SendAsync();
return;
}
@@ -167,7 +167,7 @@ public partial class Gambling
{
if (entry.Items.Count == 0)
{
await ReplyErrorLocalizedAsync(strs.out_of_stock);
await Response().Error(strs.out_of_stock).SendAsync();
return;
}
@@ -183,7 +183,7 @@ public partial class Gambling
try
{
await ctx.User.EmbedAsync(_eb.Create()
await ctx.User.EmbedAsync(new EmbedBuilder()
.WithOkColor()
.WithTitle(GetText(strs.shop_purchase(ctx.Guild.Name)))
.AddField(GetText(strs.item), item.Text)
@@ -211,14 +211,14 @@ public partial class Gambling
}
}
await ReplyErrorLocalizedAsync(strs.shop_buy_error);
await Response().Error(strs.shop_buy_error).SendAsync();
return;
}
await ReplyConfirmLocalizedAsync(strs.shop_item_purchase);
await Response().Confirm(strs.shop_item_purchase).SendAsync();
}
else
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
await Response().Error(strs.not_enough(CurrencySign)).SendAsync();
}
else if (entry.Type == ShopEntryType.Command)
{
@@ -229,24 +229,24 @@ public partial class Gambling
if (guild is null || channel is null || msg is null || user is null)
{
await ReplyErrorLocalizedAsync(strs.shop_command_invalid_context);
await Response().Error(strs.shop_command_invalid_context).SendAsync();
return;
}
if (!await _cs.RemoveAsync(ctx.User.Id, entry.Price, new("shop", "buy", entry.Type.ToString())))
{
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
await Response().Error(strs.not_enough(CurrencySign)).SendAsync();
return;
}
else
{
var cmd = entry.Command.Replace("%you%", ctx.User.Id.ToString());
var eb = _eb.Create()
var eb = new EmbedBuilder()
.WithPendingColor()
.WithTitle("Executing shop command")
.WithDescription(cmd);
var msgTask = EmbedAsync(eb);
var msgTask = Response().Embed(eb).SendAsync();
await _cs.AddAsync(entry.AuthorId,
GetProfitAmount(entry.Price),
@@ -290,7 +290,7 @@ public partial class Gambling
var entry = await _service.AddShopCommandAsync(ctx.Guild.Id, ctx.User.Id, price, command);
await ctx.Channel.EmbedAsync(EntryToEmbed(entry).WithTitle(GetText(strs.shop_item_add)));
await Response().Embed(EntryToEmbed(entry).WithTitle(GetText(strs.shop_item_add))).SendAsync();
}
[Cmd]
@@ -324,7 +324,7 @@ public partial class Gambling
uow.SaveChanges();
}
await ctx.Channel.EmbedAsync(EntryToEmbed(entry).WithTitle(GetText(strs.shop_item_add)));
await Response().Embed(EntryToEmbed(entry).WithTitle(GetText(strs.shop_item_add))).SendAsync();
}
[Cmd]
@@ -356,7 +356,7 @@ public partial class Gambling
uow.SaveChanges();
}
await ctx.Channel.EmbedAsync(EntryToEmbed(entry).WithTitle(GetText(strs.shop_item_add)));
await Response().Embed(EntryToEmbed(entry).WithTitle(GetText(strs.shop_item_add))).SendAsync();
}
[Cmd]
@@ -392,13 +392,13 @@ public partial class Gambling
}
if (entry is null)
await ReplyErrorLocalizedAsync(strs.shop_item_not_found);
await Response().Error(strs.shop_item_not_found).SendAsync();
else if (!rightType)
await ReplyErrorLocalizedAsync(strs.shop_item_wrong_type);
await Response().Error(strs.shop_item_wrong_type).SendAsync();
else if (added == false)
await ReplyErrorLocalizedAsync(strs.shop_list_item_not_unique);
await Response().Error(strs.shop_list_item_not_unique).SendAsync();
else
await ReplyConfirmLocalizedAsync(strs.shop_list_item_added);
await Response().Confirm(strs.shop_list_item_added).SendAsync();
}
[Cmd]
@@ -426,9 +426,9 @@ public partial class Gambling
}
if (removed is null)
await ReplyErrorLocalizedAsync(strs.shop_item_not_found);
await Response().Error(strs.shop_item_not_found).SendAsync();
else
await ctx.Channel.EmbedAsync(EntryToEmbed(removed).WithTitle(GetText(strs.shop_item_rm)));
await Response().Embed(EntryToEmbed(removed).WithTitle(GetText(strs.shop_item_rm))).SendAsync();
}
[Cmd]
@@ -514,19 +514,19 @@ public partial class Gambling
var succ = await _service.SetItemRoleRequirementAsync(ctx.Guild.Id, itemIndex, role?.Id);
if (!succ)
{
await ReplyErrorLocalizedAsync(strs.shop_item_not_found);
await Response().Error(strs.shop_item_not_found).SendAsync();
return;
}
if (role is null)
await ReplyConfirmLocalizedAsync(strs.shop_item_role_no_req(itemIndex));
await Response().Confirm(strs.shop_item_role_no_req(itemIndex)).SendAsync();
else
await ReplyConfirmLocalizedAsync(strs.shop_item_role_req(itemIndex + 1, role));
await Response().Confirm(strs.shop_item_role_req(itemIndex + 1, role)).SendAsync();
}
public IEmbedBuilder EntryToEmbed(ShopEntry entry)
public EmbedBuilder EntryToEmbed(ShopEntry entry)
{
var embed = _eb.Create().WithOkColor();
var embed = new EmbedBuilder().WithOkColor();
if (entry.Type == ShopEntryType.Role)
{

View File

@@ -59,7 +59,7 @@ public partial class Gambling
if (await InternalSlotAsync(amount) is not SlotResult result)
{
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
await Response().Error(strs.not_enough(CurrencySign)).SendAsync();
return;
}
@@ -69,7 +69,7 @@ public partial class Gambling
await using var imgStream = await image.ToStreamAsync();
var eb = _eb.Create(ctx)
var eb = new EmbedBuilder()
.WithAuthor(ctx.User)
.WithDescription(Format.Bold(text))
.WithImageUrl($"attachment://result.png")

View File

@@ -20,7 +20,7 @@ public partial class Gambling
public async Task WaifuReset()
{
var price = _service.GetResetPrice(ctx.User);
var embed = _eb.Create()
var embed = new EmbedBuilder()
.WithTitle(GetText(strs.waifu_reset_confirm))
.WithDescription(GetText(strs.waifu_reset_price(Format.Bold(N(price)))));
@@ -29,11 +29,11 @@ public partial class Gambling
if (await _service.TryReset(ctx.User))
{
await ReplyConfirmLocalizedAsync(strs.waifu_reset);
await Response().Confirm(strs.waifu_reset).SendAsync();
return;
}
await ReplyErrorLocalizedAsync(strs.waifu_reset_fail);
await Response().Error(strs.waifu_reset_fail).SendAsync();
}
[Cmd]
@@ -42,13 +42,13 @@ public partial class Gambling
{
if (amount < Config.Waifu.MinPrice)
{
await ReplyErrorLocalizedAsync(strs.waifu_isnt_cheap(Config.Waifu.MinPrice + CurrencySign));
await Response().Error(strs.waifu_isnt_cheap(Config.Waifu.MinPrice + CurrencySign)).SendAsync();
return;
}
if (target.Id == ctx.User.Id)
{
await ReplyErrorLocalizedAsync(strs.waifu_not_yourself);
await Response().Error(strs.waifu_not_yourself).SendAsync();
return;
}
@@ -56,14 +56,16 @@ public partial class Gambling
if (result == WaifuClaimResult.InsufficientAmount)
{
await ReplyErrorLocalizedAsync(
strs.waifu_not_enough(N((long)Math.Ceiling(w.Price * (isAffinity ? 0.88f : 1.1f)))));
await Response()
.Error(
strs.waifu_not_enough(N((long)Math.Ceiling(w.Price * (isAffinity ? 0.88f : 1.1f)))))
.SendAsync();
return;
}
if (result == WaifuClaimResult.NotEnoughFunds)
{
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
await Response().Error(strs.not_enough(CurrencySign)).SendAsync();
return;
}
@@ -72,7 +74,7 @@ public partial class Gambling
msg += "\n" + GetText(strs.waifu_fulfilled(target, N(w.Price)));
else
msg = " " + msg;
await SendConfirmAsync(ctx.User.Mention + msg);
await Response().Confirm(ctx.User.Mention + msg).SendAsync();
}
[Cmd]
@@ -82,13 +84,15 @@ public partial class Gambling
{
if (!await _service.WaifuTransfer(ctx.User, waifuId, newOwner))
{
await ReplyErrorLocalizedAsync(strs.waifu_transfer_fail);
await Response().Error(strs.waifu_transfer_fail).SendAsync();
return;
}
await ReplyConfirmLocalizedAsync(strs.waifu_transfer_success(Format.Bold(waifuId.ToString()),
Format.Bold(ctx.User.ToString()),
Format.Bold(newOwner.ToString())));
await Response()
.Confirm(strs.waifu_transfer_success(Format.Bold(waifuId.ToString()),
Format.Bold(ctx.User.ToString()),
Format.Bold(newOwner.ToString())))
.SendAsync();
}
[Cmd]
@@ -98,13 +102,15 @@ public partial class Gambling
{
if (!await _service.WaifuTransfer(ctx.User, waifu.Id, newOwner))
{
await ReplyErrorLocalizedAsync(strs.waifu_transfer_fail);
await Response().Error(strs.waifu_transfer_fail).SendAsync();
return;
}
await ReplyConfirmLocalizedAsync(strs.waifu_transfer_success(Format.Bold(waifu.ToString()),
Format.Bold(ctx.User.ToString()),
Format.Bold(newOwner.ToString())));
await Response()
.Confirm(strs.waifu_transfer_success(Format.Bold(waifu.ToString()),
Format.Bold(ctx.User.ToString()),
Format.Bold(newOwner.ToString())))
.SendAsync();
}
[Cmd]
@@ -114,7 +120,7 @@ public partial class Gambling
{
var waifuUserId = _service.GetWaifuUserId(ctx.User.Id, target);
if (waifuUserId == default)
return ReplyErrorLocalizedAsync(strs.waifu_not_yours);
return Response().Error(strs.waifu_not_yours).SendAsync();
return Divorce(waifuUserId);
}
@@ -137,18 +143,22 @@ public partial class Gambling
if (result == DivorceResult.SucessWithPenalty)
{
await ReplyConfirmLocalizedAsync(strs.waifu_divorced_like(Format.Bold(w.Waifu.ToString()),
N(amount)));
await Response()
.Confirm(strs.waifu_divorced_like(Format.Bold(w.Waifu.ToString()),
N(amount)))
.SendAsync();
}
else if (result == DivorceResult.Success)
await ReplyConfirmLocalizedAsync(strs.waifu_divorced_notlike(N(amount)));
await Response().Confirm(strs.waifu_divorced_notlike(N(amount))).SendAsync();
else if (result == DivorceResult.NotYourWife)
await ReplyErrorLocalizedAsync(strs.waifu_not_yours);
await Response().Error(strs.waifu_not_yours).SendAsync();
else
{
await ReplyErrorLocalizedAsync(strs.waifu_recent_divorce(
Format.Bold(((int)remaining?.TotalHours).ToString()),
Format.Bold(remaining?.Minutes.ToString())));
await Response()
.Error(strs.waifu_recent_divorce(
Format.Bold(((int)remaining?.TotalHours).ToString()),
Format.Bold(remaining?.Minutes.ToString())))
.SendAsync();
}
}
@@ -158,7 +168,7 @@ public partial class Gambling
{
if (user?.Id == ctx.User.Id)
{
await ReplyErrorLocalizedAsync(strs.waifu_egomaniac);
await Response().Error(strs.waifu_egomaniac).SendAsync();
return;
}
@@ -167,24 +177,28 @@ public partial class Gambling
{
if (remaining is not null)
{
await ReplyErrorLocalizedAsync(strs.waifu_affinity_cooldown(
Format.Bold(((int)remaining?.TotalHours).ToString()),
Format.Bold(remaining?.Minutes.ToString())));
await Response()
.Error(strs.waifu_affinity_cooldown(
Format.Bold(((int)remaining?.TotalHours).ToString()),
Format.Bold(remaining?.Minutes.ToString())))
.SendAsync();
}
else
await ReplyErrorLocalizedAsync(strs.waifu_affinity_already);
await Response().Error(strs.waifu_affinity_already).SendAsync();
return;
}
if (user is null)
await ReplyConfirmLocalizedAsync(strs.waifu_affinity_reset);
await Response().Confirm(strs.waifu_affinity_reset).SendAsync();
else if (oldAff is null)
await ReplyConfirmLocalizedAsync(strs.waifu_affinity_set(Format.Bold(user.ToString())));
await Response().Confirm(strs.waifu_affinity_set(Format.Bold(user.ToString()))).SendAsync();
else
{
await ReplyConfirmLocalizedAsync(strs.waifu_affinity_changed(Format.Bold(oldAff.ToString()),
Format.Bold(user.ToString())));
await Response()
.Confirm(strs.waifu_affinity_changed(Format.Bold(oldAff.ToString()),
Format.Bold(user.ToString())))
.SendAsync();
}
}
@@ -204,11 +218,11 @@ public partial class Gambling
if (waifus.Count == 0)
{
await ReplyConfirmLocalizedAsync(strs.waifus_none);
await Response().Confirm(strs.waifus_none).SendAsync();
return;
}
var embed = _eb.Create().WithTitle(GetText(strs.waifus_top_waifus)).WithOkColor();
var embed = new EmbedBuilder().WithTitle(GetText(strs.waifus_top_waifus)).WithOkColor();
var i = 0;
foreach (var w in waifus)
@@ -217,7 +231,7 @@ public partial class Gambling
embed.AddField("#" + ((page * 9) + j + 1) + " - " + N(w.Price), GetLbString(w));
}
await EmbedAsync(embed);
await Response().Embed(embed).SendAsync();
}
private string GetLbString(WaifuLbResult w)
@@ -284,15 +298,15 @@ public partial class Gambling
var fansList = await _service.GetFansNames(wi.WaifuId);
var fansStr = fansList
.Shuffle()
.Take(30)
.Select((x) => claimsNames.Contains(x) ? $"{x} 💞" : x)
.Join('\n');
.Shuffle()
.Take(30)
.Select((x) => claimsNames.Contains(x) ? $"{x} 💞" : x)
.Join('\n');
if (string.IsNullOrWhiteSpace(fansStr))
fansStr = "-";
var embed = _eb.Create()
var embed = new EmbedBuilder()
.WithOkColor()
.WithTitle(GetText(strs.waifu)
+ " "
@@ -312,7 +326,7 @@ public partial class Gambling
true)
.AddField(GetText(strs.gifts), itemsStr, true);
await ctx.Channel.EmbedAsync(embed);
await Response().Embed(embed).SendAsync();
}
[Cmd]
@@ -327,7 +341,7 @@ public partial class Gambling
await ctx.SendPaginatedConfirmAsync(page,
cur =>
{
var embed = _eb.Create().WithTitle(GetText(strs.waifu_gift_shop)).WithOkColor();
var embed = new EmbedBuilder().WithTitle(GetText(strs.waifu_gift_shop)).WithOkColor();
waifuItems.OrderBy(x => x.Negative)
.ThenBy(x => x.Price)
@@ -357,7 +371,7 @@ public partial class Gambling
var item = allItems.FirstOrDefault(x => x.Name.ToLowerInvariant() == itemName.ToLowerInvariant());
if (item is null)
{
await ReplyErrorLocalizedAsync(strs.waifu_gift_not_exist);
await Response().Error(strs.waifu_gift_not_exist).SendAsync();
return;
}
@@ -365,11 +379,13 @@ public partial class Gambling
if (sucess)
{
await ReplyConfirmLocalizedAsync(strs.waifu_gift(Format.Bold(item + " " + item.ItemEmoji),
Format.Bold(waifu.ToString())));
await Response()
.Confirm(strs.waifu_gift(Format.Bold(item + " " + item.ItemEmoji),
Format.Bold(waifu.ToString())))
.SendAsync();
}
else
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
await Response().Error(strs.not_enough(CurrencySign)).SendAsync();
}
}
}
}