Configurable connection string
This commit is contained in:
parent
12587a648e
commit
bd0b668c0d
@ -44,6 +44,9 @@ namespace NadekoBot
|
|||||||
|
|
||||||
static NadekoBot()
|
static NadekoBot()
|
||||||
{
|
{
|
||||||
|
SetupLogger();
|
||||||
|
Credentials = new BotCredentials();
|
||||||
|
|
||||||
using (var uow = DbHandler.UnitOfWork())
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
{
|
{
|
||||||
AllGuildConfigs = uow.GuildConfigs.GetAll();
|
AllGuildConfigs = uow.GuildConfigs.GetAll();
|
||||||
@ -52,16 +55,10 @@ namespace NadekoBot
|
|||||||
|
|
||||||
public async Task RunAsync(params string[] args)
|
public async Task RunAsync(params string[] args)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
SetupLogger();
|
|
||||||
_log = LogManager.GetCurrentClassLogger();
|
_log = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
_log.Info("Starting NadekoBot v" + StatsService.BotVersion);
|
_log.Info("Starting NadekoBot v" + StatsService.BotVersion);
|
||||||
|
|
||||||
|
|
||||||
Credentials = new BotCredentials();
|
|
||||||
|
|
||||||
//create client
|
//create client
|
||||||
Client = new ShardedDiscordClient(new DiscordSocketConfig
|
Client = new ShardedDiscordClient(new DiscordSocketConfig
|
||||||
{
|
{
|
||||||
@ -122,7 +119,7 @@ namespace NadekoBot
|
|||||||
await Task.Delay(-1).ConfigureAwait(false);
|
await Task.Delay(-1).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetupLogger()
|
private static void SetupLogger()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -12,7 +12,7 @@ namespace NadekoBot.Services.Database.Impl
|
|||||||
{
|
{
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
{
|
{
|
||||||
optionsBuilder.UseSqlite("Filename=./data/NadekoBot.db");
|
optionsBuilder.UseSqlite(NadekoBot.Credentials.Db.ConnectionString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,12 +14,14 @@ namespace NadekoBot.Services
|
|||||||
|
|
||||||
private static DbHandler _instance = null;
|
private static DbHandler _instance = null;
|
||||||
public static DbHandler Instance = _instance ?? (_instance = new DbHandler());
|
public static DbHandler Instance = _instance ?? (_instance = new DbHandler());
|
||||||
|
|
||||||
|
private string connectionString { get; }
|
||||||
|
|
||||||
static DbHandler() { }
|
static DbHandler() { }
|
||||||
|
|
||||||
private DbHandler() {
|
private DbHandler() {
|
||||||
dbType = typeof(NadekoSqliteContext);
|
dbType = typeof(NadekoSqliteContext);
|
||||||
|
connectionString = NadekoBot.Credentials.Db.ConnectionString;
|
||||||
//switch (NadekoBot.Credentials.Db.Type.ToUpperInvariant())
|
//switch (NadekoBot.Credentials.Db.Type.ToUpperInvariant())
|
||||||
//{
|
//{
|
||||||
// case "SQLITE":
|
// case "SQLITE":
|
||||||
@ -34,8 +36,8 @@ namespace NadekoBot.Services
|
|||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
public NadekoContext GetDbContext() =>
|
public NadekoContext GetDbContext() =>
|
||||||
Activator.CreateInstance(dbType) as NadekoContext;
|
new NadekoSqliteContext();
|
||||||
|
|
||||||
public IUnitOfWork GetUnitOfWork() =>
|
public IUnitOfWork GetUnitOfWork() =>
|
||||||
new UnitOfWork(GetDbContext());
|
new UnitOfWork(GetDbContext());
|
||||||
|
@ -15,14 +15,14 @@ namespace NadekoBot.Services
|
|||||||
string MashapeKey { get; }
|
string MashapeKey { get; }
|
||||||
string LoLApiKey { get; }
|
string LoLApiKey { get; }
|
||||||
|
|
||||||
DB Db { get; }
|
DBConfig Db { get; }
|
||||||
|
|
||||||
bool IsOwner(IUser u);
|
bool IsOwner(IUser u);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DB
|
public class DBConfig
|
||||||
{
|
{
|
||||||
public DB(string type, string connString)
|
public DBConfig(string type, string connString)
|
||||||
{
|
{
|
||||||
this.Type = type;
|
this.Type = type;
|
||||||
this.ConnectionString = connString;
|
this.ConnectionString = connString;
|
||||||
|
@ -28,7 +28,7 @@ namespace NadekoBot.Services.Impl
|
|||||||
public string OsuApiKey { get; }
|
public string OsuApiKey { get; }
|
||||||
public string SoundCloudClientId { get; }
|
public string SoundCloudClientId { get; }
|
||||||
|
|
||||||
public DB Db { get; }
|
public DBConfig Db { get; }
|
||||||
public int TotalShards { get; }
|
public int TotalShards { get; }
|
||||||
public string CarbonKey { get; }
|
public string CarbonKey { get; }
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ namespace NadekoBot.Services.Impl
|
|||||||
SoundCloudClientId = data[nameof(SoundCloudClientId)];
|
SoundCloudClientId = data[nameof(SoundCloudClientId)];
|
||||||
CarbonKey = data[nameof(CarbonKey)];
|
CarbonKey = data[nameof(CarbonKey)];
|
||||||
var dbSection = data.GetSection("db");
|
var dbSection = data.GetSection("db");
|
||||||
Db = new DB(string.IsNullOrWhiteSpace(dbSection["Type"])
|
Db = new DBConfig(string.IsNullOrWhiteSpace(dbSection["Type"])
|
||||||
? "sqlite"
|
? "sqlite"
|
||||||
: dbSection["Type"],
|
: dbSection["Type"],
|
||||||
string.IsNullOrWhiteSpace(dbSection["ConnectionString"])
|
string.IsNullOrWhiteSpace(dbSection["ConnectionString"])
|
||||||
@ -95,7 +95,7 @@ namespace NadekoBot.Services.Impl
|
|||||||
public string OsuApiKey { get; set; } = "";
|
public string OsuApiKey { get; set; } = "";
|
||||||
public string SoundCloudClientId { get; set; } = "";
|
public string SoundCloudClientId { get; set; } = "";
|
||||||
public string CarbonKey { get; set; } = "";
|
public string CarbonKey { get; set; } = "";
|
||||||
public DB Db { get; set; } = new DB("sqlite", "Filename=./data/NadekoBot.db");
|
public DBConfig Db { get; set; } = new DBConfig("sqlite", "Filename=./data/NadekoBot.db");
|
||||||
public int TotalShards { get; set; } = 1;
|
public int TotalShards { get; set; } = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user