WIP: rework of localized strings, instead of generic LocStr, LocStr is now a struct which contains both the key, and the values which should be put into the value's placeholders. strs' properties are now methods which take values as arguments, and properties if they don't

This commit is contained in:
Kwoth
2021-07-26 20:08:02 +02:00
parent 9d375dccee
commit 0115d35247
46 changed files with 176 additions and 273 deletions

View File

@@ -77,13 +77,13 @@ namespace NadekoBot.Modules.Gambling
if (race.FinishedUsers[0].Bet > 0)
{
return SendConfirmAsync(GetText(strs.animal_race),
GetText(strs.animal_race_won_money, Format.Bold(winner.Username),
GetText(strs.animal_race_won_money(Format.Bold(winner.Username)),
winner.Animal.Icon, (race.FinishedUsers[0].Bet * (race.Users.Count - 1)) + CurrencySign));
}
else
{
return SendConfirmAsync(GetText(strs.animal_race),
GetText(strs.animal_race_won, Format.Bold(winner.Username), winner.Animal.Icon));
GetText(strs.animal_race_won(Format.Bold(winner.Username), winner.Animal.Icon)));
}
}
@@ -93,8 +93,8 @@ namespace NadekoBot.Modules.Gambling
ar.OnStarted += Ar_OnStarted;
_client.MessageReceived += _client_MessageReceived;
return SendConfirmAsync(GetText(strs.animal_race), GetText(strs.animal_race_starting, options.StartTime),
footer: GetText(strs.animal_race_join_instr, Prefix));
return SendConfirmAsync(GetText(strs.animal_race), GetText(strs.animal_race_starting(options.StartTime)),
footer: GetText(strs.animal_race_join_instr(Prefix)));
}
private Task Ar_OnStarted(AnimalRace race)
@@ -102,7 +102,7 @@ namespace NadekoBot.Modules.Gambling
if (race.Users.Count == race.MaxUsers)
return SendConfirmAsync(GetText(strs.animal_race), GetText(strs.animal_race_full));
else
return SendConfirmAsync(GetText(strs.animal_race), GetText(strs.animal_race_starting_with_x, race.Users.Count));
return SendConfirmAsync(GetText(strs.animal_race), GetText(strs.animal_race_starting_with_x(race.Users.Count)));
}
private async Task Ar_OnStateUpdate(AnimalRace race)
@@ -153,9 +153,9 @@ namespace NadekoBot.Modules.Gambling
var user = await ar.JoinRace(ctx.User.Id, ctx.User.ToString(), amount)
.ConfigureAwait(false);
if (amount > 0)
await SendConfirmAsync(GetText(strs.animal_race_join_bet, ctx.User.Mention, user.Animal.Icon, amount + CurrencySign)).ConfigureAwait(false);
await SendConfirmAsync(GetText(strs.animal_race_join_bet(ctx.User.Mention, user.Animal.Icon, amount + CurrencySign)).ConfigureAwait(false));
else
await SendConfirmAsync(GetText(strs.animal_race_join, ctx.User.Mention, user.Animal.Icon)).ConfigureAwait(false);
await SendConfirmAsync(GetText(strs.animal_race_join(ctx.User.Mention, user.Animal.Icon)).ConfigureAwait(false));
}
catch (ArgumentOutOfRangeException)
{
@@ -176,7 +176,7 @@ namespace NadekoBot.Modules.Gambling
}
catch (NotEnoughFundsException)
{
await SendErrorAsync(GetText(strs.not_enough, CurrencySign)).ConfigureAwait(false);
await SendErrorAsync(GetText(strs.not_enough(CurrencySign)).ConfigureAwait(false));
}
}
}

View File

