- Added NadekoBot.Generators projects which will contain source generators

- Implemented initial version of the response strings source generator
  - Creates a class with property names equivalent to key names in responses.en-US.json
  - Each Property has struct type (with generic type parameters matching the number of string format placeholders) for type safe GetText implementation
  - Struct types are readonly refs as they should be ephermal, and only used to pass string keys to GetText
This commit is contained in:
Kwoth
2021-07-23 19:01:26 +02:00
parent e67f659a8a
commit 34d0f66466
10 changed files with 211 additions and 13 deletions

View File

@@ -31,6 +31,9 @@ namespace NadekoBot.Modules
protected string GetText(string key) =>
Strings.GetText(key, _cultureInfo);
protected string GetText(in LocStr key) =>
Strings.GetText(key.Key, _cultureInfo);
protected string GetText(string key, params object[] args) =>
Strings.GetText(key, _cultureInfo, args);

View File

@@ -51,7 +51,7 @@ namespace NadekoBot.Modules.Games
await ctx.Channel.EmbedAsync(_eb.Create().WithOkColor()
.WithDescription(ctx.User.ToString())
.AddField("❓ " + GetText("question"), question, false)
.AddField("🎱 " + GetText("8ball"), res, false));
.AddField("🎱 " + GetText("_8ball"), res, false));
}
[NadekoCommand, Aliases]

View File

@@ -532,7 +532,7 @@ namespace NadekoBot.Modules.Searches
var embed = _eb.Create()
.WithDescription(ctx.User.Mention)
.AddField(GetText("word"), data.Word, true)
.AddField(GetText("class"), data.WordType, true)
.AddField(GetText("_class"), data.WordType, true)
.AddField(GetText("definition"), data.Definition)
.WithOkColor();

View File

@@ -190,13 +190,13 @@ namespace NadekoBot.Modules.Utility
string description = "";
if (_service.IsNoRedundant(runner.Repeater.Id))
{
description = Format.Underline(Format.Bold(GetText("no_redundant:"))) + "\n\n";
description = Format.Underline(Format.Bold(GetText("no_redundant"))) + "\n\n";
}
description += $"<#{runner.Repeater.ChannelId}>\n" +
$"`{GetText("interval:")}` {intervalString}\n" +
$"`{GetText("executes_in:")}` {executesInString}\n" +
$"`{GetText("message:")}` {message}";
$"`{GetText("Comment")}` {intervalString}\n" +
$"`{GetText("executes_in_colon")}` {executesInString}\n" +
$"`{GetText("message_colon")}` {message}";
return description;
}

View File

@@ -249,7 +249,7 @@ namespace NadekoBot.Modules.Utility
.WithAuthor($"NadekoBot v{StatsService.BotVersion}",
"https://nadeko-pictures.nyc3.digitaloceanspaces.com/other/avatar.png",
"https://nadekobot.readthedocs.io/en/latest/")
.AddField(GetText("author"), _stats.Author, true)
.AddField(GetText(Strs.author), _stats.Author, true)
.AddField(GetText("botid"), _client.CurrentUser.Id.ToString(), true)
.AddField(GetText("shard"), $"#{_client.ShardId} / {_creds.TotalShards}", true)
.AddField(GetText("commands_ran"), _stats.CommandsRan.ToString(), true)

View File

@@ -58,8 +58,12 @@
<ItemGroup>
<ProjectReference Include="..\ayu\Ayu.Discord.Voice\Ayu.Discord.Voice.csproj" />
<ProjectReference Include="..\NadekoBot.Generators\NadekoBot.Generators.csproj" OutputItemType="Analyzer" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="data\strings\responses\responses.en-US.json" />
</ItemGroup>
<ItemGroup>
<Protobuf Include="..\NadekoBot.Coordinator\Protos\coordinator.proto" GrpcServices="Client">
<Link>Protos\coordinator.proto</Link>

View File

@@ -323,7 +323,7 @@
"waifu_reset_fail": "Failed resetting waifu stats. Make sure you have enough currency.",
"waifu_reset_confirm": "This will reset your waifu stats",
"waifu_reset_price": "Price: {0}",
"8ball": "8ball",
"_8ball": "8ball",
"acrophobia": "Acrophobia",
"acro_ended_no_sub": "Game ended with no submissions.",
"acro_no_votes_cast": "No votes cast. Game ended with no winner.",
@@ -508,7 +508,7 @@
"cost": "Cost",
"date": "Date",
"word": "Word",
"class": "Class",
"_class": "Class",
"definition": "Definition",
"example": "Example",
"dropped": "Dropped",
@@ -629,10 +629,10 @@
"repeater_removed": "Repeater #{0} Removed",
"repeater_exceed_limit": "You cannot have more than {0} repeaters per server.",
"repeater_remove_fail": "Failed removing repeater on that index. Either you've specified invalid index, or repeater was in executing state at that time, in which case, try again in a few seconds.",
"interval:": "Interval:",
"executes_in:": "Executes in:",
"message:": "Message:",
"no_redundant:": "Won't post duplicate message.",
"interval_colon": "Interval:",
"executes_in_colon": "Executes in:",
"message_colon": "Message:",
"no_redundant": "Won't post duplicate message.",
"name": "Name",
"nickname": "Nickname",
"nobody_playing_game": "Nobody is playing that game.",