Commands strings are now in data/command_strings.json. Database path no longer has ./ prefix and filename -> Data Source. Fixed permissions migration due to new EF behaviour. Although commands will now error if they don't have their entry in the command strings - needs fixing.
This commit is contained in:
		@@ -3,11 +3,13 @@ using System.Runtime.CompilerServices;
 | 
			
		||||
using Discord.Commands;
 | 
			
		||||
using NadekoBot.Services.Impl;
 | 
			
		||||
 | 
			
		||||
//todo what if it doesn't exist
 | 
			
		||||
 | 
			
		||||
namespace NadekoBot.Common.Attributes
 | 
			
		||||
{
 | 
			
		||||
    public class Aliases : AliasAttribute
 | 
			
		||||
    {
 | 
			
		||||
        public Aliases([CallerMemberName] string memberName = "") : base(Localization.LoadCommandString(memberName.ToLowerInvariant() + "_cmd").Split(' ').Skip(1).ToArray())
 | 
			
		||||
        public Aliases([CallerMemberName] string memberName = "") : base(Localization.LoadCommand(memberName.ToLowerInvariant()).Cmd.Split(' ').Skip(1).ToArray())
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,7 @@ namespace NadekoBot.Common.Attributes
 | 
			
		||||
{
 | 
			
		||||
    public class Description : SummaryAttribute
 | 
			
		||||
    {
 | 
			
		||||
        public Description([CallerMemberName] string memberName="") : base(Localization.LoadCommandString(memberName.ToLowerInvariant() + "_desc"))
 | 
			
		||||
        public Description([CallerMemberName] string memberName="") : base(Localization.LoadCommand(memberName.ToLowerInvariant()).Desc)
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,7 @@ namespace NadekoBot.Common.Attributes
 | 
			
		||||
{
 | 
			
		||||
    public class NadekoCommand : CommandAttribute
 | 
			
		||||
    {
 | 
			
		||||
        public NadekoCommand([CallerMemberName] string memberName="") : base(Localization.LoadCommandString(memberName.ToLowerInvariant() + "_cmd").Split(' ')[0])
 | 
			
		||||
        public NadekoCommand([CallerMemberName] string memberName="") : base(Localization.LoadCommand(memberName.ToLowerInvariant()).Cmd)
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,7 @@ namespace NadekoBot.Common.Attributes
 | 
			
		||||
{
 | 
			
		||||
    public class Usage : RemarksAttribute
 | 
			
		||||
    {
 | 
			
		||||
        public Usage([CallerMemberName] string memberName="") : base(Localization.LoadCommandString(memberName.ToLowerInvariant()+"_usage"))
 | 
			
		||||
        public Usage([CallerMemberName] string memberName="") : base(Localization.LoadCommand(memberName.ToLowerInvariant()).Usage)
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										9
									
								
								src/NadekoBot/Common/CommandData.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								src/NadekoBot/Common/CommandData.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
namespace NadekoBot.Common
 | 
			
		||||
{
 | 
			
		||||
    public class CommandData
 | 
			
		||||
    {
 | 
			
		||||
        public string Cmd { get; set; }
 | 
			
		||||
        public string Usage { get; set; }
 | 
			
		||||
        public string Desc { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -38,7 +38,7 @@ namespace NadekoBot.Modules.Games
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [NadekoCommand, Usage, Description, Aliases]
 | 
			
		||||
        public async Task _8Ball([Remainder] string question = null)
 | 
			
		||||
        public async Task EightBall([Remainder] string question = null)
 | 
			
		||||
        {
 | 
			
		||||
            if (string.IsNullOrWhiteSpace(question))
 | 
			
		||||
                return;
 | 
			
		||||
 
 | 
			
		||||
@@ -135,11 +135,11 @@ namespace NadekoBot.Modules.Permissions.Services
 | 
			
		||||
                {
 | 
			
		||||
                    var oldPrefixes = new[] { ".", ";", "!!", "!m", "!", "+", "-", "$", ">" };
 | 
			
		||||
                    uow._context.Database.ExecuteSqlCommand(
 | 
			
		||||
    $@"UPDATE {nameof(Permissionv2)}
 | 
			
		||||
    @"UPDATE Permissionv2
 | 
			
		||||
SET secondaryTargetName=trim(substr(secondaryTargetName, 3))
 | 
			
		||||
WHERE secondaryTargetName LIKE '!!%' OR secondaryTargetName LIKE '!m%';
 | 
			
		||||
 | 
			
		||||
UPDATE {nameof(Permissionv2)}
 | 
			
		||||
UPDATE Permissionv2
 | 
			
		||||
SET secondaryTargetName=substr(secondaryTargetName, 2)
 | 
			
		||||
WHERE secondaryTargetName LIKE '.%' OR
 | 
			
		||||
secondaryTargetName LIKE '~%' OR
 | 
			
		||||
 
 | 
			
		||||
@@ -80,10 +80,4 @@
 | 
			
		||||
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
 | 
			
		||||
    <DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.0" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <Compile Update="Resources\CommandStrings.Designer.cs">
 | 
			
		||||
      <SubType>Designer</SubType>
 | 
			
		||||
    </Compile>
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
</Project>
 | 
			
		||||
 
 | 
			
		||||
@@ -5,15 +5,19 @@ using NadekoBot.Services.Database.Models;
 | 
			
		||||
using NadekoBot.Extensions;
 | 
			
		||||
using System;
 | 
			
		||||
using Microsoft.EntityFrameworkCore.Design;
 | 
			
		||||
using Microsoft.Data.Sqlite;
 | 
			
		||||
using System.IO;
 | 
			
		||||
 | 
			
		||||
namespace NadekoBot.Services.Database
 | 
			
		||||
{
 | 
			
		||||
    public class NadekoContextFactory : IDesignTimeDbContextFactory<NadekoContext>
 | 
			
		||||
    {
 | 
			
		||||
    {        
 | 
			
		||||
        public NadekoContext CreateDbContext(string[] args)
 | 
			
		||||
        {
 | 
			
		||||
            var optionsBuilder = new DbContextOptionsBuilder<NadekoContext>();
 | 
			
		||||
            optionsBuilder.UseSqlite("Filename=./data/NadekoBot.db");
 | 
			
		||||
            var builder = new SqliteConnectionStringBuilder("Data Source=data/NadekoBot.db");
 | 
			
		||||
            builder.DataSource = Path.Combine(AppContext.BaseDirectory, builder.DataSource);
 | 
			
		||||
            optionsBuilder.UseSqlite(builder.ToString());
 | 
			
		||||
            var ctx = new NadekoContext(optionsBuilder.Options);
 | 
			
		||||
            ctx.Database.SetCommandTimeout(60);
 | 
			
		||||
            return ctx;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,8 @@
 | 
			
		||||
using Microsoft.EntityFrameworkCore;
 | 
			
		||||
using Microsoft.Data.Sqlite;
 | 
			
		||||
using Microsoft.EntityFrameworkCore;
 | 
			
		||||
using NadekoBot.Services.Database;
 | 
			
		||||
using System;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
 | 
			
		||||
namespace NadekoBot.Services
 | 
			
		||||
@@ -9,17 +12,17 @@ namespace NadekoBot.Services
 | 
			
		||||
        private readonly DbContextOptions<NadekoContext> options;
 | 
			
		||||
        private readonly DbContextOptions<NadekoContext> migrateOptions;
 | 
			
		||||
 | 
			
		||||
        private readonly string _connectionString;
 | 
			
		||||
 | 
			
		||||
        public DbService(IBotCredentials creds)
 | 
			
		||||
        {
 | 
			
		||||
            _connectionString = creds.Db.ConnectionString;
 | 
			
		||||
            var builder = new SqliteConnectionStringBuilder(creds.Db.ConnectionString);
 | 
			
		||||
            builder.DataSource = Path.Combine(AppContext.BaseDirectory, builder.DataSource);
 | 
			
		||||
            
 | 
			
		||||
            var optionsBuilder = new DbContextOptionsBuilder<NadekoContext>();
 | 
			
		||||
            optionsBuilder.UseSqlite(creds.Db.ConnectionString);
 | 
			
		||||
            optionsBuilder.UseSqlite(builder.ToString());
 | 
			
		||||
            options = optionsBuilder.Options;
 | 
			
		||||
 | 
			
		||||
            optionsBuilder = new DbContextOptionsBuilder<NadekoContext>();
 | 
			
		||||
            optionsBuilder.UseSqlite(creds.Db.ConnectionString, x => x.SuppressForeignKeyEnforcement());
 | 
			
		||||
            optionsBuilder.UseSqlite(builder.ToString(), x => x.SuppressForeignKeyEnforcement());
 | 
			
		||||
            migrateOptions = optionsBuilder.Options;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -101,7 +101,7 @@ namespace NadekoBot.Services.Impl
 | 
			
		||||
                                ? "sqlite" 
 | 
			
		||||
                                : dbSection["Type"], 
 | 
			
		||||
                            string.IsNullOrWhiteSpace(dbSection["ConnectionString"]) 
 | 
			
		||||
                                ? "Filename=./data/NadekoBot.db"
 | 
			
		||||
                                ? "Data Source=data/NadekoBot.db"
 | 
			
		||||
                                : dbSection["ConnectionString"]);
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception ex)
 | 
			
		||||
@@ -125,7 +125,7 @@ namespace NadekoBot.Services.Impl
 | 
			
		||||
            public string SoundCloudClientId { get; set; } = "";
 | 
			
		||||
            public string CleverbotApiKey { get; } = "";
 | 
			
		||||
            public string CarbonKey { get; set; } = "";
 | 
			
		||||
            public DBConfig Db { get; set; } = new DBConfig("sqlite", "Filename=./data/NadekoBot.db");
 | 
			
		||||
            public DBConfig Db { get; set; } = new DBConfig("sqlite", "Data Source=data/NadekoBot.db");
 | 
			
		||||
            public int TotalShards { get; set; } = 1;
 | 
			
		||||
            public string PatreonAccessToken { get; set; } = "";
 | 
			
		||||
            public string PatreonCampaignId { get; set; } = "334038";
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,9 @@ using System.Linq;
 | 
			
		||||
using Discord;
 | 
			
		||||
using NLog;
 | 
			
		||||
using NadekoBot.Services.Database.Models;
 | 
			
		||||
using NadekoBot.Common;
 | 
			
		||||
using Newtonsoft.Json;
 | 
			
		||||
using System.IO;
 | 
			
		||||
 | 
			
		||||
namespace NadekoBot.Services.Impl
 | 
			
		||||
{
 | 
			
		||||
@@ -16,6 +19,14 @@ namespace NadekoBot.Services.Impl
 | 
			
		||||
        public ConcurrentDictionary<ulong, CultureInfo> GuildCultureInfos { get; }
 | 
			
		||||
        public CultureInfo DefaultCultureInfo { get; private set; } = CultureInfo.CurrentCulture;
 | 
			
		||||
 | 
			
		||||
        private static readonly Dictionary<string, CommandData> _commandData;
 | 
			
		||||
 | 
			
		||||
        static Localization()
 | 
			
		||||
        {
 | 
			
		||||
            _commandData = JsonConvert.DeserializeObject<Dictionary<string, CommandData>>(
 | 
			
		||||
                File.ReadAllText("./data/command_strings.json"));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private Localization() { }
 | 
			
		||||
        public Localization(IBotConfigProvider bcp, IEnumerable<GuildConfig> gcs, DbService db)
 | 
			
		||||
        {
 | 
			
		||||
@@ -117,10 +128,10 @@ namespace NadekoBot.Services.Impl
 | 
			
		||||
            return info ?? DefaultCultureInfo;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static string LoadCommandString(string key)
 | 
			
		||||
        public static CommandData LoadCommand(string key)
 | 
			
		||||
        {
 | 
			
		||||
            string toReturn = Resources.CommandStrings.ResourceManager.GetString(key);
 | 
			
		||||
            return string.IsNullOrWhiteSpace(toReturn) ? key : toReturn;
 | 
			
		||||
            _commandData.TryGetValue(key, out var toReturn);
 | 
			
		||||
            return toReturn;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -13,7 +13,7 @@
 | 
			
		||||
  "CarbonKey": "",
 | 
			
		||||
  "Db": {
 | 
			
		||||
    "Type": "sqlite",
 | 
			
		||||
    "ConnectionString": "Filename=./data/NadekoBot.db"
 | 
			
		||||
    "ConnectionString": "Data Source=data/NadekoBot.db"
 | 
			
		||||
  },
 | 
			
		||||
  "TotalShards": 1,
 | 
			
		||||
  "PatreonAccessToken": "",
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2057
									
								
								src/NadekoBot/data/command_strings.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2057
									
								
								src/NadekoBot/data/command_strings.json
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Reference in New Issue
	
	Block a user