mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 01:38:27 -04:00
Second iteration of source generated localized strings
- Strs renamed to strs - Generic params will now default to object instead of string for convenient argument passing - Many strings changed to use generated properties
This commit is contained in:
@@ -72,8 +72,14 @@ namespace NadekoBot.Modules.Games.Common
|
||||
_moveLock = new SemaphoreSlim(1, 1);
|
||||
}
|
||||
|
||||
private string GetText(string key, params object[] replacements)
|
||||
=> _strings.GetText(key, _channel.GuildId, replacements);
|
||||
private string GetText(LocStr key)
|
||||
=> _strings.GetText(key, _channel.GuildId);
|
||||
|
||||
private string GetText<T>(LocStr<T> key, T param)
|
||||
=> _strings.GetText(key, _channel.GuildId, param);
|
||||
|
||||
private string GetText<T1, T2>(LocStr<T1, T2> key, T1 param, T2 param2)
|
||||
=> _strings.GetText(key, _channel.GuildId, param, param2);
|
||||
|
||||
public string GetState()
|
||||
{
|
||||
@@ -98,7 +104,7 @@ namespace NadekoBot.Modules.Games.Common
|
||||
var embed = _eb.Create()
|
||||
.WithOkColor()
|
||||
.WithDescription(Environment.NewLine + GetState())
|
||||
.WithAuthor(GetText("vs", _users[0], _users[1]));
|
||||
.WithAuthor(GetText(strs.vs, _users[0], _users[1]));
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(title))
|
||||
embed.WithTitle(title);
|
||||
@@ -106,7 +112,7 @@ namespace NadekoBot.Modules.Games.Common
|
||||
if (_winner is null)
|
||||
{
|
||||
if (_phase == Phase.Ended)
|
||||
embed.WithFooter(GetText("ttt_no_moves"));
|
||||
embed.WithFooter(GetText(strs.ttt_no_moves));
|
||||
else
|
||||
embed.WithFooter(GetText("ttt_users_move", _users[_curUserIndex]));
|
||||
}
|
||||
@@ -137,12 +143,12 @@ namespace NadekoBot.Modules.Games.Common
|
||||
{
|
||||
if (_phase == Phase.Started || _phase == Phase.Ended)
|
||||
{
|
||||
await _channel.SendErrorAsync(_eb, user.Mention + GetText("ttt_already_running")).ConfigureAwait(false);
|
||||
await _channel.SendErrorAsync(_eb, user.Mention + GetText(strs.ttt_already_running)).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
else if (_users[0] == user)
|
||||
{
|
||||
await _channel.SendErrorAsync(_eb, user.Mention + GetText("ttt_against_yourself")).ConfigureAwait(false);
|
||||
await _channel.SendErrorAsync(_eb, user.Mention + GetText(strs.ttt_against_yourself)).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -165,7 +171,7 @@ namespace NadekoBot.Modules.Games.Common
|
||||
var del = _previousMessage?.DeleteAsync();
|
||||
try
|
||||
{
|
||||
await _channel.EmbedAsync(GetEmbed(GetText("ttt_time_expired"))).ConfigureAwait(false);
|
||||
await _channel.EmbedAsync(GetEmbed(GetText(strs.ttt_time_expired))).ConfigureAwait(false);
|
||||
if (del != null)
|
||||
await del.ConfigureAwait(false);
|
||||
}
|
||||
@@ -184,7 +190,7 @@ namespace NadekoBot.Modules.Games.Common
|
||||
_client.MessageReceived += Client_MessageReceived;
|
||||
|
||||
|
||||
_previousMessage = await _channel.EmbedAsync(GetEmbed(GetText("game_started"))).ConfigureAwait(false);
|
||||
_previousMessage = await _channel.EmbedAsync(GetEmbed(GetText(strs.game_started))).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private bool IsDraw()
|
||||
@@ -255,14 +261,14 @@ namespace NadekoBot.Modules.Games.Common
|
||||
|
||||
if (_phase == Phase.Ended) // if user won, stop receiving moves
|
||||
{
|
||||
reason = GetText("ttt_matched_three");
|
||||
reason = GetText(strs.ttt_matched_three);
|
||||
_winner = _users[_curUserIndex];
|
||||
_client.MessageReceived -= Client_MessageReceived;
|
||||
OnEnded?.Invoke(this);
|
||||
}
|
||||
else if (IsDraw())
|
||||
{
|
||||
reason = GetText("ttt_a_draw");
|
||||
reason = GetText(strs.ttt_a_draw);
|
||||
_phase = Phase.Ended;
|
||||
_client.MessageReceived -= Client_MessageReceived;
|
||||
OnEnded?.Invoke(this);
|
||||
|
@@ -62,8 +62,14 @@ namespace NadekoBot.Modules.Games.Common.Trivia
|
||||
Channel = channel;
|
||||
}
|
||||
|
||||
private string GetText(string key, params object[] replacements)
|
||||
=> _strings.GetText(key, Channel.GuildId, replacements);
|
||||
private string GetText(in LocStr key)
|
||||
=> _strings.GetText(key, Channel.GuildId);
|
||||
|
||||
private string GetText<T>(in LocStr<T> key, T param1)
|
||||
=> _strings.GetText(key, Channel.GuildId, param1);
|
||||
|
||||
private string GetText<T1, T2>(in LocStr<T1, T2> key, T1 param1, T2 param2)
|
||||
=> _strings.GetText(key, Channel.GuildId, param1, param2);
|
||||
|
||||
public async Task StartGame()
|
||||
{
|
||||
@@ -78,7 +84,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
|
||||
CurrentQuestion = _questionPool.GetRandomQuestion(OldQuestions, _options.IsPokemon);
|
||||
if (string.IsNullOrWhiteSpace(CurrentQuestion?.Answer) || string.IsNullOrWhiteSpace(CurrentQuestion.Question))
|
||||
{
|
||||
await Channel.SendErrorAsync(_eb, GetText("trivia_game"), GetText("failed_loading_question")).ConfigureAwait(false);
|
||||
await Channel.SendErrorAsync(_eb, GetText(strs.trivia_game), GetText(strs.failed_loading_question)).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
OldQuestions.Add(CurrentQuestion); //add it to exclusion list so it doesn't show up again
|
||||
@@ -88,12 +94,12 @@ namespace NadekoBot.Modules.Games.Common.Trivia
|
||||
try
|
||||
{
|
||||
questionEmbed = _eb.Create().WithOkColor()
|
||||
.WithTitle(GetText("trivia_game"))
|
||||
.AddField(GetText("category"), CurrentQuestion.Category)
|
||||
.AddField(GetText("question"), CurrentQuestion.Question);
|
||||
.WithTitle(GetText(strs.trivia_game))
|
||||
.AddField(GetText(strs.category), CurrentQuestion.Category)
|
||||
.AddField(GetText(strs.question), CurrentQuestion.Question);
|
||||
|
||||
if (showHowToQuit)
|
||||
questionEmbed.WithFooter(GetText("trivia_quit", _quitCommand));
|
||||
questionEmbed.WithFooter(GetText(strs.trivia_quit, _quitCommand));
|
||||
|
||||
if (Uri.IsWellFormedUriString(CurrentQuestion.ImageUrl, UriKind.Absolute))
|
||||
questionEmbed.WithImageUrl(CurrentQuestion.ImageUrl);
|
||||
@@ -152,8 +158,8 @@ namespace NadekoBot.Modules.Games.Common.Trivia
|
||||
try
|
||||
{
|
||||
var embed = _eb.Create().WithErrorColor()
|
||||
.WithTitle(GetText("trivia_game"))
|
||||
.WithDescription(GetText("trivia_times_up", Format.Bold(CurrentQuestion.Answer)));
|
||||
.WithTitle(GetText(strs.trivia_game))
|
||||
.WithDescription(GetText(strs.trivia_times_up, Format.Bold(CurrentQuestion.Answer)));
|
||||
if (Uri.IsWellFormedUriString(CurrentQuestion.AnswerImageUrl, UriKind.Absolute))
|
||||
embed.WithImageUrl(CurrentQuestion.AnswerImageUrl);
|
||||
|
||||
@@ -190,8 +196,8 @@ namespace NadekoBot.Modules.Games.Common.Trivia
|
||||
try
|
||||
{
|
||||
await Channel.SendConfirmAsync(_eb,
|
||||
GetText("trivia_game"),
|
||||
GetText("trivia_stopping"));
|
||||
GetText(strs.trivia_game),
|
||||
GetText(strs.trivia_stopping));
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -239,7 +245,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
|
||||
try
|
||||
{
|
||||
var embedS = _eb.Create().WithOkColor()
|
||||
.WithTitle(GetText("trivia_game"))
|
||||
.WithTitle(GetText(strs.trivia_game))
|
||||
.WithDescription(GetText("trivia_win",
|
||||
guildUser.Mention,
|
||||
Format.Bold(CurrentQuestion.Answer)));
|
||||
@@ -257,7 +263,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
|
||||
return;
|
||||
}
|
||||
var embed = _eb.Create().WithOkColor()
|
||||
.WithTitle(GetText("trivia_game"))
|
||||
.WithTitle(GetText(strs.trivia_game))
|
||||
.WithDescription(GetText("trivia_guess", guildUser.Mention, Format.Bold(CurrentQuestion.Answer)));
|
||||
if (Uri.IsWellFormedUriString(CurrentQuestion.AnswerImageUrl, UriKind.Absolute))
|
||||
embed.WithImageUrl(CurrentQuestion.AnswerImageUrl);
|
||||
@@ -271,7 +277,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
|
||||
public string GetLeaderboard()
|
||||
{
|
||||
if (Users.Count == 0)
|
||||
return GetText("no_results");
|
||||
return GetText(strs.no_results);
|
||||
|
||||
var sb = new StringBuilder();
|
||||
|
||||
|
Reference in New Issue
Block a user