Updated bootstrap and merged gitlab project

This commit is contained in:
2024-09-17 15:30:08 +03:00
parent a584423939
commit be75ef03cb
2097 changed files with 14141 additions and 148 deletions

View File

@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DiscordBotCore;
using DiscordBotCore.Others;
using Spectre.Console;
namespace DiscordBot;
@@ -42,8 +44,25 @@ public static class Installer
if (!Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey("ServerID"))
{
var response = AskForConfig("ServerID", "Please enter the server Ids where the bot will be used (separated by ;):");
Application.CurrentApplication.ApplicationEnvironmentVariables.Add("ServerID", response);
var response = AskForConfig("ServerID", "Please enter the server Ids where the bot will be used (separated by ;):");
List<ulong> serverIds = new List<ulong>();
foreach (var id in response.Split(';'))
{
if(!ulong.TryParse(id, out ulong sID))
{
Application.Logger.Log($"Invalid server ID {id}", LogType.Warning);
}
serverIds.Add(sID);
}
if(!serverIds.Any())
{
Application.Logger.Log($"No valid server id provided", LogType.Critical);
Environment.Exit(-20);
}
Application.CurrentApplication.ApplicationEnvironmentVariables.Add("ServerID", serverIds);
}
await Application.CurrentApplication.ApplicationEnvironmentVariables.SaveToFile();

View File

@@ -3,12 +3,13 @@ using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using DiscordBot.Bot.Actions.Extra;
using DiscordBot.Utilities;
using DiscordBotCore;
using DiscordBotCore.Bot;
using DiscordBot.Bot.Actions.Extra;
using DiscordBotCore.Updater.Application;
using DiscordBot.Utilities;
using DiscordBotCore.Others;
using DiscordBotCore.Others.Exceptions;
using DiscordBotCore.Updater.Application;
using Spectre.Console;
@@ -27,30 +28,22 @@ public class Program
await ConsoleInputHandler();
}
/// <summary>
/// The main loop for the discord bot
/// </summary>
private static async Task ConsoleInputHandler()
{
while (true)
{
var cmd = Console.ReadLine();
if (cmd is null)
{
break;
}
var args = cmd.Split(' ');
if (args.Length == 0)
{
continue; // Skip empty command
}
var cmd = Console.ReadLine();
var args = cmd.Split(' ');
var command = args[0];
args = args.Skip(1).ToArray();
if (args.Length == 0)
{
args = null;
}
await Application.CurrentApplication.InternalActionManager.Execute(command, args);
await Application.CurrentApplication.InternalActionManager.Execute(command, args);
}
}
@@ -98,8 +91,31 @@ public class Program
await ConsoleUtilities.ExecuteTaskWithBuiltInProgress(updater.SelfUpdate, update, "Discord Bot Update");
return;
}
void LogMessageFunction(string message, LogType logType)
{
string messageAsString = message;
switch (logType)
{
case LogType.Info:
messageAsString = $"[green]{messageAsString} [/]";
break;
case LogType.Warning:
messageAsString = $"[yellow]{messageAsString} [/]";
break;
case LogType.Error:
messageAsString = $"[red]{messageAsString} [/]";
break;
case LogType.Critical:
messageAsString = $"[red] [bold]{messageAsString} [/][/]";
break;
Application.Logger.SetOutFunction(AnsiConsole.MarkupLine);
}
AnsiConsole.MarkupLine(messageAsString);
}
Application.Logger.SetOutFunction(LogMessageFunction);
if (!Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey("ServerID") ||