@@ -129,11 +129,11 @@ namespace NadekoBot.Modules.Gambling
string title;
if (result == Connect4Game.Result.CurrentPlayerWon)
{
title = GetText(strs.connect4_won, Format.Bold(arg.CurrentPlayer.Username), Format.Bold(arg.OtherPlayer.Username));
title = GetText(strs.connect4_won(Format.Bold(arg.CurrentPlayer.Username), Format.Bold(arg.OtherPlayer.Username)));
}
else if (result == Connect4Game.Result.OtherPlayerWon)
{
title = GetText(strs.connect4_won, Format.Bold(arg.OtherPlayer.Username), Format.Bold(arg.CurrentPlayer.Username));
title = GetText(strs.connect4_won(Format.Bold(arg.OtherPlayer.Username), Format.Bold(arg.CurrentPlayer.Username)));
}
else
title = GetText(strs.connect4_draw);
@@ -180,7 +180,7 @@ namespace NadekoBot.Modules.Gambling
if (game.CurrentPhase == Connect4Game.Phase.P1Move ||
game.CurrentPhase == Connect4Game.Phase.P2Move)
sb.AppendLine(GetText(strs.connect4_player_to_move, Format.Bold(game.CurrentPlayer.Username)));
sb.AppendLine(GetText(strs.connect4_player_to_move(Format.Bold(game.CurrentPlayer.Username))));
for (int i = Connect4Game.NumberOfRows; i > 0; i--)
{

View File

@@ -52,15 +52,15 @@ namespace NadekoBot.Modules.Gambling
case CurrencyEvent.Type.Reaction:
return _eb.Create()
.WithOkColor()
.WithTitle(GetText(strs.event_title, type.ToString()))
.WithTitle(GetText(strs.event_title(type.ToString())))
.WithDescription(GetReactionDescription(opts.Amount, currentPot))
.WithFooter(GetText(strs.event_duration_footer, opts.Hours));
.WithFooter(GetText(strs.event_duration_footer(opts.Hours)));
case CurrencyEvent.Type.GameStatus:
return _eb.Create()
.WithOkColor()
.WithTitle(GetText(strs.event_title, type.ToString()))
.WithTitle(GetText(strs.event_title(type.ToString())))
.WithDescription(GetGameStatusDescription(opts.Amount, currentPot))
.WithFooter(GetText(strs.event_duration_footer, opts.Hours));
.WithFooter(GetText(strs.event_duration_footer(opts.Hours)));
default:
break;
}

View File

@@ -35,7 +35,7 @@ namespace NadekoBot.Modules.Gambling
return;
async Task OnEnded(IUser arg, long won)
{
await SendConfirmAsync(GetText(strs.rafflecur_ended, CurrencyName, Format.Bold(arg.ToString()), won + CurrencySign)).ConfigureAwait(false);
await SendConfirmAsync(GetText(strs.rafflecur_ended(CurrencyName, Format.Bold(arg.ToString()), won + CurrencySign)).ConfigureAwait(false));
}
var res = await _service.JoinOrCreateGame(ctx.Channel.Id,
ctx.User, amount, mixed, OnEnded)
@@ -43,9 +43,9 @@ namespace NadekoBot.Modules.Gambling
if (res.Item1 != null)
{
await SendConfirmAsync(GetText(strs.rafflecur, res.Item1.GameType.ToString()),
await SendConfirmAsync(GetText(strs.rafflecur(res.Item1.GameType.ToString())),
string.Join("\n", res.Item1.Users.Select(x => $"{x.DiscordUser} ({x.Amount})")),
footer: GetText(strs.rafflecur_joined, ctx.User.ToString())).ConfigureAwait(false);
footer: GetText(strs.rafflecur_joined(ctx.User.ToString())).ConfigureAwait(false));
}
else
{

View File

@@ -47,7 +47,7 @@ namespace NadekoBot.Modules.Gambling
{
await ctx.Channel.SendFileAsync(ms,
$"dice.{format.FileExtensions.First()}",
Format.Bold(ctx.User.ToString()) + " " + GetText(strs.dice_rolled, Format.Code(gen.ToString()))).ConfigureAwait(false);
Format.Bold(ctx.User.ToString()) + " " + GetText(strs.dice_rolled(Format.Code(gen.ToString()))).ConfigureAwait(false));
}
}
@@ -128,7 +128,7 @@ namespace NadekoBot.Modules.Gambling
await ctx.Channel.SendFileAsync(ms, $"dice.{format.FileExtensions.First()}",
Format.Bold(ctx.User.ToString()) + " " +
GetText(strs.dice_rolled_num, Format.Bold(values.Count.ToString())) +
GetText(strs.dice_rolled_num(Format.Bold(values.Count.ToString()))) +
" " + GetText(strs.total_average,
Format.Bold(values.Sum().ToString()),
Format.Bold((values.Sum() / (1.0f * values.Count)).ToString("N2")))).ConfigureAwait(false);
@@ -152,7 +152,7 @@ namespace NadekoBot.Modules.Gambling
}
var embed = _eb.Create()
.WithOkColor()
.WithDescription(ctx.User.Mention + " " + GetText(strs.dice_rolled_num, Format.Bold(n1.ToString())))
.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);
@@ -177,7 +177,7 @@ namespace NadekoBot.Modules.Gambling
var sum = arr.Sum();
var embed = _eb.Create().WithOkColor()
.WithDescription(ctx.User.Mention + " " + GetText(strs.dice_rolled_num, n1) + $"`1 - {n2}`")
.WithDescription(ctx.User.Mention + " " + GetText(strs.dice_rolled_num(n1) + $"`1 - {n2}`"))
.AddField(Format.Bold("Rolls"), string.Join(" ",
(ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x =>
Format.Code(x.ToString()))))

