Renamed PluginManager to DiscordBotCore.
Revamped the Logger
This commit is contained in:
50
DiscordBotCore/Interfaces/DBCommand.cs
Normal file
50
DiscordBotCore/Interfaces/DBCommand.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System.Collections.Generic;
|
||||
using DiscordBotCore.Others;
|
||||
|
||||
namespace DiscordBotCore.Interfaces;
|
||||
|
||||
public interface DBCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Command to be executed
|
||||
/// It's CaSe SeNsItIvE
|
||||
/// </summary>
|
||||
string Command { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Command aliases. Users may use this to execute the command
|
||||
/// </summary>
|
||||
List<string>? Aliases { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Command description
|
||||
/// </summary>
|
||||
string Description { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The usage for your command.
|
||||
/// It will be displayed when users type help
|
||||
/// </summary>
|
||||
string Usage { get; }
|
||||
|
||||
/// <summary>
|
||||
/// true if the command requre admin, otherwise false
|
||||
/// </summary>
|
||||
bool requireAdmin { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The main body of the command. This is what is executed when user calls the command in Server
|
||||
/// </summary>
|
||||
/// <param name="args">The disocrd Context</param>
|
||||
void ExecuteServer(DbCommandExecutingArguments args)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The main body of the command. This is what is executed when user calls the command in DM
|
||||
/// </summary>
|
||||
/// <param name="args">The disocrd Context</param>
|
||||
void ExecuteDM(DbCommandExecutingArguments args)
|
||||
{
|
||||
}
|
||||
}
|
||||
22
DiscordBotCore/Interfaces/DBEvent.cs
Normal file
22
DiscordBotCore/Interfaces/DBEvent.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Discord.WebSocket;
|
||||
|
||||
namespace DiscordBotCore.Interfaces;
|
||||
|
||||
public interface DBEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// The name of the event
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The description of the event
|
||||
/// </summary>
|
||||
string Description { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The method that is invoked when the event is loaded into memory
|
||||
/// </summary>
|
||||
/// <param name="client">The discord bot client</param>
|
||||
void Start(DiscordSocketClient client);
|
||||
}
|
||||
24
DiscordBotCore/Interfaces/DBSlashCommand.cs
Normal file
24
DiscordBotCore/Interfaces/DBSlashCommand.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
|
||||
namespace DiscordBotCore.Interfaces;
|
||||
|
||||
public interface DBSlashCommand
|
||||
{
|
||||
string Name { get; }
|
||||
string Description { get; }
|
||||
bool canUseDM { get; }
|
||||
bool HasInteraction { get; }
|
||||
|
||||
List<SlashCommandOptionBuilder> Options { get; }
|
||||
|
||||
void ExecuteServer(SocketSlashCommand context)
|
||||
{ }
|
||||
|
||||
void ExecuteDM(SocketSlashCommand context) { }
|
||||
|
||||
Task ExecuteInteraction(SocketInteraction interaction) => Task.CompletedTask;
|
||||
}
|
||||
22
DiscordBotCore/Interfaces/ICommandAction.cs
Normal file
22
DiscordBotCore/Interfaces/ICommandAction.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordBotCore.Others;
|
||||
using DiscordBotCore.Others.Actions;
|
||||
|
||||
namespace DiscordBotCore.Interfaces;
|
||||
|
||||
public interface ICommandAction
|
||||
{
|
||||
public string ActionName { get; }
|
||||
|
||||
public string? Description { get; }
|
||||
|
||||
public string? Usage { get; }
|
||||
|
||||
public IEnumerable<InternalActionOption> ListOfOptions { get; }
|
||||
|
||||
public InternalActionRunType RunType { get; }
|
||||
|
||||
public Task Execute(string[]? args);
|
||||
}
|
||||
15
DiscordBotCore/Interfaces/Logger/ILogMessage.cs
Normal file
15
DiscordBotCore/Interfaces/Logger/ILogMessage.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using DiscordBotCore.Others;
|
||||
|
||||
using System;
|
||||
|
||||
namespace DiscordBotCore.Interfaces.Logger
|
||||
{
|
||||
public interface ILogMessage
|
||||
{
|
||||
public string Message { get; protected set; }
|
||||
public DateTime ThrowTime { get; protected set; }
|
||||
public string SenderName { get; protected set; }
|
||||
public LogType LogMessageType { get; protected set; }
|
||||
|
||||
}
|
||||
}
|
||||
19
DiscordBotCore/Interfaces/Logger/ILogger.cs
Normal file
19
DiscordBotCore/Interfaces/Logger/ILogger.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using DiscordBotCore.Others;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DiscordBotCore.Interfaces.Logger
|
||||
{
|
||||
public interface ILogger
|
||||
{
|
||||
public struct FormattedMessage { public string Message; public LogType Type; }
|
||||
public string LogMessageFormat { get; set; }
|
||||
|
||||
public void Log(ILogMessage message);
|
||||
public void LogException(Exception exception, object Sender);
|
||||
|
||||
public event EventHandler<FormattedMessage> OnFormattedLog;
|
||||
public event EventHandler<ILogMessage> OnRawLog;
|
||||
}
|
||||
}
|
||||
83
DiscordBotCore/Interfaces/Updater/AppVersion.cs
Normal file
83
DiscordBotCore/Interfaces/Updater/AppVersion.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
|
||||
namespace DiscordBotCore.Interfaces.Updater
|
||||
{
|
||||
public class AppVersion : IVersion
|
||||
{
|
||||
public int Major { get; set; }
|
||||
|
||||
public int Minor { get; set; }
|
||||
|
||||
public int Patch { get; set; }
|
||||
|
||||
public int PatchVersion { get; set; }
|
||||
|
||||
public static readonly AppVersion CurrentAppVersion = new AppVersion(Application.CurrentApplication.ApplicationEnvironmentVariables["Version"]);
|
||||
|
||||
private readonly char _Separator = '.';
|
||||
|
||||
public AppVersion(string versionAsString)
|
||||
{
|
||||
string[] versionParts = versionAsString.Split(_Separator);
|
||||
|
||||
if (versionParts.Length != 4)
|
||||
{
|
||||
throw new ArgumentException("Invalid version string");
|
||||
}
|
||||
|
||||
Major = int.Parse(versionParts[0]);
|
||||
Minor = int.Parse(versionParts[1]);
|
||||
Patch = int.Parse(versionParts[2]);
|
||||
PatchVersion = int.Parse(versionParts[3]);
|
||||
}
|
||||
|
||||
public bool IsNewerThan(IVersion version)
|
||||
{
|
||||
if (Major > version.Major)
|
||||
return true;
|
||||
|
||||
if (Major == version.Major && Minor > version.Minor)
|
||||
return true;
|
||||
|
||||
if (Major == version.Major && Minor == version.Minor && Patch > version.Patch)
|
||||
return true;
|
||||
|
||||
if (Major == version.Major && Minor == version.Minor && Patch == version.Patch && PatchVersion > version.PatchVersion)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsOlderThan(IVersion version)
|
||||
{
|
||||
if (Major < version.Major)
|
||||
return true;
|
||||
|
||||
if (Major == version.Major && Minor < version.Minor)
|
||||
return true;
|
||||
|
||||
if (Major == version.Major && Minor == version.Minor && Patch < version.Patch)
|
||||
return true;
|
||||
|
||||
if (Major == version.Major && Minor == version.Minor && Patch == version.Patch && PatchVersion < version.PatchVersion)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsEqualTo(IVersion version)
|
||||
{
|
||||
return Major == version.Major && Minor == version.Minor && Patch == version.Patch && PatchVersion == version.PatchVersion;
|
||||
}
|
||||
|
||||
public string ToShortString()
|
||||
{
|
||||
return $"{Major}.{Minor}.{Patch}.{PatchVersion}";
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ToShortString();
|
||||
}
|
||||
}
|
||||
}
|
||||
17
DiscordBotCore/Interfaces/Updater/IVersion.cs
Normal file
17
DiscordBotCore/Interfaces/Updater/IVersion.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace DiscordBotCore.Interfaces.Updater;
|
||||
|
||||
public interface IVersion
|
||||
{
|
||||
public int Major { get; }
|
||||
public int Minor { get; }
|
||||
public int Patch { get; }
|
||||
public int PatchVersion => 0;
|
||||
|
||||
public bool IsNewerThan(IVersion version);
|
||||
|
||||
public bool IsOlderThan(IVersion version);
|
||||
|
||||
public bool IsEqualTo(IVersion version);
|
||||
|
||||
public string ToShortString();
|
||||
}
|
||||
76
DiscordBotCore/Interfaces/Updater/Version.cs
Normal file
76
DiscordBotCore/Interfaces/Updater/Version.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
|
||||
namespace DiscordBotCore.Interfaces.Updater;
|
||||
|
||||
public abstract class Version: IVersion
|
||||
{
|
||||
public int Major { get; }
|
||||
public int Minor { get; }
|
||||
public int Patch { get; }
|
||||
|
||||
protected readonly char _Separator = '.';
|
||||
|
||||
protected Version(int major, int minor, int patch)
|
||||
{
|
||||
Major = major;
|
||||
Minor = minor;
|
||||
Patch = patch;
|
||||
}
|
||||
|
||||
protected Version(string versionAsString)
|
||||
{
|
||||
string[] versionParts = versionAsString.Split(_Separator);
|
||||
|
||||
if (versionParts.Length != 3)
|
||||
{
|
||||
throw new ArgumentException("Invalid version string");
|
||||
}
|
||||
|
||||
Major = int.Parse(versionParts[0]);
|
||||
Minor = int.Parse(versionParts[1]);
|
||||
Patch = int.Parse(versionParts[2]);
|
||||
}
|
||||
|
||||
public bool IsNewerThan(IVersion version)
|
||||
{
|
||||
if (Major > version.Major)
|
||||
return true;
|
||||
|
||||
if (Major == version.Major && Minor > version.Minor)
|
||||
return true;
|
||||
|
||||
if (Major == version.Major && Minor == version.Minor && Patch > version.Patch)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsOlderThan(IVersion version)
|
||||
{
|
||||
if (Major < version.Major)
|
||||
return true;
|
||||
|
||||
if (Major == version.Major && Minor < version.Minor)
|
||||
return true;
|
||||
|
||||
if (Major == version.Major && Minor == version.Minor && Patch < version.Patch)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsEqualTo(IVersion version)
|
||||
{
|
||||
return Major == version.Major && Minor == version.Minor && Patch == version.Patch;
|
||||
}
|
||||
|
||||
public string ToShortString()
|
||||
{
|
||||
return $"{Major}.{Minor}.{Patch}";
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ToShortString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user