From 90af781c7ba5f484ba34ef714c84aab1d455f9d2 Mon Sep 17 00:00:00 2001 From: runebaas Date: Fri, 14 Aug 2020 03:30:54 +0200 Subject: [PATCH 1/4] Start Using resource files (.resx) for translations. Create GeekbotCommandBase to reduce command boilerplate. Convert admin, choose, cookies, karma, quote, rank, roll and ship to the new localization method. --- src/Bot/Bot.csproj | 88 ++++++++++ src/Bot/Commands/Admin/Admin.cs | 71 +++++--- src/Bot/Commands/Games/Roll/Roll.cs | 23 ++- src/Bot/Commands/Randomness/Ship.cs | 29 ++-- src/Bot/Commands/Rpg/Cookies.cs | 38 ++--- src/Bot/Commands/User/Karma.cs | 47 +++--- src/Bot/Commands/User/Ranking/Rank.cs | 40 ++--- src/Bot/Commands/Utils/Choose.cs | 15 +- src/Bot/Commands/Utils/Quote/Quote.cs | 61 +++---- src/Bot/Localization/Admin.Designer.cs | 81 ++++++++++ src/Bot/Localization/Admin.de-ch.resx | 20 +++ src/Bot/Localization/Admin.resx | 27 ++++ src/Bot/Localization/Choose.Designer.cs | 72 +++++++++ src/Bot/Localization/Choose.de-ch.resx | 17 ++ src/Bot/Localization/Choose.resx | 24 +++ src/Bot/Localization/Cookies.Designer.cs | 126 +++++++++++++++ src/Bot/Localization/Cookies.de-ch.resx | 35 ++++ src/Bot/Localization/Cookies.resx | 42 +++++ src/Bot/Localization/Internal.Designer.cs | 126 +++++++++++++++ src/Bot/Localization/Internal.de-ch.resx | 35 ++++ src/Bot/Localization/Internal.resx | 42 +++++ src/Bot/Localization/Karma.Designer.cs | 135 ++++++++++++++++ src/Bot/Localization/Karma.de-ch.resx | 38 +++++ src/Bot/Localization/Karma.resx | 45 ++++++ src/Bot/Localization/Quote.Designer.cs | 162 +++++++++++++++++++ src/Bot/Localization/Quote.de-ch.resx | 47 ++++++ src/Bot/Localization/Quote.resx | 54 +++++++ src/Bot/Localization/Rank.Designer.cs | 108 +++++++++++++ src/Bot/Localization/Rank.de-ch.resx | 29 ++++ src/Bot/Localization/Rank.resx | 36 +++++ src/Bot/Localization/Roll.Designer.cs | 99 ++++++++++++ src/Bot/Localization/Roll.de-ch.resx | 26 +++ src/Bot/Localization/Roll.resx | 33 ++++ src/Bot/Localization/Ship.Designer.cs | 117 ++++++++++++++ src/Bot/Localization/Ship.de-ch.resx | 32 ++++ src/Bot/Localization/Ship.resx | 39 +++++ src/Core/GeekbotCommandBase.cs | 27 ++++ src/Core/Localization/ITranslationHandler.cs | 1 + src/Core/Localization/TranslationHandler.cs | 16 +- src/Core/Localization/Translations.yml | 159 +----------------- 40 files changed, 1935 insertions(+), 327 deletions(-) create mode 100644 src/Bot/Localization/Admin.Designer.cs create mode 100644 src/Bot/Localization/Admin.de-ch.resx create mode 100644 src/Bot/Localization/Admin.resx create mode 100644 src/Bot/Localization/Choose.Designer.cs create mode 100644 src/Bot/Localization/Choose.de-ch.resx create mode 100644 src/Bot/Localization/Choose.resx create mode 100644 src/Bot/Localization/Cookies.Designer.cs create mode 100644 src/Bot/Localization/Cookies.de-ch.resx create mode 100644 src/Bot/Localization/Cookies.resx create mode 100644 src/Bot/Localization/Internal.Designer.cs create mode 100644 src/Bot/Localization/Internal.de-ch.resx create mode 100644 src/Bot/Localization/Internal.resx create mode 100644 src/Bot/Localization/Karma.Designer.cs create mode 100644 src/Bot/Localization/Karma.de-ch.resx create mode 100644 src/Bot/Localization/Karma.resx create mode 100644 src/Bot/Localization/Quote.Designer.cs create mode 100644 src/Bot/Localization/Quote.de-ch.resx create mode 100644 src/Bot/Localization/Quote.resx create mode 100644 src/Bot/Localization/Rank.Designer.cs create mode 100644 src/Bot/Localization/Rank.de-ch.resx create mode 100644 src/Bot/Localization/Rank.resx create mode 100644 src/Bot/Localization/Roll.Designer.cs create mode 100644 src/Bot/Localization/Roll.de-ch.resx create mode 100644 src/Bot/Localization/Roll.resx create mode 100644 src/Bot/Localization/Ship.Designer.cs create mode 100644 src/Bot/Localization/Ship.de-ch.resx create mode 100644 src/Bot/Localization/Ship.resx create mode 100644 src/Core/GeekbotCommandBase.cs diff --git a/src/Bot/Bot.csproj b/src/Bot/Bot.csproj index c7889ae..601766a 100644 --- a/src/Bot/Bot.csproj +++ b/src/Bot/Bot.csproj @@ -40,4 +40,92 @@ + + + ResXFileCodeGenerator + Ship.Designer.cs + + + ResXFileCodeGenerator + Rank.Designer.cs + + + ResXFileCodeGenerator + Karma.Designer.cs + + + ResXFileCodeGenerator + Internal.Designer.cs + + + ResXFileCodeGenerator + Cookies.Designer.cs + + + ResXFileCodeGenerator + Roll.Designer.cs + + + ResXFileCodeGenerator + Choose.Designer.cs + + + ResXFileCodeGenerator + Admin.Designer.cs + + + ResXFileCodeGenerator + Quote.Designer.cs + + + + + True + True + ship.resx + + + True + True + Rank.resx + + + Ship.resx + + + True + True + Karma.resx + + + True + True + Internal.resx + + + True + True + Cookies.resx + + + True + True + Roll.resx + + + True + True + Choose.resx + + + True + True + Admin.resx + + + True + True + Quote.resx + + diff --git a/src/Bot/Commands/Admin/Admin.cs b/src/Bot/Commands/Admin/Admin.cs index f6c4210..2627f86 100644 --- a/src/Bot/Commands/Admin/Admin.cs +++ b/src/Bot/Commands/Admin/Admin.cs @@ -1,9 +1,15 @@ using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Resources; using System.Text; +using System.Threading; using System.Threading.Tasks; using Discord; using Discord.Commands; using Discord.WebSocket; +using Geekbot.Core; using Geekbot.Core.CommandPreconditions; using Geekbot.Core.ErrorHandling; using Geekbot.Core.Extensions; @@ -15,19 +21,15 @@ namespace Geekbot.Bot.Commands.Admin [Group("admin")] [RequireUserPermission(GuildPermission.Administrator)] [DisableInDirectMessage] - public class Admin : ModuleBase + public class Admin : GeekbotCommandBase { private readonly DiscordSocketClient _client; - private readonly IErrorHandler _errorHandler; private readonly IGuildSettingsManager _guildSettingsManager; - private readonly ITranslationHandler _translation; - public Admin(DiscordSocketClient client, IErrorHandler errorHandler, IGuildSettingsManager guildSettingsManager, ITranslationHandler translationHandler) + public Admin(DiscordSocketClient client, IErrorHandler errorHandler, IGuildSettingsManager guildSettingsManager, ITranslationHandler translationHandler) : base(errorHandler, translationHandler) { _client = client; - _errorHandler = errorHandler; _guildSettingsManager = guildSettingsManager; - _translation = translationHandler; } [Command("welcome", RunMode = RunMode.Async)] @@ -60,7 +62,7 @@ namespace Geekbot.Bot.Commands.Admin } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context, "That channel doesn't seem to exist or i don't have write permissions"); + await ErrorHandler.HandleCommandException(e, Context, "That channel doesn't seem to exist or i don't have write permissions"); } } @@ -84,7 +86,7 @@ namespace Geekbot.Bot.Commands.Admin } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context, "That channel doesn't seem to exist or i don't have write permissions"); + await ErrorHandler.HandleCommandException(e, Context, "That channel doesn't seem to exist or i don't have write permissions"); } } @@ -107,7 +109,7 @@ namespace Geekbot.Bot.Commands.Admin } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } @@ -130,7 +132,7 @@ namespace Geekbot.Bot.Commands.Admin } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } @@ -141,24 +143,30 @@ namespace Geekbot.Bot.Commands.Admin try { var language = languageRaw.ToUpper(); - var success = await _translation.SetLanguage(Context.Guild.Id, language); + var success = await Translations.SetLanguage(Context.Guild.Id, language); if (success) { var guild = _guildSettingsManager.GetSettings(Context.Guild.Id); guild.Language = language; await _guildSettingsManager.UpdateSettings(guild); - var transContext = await _translation.GetGuildContext(Context); - await ReplyAsync(transContext.GetString("NewLanguageSet")); + if (language.ToLower() == "chde") + { + Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de-ch"); + } + + await ReplyAsync(Localization.Admin.NewLanguageSet); return; } - await ReplyAsync( - $"That doesn't seem to be a supported language\r\nSupported Languages are {string.Join(", ", _translation.SupportedLanguages)}"); + var available = new List(); + available.Add("en-GB"); // default + available.AddRange(GetAvailableCultures().Select(culture => culture.Name)); + await ReplyAsync($"That doesn't seem to be a supported language\nSupported Languages are {string.Join(", ", available)}"); } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } @@ -177,7 +185,7 @@ namespace Geekbot.Bot.Commands.Admin } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } @@ -194,7 +202,7 @@ namespace Geekbot.Bot.Commands.Admin } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } @@ -211,7 +219,7 @@ namespace Geekbot.Bot.Commands.Admin } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } @@ -230,5 +238,30 @@ namespace Geekbot.Bot.Commands.Admin return null; } } + + private IEnumerable GetAvailableCultures() + { + var result = new List(); + var rm = new ResourceManager(typeof(Localization.Admin)); + var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures); + foreach (var culture in cultures) + { + try + { + if (culture.Equals(CultureInfo.InvariantCulture)) continue; //do not use "==", won't work + + var rs = rm.GetResourceSet(culture, true, false); + if (rs != null) + { + result.Add(culture); + } + } + catch (CultureNotFoundException) + { + //NOP + } + } + return result; + } } } \ No newline at end of file diff --git a/src/Bot/Commands/Games/Roll/Roll.cs b/src/Bot/Commands/Games/Roll/Roll.cs index 6241ba1..244edbe 100644 --- a/src/Bot/Commands/Games/Roll/Roll.cs +++ b/src/Bot/Commands/Games/Roll/Roll.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Threading.Tasks; using Discord.Commands; +using Geekbot.Core; using Geekbot.Core.Database; using Geekbot.Core.Database.Models; using Geekbot.Core.ErrorHandling; @@ -12,21 +13,17 @@ using Geekbot.Core.RandomNumberGenerator; namespace Geekbot.Bot.Commands.Games.Roll { - public class Roll : ModuleBase + public class Roll : GeekbotCommandBase { - private readonly IErrorHandler _errorHandler; private readonly IKvInMemoryStore _kvInMemoryStore; - private readonly ITranslationHandler _translation; private readonly DatabaseContext _database; private readonly IRandomNumberGenerator _randomNumberGenerator; - public Roll(IKvInMemoryStore kvInMemoryStore,IErrorHandler errorHandler, ITranslationHandler translation, DatabaseContext database, IRandomNumberGenerator randomNumberGenerator) + public Roll(IKvInMemoryStore kvInMemoryStore,IErrorHandler errorHandler, ITranslationHandler translation, DatabaseContext database, IRandomNumberGenerator randomNumberGenerator) : base(errorHandler, translation) { _kvInMemoryStore = kvInMemoryStore; - _translation = translation; _database = database; _randomNumberGenerator = randomNumberGenerator; - _errorHandler = errorHandler; } [Command("roll", RunMode = RunMode.Async)] @@ -37,7 +34,7 @@ namespace Geekbot.Bot.Commands.Games.Roll { var number = _randomNumberGenerator.Next(1, 100); int.TryParse(stuff, out var guess); - var transContext = await _translation.GetGuildContext(Context); + var transContext = await Translations.GetGuildContext(Context); if (guess <= 100 && guess > 0) { var kvKey = $"{Context.Guild.Id}:{Context.User.Id}:RollsPrevious"; @@ -46,8 +43,8 @@ namespace Geekbot.Bot.Commands.Games.Roll if (prevRoll?.LastGuess == guess && prevRoll?.GuessedOn.AddDays(1) > DateTime.Now) { - await ReplyAsync(transContext.GetString( - "NoPrevGuess", + await ReplyAsync(string.Format( + Localization.Roll.NoPrevGuess, Context.Message.Author.Mention, transContext.FormatDateTimeAsRemaining(prevRoll.GuessedOn.AddDays(1)))); return; @@ -55,10 +52,10 @@ namespace Geekbot.Bot.Commands.Games.Roll _kvInMemoryStore.Set(kvKey, new RollTimeout { LastGuess = guess, GuessedOn = DateTime.Now }); - await ReplyAsync(transContext.GetString("Rolled", Context.Message.Author.Mention, number, guess)); + await ReplyAsync(string.Format(Localization.Roll.Rolled, Context.Message.Author.Mention, number, guess)); if (guess == number) { - await ReplyAsync(transContext.GetString("Gratz", Context.Message.Author)); + await ReplyAsync(string.Format(Localization.Roll.Gratz, Context.Message.Author)); var user = await GetUser(Context.User.Id); user.Rolls += 1; _database.Rolls.Update(user); @@ -67,12 +64,12 @@ namespace Geekbot.Bot.Commands.Games.Roll } else { - await ReplyAsync(transContext.GetString("RolledNoGuess", Context.Message.Author.Mention, number)); + await ReplyAsync(string.Format(Localization.Roll.RolledNoGuess, Context.Message.Author.Mention, number)); } } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } diff --git a/src/Bot/Commands/Randomness/Ship.cs b/src/Bot/Commands/Randomness/Ship.cs index d5d9eea..78f3c99 100644 --- a/src/Bot/Commands/Randomness/Ship.cs +++ b/src/Bot/Commands/Randomness/Ship.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading.Tasks; using Discord; using Discord.Commands; +using Geekbot.Core; using Geekbot.Core.Database; using Geekbot.Core.Database.Models; using Geekbot.Core.ErrorHandling; @@ -12,19 +13,15 @@ using Geekbot.Core.RandomNumberGenerator; namespace Geekbot.Bot.Commands.Randomness { - public class Ship : ModuleBase + public class Ship : GeekbotCommandBase { - private readonly IErrorHandler _errorHandler; private readonly IRandomNumberGenerator _randomNumberGenerator; - private readonly ITranslationHandler _translation; private readonly DatabaseContext _database; - public Ship(DatabaseContext database, IErrorHandler errorHandler, IRandomNumberGenerator randomNumberGenerator, ITranslationHandler translation) + public Ship(DatabaseContext database, IErrorHandler errorHandler, IRandomNumberGenerator randomNumberGenerator, ITranslationHandler translations) : base(errorHandler, translations) { _database = database; - _errorHandler = errorHandler; _randomNumberGenerator = randomNumberGenerator; - _translation = translation; } [Command("Ship", RunMode = RunMode.Async)] @@ -58,28 +55,26 @@ namespace Geekbot.Bot.Commands.Randomness shippingRate = dbval.Strength; } - var transContext = await _translation.GetGuildContext(Context); - - var reply = $":heartpulse: **{transContext.GetString("Matchmaking")}** :heartpulse:\r\n"; + var reply = $":heartpulse: **{Localization.Ship.Matchmaking}** :heartpulse:\r\n"; reply += $":two_hearts: {user1.Mention} :heart: {user2.Mention} :two_hearts:\r\n"; - reply += $"0% [{BlockCounter(shippingRate)}] 100% - {DeterminateSuccess(shippingRate, transContext)}"; + reply += $"0% [{BlockCounter(shippingRate)}] 100% - {DeterminateSuccess(shippingRate)}"; await ReplyAsync(reply); } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } - private string DeterminateSuccess(int rate, TranslationGuildContext transContext) + private string DeterminateSuccess(int rate) { return (rate / 20) switch { - 0 => transContext.GetString("NotGonnaToHappen"), - 1 => transContext.GetString("NotSuchAGoodIdea"), - 2 => transContext.GetString("ThereMightBeAChance"), - 3 => transContext.GetString("CouldWork"), - 4 => transContext.GetString("ItsAMatch"), + 0 => Localization.Ship.NotGoingToHappen, + 1 => Localization.Ship.NotSuchAGoodIdea, + 2 => Localization.Ship.ThereMightBeAChance, + 3 => Localization.Ship.CouldWork, + 4 => Localization.Ship.ItsAMatch, _ => "nope" }; } diff --git a/src/Bot/Commands/Rpg/Cookies.cs b/src/Bot/Commands/Rpg/Cookies.cs index f581105..570f08a 100644 --- a/src/Bot/Commands/Rpg/Cookies.cs +++ b/src/Bot/Commands/Rpg/Cookies.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading.Tasks; using Discord; using Discord.Commands; +using Geekbot.Core; using Geekbot.Core.CommandPreconditions; using Geekbot.Core.Database; using Geekbot.Core.Database.Models; @@ -16,18 +17,14 @@ namespace Geekbot.Bot.Commands.Rpg [DisableInDirectMessage] [Group("cookies")] [Alias("cookie")] - public class Cookies : ModuleBase + public class Cookies : GeekbotCommandBase { private readonly DatabaseContext _database; - private readonly IErrorHandler _errorHandler; - private readonly ITranslationHandler _translation; private readonly IRandomNumberGenerator _randomNumberGenerator; - public Cookies(DatabaseContext database, IErrorHandler errorHandler, ITranslationHandler translation , IRandomNumberGenerator randomNumberGenerator) + public Cookies(DatabaseContext database, IErrorHandler errorHandler, ITranslationHandler translations , IRandomNumberGenerator randomNumberGenerator) : base(errorHandler, translations) { _database = database; - _errorHandler = errorHandler; - _translation = translation; _randomNumberGenerator = randomNumberGenerator; } @@ -37,23 +34,23 @@ namespace Geekbot.Bot.Commands.Rpg { try { - var transContext = await _translation.GetGuildContext(Context); + var transContext = await Translations.GetGuildContext(Context); var actor = await GetUser(Context.User.Id); if (actor.LastPayout.Value.AddDays(1).Date > DateTime.Now.Date) { var formatedWaitTime = transContext.FormatDateTimeAsRemaining(DateTimeOffset.Now.AddDays(1).Date); - await ReplyAsync(transContext.GetString("WaitForMoreCookies", formatedWaitTime)); + await ReplyAsync(string.Format(Localization.Cookies.WaitForMoreCookies, formatedWaitTime)); return; } actor.Cookies += 10; actor.LastPayout = DateTimeOffset.Now; await SetUser(actor); - await ReplyAsync(transContext.GetString("GetCookies", 10, actor.Cookies)); + await ReplyAsync(string.Format(Localization.Cookies.GetCookies, 10, actor.Cookies)); } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } @@ -63,13 +60,12 @@ namespace Geekbot.Bot.Commands.Rpg { try { - var transContext = await _translation.GetGuildContext(Context); var actor = await GetUser(Context.User.Id); - await ReplyAsync(transContext.GetString("InYourJar", actor.Cookies)); + await ReplyAsync(string.Format(Localization.Cookies.InYourJar, actor.Cookies)); } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } @@ -79,12 +75,11 @@ namespace Geekbot.Bot.Commands.Rpg { try { - var transContext = await _translation.GetGuildContext(Context); var giver = await GetUser(Context.User.Id); if (giver.Cookies < amount) { - await ReplyAsync(transContext.GetString("NotEnoughToGive")); + await ReplyAsync(Localization.Cookies.NotEnoughToGive); return; } @@ -96,11 +91,11 @@ namespace Geekbot.Bot.Commands.Rpg await SetUser(giver); await SetUser(taker); - await ReplyAsync(transContext.GetString("Given", amount, user.Username)); + await ReplyAsync(string.Format(Localization.Cookies.Given, amount, user.Username)); } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } @@ -110,12 +105,11 @@ namespace Geekbot.Bot.Commands.Rpg { try { - var transContext = await _translation.GetGuildContext(Context); var actor = await GetUser(Context.User.Id); if (actor.Cookies < 5) { - await ReplyAsync(transContext.GetString("NotEnoughCookiesToEat")); + await ReplyAsync(Localization.Cookies.NotEnoughCookiesToEat); return; } @@ -124,14 +118,14 @@ namespace Geekbot.Bot.Commands.Rpg await SetUser(actor); - await ReplyAsync(transContext.GetString("AteCookies", amount, actor.Cookies)); + await ReplyAsync(string.Format(Localization.Cookies.AteCookies, amount, actor.Cookies)); } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } - + private async Task GetUser(ulong userId) { var user = _database.Cookies.FirstOrDefault(u =>u.GuildId.Equals(Context.Guild.Id.AsLong()) && u.UserId.Equals(userId.AsLong())) ?? await CreateNewRow(userId); diff --git a/src/Bot/Commands/User/Karma.cs b/src/Bot/Commands/User/Karma.cs index 3efc381..41a401c 100644 --- a/src/Bot/Commands/User/Karma.cs +++ b/src/Bot/Commands/User/Karma.cs @@ -1,8 +1,11 @@ using System; +using System.Globalization; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Discord; using Discord.Commands; +using Geekbot.Core; using Geekbot.Core.CommandPreconditions; using Geekbot.Core.Database; using Geekbot.Core.Database.Models; @@ -13,17 +16,15 @@ using Geekbot.Core.Localization; namespace Geekbot.Bot.Commands.User { [DisableInDirectMessage] - public class Karma : ModuleBase + public class Karma : GeekbotCommandBase { - private readonly IErrorHandler _errorHandler; private readonly DatabaseContext _database; - private readonly ITranslationHandler _translation; + private readonly ITranslationHandler _translations; - public Karma(DatabaseContext database, IErrorHandler errorHandler, ITranslationHandler translation) + public Karma(DatabaseContext database, IErrorHandler errorHandler, ITranslationHandler translations) : base(errorHandler, translations) { _database = database; - _errorHandler = errorHandler; - _translation = translation; + _translations = translations; } [Command("good", RunMode = RunMode.Async)] @@ -32,16 +33,17 @@ namespace Geekbot.Bot.Commands.User { try { - var transContext = await _translation.GetGuildContext(Context); + var transContext = await _translations.GetGuildContext(Context); + var actor = await GetUser(Context.User.Id); if (user.Id == Context.User.Id) { - await ReplyAsync(transContext.GetString("CannotChangeOwn", Context.User.Username)); + await ReplyAsync(string.Format(Localization.Karma.CannotChangeOwnUp, Context.User.Username)); } else if (TimeoutFinished(actor.TimeOut)) { var formatedWaitTime = transContext.FormatDateTimeAsRemaining(actor.TimeOut.AddMinutes(3)); - await ReplyAsync(transContext.GetString("WaitUntill", Context.User.Username, formatedWaitTime)); + await ReplyAsync(string.Format(Localization.Karma.WaitUntill, Context.User.Username, formatedWaitTime)); } else { @@ -60,16 +62,16 @@ namespace Geekbot.Bot.Commands.User .WithName(user.Username)); eb.WithColor(new Color(138, 219, 146)); - eb.Title = transContext.GetString("Increased"); - eb.AddInlineField(transContext.GetString("By"), Context.User.Username); - eb.AddInlineField(transContext.GetString("Amount"), "+1"); - eb.AddInlineField(transContext.GetString("Current"), target.Karma); + eb.Title = Localization.Karma.Increased; + eb.AddInlineField(Localization.Karma.By, Context.User.Username); + eb.AddInlineField(Localization.Karma.Amount, "+1"); + eb.AddInlineField(Localization.Karma.Current, target.Karma); await ReplyAsync("", false, eb.Build()); } } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } @@ -79,16 +81,17 @@ namespace Geekbot.Bot.Commands.User { try { - var transContext = await _translation.GetGuildContext(Context); + var transContext = await _translations.GetGuildContext(Context); + var actor = await GetUser(Context.User.Id); if (user.Id == Context.User.Id) { - await ReplyAsync(transContext.GetString("CannotChangeOwn", Context.User.Username)); + await ReplyAsync(string.Format(Localization.Karma.CannotChangeOwnDown, Context.User.Username)); } else if (TimeoutFinished(actor.TimeOut)) { var formatedWaitTime = transContext.FormatDateTimeAsRemaining(actor.TimeOut.AddMinutes(3)); - await ReplyAsync(transContext.GetString("WaitUntill", Context.User.Username, formatedWaitTime)); + await ReplyAsync(string.Format(Localization.Karma.WaitUntill, Context.User.Username, formatedWaitTime)); } else { @@ -107,16 +110,16 @@ namespace Geekbot.Bot.Commands.User .WithName(user.Username)); eb.WithColor(new Color(138, 219, 146)); - eb.Title = transContext.GetString("Decreased"); - eb.AddInlineField(transContext.GetString("By"), Context.User.Username); - eb.AddInlineField(transContext.GetString("Amount"), "-1"); - eb.AddInlineField(transContext.GetString("Current"), target.Karma); + eb.Title = Localization.Karma.Decreased; + eb.AddInlineField(Localization.Karma.By, Context.User.Username); + eb.AddInlineField(Localization.Karma.Amount, "-1"); + eb.AddInlineField(Localization.Karma.Current, target.Karma); await ReplyAsync("", false, eb.Build()); } } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } diff --git a/src/Bot/Commands/User/Ranking/Rank.cs b/src/Bot/Commands/User/Ranking/Rank.cs index ae1bec9..d73aacc 100644 --- a/src/Bot/Commands/User/Ranking/Rank.cs +++ b/src/Bot/Commands/User/Ranking/Rank.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Discord.Commands; +using Geekbot.Core; using Geekbot.Core.CommandPreconditions; using Geekbot.Core.Converters; using Geekbot.Core.Database; @@ -11,28 +12,20 @@ using Geekbot.Core.ErrorHandling; using Geekbot.Core.Extensions; using Geekbot.Core.Highscores; using Geekbot.Core.Localization; -using Geekbot.Core.UserRepository; namespace Geekbot.Bot.Commands.User.Ranking { - public class Rank : ModuleBase + public class Rank : GeekbotCommandBase { private readonly IEmojiConverter _emojiConverter; private readonly IHighscoreManager _highscoreManager; - private readonly ITranslationHandler _translationHandler; - private readonly IErrorHandler _errorHandler; private readonly DatabaseContext _database; - private readonly IUserRepository _userRepository; - public Rank(DatabaseContext database, IErrorHandler errorHandler, IUserRepository userRepository, - IEmojiConverter emojiConverter, IHighscoreManager highscoreManager, ITranslationHandler translationHandler) + public Rank(DatabaseContext database, IErrorHandler errorHandler, IEmojiConverter emojiConverter, IHighscoreManager highscoreManager, ITranslationHandler translations): base(errorHandler, translations) { _database = database; - _errorHandler = errorHandler; - _userRepository = userRepository; _emojiConverter = emojiConverter; _highscoreManager = highscoreManager; - _translationHandler = translationHandler; } [Command("rank", RunMode = RunMode.Async)] @@ -42,7 +35,6 @@ namespace Geekbot.Bot.Commands.User.Ranking { try { - var transContext = await _translationHandler.GetGuildContext(Context); HighscoreTypes type; try { @@ -51,14 +43,14 @@ namespace Geekbot.Bot.Commands.User.Ranking } catch { - await ReplyAsync(transContext.GetString("InvalidType")); + await ReplyAsync(Localization.Rank.InvalidType); return; } var replyBuilder = new StringBuilder(); if (amount > 20) { - await ReplyAsync(transContext.GetString("LimitingTo20Warning")); + await ReplyAsync(Localization.Rank.LimitingTo20Warning); amount = 20; } @@ -70,7 +62,7 @@ namespace Geekbot.Bot.Commands.User.Ranking } catch (HighscoreListEmptyException) { - await ReplyAsync(transContext.GetString("NoTypeFoundForServer", type)); + await ReplyAsync(string.Format(Localization.Rank.NoTypeFoundForServer, type)); return; } @@ -85,22 +77,24 @@ namespace Geekbot.Bot.Commands.User.Ranking var failedToRetrieveUser = highscoreUsers.Any(e => string.IsNullOrEmpty(e.Key.Username)); - if (failedToRetrieveUser) replyBuilder.AppendLine(transContext.GetString("FailedToResolveAllUsernames")); - replyBuilder.AppendLine(transContext.GetString("HighscoresFor", type.ToString().CapitalizeFirst(), Context.Guild.Name)); + if (failedToRetrieveUser) replyBuilder.AppendLine(Localization.Rank.FailedToResolveAllUsernames).AppendLine(); + + replyBuilder.AppendLine(string.Format(Localization.Rank.HighscoresFor, type.ToString().CapitalizeFirst(), Context.Guild.Name)); + var highscorePlace = 1; - foreach (var user in highscoreUsers) + foreach (var (user, value) in highscoreUsers) { replyBuilder.Append(highscorePlace < 11 ? $"{_emojiConverter.NumberToEmoji(highscorePlace)} " : $"`{highscorePlace}.` "); - replyBuilder.Append(user.Key.Username != null - ? $"**{user.Key.Username}#{user.Key.Discriminator}**" - : $"**{user.Key.Id}**"); + replyBuilder.Append(user.Username != null + ? $"**{user.Username}#{user.Discriminator}**" + : $"**{user.Id}**"); replyBuilder.Append(type == HighscoreTypes.messages - ? $" - {user.Value} {type} - {Math.Round((double) (100 * user.Value) / guildMessages, 2)}%\n" - : $" - {user.Value} {type}\n"); + ? $" - {value} {type} - {Math.Round((double) (100 * value) / guildMessages, 2)}%\n" + : $" - {value} {type}\n"); highscorePlace++; } @@ -109,7 +103,7 @@ namespace Geekbot.Bot.Commands.User.Ranking } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } } diff --git a/src/Bot/Commands/Utils/Choose.cs b/src/Bot/Commands/Utils/Choose.cs index d245bd2..ea239d7 100644 --- a/src/Bot/Commands/Utils/Choose.cs +++ b/src/Bot/Commands/Utils/Choose.cs @@ -1,20 +1,16 @@ using System; using System.Threading.Tasks; using Discord.Commands; +using Geekbot.Core; using Geekbot.Core.ErrorHandling; using Geekbot.Core.Localization; namespace Geekbot.Bot.Commands.Utils { - public class Choose : ModuleBase + public class Choose : GeekbotCommandBase { - private readonly IErrorHandler _errorHandler; - private readonly ITranslationHandler _translation; - - public Choose(IErrorHandler errorHandler, ITranslationHandler translation) + public Choose(IErrorHandler errorHandler, ITranslationHandler translation) : base(errorHandler, translation) { - _errorHandler = errorHandler; - _translation = translation; } [Command("choose", RunMode = RunMode.Async)] @@ -24,14 +20,13 @@ namespace Geekbot.Bot.Commands.Utils { try { - var transContext = await _translation.GetGuildContext(Context); var choicesArray = choices.Split(';'); var choice = new Random().Next(choicesArray.Length); - await ReplyAsync(transContext.GetString("Choice", choicesArray[choice].Trim())); + await ReplyAsync(string.Format(Localization.Choose.Choice, choicesArray[choice].Trim())); } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } } diff --git a/src/Bot/Commands/Utils/Quote/Quote.cs b/src/Bot/Commands/Utils/Quote/Quote.cs index a731273..5bb23a9 100644 --- a/src/Bot/Commands/Utils/Quote/Quote.cs +++ b/src/Bot/Commands/Utils/Quote/Quote.cs @@ -17,20 +17,16 @@ namespace Geekbot.Bot.Commands.Utils.Quote { [Group("quote")] [DisableInDirectMessage] - public class Quote : ModuleBase + public class Quote : GeekbotCommandBase { - private readonly IErrorHandler _errorHandler; private readonly DatabaseContext _database; private readonly IRandomNumberGenerator _randomNumberGenerator; - private readonly ITranslationHandler _translationHandler; private readonly bool _isDev; - public Quote(IErrorHandler errorHandler, DatabaseContext database, IRandomNumberGenerator randomNumberGenerator, ITranslationHandler translationHandler) + public Quote(IErrorHandler errorHandler, DatabaseContext database, IRandomNumberGenerator randomNumberGenerator, ITranslationHandler translationHandler) : base(errorHandler, translationHandler) { - _errorHandler = errorHandler; _database = database; _randomNumberGenerator = randomNumberGenerator; - _translationHandler = translationHandler; // to remove restrictions when developing _isDev = Constants.BotVersion() == "0.0.0-DEV"; } @@ -45,8 +41,7 @@ namespace Geekbot.Bot.Commands.Utils.Quote if (!s.Any()) { - var transContext = await _translationHandler.GetGuildContext(Context); - await ReplyAsync(transContext.GetString("NoQuotesFound")); + await ReplyAsync(Localization.Quote.NoQuotesFound); return; } @@ -58,7 +53,7 @@ namespace Geekbot.Bot.Commands.Utils.Quote } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context, "Whoops, seems like the quote was to edgy to return"); + await ErrorHandler.HandleCommandException(e, Context, "Whoops, seems like the quote was to edgy to return"); } } @@ -117,23 +112,22 @@ namespace Geekbot.Bot.Commands.Utils.Quote { try { - var transContext = await _translationHandler.GetGuildContext(Context); var quote = _database.Quotes.Where(e => e.GuildId == Context.Guild.Id.AsLong() && e.InternalId == id)?.FirstOrDefault(); if (quote != null) { _database.Quotes.Remove(quote); await _database.SaveChangesAsync(); var embed = QuoteBuilder(quote); - await ReplyAsync(transContext.GetString("Removed", id), false, embed.Build()); + await ReplyAsync(string.Format(Localization.Quote.Removed, id), false, embed.Build()); } else { - await ReplyAsync(transContext.GetString("NotFoundWithId")); + await ReplyAsync(Localization.Quote.NotFoundWithId); } } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context, "I couldn't find a quote with that id :disappointed:"); + await ErrorHandler.HandleCommandException(e, Context, "I couldn't find a quote with that id :disappointed:"); } } @@ -144,12 +138,11 @@ namespace Geekbot.Bot.Commands.Utils.Quote try { // setup - var transContext = await _translationHandler.GetGuildContext(Context); var eb = new EmbedBuilder(); eb.Author = new EmbedAuthorBuilder() { IconUrl = Context.Guild.IconUrl, - Name = $"{Context.Guild.Name} - {transContext.GetString("QuoteStats")}" + Name = $"{Context.Guild.Name} - {Localization.Quote.QuoteStats}" }; // gather data @@ -157,7 +150,7 @@ namespace Geekbot.Bot.Commands.Utils.Quote if (totalQuotes == 0) { // no quotes, no stats, end of the road - await ReplyAsync(transContext.GetString("NoQuotesFound")); + await ReplyAsync(Localization.Quote.NoQuotesFound); return; } @@ -176,8 +169,8 @@ namespace Geekbot.Bot.Commands.Utils.Quote .OrderBy(row => row.year); // add data to the embed - eb.AddField(transContext.GetString("MostQuotesPerson"), $"{mostQuotedPersonUser.Username} ({mostQuotedPerson.amount})"); - eb.AddInlineField(transContext.GetString("TotalQuotes"), totalQuotes); + eb.AddField(Localization.Quote.MostQuotesPerson, $"{mostQuotedPersonUser.Username} ({mostQuotedPerson.amount})"); + eb.AddInlineField(Localization.Quote.TotalQuotes, totalQuotes); foreach (var year in quotesByYear) { @@ -188,7 +181,7 @@ namespace Geekbot.Bot.Commands.Utils.Quote } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } @@ -196,8 +189,6 @@ namespace Geekbot.Bot.Commands.Utils.Quote { try { - var transContext = await _translationHandler.GetGuildContext(Context); - var list = Context.Channel.GetMessagesAsync().Flatten(); var message = await list.FirstOrDefaultAsync(msg => msg.Author.Id == user.Id && @@ -206,11 +197,11 @@ namespace Geekbot.Bot.Commands.Utils.Quote !msg.Content.ToLower().StartsWith("!")); if (message == null) return; - await ProcessQuote(message, saveToDb, transContext); + await ProcessQuote(message, saveToDb); } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context, $"No quoteable messages have been sent by {user.Username} in this channel"); + await ErrorHandler.HandleCommandException(e, Context, $"No quoteable messages have been sent by {user.Username} in this channel"); } } @@ -219,14 +210,14 @@ namespace Geekbot.Bot.Commands.Utils.Quote { try { - var transContext = await _translationHandler.GetGuildContext(Context); + // var transContext = await _translationHandler.GetGuildContext(Context); var message = await Context.Channel.GetMessageAsync(messageId); - await ProcessQuote(message, saveToDb, transContext); + await ProcessQuote(message, saveToDb); } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context, "I couldn't find a message with that id :disappointed:"); + await ErrorHandler.HandleCommandException(e, Context, "I couldn't find a message with that id :disappointed:"); } } @@ -234,18 +225,18 @@ namespace Geekbot.Bot.Commands.Utils.Quote { try { - var transContext = await _translationHandler.GetGuildContext(Context); + // var transContext = await _translationHandler.GetGuildContext(Context); if (!MessageLink.IsValid(messageLink)) { - await ReplyAsync(transContext.GetString("NotAValidMessageLink")); + await ReplyAsync(Localization.Quote.NotAValidMessageLink); return; } var link = new MessageLink(messageLink); if (link.GuildId != Context.Guild.Id) { - await ReplyAsync(transContext.GetString("OnlyQuoteFromSameServer")); + await ReplyAsync(Localization.Quote.OnlyQuoteFromSameServer); return; } @@ -255,25 +246,25 @@ namespace Geekbot.Bot.Commands.Utils.Quote var message = await channel.GetMessageAsync(link.MessageId); - await ProcessQuote(message, saveToDb, transContext); + await ProcessQuote(message, saveToDb); } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context, "I couldn't find that message :disappointed:"); + await ErrorHandler.HandleCommandException(e, Context, "I couldn't find that message :disappointed:"); } } - private async Task ProcessQuote(IMessage message, bool saveToDb, TranslationGuildContext transContext) + private async Task ProcessQuote(IMessage message, bool saveToDb) { if (message.Author.Id == Context.Message.Author.Id && saveToDb && !_isDev) { - await ReplyAsync(transContext.GetString("CannotSaveOwnQuotes")); + await ReplyAsync(Localization.Quote.CannotSaveOwnQuotes); return; } if (message.Author.IsBot && saveToDb && !_isDev) { - await ReplyAsync(transContext.GetString("CannotQuoteBots")); + await ReplyAsync(Localization.Quote.CannotQuoteBots); return; } @@ -285,7 +276,7 @@ namespace Geekbot.Bot.Commands.Utils.Quote } var embed = QuoteBuilder(quote); - await ReplyAsync(saveToDb ? transContext.GetString("QuoteAdded") : string.Empty, false, embed.Build()); + await ReplyAsync(saveToDb ? Localization.Quote.QuoteAdded : string.Empty, false, embed.Build()); } private EmbedBuilder QuoteBuilder(QuoteModel quote) diff --git a/src/Bot/Localization/Admin.Designer.cs b/src/Bot/Localization/Admin.Designer.cs new file mode 100644 index 0000000..c55adf1 --- /dev/null +++ b/src/Bot/Localization/Admin.Designer.cs @@ -0,0 +1,81 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Geekbot.Bot.Localization { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Admin { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Admin() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Geekbot.Bot.Localization.Admin", typeof(Admin).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to I'm talking english. + /// + internal static string GetLanguage { + get { + return ResourceManager.GetString("GetLanguage", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to I will reply in english from now on. + /// + internal static string NewLanguageSet { + get { + return ResourceManager.GetString("NewLanguageSet", resourceCulture); + } + } + } +} diff --git a/src/Bot/Localization/Admin.de-ch.resx b/src/Bot/Localization/Admin.de-ch.resx new file mode 100644 index 0000000..b89939b --- /dev/null +++ b/src/Bot/Localization/Admin.de-ch.resx @@ -0,0 +1,20 @@ + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + I werd ab jetzt uf schwiizerdüütsch antworte, äuuä + + + I red schwiizerdüütsch + + \ No newline at end of file diff --git a/src/Bot/Localization/Admin.resx b/src/Bot/Localization/Admin.resx new file mode 100644 index 0000000..6fd2c62 --- /dev/null +++ b/src/Bot/Localization/Admin.resx @@ -0,0 +1,27 @@ + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + I will reply in english from now on + + + I'm talking english + + \ No newline at end of file diff --git a/src/Bot/Localization/Choose.Designer.cs b/src/Bot/Localization/Choose.Designer.cs new file mode 100644 index 0000000..1319140 --- /dev/null +++ b/src/Bot/Localization/Choose.Designer.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Geekbot.Bot.Localization { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Choose { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Choose() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Geekbot.Bot.Localization.Choose", typeof(Choose).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to I Choose **{0}**. + /// + internal static string Choice { + get { + return ResourceManager.GetString("Choice", resourceCulture); + } + } + } +} diff --git a/src/Bot/Localization/Choose.de-ch.resx b/src/Bot/Localization/Choose.de-ch.resx new file mode 100644 index 0000000..eedc39b --- /dev/null +++ b/src/Bot/Localization/Choose.de-ch.resx @@ -0,0 +1,17 @@ + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + I nimme **{0}** + + \ No newline at end of file diff --git a/src/Bot/Localization/Choose.resx b/src/Bot/Localization/Choose.resx new file mode 100644 index 0000000..052177b --- /dev/null +++ b/src/Bot/Localization/Choose.resx @@ -0,0 +1,24 @@ + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + I Choose **{0}** + + \ No newline at end of file diff --git a/src/Bot/Localization/Cookies.Designer.cs b/src/Bot/Localization/Cookies.Designer.cs new file mode 100644 index 0000000..5f2528f --- /dev/null +++ b/src/Bot/Localization/Cookies.Designer.cs @@ -0,0 +1,126 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Geekbot.Bot.Localization { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Cookies { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Cookies() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Geekbot.Bot.Localization.Cookies", typeof(Cookies).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to You ate {0} cookies, you've only got {1} cookies left. + /// + internal static string AteCookies { + get { + return ResourceManager.GetString("AteCookies", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to You got {0} cookies, there are now {1} cookies in you cookie jar. + /// + internal static string GetCookies { + get { + return ResourceManager.GetString("GetCookies", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to You gave {0} cookies to {1}. + /// + internal static string Given { + get { + return ResourceManager.GetString("Given", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to There are {0} cookies in you cookie jar. + /// + internal static string InYourJar { + get { + return ResourceManager.GetString("InYourJar", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Your cookie jar looks almost empty, you should probably not eat a cookie. + /// + internal static string NotEnoughCookiesToEat { + get { + return ResourceManager.GetString("NotEnoughCookiesToEat", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to You don't have enough cookies. + /// + internal static string NotEnoughToGive { + get { + return ResourceManager.GetString("NotEnoughToGive", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to You already got cookies today, you can have more cookies in {0}. + /// + internal static string WaitForMoreCookies { + get { + return ResourceManager.GetString("WaitForMoreCookies", resourceCulture); + } + } + } +} diff --git a/src/Bot/Localization/Cookies.de-ch.resx b/src/Bot/Localization/Cookies.de-ch.resx new file mode 100644 index 0000000..b53b588 --- /dev/null +++ b/src/Bot/Localization/Cookies.de-ch.resx @@ -0,0 +1,35 @@ + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Du häsch {0} guetzli becho, du häsch jetzt {1} guetzli ih dr büchse + + + Du hesch scho guetzli becho hüt, du chasch meh ha in {0} + + + Es hät {0} guetzli ih dineri büchs + + + Du hesch {1} {0} guetzli geh + + + Du hesch nid gnueg guetzli + + + Du hesch chuum no guetzli ih dineri büchs, du sötsch warschinli keini esse + + + Du hesch {0} guetzli gesse und hesch jezt no {1} übrig + + \ No newline at end of file diff --git a/src/Bot/Localization/Cookies.resx b/src/Bot/Localization/Cookies.resx new file mode 100644 index 0000000..53207fa --- /dev/null +++ b/src/Bot/Localization/Cookies.resx @@ -0,0 +1,42 @@ + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + You got {0} cookies, there are now {1} cookies in you cookie jar + + + You already got cookies today, you can have more cookies in {0} + + + There are {0} cookies in you cookie jar + + + You gave {0} cookies to {1} + + + You don't have enough cookies + + + Your cookie jar looks almost empty, you should probably not eat a cookie + + + You ate {0} cookies, you've only got {1} cookies left + + \ No newline at end of file diff --git a/src/Bot/Localization/Internal.Designer.cs b/src/Bot/Localization/Internal.Designer.cs new file mode 100644 index 0000000..e7c18af --- /dev/null +++ b/src/Bot/Localization/Internal.Designer.cs @@ -0,0 +1,126 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Geekbot.Bot.Localization { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Internal { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Internal() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Geekbot.Bot.Localization.Internal", typeof(Internal).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to and. + /// + internal static string And { + get { + return ResourceManager.GetString("And", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to day|days. + /// + internal static string Days { + get { + return ResourceManager.GetString("Days", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to hour|hours. + /// + internal static string Hours { + get { + return ResourceManager.GetString("Hours", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Seems like i don't have enough permission to that :confused:. + /// + internal static string Http403 { + get { + return ResourceManager.GetString("Http403", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to minute|minutes. + /// + internal static string Minutes { + get { + return ResourceManager.GetString("Minutes", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to second|seconds. + /// + internal static string Seconds { + get { + return ResourceManager.GetString("Seconds", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Something went wrong :confused:. + /// + internal static string SomethingWentWrong { + get { + return ResourceManager.GetString("SomethingWentWrong", resourceCulture); + } + } + } +} diff --git a/src/Bot/Localization/Internal.de-ch.resx b/src/Bot/Localization/Internal.de-ch.resx new file mode 100644 index 0000000..568bb1f --- /dev/null +++ b/src/Bot/Localization/Internal.de-ch.resx @@ -0,0 +1,35 @@ + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Öppis isch schief gange :confused: + + + Gseht danach us das ich nid gnueg recht han zum das mache :confused: + + + tag|täg + + + stund|stunde + + + minute|minute + + + sekunde|sekunde + + + und + + \ No newline at end of file diff --git a/src/Bot/Localization/Internal.resx b/src/Bot/Localization/Internal.resx new file mode 100644 index 0000000..a771d6b --- /dev/null +++ b/src/Bot/Localization/Internal.resx @@ -0,0 +1,42 @@ + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Something went wrong :confused: + + + Seems like i don't have enough permission to that :confused: + + + day|days + + + hour|hours + + + minute|minutes + + + second|seconds + + + and + + \ No newline at end of file diff --git a/src/Bot/Localization/Karma.Designer.cs b/src/Bot/Localization/Karma.Designer.cs new file mode 100644 index 0000000..4191fa2 --- /dev/null +++ b/src/Bot/Localization/Karma.Designer.cs @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Geekbot.Bot.Localization { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Karma { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Karma() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Geekbot.Bot.Localization.Karma", typeof(Karma).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Amount. + /// + internal static string Amount { + get { + return ResourceManager.GetString("Amount", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to By. + /// + internal static string By { + get { + return ResourceManager.GetString("By", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Sorry {0}, but you can't lower your own karma. + /// + internal static string CannotChangeOwnDown { + get { + return ResourceManager.GetString("CannotChangeOwnDown", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Sorry {0}, but you can't give yourself karma. + /// + internal static string CannotChangeOwnUp { + get { + return ResourceManager.GetString("CannotChangeOwnUp", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Current. + /// + internal static string Current { + get { + return ResourceManager.GetString("Current", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Karma lowered. + /// + internal static string Decreased { + get { + return ResourceManager.GetString("Decreased", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Gained Karma. + /// + internal static string Increased { + get { + return ResourceManager.GetString("Increased", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Sorry {0}, but you have to wait {1} before you can give karma again.... + /// + internal static string WaitUntill { + get { + return ResourceManager.GetString("WaitUntill", resourceCulture); + } + } + } +} diff --git a/src/Bot/Localization/Karma.de-ch.resx b/src/Bot/Localization/Karma.de-ch.resx new file mode 100644 index 0000000..294c105 --- /dev/null +++ b/src/Bot/Localization/Karma.de-ch.resx @@ -0,0 +1,38 @@ + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Sorry {0}, aber du chasch dr selber kei karma geh + + + Sorry {0}, aber du musch no {1} warte bisch d wieder karma chasch geh... + + + Karma becho + + + Vo + + + Mengi + + + Jetzt + + + Sorry {0}, aber du chasch dr din eigete karma nid weg neh + + + Karma gsenkt + + \ No newline at end of file diff --git a/src/Bot/Localization/Karma.resx b/src/Bot/Localization/Karma.resx new file mode 100644 index 0000000..3a8fe5a --- /dev/null +++ b/src/Bot/Localization/Karma.resx @@ -0,0 +1,45 @@ + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Sorry {0}, but you can't give yourself karma + + + Sorry {0}, but you have to wait {1} before you can give karma again... + + + Gained Karma + + + By + + + Amount + + + Current + + + Sorry {0}, but you can't lower your own karma + + + Karma lowered + + \ No newline at end of file diff --git a/src/Bot/Localization/Quote.Designer.cs b/src/Bot/Localization/Quote.Designer.cs new file mode 100644 index 0000000..342c181 --- /dev/null +++ b/src/Bot/Localization/Quote.Designer.cs @@ -0,0 +1,162 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Geekbot.Bot.Localization { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Quote { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Quote() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Geekbot.Bot.Localization.Quote", typeof(Quote).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to You can't save quotes by a bot.... + /// + internal static string CannotQuoteBots { + get { + return ResourceManager.GetString("CannotQuoteBots", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to You can't save your own quotes.... + /// + internal static string CannotSaveOwnQuotes { + get { + return ResourceManager.GetString("CannotSaveOwnQuotes", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Most quoted person. + /// + internal static string MostQuotesPerson { + get { + return ResourceManager.GetString("MostQuotesPerson", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to This server doesn't seem to have any quotes yet. You can add a quote with `!quote save @user` or `!quote save <messageId>`. + /// + internal static string NoQuotesFound { + get { + return ResourceManager.GetString("NoQuotesFound", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to That is not a valid message link. + /// + internal static string NotAValidMessageLink { + get { + return ResourceManager.GetString("NotAValidMessageLink", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to I couldn't find a quote with that ID :disappointed:. + /// + internal static string NotFoundWithId { + get { + return ResourceManager.GetString("NotFoundWithId", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to You can only quote messages from the same server. + /// + internal static string OnlyQuoteFromSameServer { + get { + return ResourceManager.GetString("OnlyQuoteFromSameServer", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to **Quote Added**. + /// + internal static string QuoteAdded { + get { + return ResourceManager.GetString("QuoteAdded", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Quote Stats. + /// + internal static string QuoteStats { + get { + return ResourceManager.GetString("QuoteStats", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to **Removed #{0}**. + /// + internal static string Removed { + get { + return ResourceManager.GetString("Removed", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Total. + /// + internal static string TotalQuotes { + get { + return ResourceManager.GetString("TotalQuotes", resourceCulture); + } + } + } +} diff --git a/src/Bot/Localization/Quote.de-ch.resx b/src/Bot/Localization/Quote.de-ch.resx new file mode 100644 index 0000000..99fd959 --- /dev/null +++ b/src/Bot/Localization/Quote.de-ch.resx @@ -0,0 +1,47 @@ + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Dä server het no kei quotes. Du chasch quotes hinzuefüege mit `!quote save @user` oder `!quote save <messageId>` + + + Du chasch kei quotes vo dir selber speichere... + + + Du chasch kei quotes vomne bot speichere... + + + **Quote hinzugfüegt** + + + **#{0} glöscht** + + + Ich chan kei quote finde mit därri ID :disappointed: + + + Quote statistike + + + Total + + + Meist quoteti person + + + Das isch kei korrete nachrichtelink + + + Du chasch numme nachrichte vom gliche server quote + + \ No newline at end of file diff --git a/src/Bot/Localization/Quote.resx b/src/Bot/Localization/Quote.resx new file mode 100644 index 0000000..b51d79c --- /dev/null +++ b/src/Bot/Localization/Quote.resx @@ -0,0 +1,54 @@ + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + This server doesn't seem to have any quotes yet. You can add a quote with `!quote save @user` or `!quote save <messageId>` + + + You can't save your own quotes... + + + You can't save quotes by a bot... + + + **Quote Added** + + + **Removed #{0}** + + + I couldn't find a quote with that ID :disappointed: + + + Quote Stats + + + Total + + + Most quoted person + + + That is not a valid message link + + + You can only quote messages from the same server + + \ No newline at end of file diff --git a/src/Bot/Localization/Rank.Designer.cs b/src/Bot/Localization/Rank.Designer.cs new file mode 100644 index 0000000..23f5e16 --- /dev/null +++ b/src/Bot/Localization/Rank.Designer.cs @@ -0,0 +1,108 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Geekbot.Bot.Localization { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Rank { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Rank() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Geekbot.Bot.Localization.Rank", typeof(Rank).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to :warning: I couldn't find all usernames. Maybe they left the server?. + /// + internal static string FailedToResolveAllUsernames { + get { + return ResourceManager.GetString("FailedToResolveAllUsernames", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to :bar_chart: **{0} Highscore for {1}**. + /// + internal static string HighscoresFor { + get { + return ResourceManager.GetString("HighscoresFor", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Valid types are '`messages`' '`karma`', '`rolls`' and '`cookies`'. + /// + internal static string InvalidType { + get { + return ResourceManager.GetString("InvalidType", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to :warning: Limiting to 20. + /// + internal static string LimitingTo20Warning { + get { + return ResourceManager.GetString("LimitingTo20Warning", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to No {0} found on this server. + /// + internal static string NoTypeFoundForServer { + get { + return ResourceManager.GetString("NoTypeFoundForServer", resourceCulture); + } + } + } +} diff --git a/src/Bot/Localization/Rank.de-ch.resx b/src/Bot/Localization/Rank.de-ch.resx new file mode 100644 index 0000000..0b22fe4 --- /dev/null +++ b/src/Bot/Localization/Rank.de-ch.resx @@ -0,0 +1,29 @@ + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + :warning: Limitiert uf 20 + + + Kei {0} gfunde für dä server + + + :warning: Ich han nid alli benutzername gfunde. villiicht hend sie de server verlah? + + + :bar_chart: **{0} Highscore für {1}** + + + Gültigi paramenter sind '`messages`' '`karma`', '`rolls`' und '`cookies` + + \ No newline at end of file diff --git a/src/Bot/Localization/Rank.resx b/src/Bot/Localization/Rank.resx new file mode 100644 index 0000000..9598cf8 --- /dev/null +++ b/src/Bot/Localization/Rank.resx @@ -0,0 +1,36 @@ + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Valid types are '`messages`' '`karma`', '`rolls`' and '`cookies`' + + + :warning: Limiting to 20 + + + No {0} found on this server + + + :warning: I couldn't find all usernames. Maybe they left the server? + + + :bar_chart: **{0} Highscore for {1}** + + \ No newline at end of file diff --git a/src/Bot/Localization/Roll.Designer.cs b/src/Bot/Localization/Roll.Designer.cs new file mode 100644 index 0000000..fda0536 --- /dev/null +++ b/src/Bot/Localization/Roll.Designer.cs @@ -0,0 +1,99 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Geekbot.Bot.Localization { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Roll { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Roll() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Geekbot.Bot.Localization.Roll", typeof(Roll).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Congratulations {0}, your guess was correct!. + /// + internal static string Gratz { + get { + return ResourceManager.GetString("Gratz", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to :red_circle: {0}, you can't guess the same number again, guess another number or wait {1}. + /// + internal static string NoPrevGuess { + get { + return ResourceManager.GetString("NoPrevGuess", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0}, you rolled {1}, your guess was {2}. + /// + internal static string Rolled { + get { + return ResourceManager.GetString("Rolled", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0}, you rolled {1}. + /// + internal static string RolledNoGuess { + get { + return ResourceManager.GetString("RolledNoGuess", resourceCulture); + } + } + } +} diff --git a/src/Bot/Localization/Roll.de-ch.resx b/src/Bot/Localization/Roll.de-ch.resx new file mode 100644 index 0000000..ba73316 --- /dev/null +++ b/src/Bot/Localization/Roll.de-ch.resx @@ -0,0 +1,26 @@ + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + {0}, du hesch {1} grollt und hesch {2} grate + + + Gratuliere {0}, du hesch richtig grate! + + + {0}, du hesch {1} grollt + + + :red_circle: {0}, du chasch nid nomol es gliche rate, rate öppis anders oder warte {1} + + \ No newline at end of file diff --git a/src/Bot/Localization/Roll.resx b/src/Bot/Localization/Roll.resx new file mode 100644 index 0000000..822abb6 --- /dev/null +++ b/src/Bot/Localization/Roll.resx @@ -0,0 +1,33 @@ + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + {0}, you rolled {1}, your guess was {2} + + + Congratulations {0}, your guess was correct! + + + {0}, you rolled {1} + + + :red_circle: {0}, you can't guess the same number again, guess another number or wait {1} + + \ No newline at end of file diff --git a/src/Bot/Localization/Ship.Designer.cs b/src/Bot/Localization/Ship.Designer.cs new file mode 100644 index 0000000..d959693 --- /dev/null +++ b/src/Bot/Localization/Ship.Designer.cs @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Geekbot.Bot.Localization { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Ship { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Ship() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Geekbot.Bot.Localization.Ship", typeof(Ship).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Almost a match. + /// + internal static string CouldWork { + get { + return ResourceManager.GetString("CouldWork", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to It's a match. + /// + internal static string ItsAMatch { + get { + return ResourceManager.GetString("ItsAMatch", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Matchmaking. + /// + internal static string Matchmaking { + get { + return ResourceManager.GetString("Matchmaking", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Not going happen. + /// + internal static string NotGoingToHappen { + get { + return ResourceManager.GetString("NotGoingToHappen", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Not such a good idea. + /// + internal static string NotSuchAGoodIdea { + get { + return ResourceManager.GetString("NotSuchAGoodIdea", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to There might be a chance. + /// + internal static string ThereMightBeAChance { + get { + return ResourceManager.GetString("ThereMightBeAChance", resourceCulture); + } + } + } +} diff --git a/src/Bot/Localization/Ship.de-ch.resx b/src/Bot/Localization/Ship.de-ch.resx new file mode 100644 index 0000000..ec2880b --- /dev/null +++ b/src/Bot/Localization/Ship.de-ch.resx @@ -0,0 +1,32 @@ + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Verkupple + + + Wird nöd klappe + + + Nöd so ä gueti idee + + + Es gid eventuel ä chance + + + Fasch en match + + + Es isch es traumpaar + + \ No newline at end of file diff --git a/src/Bot/Localization/Ship.resx b/src/Bot/Localization/Ship.resx new file mode 100644 index 0000000..611040f --- /dev/null +++ b/src/Bot/Localization/Ship.resx @@ -0,0 +1,39 @@ + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Matchmaking + + + Not going happen + + + Not such a good idea + + + There might be a chance + + + Almost a match + + + It's a match + + \ No newline at end of file diff --git a/src/Core/GeekbotCommandBase.cs b/src/Core/GeekbotCommandBase.cs new file mode 100644 index 0000000..8df5265 --- /dev/null +++ b/src/Core/GeekbotCommandBase.cs @@ -0,0 +1,27 @@ +using System.Globalization; +using System.Threading; +using Discord.Commands; +using Geekbot.Core.ErrorHandling; +using Geekbot.Core.Localization; + +namespace Geekbot.Core +{ + public class GeekbotCommandBase : ModuleBase + { + protected readonly IErrorHandler ErrorHandler; + protected readonly ITranslationHandler Translations; + + protected GeekbotCommandBase(IErrorHandler errorHandler, ITranslationHandler translations) + { + ErrorHandler = errorHandler; + Translations = translations; + } + + protected override void BeforeExecute(CommandInfo command) + { + base.BeforeExecute(command); + var language = Translations.GetServerLanguage(Context.Guild.Id); + Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(language == "CHDE" ? "de-ch" : language); + } + } +} \ No newline at end of file diff --git a/src/Core/Localization/ITranslationHandler.cs b/src/Core/Localization/ITranslationHandler.cs index 74b3e88..1cc06fa 100644 --- a/src/Core/Localization/ITranslationHandler.cs +++ b/src/Core/Localization/ITranslationHandler.cs @@ -12,5 +12,6 @@ namespace Geekbot.Core.Localization Task GetGuildContext(ICommandContext context); Task SetLanguage(ulong guildId, string language); List SupportedLanguages { get; } + string GetServerLanguage(ulong guildId); } } \ No newline at end of file diff --git a/src/Core/Localization/TranslationHandler.cs b/src/Core/Localization/TranslationHandler.cs index c7d35e9..1a46ada 100644 --- a/src/Core/Localization/TranslationHandler.cs +++ b/src/Core/Localization/TranslationHandler.cs @@ -89,7 +89,7 @@ namespace Geekbot.Core.Localization } } - private Task GetServerLanguage(ulong guildId) + public string GetServerLanguage(ulong guildId) { try { @@ -99,7 +99,7 @@ namespace Geekbot.Core.Localization lang = _serverLanguages[guildId]; if (!string.IsNullOrEmpty(lang)) { - return Task.FromResult(lang); + return lang; } throw new Exception(); } @@ -107,19 +107,19 @@ namespace Geekbot.Core.Localization { lang = _guildSettingsManager.GetSettings(guildId, false)?.Language ?? "EN"; _serverLanguages[guildId] = lang; - return Task.FromResult(lang); + return lang; } } catch (Exception e) { _logger.Error(LogSource.Geekbot, "Could not get guild language", e); - return Task.FromResult("EN"); + return "EN"; } } public async Task GetString(ulong guildId, string command, string stringName) { - var serverLang = await GetServerLanguage(guildId); + var serverLang = GetServerLanguage(guildId); return GetString(serverLang, command, stringName); } @@ -140,7 +140,7 @@ namespace Geekbot.Core.Localization try { var command = context.Message.Content.Split(' ').First().TrimStart('!').ToLower(); - var serverLanguage = await GetServerLanguage(context.Guild?.Id ?? 0); + var serverLanguage = GetServerLanguage(context.Guild?.Id ?? 0); return _translations[serverLanguage][command]; } catch (Exception e) @@ -153,7 +153,7 @@ namespace Geekbot.Core.Localization public async Task GetGuildContext(ICommandContext context) { var dict = await GetDict(context); - var language = await GetServerLanguage(context.Guild?.Id ?? 0); + var language = GetServerLanguage(context.Guild?.Id ?? 0); return new TranslationGuildContext(this, language, dict); } @@ -161,7 +161,7 @@ namespace Geekbot.Core.Localization { try { - var serverLanguage = await GetServerLanguage(context.Guild?.Id ?? 0); + var serverLanguage = GetServerLanguage(context.Guild?.Id ?? 0); return _translations[serverLanguage][command]; } catch (Exception e) diff --git a/src/Core/Localization/Translations.yml b/src/Core/Localization/Translations.yml index fbb55bf..678755d 100644 --- a/src/Core/Localization/Translations.yml +++ b/src/Core/Localization/Translations.yml @@ -15,13 +15,6 @@ dateTime: And: EN: "and" CHDE: "und" -admin: - NewLanguageSet: - EN: "I will reply in english from now on" - CHDE: "I werd ab jetzt uf schwiizerdüütsch antworte, äuuä" - GetLanguage: - EN: "I'm talking english" - CHDE: "I red schwiizerdüütsch" errorHandler: SomethingWentWrong: EN: "Something went wrong :confused:" @@ -30,86 +23,6 @@ httpErrors: 403: EN: "Seems like i don't have enough permission to that :confused:" CHDE: "Gseht danach us das ich nid gnueg recht han zum das mache :confused:" -choose: - Choice: - EN: "I Choose **{0}**" - CHDE: "I nimme **{0}**" -good: - CannotChangeOwn: - EN: "Sorry {0}, but you can't give yourself karma" - CHDE: "Sorry {0}, aber du chasch dr selber kei karma geh" - WaitUntill: - EN: "Sorry {0}, but you have to wait {1} before you can give karma again..." - CHDE: "Sorry {0}, aber du musch no {1} warte bisch d wieder karma chasch geh..." - Increased: - EN: "Karma gained" - CHDE: "Karma becho" - By: - EN: "By" - CHDE: "Vo" - Amount: - EN: "Amount" - CHDE: "Mengi" - Current: - EN: "Current" - CHDE: "Jetzt" -bad: - CannotChangeOwn: - EN: "Sorry {0}, but you can't lower your own karma" - CHDE: "Sorry {0}, aber du chasch dr din eigete karma nid weg neh" - WaitUntill: - EN: "Sorry {0}, but you have to wait {1} before you can lower karma again..." - CHDE: "Sorry {0}, aber du musch no {1} warte bisch d wieder karma chasch senke..." - Decreased: - EN: "Karma lowered" - CHDE: "Karma gsenkt" - By: - EN: "By" - CHDE: "Vo" - Amount: - EN: "Amount" - CHDE: "Mengi" - Current: - EN: "Current" - CHDE: "Jetzt" -roll: - Rolled: - EN: "{0}, you rolled {1}, your guess was {2}" - CHDE: "{0}, du hesch {1} grollt und hesch {2} grate" - Gratz: - EN: "Congratulations {0}, your guess was correct!" - CHDE: "Gratuliere {0}, du hesch richtig grate!" - RolledNoGuess: - EN: "{0}, you rolled {1}" - CHDE: "{0}, du hesch {1} grollt" - NoPrevGuess: - EN: ":red_circle: {0}, you can't guess the same number again, guess another number or wait {1}" - CHDE: ":red_circle: {0}, du chasch nid nomol es gliche rate, rate öppis anders oder warte {1}" -cookies: &cookiesAlias - GetCookies: - EN: "You got {0} cookies, there are now {1} cookies in you cookie jar" - CHDE: "Du häsch {0} guetzli becho, du häsch jetzt {1} guetzli ih dr büchse" - WaitForMoreCookies: - EN: "You already got cookies today, you can have more cookies in {0}" - CHDE: "Du hesch scho guetzli becho hüt, du chasch meh ha in {0}" - InYourJar: - EN: "There are {0} cookies in you cookie jar" - CHDE: "Es hät {0} guetzli ih dineri büchs" - Given: - EN: "You gave {0} cookies to {1}" - CHDE: "Du hesch {1} {0} guetzli geh" - NotEnoughToGive: - EN: "You don't have enough cookies" - CHDE: "Du hesch nid gnueg guetzli" - NotEnoughCookiesToEat: - EN: "Your cookie jar looks almost empty, you should probably not eat a cookie" - CHDE: "Du hesch chuum no guetzli ih dineri büchs, du sötsch warschinli keini esse" - AteCookies: - EN: "You ate {0} cookies, you've only got {1} cookies left" - CHDE: "Du hesch {0} guetzli gesse und hesch jezt no {1} übrig" -cookie: - # because command aliases are to hard to deal with... - <<: *cookiesAlias role: NoRolesConfigured: EN: "There are no roles configured for this server" @@ -140,74 +53,4 @@ role: CHDE: "{0} isch zur whitelist hinzuegfüegt" RemovedRoleFromWhitelist: EN: "Removed {0} from the whitelist" - CHDE: "{0} isch vo dr whitelist glöscht" -quote: - NoQuotesFound: - EN: "This server doesn't seem to have any quotes yet. You can add a quote with `!quote save @user` or `!quote save `" - CHDE: "Dä server het no kei quotes. Du chasch quotes hinzuefüege mit `!quote save @user` oder `!quote save `" - CannotSaveOwnQuotes: - EN: "You can't save your own quotes..." - CHDE: "Du chasch kei quotes vo dir selber speichere..." - CannotQuoteBots: - EN: "You can't save quotes by a bot..." - CHDE: "Du chasch kei quotes vomne bot speichere..." - QuoteAdded: - EN: "**Quote Added**" - CHDE: "**Quote hinzugfüegt**" - Removed: - EN: "**Removed #{0}**" - CHDE: "**#{0} glöscht**" - NotFoundWithId: - EN: "I couldn't find a quote with that ID :disappointed:" - CHDE: "Ich chan kei quote finde mit därri ID :disappointed:" - QuoteStats: - EN: "Quote Stats" - CHDE: "Quote statistike" - TotalQuotes: - EN: "Total" - CHDE: "Total" - MostQuotesPerson: - EN: "Most quoted person" - CHDE: "Meist quoteti person" - NotAValidMessageLink: - EN: "That is not a valid message link" - CHDE: "Das isch kei korrete nachrichtelink" - OnlyQuoteFromSameServer: - EN: "You can only quote messages from the same server" - CHDE: "Du chasch numme nachrichte vom gliche server quote" -rank: - InvalidType: - EN: "Valid types are '`messages`' '`karma`', '`rolls`' and '`cookies`'" - CHDE: "Gültigi paramenter sind '`messages`' '`karma`', '`rolls`' und '`cookies`'" - LimitingTo20Warning: - EN: ":warning: Limiting to 20\n" - CHDE: ":warning: Limitiert uf 20\n" - NoTypeFoundForServer: - EN: "No {0} found on this server" - CHDE: "Kei {0} gfunde für dä server" - FailedToResolveAllUsernames: - EN: ":warning: I couldn't find all usernames. Maybe they left the server?\n" - CHDE: ":warning: Ich han nid alli benutzername gfunde. villiicht hend sie de server verlah?\n" - HighscoresFor: - EN: ":bar_chart: **{0} Highscore for {1}**" - CHDE: ":bar_chart: **{0} Highscore für {1}**" -ship: - Matchmaking: - EN: "Matchmaking" - CHDE: "Verkupple" - NotGonnaToHappen: - EN: "Not gonna happen" - CHDE: "Wird nöd klappe" - NotSuchAGoodIdea: - EN: "Not such a good idea" - CHDE: "Nöd so ä gueti idee" - ThereMightBeAChance: - EN: "There might be a chance" - CHDE: "Es gid eventuel ä chance" - CouldWork: - EN: "Almost a match" - CHDE: "Fasch en match" - ItsAMatch: - EN: "It's a match" - CHDE: "Es isch es traumpaar" - \ No newline at end of file + CHDE: "{0} isch vo dr whitelist glöscht" \ No newline at end of file From 078c884df73c668aab75f916cd175deaaac7bd4c Mon Sep 17 00:00:00 2001 From: runebaas Date: Fri, 14 Aug 2020 18:11:52 +0200 Subject: [PATCH 2/4] Convert Role command to new localization method --- src/Bot/Bot.csproj | 9 ++ src/Bot/Commands/Admin/Role.cs | 52 ++++----- src/Bot/Localization/Role.Designer.cs | 153 +++++++++++++++++++++++++ src/Bot/Localization/Role.de-ch.resx | 44 +++++++ src/Bot/Localization/Role.resx | 51 +++++++++ src/Core/Localization/Translations.yml | 33 +----- 6 files changed, 280 insertions(+), 62 deletions(-) create mode 100644 src/Bot/Localization/Role.Designer.cs create mode 100644 src/Bot/Localization/Role.de-ch.resx create mode 100644 src/Bot/Localization/Role.resx diff --git a/src/Bot/Bot.csproj b/src/Bot/Bot.csproj index 601766a..2d3cd2f 100644 --- a/src/Bot/Bot.csproj +++ b/src/Bot/Bot.csproj @@ -77,6 +77,10 @@ ResXFileCodeGenerator Quote.Designer.cs + + ResXFileCodeGenerator + Role.Designer.cs + @@ -127,5 +131,10 @@ True Quote.resx + + True + True + Role.resx + diff --git a/src/Bot/Commands/Admin/Role.cs b/src/Bot/Commands/Admin/Role.cs index e997fa8..c8459dd 100644 --- a/src/Bot/Commands/Admin/Role.cs +++ b/src/Bot/Commands/Admin/Role.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Discord; using Discord.Commands; using Discord.Net; +using Geekbot.Core; using Geekbot.Core.CommandPreconditions; using Geekbot.Core.Database; using Geekbot.Core.Database.Models; @@ -17,19 +18,15 @@ namespace Geekbot.Bot.Commands.Admin { [Group("role")] [DisableInDirectMessage] - public class Role : ModuleBase + public class Role : GeekbotCommandBase { private readonly DatabaseContext _database; - private readonly IErrorHandler _errorHandler; private readonly IReactionListener _reactionListener; - private readonly ITranslationHandler _translationHandler; - public Role(DatabaseContext database, IErrorHandler errorHandler, IReactionListener reactionListener, ITranslationHandler translationHandler) + public Role(DatabaseContext database, IErrorHandler errorHandler, IReactionListener reactionListener, ITranslationHandler translationHandler) : base(errorHandler, translationHandler) { _database = database; - _errorHandler = errorHandler; _reactionListener = reactionListener; - _translationHandler = translationHandler; } [Command(RunMode = RunMode.Async)] @@ -38,23 +35,22 @@ namespace Geekbot.Bot.Commands.Admin { try { - var transContext = await _translationHandler.GetGuildContext(Context); var roles = _database.RoleSelfService.Where(g => g.GuildId.Equals(Context.Guild.Id.AsLong())).ToList(); if (roles.Count == 0) { - await ReplyAsync(transContext.GetString("NoRolesConfigured")); + await ReplyAsync(Localization.Role.NoRolesConfigured); return; } var sb = new StringBuilder(); - sb.AppendLine(transContext.GetString("ListHeader", Context.Guild.Name)); - sb.AppendLine(transContext.GetString("ListInstruction")); + sb.AppendLine(string.Format(Localization.Role.ListHeader, Context.Guild.Name)); + sb.AppendLine(Localization.Role.ListInstruction); foreach (var role in roles) sb.AppendLine($"- {role.WhiteListName}"); await ReplyAsync(sb.ToString()); } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } @@ -64,7 +60,6 @@ namespace Geekbot.Bot.Commands.Admin { try { - var transContext = await _translationHandler.GetGuildContext(Context); var roleName = roleNameRaw.ToLower(); var roleFromDb = _database.RoleSelfService.FirstOrDefault(e => e.GuildId.Equals(Context.Guild.Id.AsLong()) && e.WhiteListName.Equals(roleName)); @@ -74,31 +69,31 @@ namespace Geekbot.Bot.Commands.Admin var role = Context.Guild.Roles.First(r => r.Id == roleFromDb.RoleId.AsUlong()); if (role == null) { - await ReplyAsync(transContext.GetString("RoleNotFound")); + await ReplyAsync(Localization.Role.RoleNotFound); return; } if (guildUser.RoleIds.Contains(role.Id)) { await guildUser.RemoveRoleAsync(role); - await ReplyAsync(transContext.GetString("RemovedUserFromRole", role.Name)); + await ReplyAsync(string.Format(Localization.Role.RemovedUserFromRole, role.Name)); return; } await guildUser.AddRoleAsync(role); - await ReplyAsync(transContext.GetString("AddedUserFromRole", role.Name)); + await ReplyAsync(string.Format(Localization.Role.AddedUserFromRole, role.Name)); return; } - await ReplyAsync(transContext.GetString("RoleNotFound")); + await ReplyAsync(Localization.Role.RoleNotFound); } catch (HttpException e) { - await _errorHandler.HandleHttpException(e, Context); + await ErrorHandler.HandleHttpException(e, Context); } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } @@ -109,10 +104,9 @@ namespace Geekbot.Bot.Commands.Admin { try { - var transContext = await _translationHandler.GetGuildContext(Context); if (role.IsManaged) { - await ReplyAsync(transContext.GetString("CannotAddManagedRole")); + await ReplyAsync(Localization.Role.CannotAddManagedRole); return; } @@ -122,7 +116,7 @@ namespace Geekbot.Bot.Commands.Admin || role.Permissions.BanMembers || role.Permissions.KickMembers) { - await ReplyAsync(transContext.GetString("CannotAddDangerousRole")); + await ReplyAsync(Localization.Role.CannotAddDangerousRole); return; } @@ -133,11 +127,11 @@ namespace Geekbot.Bot.Commands.Admin WhiteListName = roleName }); await _database.SaveChangesAsync(); - await ReplyAsync(transContext.GetString("AddedRoleToWhitelist", role.Name)); + await ReplyAsync(string.Format(Localization.Role.AddedRoleToWhitelist, role.Name)); } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } @@ -148,22 +142,21 @@ namespace Geekbot.Bot.Commands.Admin { try { - var transContext = await _translationHandler.GetGuildContext(Context); var roleFromDb = _database.RoleSelfService.FirstOrDefault(e => e.GuildId.Equals(Context.Guild.Id.AsLong()) && e.WhiteListName.Equals(roleName)); if (roleFromDb != null) { _database.RoleSelfService.Remove(roleFromDb); await _database.SaveChangesAsync(); - await ReplyAsync(transContext.GetString("RemovedRoleFromWhitelist", roleName)); + await ReplyAsync(string.Format(Localization.Role.RemovedRoleFromWhitelist, roleName)); return; } - await ReplyAsync(transContext.GetString("RoleNotFound")); + await ReplyAsync(Localization.Role.RoleNotFound); } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } @@ -182,14 +175,13 @@ namespace Geekbot.Bot.Commands.Admin await _reactionListener.AddRoleToListener(messageId, Context.Guild.Id, emoji, role); await Context.Message.DeleteAsync(); } - catch (HttpException e) + catch (HttpException) { await Context.Channel.SendMessageAsync("Custom emojis from other servers are not supported"); - Console.WriteLine(e); } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } } diff --git a/src/Bot/Localization/Role.Designer.cs b/src/Bot/Localization/Role.Designer.cs new file mode 100644 index 0000000..9128e3d --- /dev/null +++ b/src/Bot/Localization/Role.Designer.cs @@ -0,0 +1,153 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Geekbot.Bot.Localization { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Role { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Role() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Geekbot.Bot.Localization.Role", typeof(Role).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Added {0} to the whitelist. + /// + internal static string AddedRoleToWhitelist { + get { + return ResourceManager.GetString("AddedRoleToWhitelist", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Added you to {0}. + /// + internal static string AddedUserFromRole { + get { + return ResourceManager.GetString("AddedUserFromRole", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to You cannot add that role to self service because it contains one or more dangerous permissions. + /// + internal static string CannotAddDangerousRole { + get { + return ResourceManager.GetString("CannotAddDangerousRole", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to You can't add a role that is managed by discord. + /// + internal static string CannotAddManagedRole { + get { + return ResourceManager.GetString("CannotAddManagedRole", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to **Self Service Roles on {0}**. + /// + internal static string ListHeader { + get { + return ResourceManager.GetString("ListHeader", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to To get a role, use `!role [name]`. + /// + internal static string ListInstruction { + get { + return ResourceManager.GetString("ListInstruction", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to There are no roles configured for this server. + /// + internal static string NoRolesConfigured { + get { + return ResourceManager.GetString("NoRolesConfigured", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Removed {0} from the whitelist. + /// + internal static string RemovedRoleFromWhitelist { + get { + return ResourceManager.GetString("RemovedRoleFromWhitelist", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Removed you from {0}. + /// + internal static string RemovedUserFromRole { + get { + return ResourceManager.GetString("RemovedUserFromRole", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to That role doesn't exist or is not on the whitelist. + /// + internal static string RoleNotFound { + get { + return ResourceManager.GetString("RoleNotFound", resourceCulture); + } + } + } +} diff --git a/src/Bot/Localization/Role.de-ch.resx b/src/Bot/Localization/Role.de-ch.resx new file mode 100644 index 0000000..b0b3259 --- /dev/null +++ b/src/Bot/Localization/Role.de-ch.resx @@ -0,0 +1,44 @@ + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Es sind kei rolle für dä server konfiguriert + + + **Self Service Rollene uf {0}** + + + Zum ä rolle becho, schriib `!role [name]` + + + Die rolle gids nid or isch nid uf dr whitelist + + + Han di entfernt vo {0} + + + Han di hinzue gfüegt zu {0} + + + Du chasch kei rolle hinzuefüge wo verwalted wird vo discord + + + Du chasch die rolle nid hinzuefüge will er ein oder mehreri gföhrlichi berechtigunge het + + + {0} isch zur whitelist hinzuegfüegt + + + {0} isch vo dr whitelist glöscht + + \ No newline at end of file diff --git a/src/Bot/Localization/Role.resx b/src/Bot/Localization/Role.resx new file mode 100644 index 0000000..63b70d0 --- /dev/null +++ b/src/Bot/Localization/Role.resx @@ -0,0 +1,51 @@ + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + There are no roles configured for this server + + + **Self Service Roles on {0}** + + + To get a role, use `!role [name]` + + + That role doesn't exist or is not on the whitelist + + + Removed you from {0} + + + Added you to {0} + + + You can't add a role that is managed by discord + + + You cannot add that role to self service because it contains one or more dangerous permissions + + + Added {0} to the whitelist + + + Removed {0} from the whitelist + + \ No newline at end of file diff --git a/src/Core/Localization/Translations.yml b/src/Core/Localization/Translations.yml index 678755d..dc18c2b 100644 --- a/src/Core/Localization/Translations.yml +++ b/src/Core/Localization/Translations.yml @@ -22,35 +22,4 @@ errorHandler: httpErrors: 403: EN: "Seems like i don't have enough permission to that :confused:" - CHDE: "Gseht danach us das ich nid gnueg recht han zum das mache :confused:" -role: - NoRolesConfigured: - EN: "There are no roles configured for this server" - CHDE: "Es sind kei rolle für dä server konfiguriert" - ListHeader: - EN: "**Self Service Roles on {0}**" - CHDE: "**Self Service Rollene uf {0}**" - ListInstruction: - EN: "To get a role, use `!role [name]`" - CHDE: "Zum ä rolle becho, schriib `!role [name]`" - RoleNotFound: - EN: "That role doesn't exist or is not on the whitelist" - CHDE: "Die rolle gids nid or isch nid uf dr whitelist" - RemovedUserFromRole: - EN: "Removed you from {0}" - CHDE: "Han di entfernt vo {0}" - AddedUserFromRole: - EN: "Added you to {0}" - CHDE: "Han di hinzue gfüegt zu {0}" - CannotAddManagedRole: - EN: "You can't add a role that is managed by discord" - CHDE: "Du chasch kei rolle hinzuefüge wo verwalted wird vo discord" - CannotAddDangerousRole: - EN: "You cannot add that role to self service because it contains one or more dangerous permissions" - CHDE: "Du chasch die rolle nid hinzuefüge will er ein oder mehreri gföhrlichi berechtigunge het" - AddedRoleToWhitelist: - EN: "Added {0} to the whitelist" - CHDE: "{0} isch zur whitelist hinzuegfüegt" - RemovedRoleFromWhitelist: - EN: "Removed {0} from the whitelist" - CHDE: "{0} isch vo dr whitelist glöscht" \ No newline at end of file + CHDE: "Gseht danach us das ich nid gnueg recht han zum das mache :confused:" \ No newline at end of file From 33829e91bc2df8c1852c0c32d91c97dcc9f7c71f Mon Sep 17 00:00:00 2001 From: runebaas Date: Fri, 14 Aug 2020 23:15:11 +0200 Subject: [PATCH 3/4] Delete the TranslationHandler and the old translations file. Refactor GeekbotCommandBase to get the server language from guild settings. Create DateLocalization to create a localized relative time remaining string. --- src/Bot/Commands/Admin/Admin.cs | 87 ++++---- src/Bot/Commands/Admin/Owner/Owner.cs | 19 +- src/Bot/Commands/Admin/Role.cs | 14 +- src/Bot/Commands/Games/Roll/Roll.cs | 19 +- src/Bot/Commands/Randomness/Ship.cs | 4 +- src/Bot/Commands/Rpg/Cookies.cs | 11 +- src/Bot/Commands/User/Karma.cs | 17 +- src/Bot/Commands/User/Ranking/Rank.cs | 13 +- src/Bot/Commands/Utils/Choose.cs | 4 +- src/Bot/Commands/Utils/Quote/Quote.cs | 5 +- src/Bot/Program.cs | 5 +- src/Bot/Utils/DateLocalization.cs | 49 +++++ src/Core/Core.csproj | 6 - src/Core/ErrorHandling/ErrorHandler.cs | 24 +-- src/Core/ErrorHandling/IErrorHandler.cs | 2 - src/Core/GeekbotCommandBase.cs | 13 +- src/Core/Localization/ITranslationHandler.cs | 17 -- .../Localization/TranslationGuildContext.cs | 90 -------- src/Core/Localization/TranslationHandler.cs | 194 ------------------ src/Core/Localization/Translations.yml | 25 --- .../TranslationGuildContext.test.cs | 71 ------- tests/Core/Localization/Translations.test.cs | 46 ----- 22 files changed, 156 insertions(+), 579 deletions(-) create mode 100644 src/Bot/Utils/DateLocalization.cs delete mode 100644 src/Core/Localization/ITranslationHandler.cs delete mode 100644 src/Core/Localization/TranslationGuildContext.cs delete mode 100644 src/Core/Localization/TranslationHandler.cs delete mode 100644 src/Core/Localization/Translations.yml delete mode 100644 tests/Core/Localization/TranslationGuildContext.test.cs delete mode 100644 tests/Core/Localization/Translations.test.cs diff --git a/src/Bot/Commands/Admin/Admin.cs b/src/Bot/Commands/Admin/Admin.cs index 2627f86..60ba8ac 100644 --- a/src/Bot/Commands/Admin/Admin.cs +++ b/src/Bot/Commands/Admin/Admin.cs @@ -14,7 +14,6 @@ using Geekbot.Core.CommandPreconditions; using Geekbot.Core.ErrorHandling; using Geekbot.Core.Extensions; using Geekbot.Core.GuildSettingsManager; -using Geekbot.Core.Localization; namespace Geekbot.Bot.Commands.Admin { @@ -24,21 +23,18 @@ namespace Geekbot.Bot.Commands.Admin public class Admin : GeekbotCommandBase { private readonly DiscordSocketClient _client; - private readonly IGuildSettingsManager _guildSettingsManager; - public Admin(DiscordSocketClient client, IErrorHandler errorHandler, IGuildSettingsManager guildSettingsManager, ITranslationHandler translationHandler) : base(errorHandler, translationHandler) + public Admin(DiscordSocketClient client, IErrorHandler errorHandler, IGuildSettingsManager guildSettingsManager) : base(errorHandler, guildSettingsManager) { _client = client; - _guildSettingsManager = guildSettingsManager; } [Command("welcome", RunMode = RunMode.Async)] [Summary("Set a Welcome Message (use '$user' to mention the new joined user).")] public async Task SetWelcomeMessage([Remainder, Summary("message")] string welcomeMessage) { - var guild = _guildSettingsManager.GetSettings(Context.Guild.Id); - guild.WelcomeMessage = welcomeMessage; - await _guildSettingsManager.UpdateSettings(guild); + GuildSettings.WelcomeMessage = welcomeMessage; + await GuildSettingsManager.UpdateSettings(GuildSettings); var formatedMessage = welcomeMessage.Replace("$user", Context.User.Mention); await ReplyAsync($"Welcome message has been changed\r\nHere is an example of how it would look:\r\n{formatedMessage}"); @@ -52,9 +48,8 @@ namespace Geekbot.Bot.Commands.Admin { var m = await channel.SendMessageAsync("..."); - var guild = _guildSettingsManager.GetSettings(Context.Guild.Id); - guild.WelcomeChannel = channel.Id.AsLong(); - await _guildSettingsManager.UpdateSettings(guild); + GuildSettings.WelcomeChannel = channel.Id.AsLong(); + await GuildSettingsManager.UpdateSettings(GuildSettings); await m.DeleteAsync(); @@ -74,9 +69,8 @@ namespace Geekbot.Bot.Commands.Admin { var m = await channel.SendMessageAsync("verifying..."); - var guild = _guildSettingsManager.GetSettings(Context.Guild.Id); - guild.ModChannel = channel.Id.AsLong(); - await _guildSettingsManager.UpdateSettings(guild); + GuildSettings.ModChannel = channel.Id.AsLong(); + await GuildSettingsManager.UpdateSettings(GuildSettings); var sb = new StringBuilder(); sb.AppendLine("Successfully saved mod channel, you can now do the following"); @@ -96,13 +90,12 @@ namespace Geekbot.Bot.Commands.Admin { try { - var guild = _guildSettingsManager.GetSettings(Context.Guild.Id); - var modChannel = await GetModChannel(guild.ModChannel.AsUlong()); + var modChannel = await GetModChannel(GuildSettings.ModChannel.AsUlong()); if (modChannel == null) return; - guild.ShowLeave = !guild.ShowLeave; - await _guildSettingsManager.UpdateSettings(guild); - await modChannel.SendMessageAsync(guild.ShowLeave + GuildSettings.ShowLeave = !GuildSettings.ShowLeave; + await GuildSettingsManager.UpdateSettings(GuildSettings); + await modChannel.SendMessageAsync(GuildSettings.ShowLeave ? "Saved - now sending messages here when someone leaves" : "Saved - stopping sending messages here when someone leaves" ); @@ -119,13 +112,12 @@ namespace Geekbot.Bot.Commands.Admin { try { - var guild = _guildSettingsManager.GetSettings(Context.Guild.Id); - var modChannel = await GetModChannel(guild.ModChannel.AsUlong()); + var modChannel = await GetModChannel(GuildSettings.ModChannel.AsUlong()); if (modChannel == null) return; - guild.ShowDelete = !guild.ShowDelete; - await _guildSettingsManager.UpdateSettings(guild); - await modChannel.SendMessageAsync(guild.ShowDelete + GuildSettings.ShowDelete = !GuildSettings.ShowDelete; + await GuildSettingsManager.UpdateSettings(GuildSettings); + await modChannel.SendMessageAsync(GuildSettings.ShowDelete ? "Saved - now sending messages here when someone deletes a message" : "Saved - stopping sending messages here when someone deletes a message" ); @@ -138,31 +130,25 @@ namespace Geekbot.Bot.Commands.Admin [Command("setlang", RunMode = RunMode.Async)] [Summary("Change the bots language")] - public async Task SetLanguage([Summary("language")] string languageRaw) + public async Task SetLanguage([Summary("language")] string language) { try { - var language = languageRaw.ToUpper(); - var success = await Translations.SetLanguage(Context.Guild.Id, language); - if (success) + var availableLanguages = new List(); + availableLanguages.Add("en-GB"); // default + availableLanguages.AddRange(GetAvailableCultures().Select(culture => culture.Name)); + if (availableLanguages.Contains(language)) { - var guild = _guildSettingsManager.GetSettings(Context.Guild.Id); - guild.Language = language; - await _guildSettingsManager.UpdateSettings(guild); + GuildSettings.Language = language; + await GuildSettingsManager.UpdateSettings(GuildSettings); + + Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(language.ToLower() == "chde" ? "de-CH" : language); - if (language.ToLower() == "chde") - { - Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de-ch"); - } - await ReplyAsync(Localization.Admin.NewLanguageSet); return; } - - var available = new List(); - available.Add("en-GB"); // default - available.AddRange(GetAvailableCultures().Select(culture => culture.Name)); - await ReplyAsync($"That doesn't seem to be a supported language\nSupported Languages are {string.Join(", ", available)}"); + + await ReplyAsync($"That doesn't seem to be a supported language\nSupported Languages are {string.Join(", ", availableLanguages)}"); } catch (Exception e) { @@ -177,9 +163,8 @@ namespace Geekbot.Bot.Commands.Admin try { var language = languageRaw.ToLower(); - var guild = _guildSettingsManager.GetSettings(Context.Guild.Id); - guild.WikiLang = language; - await _guildSettingsManager.UpdateSettings(guild); + GuildSettings.WikiLang = language; + await GuildSettingsManager.UpdateSettings(GuildSettings); await ReplyAsync($"Now using the {language} wikipedia"); } @@ -195,10 +180,10 @@ namespace Geekbot.Bot.Commands.Admin { try { - var guild = _guildSettingsManager.GetSettings(Context.Guild.Id); - guild.Ping = !guild.Ping; - await _guildSettingsManager.UpdateSettings(guild); - await ReplyAsync(guild.Ping ? "i will reply to ping now" : "No more pongs..."); + // var guild = _guildSettingsManager.GetSettings(Context.Guild.Id); + GuildSettings.Ping = !GuildSettings.Ping; + await GuildSettingsManager.UpdateSettings(GuildSettings); + await ReplyAsync(GuildSettings.Ping ? "i will reply to ping now" : "No more pongs..."); } catch (Exception e) { @@ -212,10 +197,10 @@ namespace Geekbot.Bot.Commands.Admin { try { - var guild = _guildSettingsManager.GetSettings(Context.Guild.Id); - guild.Hui = !guild.Hui; - await _guildSettingsManager.UpdateSettings(guild); - await ReplyAsync(guild.Hui ? "i will reply to hui now" : "No more hui's..."); + // var guild = _guildSettingsManager.GetSettings(Context.Guild.Id); + GuildSettings.Hui = !GuildSettings.Hui; + await GuildSettingsManager.UpdateSettings(GuildSettings); + await ReplyAsync(GuildSettings.Hui ? "i will reply to hui now" : "No more hui's..."); } catch (Exception e) { diff --git a/src/Bot/Commands/Admin/Owner/Owner.cs b/src/Bot/Commands/Admin/Owner/Owner.cs index 5fa3976..64292e9 100644 --- a/src/Bot/Commands/Admin/Owner/Owner.cs +++ b/src/Bot/Commands/Admin/Owner/Owner.cs @@ -3,8 +3,10 @@ using System.Threading.Tasks; using Discord; using Discord.Commands; using Discord.WebSocket; +using Geekbot.Core; using Geekbot.Core.ErrorHandling; using Geekbot.Core.GlobalSettings; +using Geekbot.Core.GuildSettingsManager; using Geekbot.Core.Logger; using Geekbot.Core.UserRepository; @@ -12,20 +14,19 @@ namespace Geekbot.Bot.Commands.Admin.Owner { [Group("owner")] [RequireOwner] - public class Owner : ModuleBase + public class Owner : GeekbotCommandBase { private readonly DiscordSocketClient _client; - private readonly IErrorHandler _errorHandler; private readonly IGlobalSettings _globalSettings; private readonly IGeekbotLogger _logger; private readonly IUserRepository _userRepository; - public Owner(DiscordSocketClient client, IGeekbotLogger logger, IUserRepository userRepositry, IErrorHandler errorHandler, IGlobalSettings globalSettings) + public Owner(DiscordSocketClient client, IGeekbotLogger logger, IUserRepository userRepositry, IErrorHandler errorHandler, IGlobalSettings globalSettings, + IGuildSettingsManager guildSettingsManager) : base(errorHandler, guildSettingsManager) { _client = client; _logger = logger; _userRepository = userRepositry; - _errorHandler = errorHandler; _globalSettings = globalSettings; } @@ -73,7 +74,7 @@ namespace Geekbot.Bot.Commands.Admin.Owner } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context, + await ErrorHandler.HandleCommandException(e, Context, "Couldn't complete User Repository, see console for more info"); } } @@ -89,10 +90,10 @@ namespace Geekbot.Bot.Commands.Admin.Owner } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } - + [Command("refreshuser", RunMode = RunMode.Async)] [Summary("Refresh a user in the user cache")] public async Task PopUserRepoCommand([Summary("user-id")] ulong userId) @@ -105,7 +106,7 @@ namespace Geekbot.Bot.Commands.Admin.Owner } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } @@ -119,7 +120,7 @@ namespace Geekbot.Bot.Commands.Admin.Owner } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } } diff --git a/src/Bot/Commands/Admin/Role.cs b/src/Bot/Commands/Admin/Role.cs index c8459dd..efec7bd 100644 --- a/src/Bot/Commands/Admin/Role.cs +++ b/src/Bot/Commands/Admin/Role.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Net; using System.Text; using System.Threading.Tasks; using Discord; @@ -11,7 +12,7 @@ using Geekbot.Core.Database; using Geekbot.Core.Database.Models; using Geekbot.Core.ErrorHandling; using Geekbot.Core.Extensions; -using Geekbot.Core.Localization; +using Geekbot.Core.GuildSettingsManager; using Geekbot.Core.ReactionListener; namespace Geekbot.Bot.Commands.Admin @@ -23,7 +24,7 @@ namespace Geekbot.Bot.Commands.Admin private readonly DatabaseContext _database; private readonly IReactionListener _reactionListener; - public Role(DatabaseContext database, IErrorHandler errorHandler, IReactionListener reactionListener, ITranslationHandler translationHandler) : base(errorHandler, translationHandler) + public Role(DatabaseContext database, IErrorHandler errorHandler, IReactionListener reactionListener, IGuildSettingsManager guildSettingsManager) : base(errorHandler, guildSettingsManager) { _database = database; _reactionListener = reactionListener; @@ -89,7 +90,14 @@ namespace Geekbot.Bot.Commands.Admin } catch (HttpException e) { - await ErrorHandler.HandleHttpException(e, Context); + if (e.HttpCode == HttpStatusCode.Forbidden) + { + await ReplyAsync(Localization.Internal.Http403); + } + else + { + await ErrorHandler.HandleCommandException(e, Context); + } } catch (Exception e) { diff --git a/src/Bot/Commands/Games/Roll/Roll.cs b/src/Bot/Commands/Games/Roll/Roll.cs index 244edbe..6ef9322 100644 --- a/src/Bot/Commands/Games/Roll/Roll.cs +++ b/src/Bot/Commands/Games/Roll/Roll.cs @@ -2,13 +2,14 @@ using System.Linq; using System.Threading.Tasks; using Discord.Commands; +using Geekbot.Bot.Utils; using Geekbot.Core; using Geekbot.Core.Database; using Geekbot.Core.Database.Models; using Geekbot.Core.ErrorHandling; using Geekbot.Core.Extensions; +using Geekbot.Core.GuildSettingsManager; using Geekbot.Core.KvInMemoryStore; -using Geekbot.Core.Localization; using Geekbot.Core.RandomNumberGenerator; namespace Geekbot.Bot.Commands.Games.Roll @@ -19,7 +20,8 @@ namespace Geekbot.Bot.Commands.Games.Roll private readonly DatabaseContext _database; private readonly IRandomNumberGenerator _randomNumberGenerator; - public Roll(IKvInMemoryStore kvInMemoryStore,IErrorHandler errorHandler, ITranslationHandler translation, DatabaseContext database, IRandomNumberGenerator randomNumberGenerator) : base(errorHandler, translation) + public Roll(IKvInMemoryStore kvInMemoryStore, IErrorHandler errorHandler, DatabaseContext database, IRandomNumberGenerator randomNumberGenerator, IGuildSettingsManager guildSettingsManager) + : base(errorHandler, guildSettingsManager) { _kvInMemoryStore = kvInMemoryStore; _database = database; @@ -34,10 +36,9 @@ namespace Geekbot.Bot.Commands.Games.Roll { var number = _randomNumberGenerator.Next(1, 100); int.TryParse(stuff, out var guess); - var transContext = await Translations.GetGuildContext(Context); if (guess <= 100 && guess > 0) { - var kvKey = $"{Context.Guild.Id}:{Context.User.Id}:RollsPrevious"; + var kvKey = $"{Context?.Guild?.Id ?? 0}:{Context.User.Id}:RollsPrevious"; var prevRoll = _kvInMemoryStore.Get(kvKey); @@ -46,11 +47,11 @@ namespace Geekbot.Bot.Commands.Games.Roll await ReplyAsync(string.Format( Localization.Roll.NoPrevGuess, Context.Message.Author.Mention, - transContext.FormatDateTimeAsRemaining(prevRoll.GuessedOn.AddDays(1)))); + DateLocalization.FormatDateTimeAsRemaining(prevRoll.GuessedOn.AddDays(1)))); return; } - _kvInMemoryStore.Set(kvKey, new RollTimeout { LastGuess = guess, GuessedOn = DateTime.Now }); + _kvInMemoryStore.Set(kvKey, new RollTimeout {LastGuess = guess, GuessedOn = DateTime.Now}); await ReplyAsync(string.Format(Localization.Roll.Rolled, Context.Message.Author.Mention, number, guess)); if (guess == number) @@ -72,13 +73,13 @@ namespace Geekbot.Bot.Commands.Games.Roll await ErrorHandler.HandleCommandException(e, Context); } } - + private async Task GetUser(ulong userId) { - var user = _database.Rolls.FirstOrDefault(u =>u.GuildId.Equals(Context.Guild.Id.AsLong()) && u.UserId.Equals(userId.AsLong())) ?? await CreateNewRow(userId); + var user = _database.Rolls.FirstOrDefault(u => u.GuildId.Equals(Context.Guild.Id.AsLong()) && u.UserId.Equals(userId.AsLong())) ?? await CreateNewRow(userId); return user; } - + private async Task CreateNewRow(ulong userId) { var user = new RollsModel() diff --git a/src/Bot/Commands/Randomness/Ship.cs b/src/Bot/Commands/Randomness/Ship.cs index 78f3c99..f48713e 100644 --- a/src/Bot/Commands/Randomness/Ship.cs +++ b/src/Bot/Commands/Randomness/Ship.cs @@ -8,7 +8,7 @@ using Geekbot.Core.Database; using Geekbot.Core.Database.Models; using Geekbot.Core.ErrorHandling; using Geekbot.Core.Extensions; -using Geekbot.Core.Localization; +using Geekbot.Core.GuildSettingsManager; using Geekbot.Core.RandomNumberGenerator; namespace Geekbot.Bot.Commands.Randomness @@ -18,7 +18,7 @@ namespace Geekbot.Bot.Commands.Randomness private readonly IRandomNumberGenerator _randomNumberGenerator; private readonly DatabaseContext _database; - public Ship(DatabaseContext database, IErrorHandler errorHandler, IRandomNumberGenerator randomNumberGenerator, ITranslationHandler translations) : base(errorHandler, translations) + public Ship(DatabaseContext database, IErrorHandler errorHandler, IRandomNumberGenerator randomNumberGenerator, IGuildSettingsManager guildSettingsManager) : base(errorHandler, guildSettingsManager) { _database = database; _randomNumberGenerator = randomNumberGenerator; diff --git a/src/Bot/Commands/Rpg/Cookies.cs b/src/Bot/Commands/Rpg/Cookies.cs index 570f08a..a51d652 100644 --- a/src/Bot/Commands/Rpg/Cookies.cs +++ b/src/Bot/Commands/Rpg/Cookies.cs @@ -3,13 +3,14 @@ using System.Linq; using System.Threading.Tasks; using Discord; using Discord.Commands; +using Geekbot.Bot.Utils; using Geekbot.Core; using Geekbot.Core.CommandPreconditions; using Geekbot.Core.Database; using Geekbot.Core.Database.Models; using Geekbot.Core.ErrorHandling; using Geekbot.Core.Extensions; -using Geekbot.Core.Localization; +using Geekbot.Core.GuildSettingsManager; using Geekbot.Core.RandomNumberGenerator; namespace Geekbot.Bot.Commands.Rpg @@ -22,7 +23,8 @@ namespace Geekbot.Bot.Commands.Rpg private readonly DatabaseContext _database; private readonly IRandomNumberGenerator _randomNumberGenerator; - public Cookies(DatabaseContext database, IErrorHandler errorHandler, ITranslationHandler translations , IRandomNumberGenerator randomNumberGenerator) : base(errorHandler, translations) + public Cookies(DatabaseContext database, IErrorHandler errorHandler, IRandomNumberGenerator randomNumberGenerator, IGuildSettingsManager guildSettingsManager) + : base(errorHandler, guildSettingsManager) { _database = database; _randomNumberGenerator = randomNumberGenerator; @@ -34,12 +36,11 @@ namespace Geekbot.Bot.Commands.Rpg { try { - var transContext = await Translations.GetGuildContext(Context); var actor = await GetUser(Context.User.Id); if (actor.LastPayout.Value.AddDays(1).Date > DateTime.Now.Date) { - var formatedWaitTime = transContext.FormatDateTimeAsRemaining(DateTimeOffset.Now.AddDays(1).Date); - await ReplyAsync(string.Format(Localization.Cookies.WaitForMoreCookies, formatedWaitTime)); + var formattedWaitTime = DateLocalization.FormatDateTimeAsRemaining(DateTimeOffset.Now.AddDays(1).Date); + await ReplyAsync(string.Format(Localization.Cookies.WaitForMoreCookies, formattedWaitTime)); return; } actor.Cookies += 10; diff --git a/src/Bot/Commands/User/Karma.cs b/src/Bot/Commands/User/Karma.cs index 41a401c..4778bce 100644 --- a/src/Bot/Commands/User/Karma.cs +++ b/src/Bot/Commands/User/Karma.cs @@ -1,17 +1,16 @@ using System; -using System.Globalization; using System.Linq; -using System.Threading; using System.Threading.Tasks; using Discord; using Discord.Commands; +using Geekbot.Bot.Utils; using Geekbot.Core; using Geekbot.Core.CommandPreconditions; using Geekbot.Core.Database; using Geekbot.Core.Database.Models; using Geekbot.Core.ErrorHandling; using Geekbot.Core.Extensions; -using Geekbot.Core.Localization; +using Geekbot.Core.GuildSettingsManager; namespace Geekbot.Bot.Commands.User { @@ -19,12 +18,10 @@ namespace Geekbot.Bot.Commands.User public class Karma : GeekbotCommandBase { private readonly DatabaseContext _database; - private readonly ITranslationHandler _translations; - public Karma(DatabaseContext database, IErrorHandler errorHandler, ITranslationHandler translations) : base(errorHandler, translations) + public Karma(DatabaseContext database, IErrorHandler errorHandler, IGuildSettingsManager guildSettingsManager) : base(errorHandler, guildSettingsManager) { _database = database; - _translations = translations; } [Command("good", RunMode = RunMode.Async)] @@ -33,8 +30,6 @@ namespace Geekbot.Bot.Commands.User { try { - var transContext = await _translations.GetGuildContext(Context); - var actor = await GetUser(Context.User.Id); if (user.Id == Context.User.Id) { @@ -42,7 +37,7 @@ namespace Geekbot.Bot.Commands.User } else if (TimeoutFinished(actor.TimeOut)) { - var formatedWaitTime = transContext.FormatDateTimeAsRemaining(actor.TimeOut.AddMinutes(3)); + var formatedWaitTime = DateLocalization.FormatDateTimeAsRemaining(actor.TimeOut.AddMinutes(3)); await ReplyAsync(string.Format(Localization.Karma.WaitUntill, Context.User.Username, formatedWaitTime)); } else @@ -81,8 +76,6 @@ namespace Geekbot.Bot.Commands.User { try { - var transContext = await _translations.GetGuildContext(Context); - var actor = await GetUser(Context.User.Id); if (user.Id == Context.User.Id) { @@ -90,7 +83,7 @@ namespace Geekbot.Bot.Commands.User } else if (TimeoutFinished(actor.TimeOut)) { - var formatedWaitTime = transContext.FormatDateTimeAsRemaining(actor.TimeOut.AddMinutes(3)); + var formatedWaitTime = DateLocalization.FormatDateTimeAsRemaining(actor.TimeOut.AddMinutes(3)); await ReplyAsync(string.Format(Localization.Karma.WaitUntill, Context.User.Username, formatedWaitTime)); } else diff --git a/src/Bot/Commands/User/Ranking/Rank.cs b/src/Bot/Commands/User/Ranking/Rank.cs index d73aacc..20749a8 100644 --- a/src/Bot/Commands/User/Ranking/Rank.cs +++ b/src/Bot/Commands/User/Ranking/Rank.cs @@ -10,8 +10,8 @@ using Geekbot.Core.Converters; using Geekbot.Core.Database; using Geekbot.Core.ErrorHandling; using Geekbot.Core.Extensions; +using Geekbot.Core.GuildSettingsManager; using Geekbot.Core.Highscores; -using Geekbot.Core.Localization; namespace Geekbot.Bot.Commands.User.Ranking { @@ -21,7 +21,8 @@ namespace Geekbot.Bot.Commands.User.Ranking private readonly IHighscoreManager _highscoreManager; private readonly DatabaseContext _database; - public Rank(DatabaseContext database, IErrorHandler errorHandler, IEmojiConverter emojiConverter, IHighscoreManager highscoreManager, ITranslationHandler translations): base(errorHandler, translations) + public Rank(DatabaseContext database, IErrorHandler errorHandler, IEmojiConverter emojiConverter, IHighscoreManager highscoreManager, IGuildSettingsManager guildSettingsManager) + : base(errorHandler, guildSettingsManager) { _database = database; _emojiConverter = emojiConverter; @@ -53,7 +54,7 @@ namespace Geekbot.Bot.Commands.User.Ranking await ReplyAsync(Localization.Rank.LimitingTo20Warning); amount = 20; } - + var guildId = Context.Guild.Id; Dictionary highscoreUsers; try @@ -78,9 +79,9 @@ namespace Geekbot.Bot.Commands.User.Ranking var failedToRetrieveUser = highscoreUsers.Any(e => string.IsNullOrEmpty(e.Key.Username)); if (failedToRetrieveUser) replyBuilder.AppendLine(Localization.Rank.FailedToResolveAllUsernames).AppendLine(); - + replyBuilder.AppendLine(string.Format(Localization.Rank.HighscoresFor, type.ToString().CapitalizeFirst(), Context.Guild.Name)); - + var highscorePlace = 1; foreach (var (user, value) in highscoreUsers) { @@ -91,7 +92,7 @@ namespace Geekbot.Bot.Commands.User.Ranking replyBuilder.Append(user.Username != null ? $"**{user.Username}#{user.Discriminator}**" : $"**{user.Id}**"); - + replyBuilder.Append(type == HighscoreTypes.messages ? $" - {value} {type} - {Math.Round((double) (100 * value) / guildMessages, 2)}%\n" : $" - {value} {type}\n"); diff --git a/src/Bot/Commands/Utils/Choose.cs b/src/Bot/Commands/Utils/Choose.cs index ea239d7..731bee6 100644 --- a/src/Bot/Commands/Utils/Choose.cs +++ b/src/Bot/Commands/Utils/Choose.cs @@ -3,13 +3,13 @@ using System.Threading.Tasks; using Discord.Commands; using Geekbot.Core; using Geekbot.Core.ErrorHandling; -using Geekbot.Core.Localization; +using Geekbot.Core.GuildSettingsManager; namespace Geekbot.Bot.Commands.Utils { public class Choose : GeekbotCommandBase { - public Choose(IErrorHandler errorHandler, ITranslationHandler translation) : base(errorHandler, translation) + public Choose(IErrorHandler errorHandler, IGuildSettingsManager guildSettingsManager) : base(errorHandler, guildSettingsManager) { } diff --git a/src/Bot/Commands/Utils/Quote/Quote.cs b/src/Bot/Commands/Utils/Quote/Quote.cs index 5bb23a9..a7d3ff1 100644 --- a/src/Bot/Commands/Utils/Quote/Quote.cs +++ b/src/Bot/Commands/Utils/Quote/Quote.cs @@ -9,7 +9,7 @@ using Geekbot.Core.Database; using Geekbot.Core.Database.Models; using Geekbot.Core.ErrorHandling; using Geekbot.Core.Extensions; -using Geekbot.Core.Localization; +using Geekbot.Core.GuildSettingsManager; using Geekbot.Core.Polyfills; using Geekbot.Core.RandomNumberGenerator; @@ -23,7 +23,8 @@ namespace Geekbot.Bot.Commands.Utils.Quote private readonly IRandomNumberGenerator _randomNumberGenerator; private readonly bool _isDev; - public Quote(IErrorHandler errorHandler, DatabaseContext database, IRandomNumberGenerator randomNumberGenerator, ITranslationHandler translationHandler) : base(errorHandler, translationHandler) + public Quote(IErrorHandler errorHandler, DatabaseContext database, IRandomNumberGenerator randomNumberGenerator, IGuildSettingsManager guildSettingsManager) + : base(errorHandler, guildSettingsManager) { _database = database; _randomNumberGenerator = randomNumberGenerator; diff --git a/src/Bot/Program.cs b/src/Bot/Program.cs index 04b1450..5a4b456 100644 --- a/src/Bot/Program.cs +++ b/src/Bot/Program.cs @@ -17,7 +17,6 @@ using Geekbot.Core.GuildSettingsManager; using Geekbot.Core.Highscores; using Geekbot.Core.KvInMemoryStore; using Geekbot.Core.Levels; -using Geekbot.Core.Localization; using Geekbot.Core.Logger; using Geekbot.Core.MalClient; using Geekbot.Core.Media; @@ -168,8 +167,7 @@ namespace Geekbot.Bot var randomNumberGenerator = new RandomNumberGenerator(); var mediaProvider = new MediaProvider(_logger, randomNumberGenerator); var kvMemoryStore = new KvInInMemoryStore(); - var translationHandler = new TranslationHandler(_logger, _guildSettingsManager); - var errorHandler = new ErrorHandler(_logger, translationHandler, _runParameters); + var errorHandler = new ErrorHandler(_logger, _runParameters, () => Localization.Internal.SomethingWentWrong); var diceParser = new DiceParser(randomNumberGenerator); services.AddSingleton(_userRepository); @@ -186,7 +184,6 @@ namespace Geekbot.Bot services.AddSingleton(_globalSettings); services.AddSingleton(errorHandler); services.AddSingleton(diceParser); - services.AddSingleton(translationHandler); services.AddSingleton(_reactionListener); services.AddSingleton(_guildSettingsManager); services.AddSingleton(_client); diff --git a/src/Bot/Utils/DateLocalization.cs b/src/Bot/Utils/DateLocalization.cs new file mode 100644 index 0000000..eea40fb --- /dev/null +++ b/src/Bot/Utils/DateLocalization.cs @@ -0,0 +1,49 @@ +using System; +using System.Text; + +namespace Geekbot.Bot.Utils +{ + public class DateLocalization + { + public static string FormatDateTimeAsRemaining(DateTimeOffset dateTime) + { + var remaining = dateTime - DateTimeOffset.Now; + const string formattable = "{0} {1}"; + var sb = new StringBuilder(); + + if (remaining.Days > 0) + { + sb.AppendFormat(formattable, remaining.Days, GetSingularOrPlural(remaining.Days, Localization.Internal.Days)); + } + + if (remaining.Hours > 0) + { + if (sb.Length > 0) sb.Append(", "); + sb.AppendFormat(formattable, remaining.Hours, GetSingularOrPlural(remaining.Hours, Localization.Internal.Hours)); + } + + if (remaining.Minutes > 0) + { + if (sb.Length > 0) sb.Append(", "); + sb.AppendFormat(formattable, remaining.Minutes, GetSingularOrPlural(remaining.Minutes, Localization.Internal.Minutes)); + } + + if (remaining.Seconds > 0) + { + if (sb.Length > 0) + { + sb.AppendFormat(" {0} ", Localization.Internal.And); + } + sb.AppendFormat(formattable, remaining.Seconds, GetSingularOrPlural(remaining.Seconds, Localization.Internal.Seconds)); + } + + return sb.ToString().Trim(); + } + + private static string GetSingularOrPlural(int number, string rawString) + { + var versions = rawString.Split('|'); + return number == 1 ? versions[0] : versions[1]; + } + } +} \ No newline at end of file diff --git a/src/Core/Core.csproj b/src/Core/Core.csproj index fcbce09..fd44a95 100644 --- a/src/Core/Core.csproj +++ b/src/Core/Core.csproj @@ -31,10 +31,4 @@ - - - PreserveNewest - - - diff --git a/src/Core/ErrorHandling/ErrorHandler.cs b/src/Core/ErrorHandling/ErrorHandler.cs index 02402f2..47ed22d 100644 --- a/src/Core/ErrorHandling/ErrorHandler.cs +++ b/src/Core/ErrorHandling/ErrorHandler.cs @@ -1,9 +1,6 @@ using System; -using System.Net; using System.Threading.Tasks; using Discord.Commands; -using Discord.Net; -using Geekbot.Core.Localization; using Geekbot.Core.Logger; using SharpRaven; using SharpRaven.Data; @@ -14,14 +11,14 @@ namespace Geekbot.Core.ErrorHandling public class ErrorHandler : IErrorHandler { private readonly IGeekbotLogger _logger; - private readonly ITranslationHandler _translation; + private readonly Func _getDefaultErrorText; private readonly IRavenClient _raven; private readonly bool _errorsInChat; - public ErrorHandler(IGeekbotLogger logger, ITranslationHandler translation, RunParameters runParameters) + public ErrorHandler(IGeekbotLogger logger, RunParameters runParameters, Func getDefaultErrorText) { _logger = logger; - _translation = translation; + _getDefaultErrorText = getDefaultErrorText; _errorsInChat = runParameters.ExposeErrors; var sentryDsn = runParameters.SentryEndpoint; @@ -40,7 +37,9 @@ namespace Geekbot.Core.ErrorHandling { try { - var errorString = errorMessage == "def" ? await _translation.GetString(context.Guild?.Id ?? 0, "errorHandler", "SomethingWentWrong") : errorMessage; + var errorString = errorMessage == "def" + ? _getDefaultErrorText() + : errorMessage; var errorObj = SimpleConextConverter.ConvertContext(context); if (e.Message.Contains("50007")) return; if (e.Message.Contains("50013")) return; @@ -76,17 +75,6 @@ namespace Geekbot.Core.ErrorHandling } } - public async Task HandleHttpException(HttpException e, ICommandContext context) - { - var errorStrings = await _translation.GetDict(context, "httpErrors"); - switch(e.HttpCode) - { - case HttpStatusCode.Forbidden: - await context.Channel.SendMessageAsync(errorStrings["403"]); - break; - } - } - private void ReportExternal(Exception e, MessageDto errorObj) { if (_raven == null) return; diff --git a/src/Core/ErrorHandling/IErrorHandler.cs b/src/Core/ErrorHandling/IErrorHandler.cs index c012b82..d0e1d20 100644 --- a/src/Core/ErrorHandling/IErrorHandler.cs +++ b/src/Core/ErrorHandling/IErrorHandler.cs @@ -1,13 +1,11 @@ using System; using System.Threading.Tasks; using Discord.Commands; -using Discord.Net; namespace Geekbot.Core.ErrorHandling { public interface IErrorHandler { Task HandleCommandException(Exception e, ICommandContext context, string errorMessage = "def"); - Task HandleHttpException(HttpException e, ICommandContext context); } } \ No newline at end of file diff --git a/src/Core/GeekbotCommandBase.cs b/src/Core/GeekbotCommandBase.cs index 8df5265..43ced95 100644 --- a/src/Core/GeekbotCommandBase.cs +++ b/src/Core/GeekbotCommandBase.cs @@ -1,26 +1,29 @@ using System.Globalization; using System.Threading; using Discord.Commands; +using Geekbot.Core.Database.Models; using Geekbot.Core.ErrorHandling; -using Geekbot.Core.Localization; +using Geekbot.Core.GuildSettingsManager; namespace Geekbot.Core { public class GeekbotCommandBase : ModuleBase { + protected readonly IGuildSettingsManager GuildSettingsManager; + protected GuildSettingsModel GuildSettings; protected readonly IErrorHandler ErrorHandler; - protected readonly ITranslationHandler Translations; - protected GeekbotCommandBase(IErrorHandler errorHandler, ITranslationHandler translations) + protected GeekbotCommandBase(IErrorHandler errorHandler, IGuildSettingsManager guildSettingsManager) { + GuildSettingsManager = guildSettingsManager; ErrorHandler = errorHandler; - Translations = translations; } protected override void BeforeExecute(CommandInfo command) { base.BeforeExecute(command); - var language = Translations.GetServerLanguage(Context.Guild.Id); + GuildSettings = GuildSettingsManager.GetSettings(Context?.Guild?.Id ?? 0); + var language = GuildSettings.Language; Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(language == "CHDE" ? "de-ch" : language); } } diff --git a/src/Core/Localization/ITranslationHandler.cs b/src/Core/Localization/ITranslationHandler.cs deleted file mode 100644 index 1cc06fa..0000000 --- a/src/Core/Localization/ITranslationHandler.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using Discord.Commands; - -namespace Geekbot.Core.Localization -{ - public interface ITranslationHandler - { - Task GetString(ulong guildId, string command, string stringName); - string GetString(string language, string command, string stringName); - Task> GetDict(ICommandContext context, string command); - Task GetGuildContext(ICommandContext context); - Task SetLanguage(ulong guildId, string language); - List SupportedLanguages { get; } - string GetServerLanguage(ulong guildId); - } -} \ No newline at end of file diff --git a/src/Core/Localization/TranslationGuildContext.cs b/src/Core/Localization/TranslationGuildContext.cs deleted file mode 100644 index 25685da..0000000 --- a/src/Core/Localization/TranslationGuildContext.cs +++ /dev/null @@ -1,90 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; - -namespace Geekbot.Core.Localization -{ - public class TranslationGuildContext - { - public ITranslationHandler TranslationHandler { get; } - public string Language { get; } - public Dictionary Dict { get; } - - public TranslationGuildContext(ITranslationHandler translationHandler, string language, Dictionary dict) - { - TranslationHandler = translationHandler; - Language = language; - Dict = dict; - } - - public string GetString(string stringToFormat, params object[] args) - { - return string.Format(Dict[stringToFormat] ?? "", args); - } - - public string FormatDateTimeAsRemaining(DateTimeOffset dateTime) - { - var remaining = dateTime - DateTimeOffset.Now; - const string formattable = "{0} {1}"; - var sb = new StringBuilder(); - - if (remaining.Days > 0) - { - var s = GetTimeString(TimeTypes.Days); - sb.AppendFormat(formattable, remaining.Days, GetSingOrPlur(remaining.Days, s)); - } - - if (remaining.Hours > 0) - { - if (sb.Length > 0) sb.Append(", "); - var s = GetTimeString(TimeTypes.Hours); - sb.AppendFormat(formattable, remaining.Hours, GetSingOrPlur(remaining.Hours, s)); - } - - if (remaining.Minutes > 0) - { - if (sb.Length > 0) sb.Append(", "); - var s = GetTimeString(TimeTypes.Minutes); - sb.AppendFormat(formattable, remaining.Minutes, GetSingOrPlur(remaining.Minutes, s)); - } - - if (remaining.Seconds > 0) - { - if (sb.Length > 0) - { - var and = TranslationHandler.GetString(Language, "dateTime", "And"); - sb.AppendFormat(" {0} ", and); - } - var s = GetTimeString(TimeTypes.Seconds); - sb.AppendFormat(formattable, remaining.Seconds, GetSingOrPlur(remaining.Seconds, s)); - } - - return sb.ToString().Trim(); - } - - public Task SetLanguage(ulong guildId, string language) - { - return TranslationHandler.SetLanguage(guildId, language); - } - - private string GetTimeString(TimeTypes type) - { - return TranslationHandler.GetString(Language, "dateTime", type.ToString()); - } - - private string GetSingOrPlur(int number, string rawString) - { - var versions = rawString.Split('|'); - return number == 1 ? versions[0] : versions[1]; - } - - private enum TimeTypes - { - Days, - Hours, - Minutes, - Seconds - } - } -} \ No newline at end of file diff --git a/src/Core/Localization/TranslationHandler.cs b/src/Core/Localization/TranslationHandler.cs deleted file mode 100644 index 1a46ada..0000000 --- a/src/Core/Localization/TranslationHandler.cs +++ /dev/null @@ -1,194 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Discord.Commands; -using Geekbot.Core.GuildSettingsManager; -using Geekbot.Core.Logger; -using YamlDotNet.Core; -using YamlDotNet.Serialization; - -namespace Geekbot.Core.Localization -{ - public class TranslationHandler : ITranslationHandler - { - private readonly IGeekbotLogger _logger; - private readonly IGuildSettingsManager _guildSettingsManager; - private readonly Dictionary _serverLanguages; - private Dictionary>> _translations; - - public TranslationHandler(IGeekbotLogger logger, IGuildSettingsManager guildSettingsManager) - { - _logger = logger; - _guildSettingsManager = guildSettingsManager; - _logger.Information(LogSource.Geekbot, "Loading Translations"); - LoadTranslations(); - _serverLanguages = new Dictionary(); - } - - private void LoadTranslations() - { - try - { - // Read the file - var translationFile = File.ReadAllText(Path.GetFullPath("./Localization/Translations.yml")); - - // Deserialize - var input = new StringReader(translationFile); - var mergingParser = new MergingParser(new Parser(input)); - var deserializer = new DeserializerBuilder().Build(); - var rawTranslations = deserializer.Deserialize>>>(mergingParser); - - // Sort - var sortedPerLanguage = new Dictionary>>(); - foreach (var command in rawTranslations) - { - foreach (var str in command.Value) - { - foreach (var lang in str.Value) - { - if (!sortedPerLanguage.ContainsKey(lang.Key)) - { - var commandDict = new Dictionary>(); - var strDict = new Dictionary - { - {str.Key, lang.Value} - }; - commandDict.Add(command.Key, strDict); - sortedPerLanguage.Add(lang.Key, commandDict); - } - if (!sortedPerLanguage[lang.Key].ContainsKey(command.Key)) - { - var strDict = new Dictionary - { - {str.Key, lang.Value} - }; - sortedPerLanguage[lang.Key].Add(command.Key, strDict); - } - if (!sortedPerLanguage[lang.Key][command.Key].ContainsKey(str.Key)) - { - sortedPerLanguage[lang.Key][command.Key].Add(str.Key, lang.Value); - } - } - } - } - _translations = sortedPerLanguage; - - // Find Languages - SupportedLanguages = new List(); - foreach (var lang in sortedPerLanguage) - { - SupportedLanguages.Add(lang.Key); - } - } - catch (Exception e) - { - _logger.Error(LogSource.Geekbot, "Failed to load Translations", e); - Environment.Exit(GeekbotExitCode.TranslationsFailed.GetHashCode()); - } - } - - public string GetServerLanguage(ulong guildId) - { - try - { - string lang; - try - { - lang = _serverLanguages[guildId]; - if (!string.IsNullOrEmpty(lang)) - { - return lang; - } - throw new Exception(); - } - catch - { - lang = _guildSettingsManager.GetSettings(guildId, false)?.Language ?? "EN"; - _serverLanguages[guildId] = lang; - return lang; - } - } - catch (Exception e) - { - _logger.Error(LogSource.Geekbot, "Could not get guild language", e); - return "EN"; - } - } - - public async Task GetString(ulong guildId, string command, string stringName) - { - var serverLang = GetServerLanguage(guildId); - return GetString(serverLang, command, stringName); - } - - public string GetString(string language, string command, string stringName) - { - var translation = _translations[language][command][stringName]; - if (!string.IsNullOrWhiteSpace(translation)) return translation; - translation = _translations[command][stringName]["EN"]; - if (string.IsNullOrWhiteSpace(translation)) - { - _logger.Warning(LogSource.Geekbot, $"No translation found for {command} - {stringName}"); - } - return translation; - } - - private async Task> GetDict(ICommandContext context) - { - try - { - var command = context.Message.Content.Split(' ').First().TrimStart('!').ToLower(); - var serverLanguage = GetServerLanguage(context.Guild?.Id ?? 0); - return _translations[serverLanguage][command]; - } - catch (Exception e) - { - _logger.Error(LogSource.Geekbot, "No translations for command found", e); - return new Dictionary(); - } - } - - public async Task GetGuildContext(ICommandContext context) - { - var dict = await GetDict(context); - var language = GetServerLanguage(context.Guild?.Id ?? 0); - return new TranslationGuildContext(this, language, dict); - } - - public async Task> GetDict(ICommandContext context, string command) - { - try - { - var serverLanguage = GetServerLanguage(context.Guild?.Id ?? 0); - return _translations[serverLanguage][command]; - } - catch (Exception e) - { - _logger.Error(LogSource.Geekbot, "No translations for command found", e); - return new Dictionary(); - } - } - - public async Task SetLanguage(ulong guildId, string language) - { - try - { - if (!SupportedLanguages.Contains(language)) return false; - var guild = _guildSettingsManager.GetSettings(guildId); - guild.Language = language; - await _guildSettingsManager.UpdateSettings(guild); - _serverLanguages[guildId] = language; - return true; - } - catch (Exception e) - { - _logger.Error(LogSource.Geekbot, "Error while changing language", e); - return false; - } - } - - public List SupportedLanguages { get; private set; } - } -} \ No newline at end of file diff --git a/src/Core/Localization/Translations.yml b/src/Core/Localization/Translations.yml deleted file mode 100644 index dc18c2b..0000000 --- a/src/Core/Localization/Translations.yml +++ /dev/null @@ -1,25 +0,0 @@ ---- -dateTime: - Days: - EN: "day|days" - CHDE: "tag|täg" - Hours: - EN: "hour|hours" - CHDE: "stund|stunde" - Minutes: - EN: "minute|minutes" - CHDE: "minute|minute" - Seconds: - EN: "second|seconds" - CHDE: "sekunde|sekunde" - And: - EN: "and" - CHDE: "und" -errorHandler: - SomethingWentWrong: - EN: "Something went wrong :confused:" - CHDE: "Öppis isch schief gange :confused:" -httpErrors: - 403: - EN: "Seems like i don't have enough permission to that :confused:" - CHDE: "Gseht danach us das ich nid gnueg recht han zum das mache :confused:" \ No newline at end of file diff --git a/tests/Core/Localization/TranslationGuildContext.test.cs b/tests/Core/Localization/TranslationGuildContext.test.cs deleted file mode 100644 index 4aaca16..0000000 --- a/tests/Core/Localization/TranslationGuildContext.test.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System; -using System.Collections.Generic; -using Geekbot.Core.Localization; -using Moq; -using Xunit; - -namespace Tests.Core.Localization -{ - public class TranslationGuildContext_test - { - public class FormatDateTimeAsRemainingTestDto - { - public DateTimeOffset DateTime { get; set; } - public string Expected { get; set; } - } - - public static TestData FormatDateTimeAsRemainingData => - new TestData - { - { - "Wait for days", - new FormatDateTimeAsRemainingTestDto - { - DateTime = DateTimeOffset.Now.AddDays(5), - Expected = "4 days, 23 hours, 59 minutes and 59 seconds" - } - }, - { - "Wait for minutes", - new FormatDateTimeAsRemainingTestDto - { - DateTime = DateTimeOffset.Now.AddMinutes(5), - Expected = "4 minutes and 59 seconds" - } - }, - { - "Wait for seconds", - new FormatDateTimeAsRemainingTestDto - { - DateTime = DateTimeOffset.Now.AddSeconds(5), - Expected = "4 seconds" - } - } - }; - - [Theory, MemberData(nameof(FormatDateTimeAsRemainingData))] - public void FormatDateTimeAsRemaining(string testName, FormatDateTimeAsRemainingTestDto testData) - { - var translationHandlerMock = new Mock(MockBehavior.Loose); - translationHandlerMock - .Setup(thm => thm.GetString("EN", "dateTime", "Days")) - .Returns("day|days"); - translationHandlerMock - .Setup(thm => thm.GetString("EN", "dateTime", "Hours")) - .Returns("hour|hours"); - translationHandlerMock - .Setup(thm => thm.GetString("EN", "dateTime", "Minutes")) - .Returns("minute|minutes"); - translationHandlerMock - .Setup(thm => thm.GetString("EN", "dateTime", "Seconds")) - .Returns("second|seconds"); - translationHandlerMock - .Setup(thm => thm.GetString("EN", "dateTime", "And")) - .Returns("and"); - - var context = new TranslationGuildContext(translationHandlerMock.Object, "EN", new Dictionary()); - var result = context.FormatDateTimeAsRemaining(testData.DateTime); - Assert.Equal(result, testData.Expected); - } - } -} \ No newline at end of file diff --git a/tests/Core/Localization/Translations.test.cs b/tests/Core/Localization/Translations.test.cs deleted file mode 100644 index d8a0879..0000000 --- a/tests/Core/Localization/Translations.test.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using FluentAssertions; -using Xunit; -using YamlDotNet.Core; -using YamlDotNet.Serialization; - -namespace Tests.Core.Localization -{ - public class Translations_test - { - [Fact] - public void TranslationsYamlIsValid() - { - // Read the file - var translationFile = File.ReadAllText(Path.GetFullPath("./../../../../src/Core/Localization/Translations.yml")); - - // Deserialize - var input = new StringReader(translationFile); - var mergingParser = new MergingParser(new Parser(input)); - var deserializer = new DeserializerBuilder().Build(); - var rawTranslations = deserializer.Deserialize>>>(mergingParser); - - // These languages must be supported - var supportedLanguages = new List - { - "EN", - "CHDE" - }; - - // Iterate every single key to make sure it's populated - foreach (var command in rawTranslations) - { - foreach (var str in command.Value) - { - str.Value.Select(e => e.Key).ToList().Should().BeEquivalentTo(supportedLanguages, str.Key); - foreach (var lang in str.Value) - { - lang.Value.Should().NotBeNullOrEmpty($"{command.Key} / {str.Key} / {lang.Key}"); - } - } - } - } - } -} \ No newline at end of file From 60e36daaec4a587e48d716e307c9652d7b064723 Mon Sep 17 00:00:00 2001 From: runebaas Date: Fri, 14 Aug 2020 23:34:02 +0200 Subject: [PATCH 4/4] Translate !stats --- src/Bot/Bot.csproj | 9 ++ src/Bot/Commands/User/Stats.cs | 26 ++--- src/Bot/Localization/Stats.Designer.cs | 135 +++++++++++++++++++++++++ src/Bot/Localization/Stats.de-ch.resx | 38 +++++++ src/Bot/Localization/Stats.resx | 45 +++++++++ 5 files changed, 240 insertions(+), 13 deletions(-) create mode 100644 src/Bot/Localization/Stats.Designer.cs create mode 100644 src/Bot/Localization/Stats.de-ch.resx create mode 100644 src/Bot/Localization/Stats.resx diff --git a/src/Bot/Bot.csproj b/src/Bot/Bot.csproj index 2d3cd2f..49f0b16 100644 --- a/src/Bot/Bot.csproj +++ b/src/Bot/Bot.csproj @@ -81,6 +81,10 @@ ResXFileCodeGenerator Role.Designer.cs + + ResXFileCodeGenerator + Stats.Designer.cs + @@ -136,5 +140,10 @@ True Role.resx + + True + True + Stats.resx + diff --git a/src/Bot/Commands/User/Stats.cs b/src/Bot/Commands/User/Stats.cs index 70f6247..a2a54a2 100644 --- a/src/Bot/Commands/User/Stats.cs +++ b/src/Bot/Commands/User/Stats.cs @@ -3,24 +3,24 @@ using System.Linq; using System.Threading.Tasks; using Discord; using Discord.Commands; +using Geekbot.Core; using Geekbot.Core.CommandPreconditions; using Geekbot.Core.Database; using Geekbot.Core.ErrorHandling; using Geekbot.Core.Extensions; +using Geekbot.Core.GuildSettingsManager; using Geekbot.Core.Levels; namespace Geekbot.Bot.Commands.User { - public class Stats : ModuleBase + public class Stats : GeekbotCommandBase { - private readonly IErrorHandler _errorHandler; private readonly ILevelCalc _levelCalc; private readonly DatabaseContext _database; - public Stats(DatabaseContext database, IErrorHandler errorHandler, ILevelCalc levelCalc) + public Stats(DatabaseContext database, IErrorHandler errorHandler, ILevelCalc levelCalc, IGuildSettingsManager guildSettingsManager) : base(errorHandler, guildSettingsManager) { _database = database; - _errorHandler = errorHandler; _levelCalc = levelCalc; } @@ -67,23 +67,23 @@ namespace Geekbot.Bot.Commands.User e.GuildId.Equals(Context.Guild.Id.AsLong()) && e.UserId.Equals(userInfo.Id.AsLong())); - eb.AddInlineField("Discordian Since", + eb.AddInlineField(Localization.Stats.OnDiscordSince, $"{createdAt.Day}.{createdAt.Month}.{createdAt.Year} ({age} days)") - .AddInlineField("Joined Server", + .AddInlineField(Localization.Stats.JoinedServer, $"{joinedAt.Day}.{joinedAt.Month}.{joinedAt.Year} ({joinedDayAgo} days)") - .AddInlineField("Karma", karma?.Karma ?? 0) - .AddInlineField("Level", level) - .AddInlineField("Messages Sent", messages) - .AddInlineField("Server Total", $"{percent}%"); + .AddInlineField(Localization.Stats.Karma, karma?.Karma ?? 0) + .AddInlineField(Localization.Stats.Level, level) + .AddInlineField(Localization.Stats.MessagesSent, messages) + .AddInlineField(Localization.Stats.ServerTotal, $"{percent}%"); - if (correctRolls != null) eb.AddInlineField("Guessed Rolls", correctRolls.Rolls); - if (cookies > 0) eb.AddInlineField("Cookies", cookies); + if (correctRolls != null) eb.AddInlineField(Localization.Stats.GuessedRolls, correctRolls.Rolls); + if (cookies > 0) eb.AddInlineField(Localization.Stats.Cookies, cookies); await ReplyAsync("", false, eb.Build()); } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } } diff --git a/src/Bot/Localization/Stats.Designer.cs b/src/Bot/Localization/Stats.Designer.cs new file mode 100644 index 0000000..d05f937 --- /dev/null +++ b/src/Bot/Localization/Stats.Designer.cs @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Geekbot.Bot.Localization { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Stats { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Stats() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Geekbot.Bot.Localization.Stats", typeof(Stats).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Cookies. + /// + internal static string Cookies { + get { + return ResourceManager.GetString("Cookies", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Guessed Rolls. + /// + internal static string GuessedRolls { + get { + return ResourceManager.GetString("GuessedRolls", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Joined Server. + /// + internal static string JoinedServer { + get { + return ResourceManager.GetString("JoinedServer", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Karma. + /// + internal static string Karma { + get { + return ResourceManager.GetString("Karma", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Level. + /// + internal static string Level { + get { + return ResourceManager.GetString("Level", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Messages Sent. + /// + internal static string MessagesSent { + get { + return ResourceManager.GetString("MessagesSent", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to On Discord Since. + /// + internal static string OnDiscordSince { + get { + return ResourceManager.GetString("OnDiscordSince", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Server Total. + /// + internal static string ServerTotal { + get { + return ResourceManager.GetString("ServerTotal", resourceCulture); + } + } + } +} diff --git a/src/Bot/Localization/Stats.de-ch.resx b/src/Bot/Localization/Stats.de-ch.resx new file mode 100644 index 0000000..ab44a2e --- /dev/null +++ b/src/Bot/Localization/Stats.de-ch.resx @@ -0,0 +1,38 @@ + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Server Total + + + Uf Discord siit + + + Nachrichte versendet + + + Level + + + Karma + + + Server Bitrette + + + Grateni Rolls + + + Guetzli + + \ No newline at end of file diff --git a/src/Bot/Localization/Stats.resx b/src/Bot/Localization/Stats.resx new file mode 100644 index 0000000..3b8303a --- /dev/null +++ b/src/Bot/Localization/Stats.resx @@ -0,0 +1,45 @@ + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + On Discord Since + + + Joined Server + + + Karma + + + Level + + + Messages Sent + + + Server Total + + + Guessed Rolls + + + Cookies + + \ No newline at end of file