Merge branch 'develop' #minor
This commit is contained in:
commit
7e05a74285
@ -17,7 +17,7 @@ namespace ChaosBot.ConfigHelpers
|
|||||||
|
|
||||||
public static T GetValue<T>(string key, ulong guildId, T defaultValue)
|
public static T GetValue<T>(string key, ulong guildId, T defaultValue)
|
||||||
{
|
{
|
||||||
using ChaosbotContext dbContext = new ChaosbotContext();
|
using DatabaseContext dbContext = new DatabaseContext();
|
||||||
Models.Configuration config = dbContext.Configuration
|
Models.Configuration config = dbContext.Configuration
|
||||||
.SingleOrDefault(c => c.DiscordGuildId == guildId && c.Key == key);
|
.SingleOrDefault(c => c.DiscordGuildId == guildId && c.Key == key);
|
||||||
if (config == null || string.IsNullOrEmpty(config.SerializedValue))
|
if (config == null || string.IsNullOrEmpty(config.SerializedValue))
|
||||||
@ -27,7 +27,7 @@ namespace ChaosBot.ConfigHelpers
|
|||||||
|
|
||||||
public static void SetValue<T>(string key, T value, ulong guildId)
|
public static void SetValue<T>(string key, T value, ulong guildId)
|
||||||
{
|
{
|
||||||
using ChaosbotContext dbContext = new ChaosbotContext();
|
using DatabaseContext dbContext = new DatabaseContext();
|
||||||
Models.Configuration cnfSet = new Models.Configuration();
|
Models.Configuration cnfSet = new Models.Configuration();
|
||||||
|
|
||||||
cnfSet.Key = key;
|
cnfSet.Key = key;
|
||||||
@ -41,7 +41,7 @@ namespace ChaosBot.ConfigHelpers
|
|||||||
|
|
||||||
public static void DeleteValue(string key, ulong guildId)
|
public static void DeleteValue(string key, ulong guildId)
|
||||||
{
|
{
|
||||||
using ChaosbotContext dbContext = new ChaosbotContext();
|
using DatabaseContext dbContext = new DatabaseContext();
|
||||||
Models.Configuration config = dbContext.Configuration
|
Models.Configuration config = dbContext.Configuration
|
||||||
.SingleOrDefault(c => c.DiscordGuildId == guildId && c.Key == key);
|
.SingleOrDefault(c => c.DiscordGuildId == guildId && c.Key == key);
|
||||||
if (config == null) return;
|
if (config == null) return;
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
|
using ChaosBot.Models;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
namespace ChaosBot.Models
|
namespace ChaosBot
|
||||||
{
|
{
|
||||||
public class ChaosbotContext : DbContext
|
public class DatabaseContext : DbContext
|
||||||
{
|
{
|
||||||
public DbSet<LodestoneCharacter> LodestoneCharacter { get; set; }
|
public DbSet<LodestoneCharacter> LodestoneCharacter { get; set; }
|
||||||
public DbSet<LodestoneFreeCompany> LodestoneFreeCompany { get; set; }
|
public DbSet<LodestoneFreeCompany> LodestoneFreeCompany { get; set; }
|
||||||
@ -19,31 +20,20 @@ namespace ChaosBot.Models
|
|||||||
{
|
{
|
||||||
if (!optionsBuilder.IsConfigured)
|
if (!optionsBuilder.IsConfigured)
|
||||||
{
|
{
|
||||||
string server, user, pass, name;
|
IConfiguration appSettingsHandler = Program.AppSettingsHandler;
|
||||||
int port;
|
|
||||||
|
|
||||||
if (Program.AppSettingsHandler == null)
|
if (Program.AppSettingsHandler == null)
|
||||||
{
|
{
|
||||||
IConfiguration config = Program.AppSettingsHandler = new ConfigurationBuilder()
|
appSettingsHandler = new ConfigurationBuilder()
|
||||||
.SetBasePath(System.IO.Directory.GetCurrentDirectory())
|
.SetBasePath(System.IO.Directory.GetCurrentDirectory())
|
||||||
.AddJsonFile("./appsettings.json", optional: false, reloadOnChange: true).Build();
|
.AddJsonFile(Program.AppSettingsPath).Build();
|
||||||
|
|
||||||
server = config.GetValue<string>("Database:Host");
|
|
||||||
port = config.GetValue<int>("Database:Port");
|
|
||||||
user = config.GetValue<string>("Database:User");
|
|
||||||
pass = config.GetValue<string>("Database:Pass");
|
|
||||||
name = config.GetValue<string>("Database:Name");
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
ConfigHelpers.Configuration config = new ConfigHelpers.Configuration();
|
|
||||||
|
|
||||||
server = config.GetByKey<string>("Database:Host").GetValue(readRestricted: true);
|
string server = appSettingsHandler.GetValue<string>("Database:Host");
|
||||||
port = config.GetByKey<int>("Database:Port").GetValue(readRestricted: true);
|
int port = appSettingsHandler.GetValue<int>("Database:Port");
|
||||||
user = config.GetByKey<string>("Database:User").GetValue(readRestricted: true);
|
string user = appSettingsHandler.GetValue<string>("Database:User");
|
||||||
pass = config.GetByKey<string>("Database:Pass").GetValue(readRestricted: true);
|
string pass = appSettingsHandler.GetValue<string>("Database:Pass");
|
||||||
name = config.GetByKey<string>("Database:Name").GetValue(readRestricted: true);
|
string name = appSettingsHandler.GetValue<string>("Database:Name");
|
||||||
}
|
|
||||||
|
|
||||||
optionsBuilder.UseMySql(
|
optionsBuilder.UseMySql(
|
||||||
$"server={server};port={port};user={user};password={pass};database={name}",
|
$"server={server};port={port};user={user};password={pass};database={name}",
|
||||||
@ -60,7 +60,7 @@ namespace ChaosBot.Discord.Modules.Admin
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await using (ChaosbotContext dbContext = new ChaosbotContext())
|
await using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
string parameterString = String.Join("", parameters);
|
string parameterString = String.Join("", parameters);
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ namespace ChaosBot.Discord.Modules.Admin
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await using (ChaosbotContext dbContext = new ChaosbotContext())
|
await using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
string parameterString = String.Join("", parameters);
|
string parameterString = String.Join("", parameters);
|
||||||
|
|
||||||
|
|||||||
@ -26,7 +26,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
embed.Title = $"Current Level Statistics";
|
embed.Title = $"Current Level Statistics";
|
||||||
sb.AppendLine();
|
sb.AppendLine();
|
||||||
|
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<Experience> ctxUser = dbContext.ExperiencePoints;
|
IQueryable<Experience> ctxUser = dbContext.ExperiencePoints;
|
||||||
IQueryable<Experience> usrXp = ctxUser
|
IQueryable<Experience> usrXp = ctxUser
|
||||||
|
|||||||
@ -165,7 +165,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool linked;
|
bool linked;
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<LodestoneCharacter> ctxlsChars = dbContext.LodestoneCharacter;
|
IQueryable<LodestoneCharacter> ctxlsChars = dbContext.LodestoneCharacter;
|
||||||
IQueryable<LodestoneCharacter> lsChar = ctxlsChars.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.LodestoneId.Equals(Convert.ToUInt64(character.Character.ID)));
|
IQueryable<LodestoneCharacter> lsChar = ctxlsChars.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.LodestoneId.Equals(Convert.ToUInt64(character.Character.ID)));
|
||||||
@ -184,7 +184,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
|
|
||||||
if (character.Character.Bio.Contains(b64))
|
if (character.Character.Bio.Contains(b64))
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
LodestoneCharacter lsChar = new LodestoneCharacter();
|
LodestoneCharacter lsChar = new LodestoneCharacter();
|
||||||
|
|
||||||
|
|||||||
@ -113,7 +113,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<Point> points = dbContext.Points;
|
IQueryable<Point> points = dbContext.Points;
|
||||||
cur = points
|
cur = points
|
||||||
@ -135,7 +135,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
ulong cur = 0;
|
ulong cur = 0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<Point> ctxPoints = dbContext.Points;
|
IQueryable<Point> ctxPoints = dbContext.Points;
|
||||||
|
|
||||||
@ -180,7 +180,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
{
|
{
|
||||||
if (admin)
|
if (admin)
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<Point> ctxPoints = dbContext.Points;
|
IQueryable<Point> ctxPoints = dbContext.Points;
|
||||||
|
|
||||||
@ -211,7 +211,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<Point> ctxPoints = dbContext.Points;
|
IQueryable<Point> ctxPoints = dbContext.Points;
|
||||||
|
|
||||||
@ -276,7 +276,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
Point usrPoint = new Point();
|
Point usrPoint = new Point();
|
||||||
|
|
||||||
|
|||||||
@ -126,7 +126,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
|
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
|
||||||
|
|
||||||
@ -150,7 +150,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
{
|
{
|
||||||
if (admin)
|
if (admin)
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
|
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
|
||||||
|
|
||||||
@ -187,7 +187,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
int cur = 0;
|
int cur = 0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
|
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
|
||||||
|
|
||||||
@ -224,7 +224,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
|
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
|
||||||
|
|
||||||
@ -258,7 +258,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
{
|
{
|
||||||
if(confirm == "confirm")
|
if(confirm == "confirm")
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
|
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
|
||||||
|
|
||||||
@ -293,7 +293,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
|
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using ChaosBot.ConfigHelpers;
|
||||||
using ChaosBot.Models;
|
using ChaosBot.Models;
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
@ -106,7 +107,7 @@ namespace ChaosBot.Discord.Services
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
Experience newUser = new Experience();
|
Experience newUser = new Experience();
|
||||||
newUser.Amount = 0;
|
newUser.Amount = 0;
|
||||||
@ -118,8 +119,32 @@ namespace ChaosBot.Discord.Services
|
|||||||
await dbContext.ExperiencePoints.Upsert(newUser)
|
await dbContext.ExperiencePoints.Upsert(newUser)
|
||||||
.On(x => new {x.DiscordGuildId, x.DiscordUserId}).RunAsync();
|
.On(x => new {x.DiscordGuildId, x.DiscordUserId}).RunAsync();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LoggingFacade.Exception(ex);
|
||||||
|
}
|
||||||
|
|
||||||
await user.Guild.SystemChannel.SendMessageAsync($"{user.Username} has joined the server.");
|
try
|
||||||
|
{
|
||||||
|
ulong channelId = ConfigurationRepository.GetValue<ulong>("AnnounceChannel:UserJoined", user.Guild.Id, 0);
|
||||||
|
|
||||||
|
if (channelId == 0)
|
||||||
|
{
|
||||||
|
await user.Guild.SystemChannel.SendMessageAsync($"{user.Username} has joined the server.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await user.Guild.GetTextChannel(channelId)
|
||||||
|
.SendMessageAsync($"{user.Username} has joined the server.");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LoggingFacade.Exception(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -131,7 +156,7 @@ namespace ChaosBot.Discord.Services
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<Experience> ctxUser = dbContext.ExperiencePoints;
|
IQueryable<Experience> ctxUser = dbContext.ExperiencePoints;
|
||||||
IQueryable<Experience> usrXp = ctxUser
|
IQueryable<Experience> usrXp = ctxUser
|
||||||
@ -178,8 +203,32 @@ namespace ChaosBot.Discord.Services
|
|||||||
await dbContext.Points.Upsert(usrPoint)
|
await dbContext.Points.Upsert(usrPoint)
|
||||||
.On(x => new { x.DiscordGuildId, x.DiscordUserId}).RunAsync();
|
.On(x => new { x.DiscordGuildId, x.DiscordUserId}).RunAsync();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LoggingFacade.Exception(ex);
|
||||||
|
}
|
||||||
|
|
||||||
await user.Guild.SystemChannel.SendMessageAsync($"{user.Username} has left the server.");
|
try
|
||||||
|
{
|
||||||
|
ulong channelId = ConfigurationRepository.GetValue<ulong>("AnnounceChannel:UserLeft", user.Guild.Id, 0);
|
||||||
|
|
||||||
|
if (channelId == 0)
|
||||||
|
{
|
||||||
|
await user.Guild.SystemChannel.SendMessageAsync($"{user.Username} has left the server.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await user.Guild.GetTextChannel(channelId)
|
||||||
|
.SendMessageAsync($"{user.Username} has left the server.");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LoggingFacade.Exception(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -15,7 +15,7 @@ namespace ChaosBot.Discord.Services
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await using ChaosbotContext dbContext = new ChaosbotContext();
|
await using DatabaseContext dbContext = new DatabaseContext();
|
||||||
string command = context.Message.Content.Substring(argPos);
|
string command = context.Message.Content.Substring(argPos);
|
||||||
|
|
||||||
IQueryable<CustomCommand> customCommandQuery = dbContext.CustomCommands;
|
IQueryable<CustomCommand> customCommandQuery = dbContext.CustomCommands;
|
||||||
|
|||||||
@ -18,7 +18,7 @@ namespace ChaosBot.Discord.Services
|
|||||||
{
|
{
|
||||||
if (!CheckModuleEnabled.GetResult(context, "Experience")) return;
|
if (!CheckModuleEnabled.GetResult(context, "Experience")) return;
|
||||||
|
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<Experience> ctxUser = dbContext.ExperiencePoints;
|
IQueryable<Experience> ctxUser = dbContext.ExperiencePoints;
|
||||||
IQueryable<Experience> usrXp = ctxUser
|
IQueryable<Experience> usrXp = ctxUser
|
||||||
|
|||||||
@ -17,7 +17,7 @@ namespace ChaosBot.Discord.Services
|
|||||||
if (!(optionalUser.Value is IGuildUser user)) return;
|
if (!(optionalUser.Value is IGuildUser user)) return;
|
||||||
if (!(socketMessageChannel is SocketGuildChannel channel)) return;
|
if (!(socketMessageChannel is SocketGuildChannel channel)) return;
|
||||||
|
|
||||||
await using ChaosbotContext dbContext = new ChaosbotContext();
|
await using DatabaseContext dbContext = new DatabaseContext();
|
||||||
|
|
||||||
IQueryable<RoleReaction> roleReactionsQueryable = dbContext.RoleReactions;
|
IQueryable<RoleReaction> roleReactionsQueryable = dbContext.RoleReactions;
|
||||||
List<RoleReaction> roleReactions = roleReactionsQueryable
|
List<RoleReaction> roleReactions = roleReactionsQueryable
|
||||||
@ -47,7 +47,7 @@ namespace ChaosBot.Discord.Services
|
|||||||
if (!(optionalUser.Value is IGuildUser user)) return;
|
if (!(optionalUser.Value is IGuildUser user)) return;
|
||||||
if (!(socketMessageChannel is SocketGuildChannel channel)) return;
|
if (!(socketMessageChannel is SocketGuildChannel channel)) return;
|
||||||
|
|
||||||
await using ChaosbotContext dbContext = new ChaosbotContext();
|
await using DatabaseContext dbContext = new DatabaseContext();
|
||||||
|
|
||||||
IQueryable<RoleReaction> roleReactionsQueryable = dbContext.RoleReactions;
|
IQueryable<RoleReaction> roleReactionsQueryable = dbContext.RoleReactions;
|
||||||
List<RoleReaction> roleReactions = roleReactionsQueryable
|
List<RoleReaction> roleReactions = roleReactionsQueryable
|
||||||
|
|||||||
@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
namespace ChaosBot.Migrations
|
namespace ChaosBot.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(ChaosbotContext))]
|
[DbContext(typeof(DatabaseContext))]
|
||||||
[Migration("20200804195804_LodestoneCharacter")]
|
[Migration("20200804195804_LodestoneCharacter")]
|
||||||
partial class LodestoneCharacter
|
partial class LodestoneCharacter
|
||||||
{
|
{
|
||||||
|
|||||||
@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
namespace ChaosBot.Migrations
|
namespace ChaosBot.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(ChaosbotContext))]
|
[DbContext(typeof(DatabaseContext))]
|
||||||
[Migration("20200804202834_LodestoneFreeCompany")]
|
[Migration("20200804202834_LodestoneFreeCompany")]
|
||||||
partial class LodestoneFreeCompany
|
partial class LodestoneFreeCompany
|
||||||
{
|
{
|
||||||
|
|||||||
@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
namespace ChaosBot.Migrations
|
namespace ChaosBot.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(ChaosbotContext))]
|
[DbContext(typeof(DatabaseContext))]
|
||||||
[Migration("20200804203214_Points")]
|
[Migration("20200804203214_Points")]
|
||||||
partial class Points
|
partial class Points
|
||||||
{
|
{
|
||||||
|
|||||||
@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
namespace ChaosBot.Migrations
|
namespace ChaosBot.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(ChaosbotContext))]
|
[DbContext(typeof(DatabaseContext))]
|
||||||
[Migration("20200804204404_Raffles")]
|
[Migration("20200804204404_Raffles")]
|
||||||
partial class Raffles
|
partial class Raffles
|
||||||
{
|
{
|
||||||
|
|||||||
@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
namespace ChaosBot.Migrations
|
namespace ChaosBot.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(ChaosbotContext))]
|
[DbContext(typeof(DatabaseContext))]
|
||||||
[Migration("20200804204734_CommandPermissions")]
|
[Migration("20200804204734_CommandPermissions")]
|
||||||
partial class CommandPermissions
|
partial class CommandPermissions
|
||||||
{
|
{
|
||||||
|
|||||||
@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
namespace ChaosBot.Migrations
|
namespace ChaosBot.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(ChaosbotContext))]
|
[DbContext(typeof(DatabaseContext))]
|
||||||
[Migration("20200804205955_Configuration")]
|
[Migration("20200804205955_Configuration")]
|
||||||
partial class Configuration
|
partial class Configuration
|
||||||
{
|
{
|
||||||
|
|||||||
@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
namespace ChaosBot.Migrations
|
namespace ChaosBot.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(ChaosbotContext))]
|
[DbContext(typeof(DatabaseContext))]
|
||||||
[Migration("20200804213001_ExperiencePoints")]
|
[Migration("20200804213001_ExperiencePoints")]
|
||||||
partial class ExperiencePoints
|
partial class ExperiencePoints
|
||||||
{
|
{
|
||||||
|
|||||||
@ -8,7 +8,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
namespace ChaosBot.Migrations
|
namespace ChaosBot.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(ChaosbotContext))]
|
[DbContext(typeof(DatabaseContext))]
|
||||||
[Migration("20200819203430_RoleReaction")]
|
[Migration("20200819203430_RoleReaction")]
|
||||||
partial class RoleReaction
|
partial class RoleReaction
|
||||||
{
|
{
|
||||||
|
|||||||
@ -8,7 +8,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
namespace ChaosBot.Migrations
|
namespace ChaosBot.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(ChaosbotContext))]
|
[DbContext(typeof(DatabaseContext))]
|
||||||
[Migration("20200824124830_CustomCommand")]
|
[Migration("20200824124830_CustomCommand")]
|
||||||
partial class CustomCommand
|
partial class CustomCommand
|
||||||
{
|
{
|
||||||
|
|||||||
@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
namespace ChaosBot.Migrations
|
namespace ChaosBot.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(ChaosbotContext))]
|
[DbContext(typeof(DatabaseContext))]
|
||||||
partial class ChaosbotContextModelSnapshot : ModelSnapshot
|
partial class ChaosbotContextModelSnapshot : ModelSnapshot
|
||||||
{
|
{
|
||||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||||
|
|||||||
@ -15,18 +15,16 @@ namespace ChaosBot
|
|||||||
private static ILogger _logger;
|
private static ILogger _logger;
|
||||||
public static IConfiguration AppSettingsHandler;
|
public static IConfiguration AppSettingsHandler;
|
||||||
|
|
||||||
private static string _appSettingsPath;
|
public const string AppSettingsPath = "./appsettings.json";
|
||||||
|
|
||||||
private static void Main(string[] args)
|
private static void Main(string[] args)
|
||||||
{
|
{
|
||||||
_appSettingsPath = args.Length > 0 ? args[0] : "./appsettings.json";
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Load configuration from AppSettings.Json and save as Cfg
|
* Load configuration from AppSettings.Json and save as Cfg
|
||||||
*/
|
*/
|
||||||
AppSettingsHandler = LoadConfiguration(_appSettingsPath);
|
AppSettingsHandler = LoadConfiguration(AppSettingsPath);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the _logger for logging purposes
|
* Initialize the _logger for logging purposes
|
||||||
@ -36,8 +34,8 @@ namespace ChaosBot
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.Write($"{MethodBase.GetCurrentMethod()?.ReflectedType?.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>.\n{ex.StackTrace}");
|
LoggingFacade.Exception(ex);
|
||||||
return;
|
Environment.Exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -55,6 +53,7 @@ namespace ChaosBot
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LoggingFacade.Exception(ex);
|
LoggingFacade.Exception(ex);
|
||||||
|
Environment.Exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@ namespace ChaosBot.Services
|
|||||||
|
|
||||||
// Get the possible permissions
|
// Get the possible permissions
|
||||||
List<CommandPermission> commandPermissions;
|
List<CommandPermission> commandPermissions;
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<CommandPermission> permissions = dbContext.CommandPermissions;
|
IQueryable<CommandPermission> permissions = dbContext.CommandPermissions;
|
||||||
commandPermissions = permissions.Where(p => p.Command.Equals(command))
|
commandPermissions = permissions.Where(p => p.Command.Equals(command))
|
||||||
|
|||||||
@ -33,7 +33,7 @@ namespace ChaosBot.WebServer.App.ApiControllers
|
|||||||
if (!CheckPermissions.GetResult(AccessTokenCache, Request, guildId, out IActionResult result))
|
if (!CheckPermissions.GetResult(AccessTokenCache, Request, guildId, out IActionResult result))
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
await using ChaosbotContext dbContext = new ChaosbotContext();
|
await using DatabaseContext dbContext = new DatabaseContext();
|
||||||
|
|
||||||
IQueryable<T> query = GetBasicQuery(dbContext);
|
IQueryable<T> query = GetBasicQuery(dbContext);
|
||||||
List<T> list = ApplyFilterForCurrentGuild(query, guildId).ToList();
|
List<T> list = ApplyFilterForCurrentGuild(query, guildId).ToList();
|
||||||
@ -63,7 +63,7 @@ namespace ChaosBot.WebServer.App.ApiControllers
|
|||||||
if (!ValidationService.Validate(requestBody, GetValidationRules(), out string errors))
|
if (!ValidationService.Validate(requestBody, GetValidationRules(), out string errors))
|
||||||
return BadRequest(errors);
|
return BadRequest(errors);
|
||||||
|
|
||||||
await using ChaosbotContext dbContext = new ChaosbotContext();
|
await using DatabaseContext dbContext = new DatabaseContext();
|
||||||
|
|
||||||
T databaseObject = SetDefaultFieldsForUpsert(new T(), guildId);
|
T databaseObject = SetDefaultFieldsForUpsert(new T(), guildId);
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ namespace ChaosBot.WebServer.App.ApiControllers
|
|||||||
if (!CheckPermissions.GetResult(AccessTokenCache, Request, guildId, out IActionResult result))
|
if (!CheckPermissions.GetResult(AccessTokenCache, Request, guildId, out IActionResult result))
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
await using ChaosbotContext dbContext = new ChaosbotContext();
|
await using DatabaseContext dbContext = new DatabaseContext();
|
||||||
|
|
||||||
List<T> toDelete = FilterQueryMultipleForDeletion(GetBasicQuery(dbContext), guildId, deleteParameter);
|
List<T> toDelete = FilterQueryMultipleForDeletion(GetBasicQuery(dbContext), guildId, deleteParameter);
|
||||||
toDelete.Add(FilterQueryForDeletion(GetBasicQuery(dbContext), guildId, deleteParameter));
|
toDelete.Add(FilterQueryForDeletion(GetBasicQuery(dbContext), guildId, deleteParameter));
|
||||||
@ -112,7 +112,7 @@ namespace ChaosBot.WebServer.App.ApiControllers
|
|||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract DbSet<T> GetBasicQuery(ChaosbotContext context);
|
protected abstract DbSet<T> GetBasicQuery(DatabaseContext context);
|
||||||
protected abstract IQueryable<T> ApplyFilterForCurrentGuild(IQueryable<T> query, ulong guildId);
|
protected abstract IQueryable<T> ApplyFilterForCurrentGuild(IQueryable<T> query, ulong guildId);
|
||||||
protected abstract List<string> GetIndexFields();
|
protected abstract List<string> GetIndexFields();
|
||||||
protected abstract Dictionary<string, List<string>> GetValidationRules();
|
protected abstract Dictionary<string, List<string>> GetValidationRules();
|
||||||
|
|||||||
@ -46,7 +46,7 @@ namespace ChaosBot.WebServer.App.ApiControllers
|
|||||||
return await Delete(guildId, command);
|
return await Delete(guildId, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override DbSet<CustomCommand> GetBasicQuery(ChaosbotContext context)
|
protected override DbSet<CustomCommand> GetBasicQuery(DatabaseContext context)
|
||||||
{
|
{
|
||||||
return context.CustomCommands;
|
return context.CustomCommands;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user