View File

@@ -66,7 +66,7 @@ namespace NadekoBot.Modules.Gambling
toSend += $" drew `{Deck.GetHandValue(cardObjects)}`";
if (guildId != null)
toSend += "\n" + GetText(strs.cards_left, Format.Bold(cards.CardPool.Count.ToString()));
toSend += "\n" + GetText(strs.cards_left(Format.Bold(cards.CardPool.Count.ToString())));
return (img.ToStream(), toSend);
}

View File

@@ -67,7 +67,7 @@ namespace NadekoBot.Modules.Gambling
i.Dispose();
}
var msg = count != 1
? Format.Bold(ctx.User.ToString()) + " " + GetText(strs.flip_results, count, headCount, tailCount)
? Format.Bold(ctx.User.ToString()) + " " + GetText(strs.flip_results(count, headCount, tailCount))
: Format.Bold(ctx.User.ToString()) + " " + GetText(strs.flipped, headCount > 0
? Format.Bold(GetText(strs.heads))
: Format.Bold(GetText(strs.tails)));
@@ -115,7 +115,7 @@ namespace NadekoBot.Modules.Gambling
if (guess == result)
{
var toWin = (long)(amount * _config.BetFlip.Multiplier);
str = Format.Bold(ctx.User.ToString()) + " " + GetText(strs.flip_guess, toWin + CurrencySign);
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);
}
else

View File

