Redesigned the DiscordBotCore by splitting it into multiple projects. Created a WebUI and preparing to remove the DiscordBot application
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
using Discord;
|
||||
using DiscordBotCore;
|
||||
using DiscordBotCore.Interfaces;
|
||||
using DiscordBotCore.Others;
|
||||
using DiscordBotCore.Logging;
|
||||
using DiscordBotCore.PluginCore.Helpers;
|
||||
using DiscordBotCore.PluginCore.Helpers.Execution.DbCommand;
|
||||
using DiscordBotCore.PluginCore.Interfaces;
|
||||
|
||||
namespace LevelingSystem;
|
||||
|
||||
@@ -17,11 +18,11 @@ internal class LevelCommand: IDbCommand
|
||||
|
||||
public bool RequireAdmin => false;
|
||||
|
||||
public async void ExecuteServer(DbCommandExecutingArguments args)
|
||||
public async Task ExecuteServer(IDbCommandExecutingArgument args)
|
||||
{
|
||||
if(Variables.Database is null)
|
||||
{
|
||||
Application.CurrentApplication.Logger.Log("Database is not initialized", this, LogType.Warning);
|
||||
args.Logger.Log("Database is not initialized", this);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
using Discord.WebSocket;
|
||||
|
||||
using DiscordBotCore;
|
||||
using DiscordBotCore.Database;
|
||||
using DiscordBotCore.Interfaces;
|
||||
using System.Net.Mime;
|
||||
using Discord.WebSocket;
|
||||
using DiscordBotCore.Database.Sqlite;
|
||||
using DiscordBotCore.Logging;
|
||||
using DiscordBotCore.PluginCore;
|
||||
using DiscordBotCore.PluginCore.Helpers;
|
||||
using DiscordBotCore.PluginCore.Helpers.Execution.DbEvent;
|
||||
using DiscordBotCore.PluginCore.Interfaces;
|
||||
using static LevelingSystem.Variables;
|
||||
|
||||
namespace LevelingSystem;
|
||||
@@ -12,7 +15,7 @@ internal class LevelEvent : IDbEvent
|
||||
public string Name => "Leveling System Event Handler";
|
||||
public string Description => "The Leveling System Event Handler";
|
||||
|
||||
public async void Start(DiscordSocketClient client)
|
||||
public async Task Start(IDbEventExecutingArgument args)
|
||||
{
|
||||
|
||||
Directory.CreateDirectory(DataFolder);
|
||||
@@ -29,10 +32,11 @@ internal class LevelEvent : IDbEvent
|
||||
MaxExp = 7,
|
||||
MinExp = 1
|
||||
};
|
||||
await DiscordBotCore.Others.JsonManager.SaveToJsonFile(DataFolder + "Settings.txt", GlobalSettings);
|
||||
|
||||
await DiscordBotCore.Utilities.JsonManager.SaveToJsonFile(DataFolder + "Settings.txt", GlobalSettings);
|
||||
}
|
||||
else
|
||||
GlobalSettings = await DiscordBotCore.Others.JsonManager.ConvertFromJson<Settings>(DataFolder + "Settings.txt");
|
||||
GlobalSettings = await DiscordBotCore.Utilities.JsonManager.ConvertFromJson<Settings>(DataFolder + "Settings.txt");
|
||||
|
||||
if (!await Database.TableExistsAsync("Levels"))
|
||||
await Database.CreateTableAsync("Levels", "UserID VARCHAR(128)", "Level INT", "EXP INT");
|
||||
@@ -40,14 +44,12 @@ internal class LevelEvent : IDbEvent
|
||||
if (!await Database.TableExistsAsync("Users"))
|
||||
await Database.CreateTableAsync("Users", "UserID VARCHAR(128)", "UserMention VARCHAR(128)", "Username VARCHAR(128)", "Discriminator VARCHAR(128)");
|
||||
|
||||
|
||||
|
||||
client.MessageReceived += ClientOnMessageReceived;
|
||||
args.Client.MessageReceived += (message) => ClientOnMessageReceived(message, args.BotPrefix);
|
||||
}
|
||||
|
||||
private async Task ClientOnMessageReceived(SocketMessage arg)
|
||||
private async Task ClientOnMessageReceived(SocketMessage arg, string botPrefix)
|
||||
{
|
||||
if (arg.Author.IsBot || arg.IsTTS || arg.Content.StartsWith(Application.CurrentApplication.ApplicationEnvironmentVariables.Get<string>("prefix")))
|
||||
if (arg.Author.IsBot || arg.IsTTS || arg.Content.StartsWith(botPrefix))
|
||||
return;
|
||||
|
||||
if (WaitingList.ContainsKey(arg.Author.Id) && WaitingList[arg.Author.Id] > DateTime.Now.AddSeconds(-GlobalSettings.SecondsToWaitBetweenMessages))
|
||||
|
||||
@@ -7,7 +7,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\DiscordBotCore\DiscordBotCore.csproj" />
|
||||
<ProjectReference Include="..\..\DiscordBotCore.Database.Sqlite\DiscordBotCore.Database.Sqlite.csproj" />
|
||||
<ProjectReference Include="..\..\DiscordBotCore.Logging\DiscordBotCore.Logging.csproj" />
|
||||
<ProjectReference Include="..\..\DiscordBotCore.PluginCore\DiscordBotCore.PluginCore.csproj" />
|
||||
<ProjectReference Include="..\..\DiscordBotCore.Utilities\DiscordBotCore.Utilities.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
using DiscordBotCore.Interfaces;
|
||||
using DiscordBotCore.Others;
|
||||
using DiscordBotCore.Others.Actions;
|
||||
|
||||
namespace LevelingSystem;
|
||||
|
||||
public class ReloadAction: ICommandAction
|
||||
{
|
||||
public string ActionName => "LevelingSystemReload";
|
||||
public string? Description => "Reloads the Leveling System config file";
|
||||
public string? Usage => "LevelingSystemReload";
|
||||
public InternalActionRunType RunType => InternalActionRunType.OnCall;
|
||||
public bool RequireOtherThread => false;
|
||||
public IEnumerable<InternalActionOption> ListOfOptions => [];
|
||||
|
||||
public async Task Execute(string[]? args)
|
||||
{
|
||||
Variables.GlobalSettings = await JsonManager.ConvertFromJson<Settings>(Variables.DataFolder + "Settings.txt");
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using DiscordBotCore;
|
||||
using DiscordBotCore.Database;
|
||||
using DiscordBotCore.Database.Sqlite;
|
||||
|
||||
namespace LevelingSystem;
|
||||
|
||||
@@ -12,8 +11,8 @@ public class Settings
|
||||
|
||||
internal static class Variables
|
||||
{
|
||||
internal static readonly string DataFolder = Application.GetResourceFullPath("LevelingSystem/");
|
||||
internal static SqlDatabase? Database;
|
||||
internal static readonly Dictionary<ulong, DateTime> WaitingList = new();
|
||||
internal static Settings GlobalSettings = new();
|
||||
}
|
||||
internal static readonly string DataFolder = "./Data/Resources/LevelingSystem/";
|
||||
internal static SqlDatabase? Database;
|
||||
internal static readonly Dictionary<ulong, DateTime> WaitingList = new();
|
||||
internal static Settings GlobalSettings = new();
|
||||
}
|
||||
Reference in New Issue
Block a user