redid migration in order to add botconfig.locale, added some improvements
This commit is contained in:
		@@ -10,7 +10,7 @@ using NadekoBot.Modules.Music.Classes;
 | 
			
		||||
namespace NadekoBot.Migrations
 | 
			
		||||
{
 | 
			
		||||
    [DbContext(typeof(NadekoContext))]
 | 
			
		||||
    [Migration("20170213125444_guild-timezone-and-locale")]
 | 
			
		||||
    [Migration("20170213164350_guild-timezone-and-locale")]
 | 
			
		||||
    partial class guildtimezoneandlocale
 | 
			
		||||
    {
 | 
			
		||||
        protected override void BuildTargetModel(ModelBuilder modelBuilder)
 | 
			
		||||
@@ -129,6 +129,8 @@ namespace NadekoBot.Migrations
 | 
			
		||||
 | 
			
		||||
                    b.Property<string>("HelpString");
 | 
			
		||||
 | 
			
		||||
                    b.Property<string>("Locale");
 | 
			
		||||
 | 
			
		||||
                    b.Property<int>("MigrationVersion");
 | 
			
		||||
 | 
			
		||||
                    b.Property<int>("MinimumBetAmount");
 | 
			
		||||
@@ -19,6 +19,12 @@ namespace NadekoBot.Migrations
 | 
			
		||||
                table: "GuildConfigs",
 | 
			
		||||
                nullable: true,
 | 
			
		||||
                defaultValue: null);
 | 
			
		||||
 | 
			
		||||
            migrationBuilder.AddColumn<string>(
 | 
			
		||||
                name: "Locale",
 | 
			
		||||
                table: "BotConfig",
 | 
			
		||||
                nullable: true,
 | 
			
		||||
                defaultValue: null);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        protected override void Down(MigrationBuilder migrationBuilder)
 | 
			
		||||
@@ -30,6 +36,10 @@ namespace NadekoBot.Migrations
 | 
			
		||||
            migrationBuilder.DropColumn(
 | 
			
		||||
                name: "TimeZoneId",
 | 
			
		||||
                table: "GuildConfigs");
 | 
			
		||||
 | 
			
		||||
            migrationBuilder.DropColumn(
 | 
			
		||||
                name: "Locale",
 | 
			
		||||
                table: "BotConfig");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -128,6 +128,8 @@ namespace NadekoBot.Migrations
 | 
			
		||||
 | 
			
		||||
                    b.Property<string>("HelpString");
 | 
			
		||||
 | 
			
		||||
                    b.Property<string>("Locale");
 | 
			
		||||
 | 
			
		||||
                    b.Property<int>("MigrationVersion");
 | 
			
		||||
 | 
			
		||||
                    b.Property<int>("MinimumBetAmount");
 | 
			
		||||
 
 | 
			
		||||
@@ -84,7 +84,7 @@ namespace NadekoBot
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
            //initialize Services
 | 
			
		||||
            Localization = new Localization(NadekoBot.AllGuildConfigs.ToDictionary(x => x.GuildId, x => x.Locale));
 | 
			
		||||
            Localization = new Localization(NadekoBot.BotConfig.Locale, NadekoBot.AllGuildConfigs.ToDictionary(x => x.GuildId, x => x.Locale));
 | 
			
		||||
            CommandService = new CommandService(new CommandServiceConfig() {
 | 
			
		||||
                CaseSensitiveCommands = false,
 | 
			
		||||
                DefaultRunMode = RunMode.Sync
 | 
			
		||||
 
 | 
			
		||||
@@ -60,6 +60,7 @@ Nadeko Support Server: https://discord.gg/nadekobot";
 | 
			
		||||
 | 
			
		||||
        public string OkColor { get; set; } = "71cd40";
 | 
			
		||||
        public string ErrorColor { get; set; } = "ee281f";
 | 
			
		||||
        public string Locale { get; set; } = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public class PlayingStatus :DbEntity
 | 
			
		||||
 
 | 
			
		||||
@@ -8,17 +8,35 @@ using System.Linq;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using System;
 | 
			
		||||
using NadekoBot.Services.Database;
 | 
			
		||||
using NLog;
 | 
			
		||||
 | 
			
		||||
namespace NadekoBot.Services
 | 
			
		||||
{
 | 
			
		||||
    public class Localization
 | 
			
		||||
    {
 | 
			
		||||
        private readonly Logger _log;
 | 
			
		||||
 | 
			
		||||
        public ConcurrentDictionary<ulong, CultureInfo> GuildCultureInfos { get; }
 | 
			
		||||
        public CultureInfo DefaultCultureInfo { get; private set; } = CultureInfo.CurrentCulture;
 | 
			
		||||
 | 
			
		||||
        private Localization() { }
 | 
			
		||||
        public Localization(IDictionary<ulong, string> cultureInfoNames)
 | 
			
		||||
        public Localization(string defaultCulture, IDictionary<ulong, string> cultureInfoNames)
 | 
			
		||||
        {
 | 
			
		||||
            _log = LogManager.GetCurrentClassLogger();
 | 
			
		||||
            if (string.IsNullOrWhiteSpace(defaultCulture))
 | 
			
		||||
                DefaultCultureInfo = new CultureInfo("en-US");
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    DefaultCultureInfo = new CultureInfo(defaultCulture);
 | 
			
		||||
                }
 | 
			
		||||
                catch
 | 
			
		||||
                {
 | 
			
		||||
                    _log.Warn("Unable to load default bot's locale/language. Using en-US.");
 | 
			
		||||
                    DefaultCultureInfo = new CultureInfo("en-US");
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            GuildCultureInfos = new ConcurrentDictionary<ulong, CultureInfo>(cultureInfoNames.ToDictionary(x => x.Key, x =>
 | 
			
		||||
              {
 | 
			
		||||
                  CultureInfo cultureInfo = null;
 | 
			
		||||
@@ -26,9 +44,7 @@ namespace NadekoBot.Services
 | 
			
		||||
                  {
 | 
			
		||||
                      cultureInfo = new CultureInfo(x.Value);
 | 
			
		||||
                  }
 | 
			
		||||
                  catch
 | 
			
		||||
                  {
 | 
			
		||||
                  }
 | 
			
		||||
                  catch { }
 | 
			
		||||
                  return cultureInfo;
 | 
			
		||||
              }).Where(x => x.Value != null));
 | 
			
		||||
        }
 | 
			
		||||
@@ -50,6 +66,8 @@ namespace NadekoBot.Services
 | 
			
		||||
                gc.Locale = ci.Name;
 | 
			
		||||
                uow.Complete();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            GuildCultureInfos.AddOrUpdate(guildId, ci, (id, old) => ci);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void RemoveGuildCulture(IGuild guild) => 
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user