@@ -209,7 +209,7 @@ namespace NadekoBot.Modules.Gambling
}
embed.WithDescription(desc);
embed.WithFooter(GetText(strs.page, page + 1));
embed.WithFooter(GetText(strs.page(page + 1)));
await ctx.Channel.EmbedAsync(embed).ConfigureAwait(false);
}
@@ -476,7 +476,7 @@ namespace NadekoBot.Modules.Gambling
var result = br.Roll();
var str = Format.Bold(ctx.User.ToString()) + Format.Code(GetText(strs.roll, result.Roll));
var str = Format.Bold(ctx.User.ToString()) + Format.Code(GetText(strs.roll(result.Roll)));
if (result.Multiplier > 0)
{
var win = (long)(amount * result.Multiplier);
@@ -641,7 +641,7 @@ namespace NadekoBot.Modules.Gambling
await _cs.AddAsync(ctx.User.Id,
"Rps-draw", amount, gamble: true).ConfigureAwait(false);
embed.WithOkColor();
msg = GetText(strs.rps_draw, getRpsPick(pick));
msg = GetText(strs.rps_draw(getRpsPick(pick)));
}
else if ((pick == RpsPick.Paper && nadekoPick == RpsPick.Rock) ||
(pick == RpsPick.Rock && nadekoPick == RpsPick.Scissors) ||
@@ -659,7 +659,7 @@ namespace NadekoBot.Modules.Gambling
{
embed.WithErrorColor();
amount = 0;
msg = GetText(strs.rps_win, ctx.Client.CurrentUser.Mention, getRpsPick(nadekoPick),
msg = GetText(strs.rps_win(ctx.Client.CurrentUser.Mention, getRpsPick(nadekoPick)),
getRpsPick(pick));
}

View File

@@ -173,7 +173,7 @@ namespace NadekoBot.Modules.Gambling
{
await (await ctx.User.GetOrCreateDMChannelAsync().ConfigureAwait(false))
.EmbedAsync(_eb.Create().WithOkColor()
.WithTitle(GetText(strs.shop_purchase, ctx.Guild.Name))
.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))
@@ -433,7 +433,7 @@ namespace NadekoBot.Modules.Gambling
var embed = _eb.Create().WithOkColor();
if (entry.Type == ShopEntryType.Role)
return embed.AddField(GetText(strs.name), GetText(strs.shop_role, Format.Bold(ctx.Guild.GetRole(entry.RoleId)?.Name ?? "MISSING_ROLE")), true)
return embed.AddField(GetText(strs.name), GetText(strs.shop_role(Format.Bold(ctx.Guild.GetRole(entry.RoleId)?.Name ?? "MISSING_ROLE")), true))
.AddField(GetText(strs.price), entry.Price.ToString(), true)
.AddField(GetText(strs.type), entry.Type.ToString(), true);
else if (entry.Type == ShopEntryType.List)
@@ -441,7 +441,7 @@ namespace NadekoBot.Modules.Gambling
.AddField(GetText(strs.price), entry.Price.ToString(), true)
.AddField(GetText(strs.type), GetText(strs.random_unique_item), true);
//else if (entry.Type == ShopEntryType.Infinite_List)
// return embed.AddField(GetText(strs.name), GetText(strs.shop_role, Format.Bold(entry.RoleName)), true)
// return embed.AddField(GetText(strs.name), GetText(strs.shop_role(Format.Bold(entry.RoleName)), true))
// .AddField(GetText(strs.price), entry.Price.ToString(), true)
// .AddField(GetText(strs.type), entry.Type.ToString(), true);
else return null;
@@ -451,11 +451,11 @@ namespace NadekoBot.Modules.Gambling
{
if (entry.Type == ShopEntryType.Role)
{
return GetText(strs.shop_role, Format.Bold(ctx.Guild.GetRole(entry.RoleId)?.Name ?? "MISSING_ROLE"));
return GetText(strs.shop_role(Format.Bold(ctx.Guild.GetRole(entry.RoleId)?.Name ?? "MISSING_ROLE")));
}
else if (entry.Type == ShopEntryType.List)
{
return GetText(strs.unique_items_left, entry.Items.Count) + "\n" + entry.Name;
return GetText(strs.unique_items_left(entry.Items.Count)) + "\n" + entry.Name;
}
//else if (entry.Type == ShopEntryType.Infinite_List)
//{

View File

@@ -203,13 +203,13 @@ namespace NadekoBot.Modules.Gambling
await _cs.AddAsync(ctx.User, $"Slot Machine x{result.Multiplier}", amount * result.Multiplier, false, gamble: true).ConfigureAwait(false);
Interlocked.Add(ref _totalPaidOut, amount * result.Multiplier);
if (result.Multiplier == 1)
msg = GetText(strs.slot_single, CurrencySign, 1);
msg = GetText(strs.slot_single(CurrencySign, 1));
else if (result.Multiplier == 4)
msg = GetText(strs.slot_two, CurrencySign, 4);
msg = GetText(strs.slot_two(CurrencySign, 4));
else if (result.Multiplier == 10)
msg = GetText(strs.slot_three, 10);
msg = GetText(strs.slot_three(10));
else if (result.Multiplier == 30)
msg = GetText(strs.slot_jackpot, 30);
msg = GetText(strs.slot_jackpot(30));
}
using (var imgStream = bgImage.ToStream())

View File

@@ -27,7 +27,7 @@ namespace NadekoBot.Modules.Gambling
var price = _service.GetResetPrice(ctx.User);
var embed = _eb.Create()
.WithTitle(GetText(strs.waifu_reset_confirm))
.WithDescription(GetText(strs.waifu_reset_price, Format.Bold(price + CurrencySign)));
.WithDescription(GetText(strs.waifu_reset_price(Format.Bold(price + CurrencySign))));
if (!await PromptUserConfirmAsync(embed))
return;
@@ -72,7 +72,7 @@ namespace NadekoBot.Modules.Gambling
Format.Bold(target.ToString()),
amount + CurrencySign);
if (w.Affinity?.UserId == ctx.User.Id)
msg += "\n" + GetText(strs.waifu_fulfilled, target, w.Price + CurrencySign);
msg += "\n" + GetText(strs.waifu_fulfilled(target, w.Price + CurrencySign));
else
msg = " " + msg;
await SendConfirmAsync(ctx.User.Mention + msg);
@@ -292,7 +292,7 @@ namespace NadekoBot.Modules.Gambling
.AddField(GetText(strs.changes_of_heart), $"{wi.AffinityCount} - \"the {affInfo}\"", true)
.AddField(GetText(strs.divorces), wi.DivorceCount.ToString(), true)
.AddField("\u200B", "\u200B", true)
.AddField(GetText(strs.fans, wi.Fans.Count), fansStr, true)
.AddField(GetText(strs.fans(wi.Fans.Count), fansStr, true))
.AddField($"Waifus ({wi.ClaimCount})", wi.ClaimCount == 0
? nobody
: string.Join("\n", wi.Claims.Shuffle().Take(30)), true)