Fixed some bugs and added version checking system.
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
<StartupObject />
|
<StartupObject />
|
||||||
<SignAssembly>False</SignAssembly>
|
<SignAssembly>False</SignAssembly>
|
||||||
<IsPublishable>True</IsPublishable>
|
<IsPublishable>True</IsPublishable>
|
||||||
|
<AssemblyVersion>1.0.0.1</AssemblyVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -69,7 +70,10 @@ public class Program
|
|||||||
var consoleCommandsHandler = new ConsoleCommandsHandler(discordbooter.client);
|
var consoleCommandsHandler = new ConsoleCommandsHandler(discordbooter.client);
|
||||||
if (loadPluginsOnStartup) consoleCommandsHandler.HandleCommand("lp");
|
if (loadPluginsOnStartup) consoleCommandsHandler.HandleCommand("lp");
|
||||||
if (listPluginsAtStartup) consoleCommandsHandler.HandleCommand("listplugs");
|
if (listPluginsAtStartup) consoleCommandsHandler.HandleCommand("listplugs");
|
||||||
|
|
||||||
Config.SaveConfig();
|
Config.SaveConfig();
|
||||||
|
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = ConsoleColor.White;
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
@@ -86,11 +90,16 @@ public class Program
|
|||||||
{
|
{
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.ForegroundColor = ConsoleColor.DarkYellow;
|
Console.ForegroundColor = ConsoleColor.DarkYellow;
|
||||||
Console.WriteLine("Discord BOT for Cross Platform");
|
|
||||||
Console.WriteLine("Created by: Wizzy\nDiscord: Wizzy#9181");
|
List<string> startupMessageList = await ServerCom.ReadTextFromFile("https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/StartupMessage");
|
||||||
|
|
||||||
|
foreach (var message in startupMessageList) Console.WriteLine(message);
|
||||||
|
|
||||||
|
Console.WriteLine($"Running on version: {Config.GetValue<string>("Version") ?? System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()}");
|
||||||
|
Console.WriteLine($"Git URL: {Config.GetValue<string>("GitURL") ?? " Could not find Git URL"}");
|
||||||
|
|
||||||
Console.ForegroundColor = ConsoleColor.White;
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
Console.WriteLine("============================ Discord BOT - Cross Platform ============================");
|
Console.WriteLine($"============================ LOG ============================");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -227,7 +236,76 @@ public class Program
|
|||||||
if (Config.GetValue<bool>("DeleteLogsAtStartup"))
|
if (Config.GetValue<bool>("DeleteLogsAtStartup"))
|
||||||
foreach (var file in Directory.GetFiles("./Output/Logs/"))
|
foreach (var file in Directory.GetFiles("./Output/Logs/"))
|
||||||
File.Delete(file);
|
File.Delete(file);
|
||||||
|
List<string> OnlineDefaultKeys = await ServerCom.ReadTextFromFile("https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/SetupKeys");
|
||||||
|
|
||||||
Config.Plugins.Load();
|
Config.PluginConfig.Load();
|
||||||
|
|
||||||
|
if (!Config.ContainsKey("Version"))
|
||||||
|
Config.AddValueToVariables("Version", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(), false);
|
||||||
|
else
|
||||||
|
Config.SetValue("Version", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
|
||||||
|
|
||||||
|
foreach (var key in OnlineDefaultKeys)
|
||||||
|
{
|
||||||
|
if (key.Length <= 3 || !key.Contains(' ')) continue;
|
||||||
|
string[] s = key.Split(' ');
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Config.GetAndAddValueToVariable(s[0], s[1], s[2].Equals("true", StringComparison.CurrentCultureIgnoreCase));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Functions.WriteErrFile(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<string> onlineSettingsList = await ServerCom.ReadTextFromFile("https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/OnlineData");
|
||||||
|
foreach (var key in onlineSettingsList)
|
||||||
|
{
|
||||||
|
if (key.Length <= 3 || !key.Contains(' ')) continue;
|
||||||
|
|
||||||
|
string[] s = key.Split(' ');
|
||||||
|
switch (s[0])
|
||||||
|
{
|
||||||
|
case "CurrentVersion":
|
||||||
|
string newVersion = s[1];
|
||||||
|
if (!newVersion.Equals(Config.GetValue<string>("Version")))
|
||||||
|
{
|
||||||
|
Console.WriteLine("A new version has been released on github page.");
|
||||||
|
Console.WriteLine("Download the new version using the following link wrote in yellow");
|
||||||
|
Console_Utilities.WriteColorText("&y" + Config.GetValue<string>("GitURL") + "&c");
|
||||||
|
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("Your product will work just fine on this outdated version, but an update is recommended.\n" +
|
||||||
|
"From now on, this version is no longer supported"
|
||||||
|
);
|
||||||
|
Console_Utilities.WriteColorText("&rUse at your own risk&c");
|
||||||
|
|
||||||
|
Console_Utilities.WriteColorText("&mCurrent Version: " + Config.GetValue<string>("Version") + "&c");
|
||||||
|
Console_Utilities.WriteColorText("&gNew Version: " + newVersion + "&c");
|
||||||
|
|
||||||
|
Console.WriteLine("\n\n");
|
||||||
|
await Task.Delay(1000);
|
||||||
|
|
||||||
|
int waitTime = 20; //wait time to proceed
|
||||||
|
|
||||||
|
Console.Write($"The bot will start in {waitTime} seconds");
|
||||||
|
while (waitTime > 0)
|
||||||
|
{
|
||||||
|
await Task.Delay(1000);
|
||||||
|
waitTime--;
|
||||||
|
Console.SetCursorPosition("The bot will start in ".Length, Console.CursorTop);
|
||||||
|
Console.Write(" ");
|
||||||
|
Console.SetCursorPosition("The bot will start in ".Length, Console.CursorTop);
|
||||||
|
Console.Write(waitTime + " seconds");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Config.SaveConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System.Text.Json;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace PluginManager
|
namespace PluginManager
|
||||||
{
|
{
|
||||||
@@ -16,7 +17,7 @@ namespace PluginManager
|
|||||||
|
|
||||||
public static class Config
|
public static class Config
|
||||||
{
|
{
|
||||||
public static class Plugins
|
public static class PluginConfig
|
||||||
{
|
{
|
||||||
public static List<Tuple<string, PluginType>> InstalledPlugins = new();
|
public static List<Tuple<string, PluginType>> InstalledPlugins = new();
|
||||||
|
|
||||||
@@ -81,11 +82,33 @@ namespace PluginManager
|
|||||||
if (appConfig!.ApplicationVariables!.ContainsKey(key)) return false;
|
if (appConfig!.ApplicationVariables!.ContainsKey(key)) return false;
|
||||||
if (value == null) return false;
|
if (value == null) return false;
|
||||||
appConfig.ApplicationVariables.Add(key, value);
|
appConfig.ApplicationVariables.Add(key, value);
|
||||||
if (isProtected) appConfig.ProtectedKeyWords!.Add(key);
|
if (isProtected && key != "Version") appConfig.ProtectedKeyWords!.Add(key);
|
||||||
|
|
||||||
SaveConfig();
|
SaveConfig();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void GetAndAddValueToVariable(string key, string value, bool isReadOnly)
|
||||||
|
{
|
||||||
|
if (Config.ContainsKey(key)) return;
|
||||||
|
if (int.TryParse(value, out var intValue))
|
||||||
|
Config.AddValueToVariables(key, intValue, isReadOnly);
|
||||||
|
else if (bool.TryParse(value, out var boolValue))
|
||||||
|
Config.AddValueToVariables(key, boolValue, isReadOnly);
|
||||||
|
else if (float.TryParse(value, out var floatValue))
|
||||||
|
Config.AddValueToVariables(key, floatValue, isReadOnly);
|
||||||
|
else if (double.TryParse(value, out var doubleValue))
|
||||||
|
Config.AddValueToVariables(key, doubleValue, isReadOnly);
|
||||||
|
else if (uint.TryParse(value, out var uintValue))
|
||||||
|
Config.AddValueToVariables(key, uintValue, isReadOnly);
|
||||||
|
else if (long.TryParse(value, out var longValue))
|
||||||
|
Config.AddValueToVariables(key, longValue, isReadOnly);
|
||||||
|
else if (byte.TryParse(value, out var byteValue))
|
||||||
|
Config.AddValueToVariables(key, byteValue, isReadOnly);
|
||||||
|
else
|
||||||
|
Config.AddValueToVariables(key, value, isReadOnly);
|
||||||
|
}
|
||||||
|
|
||||||
public static T? GetValue<T>(string key)
|
public static T? GetValue<T>(string key)
|
||||||
{
|
{
|
||||||
if (!appConfig!.ApplicationVariables!.ContainsKey(key)) return default;
|
if (!appConfig!.ApplicationVariables!.ContainsKey(key)) return default;
|
||||||
|
|||||||
@@ -32,16 +32,6 @@ public class ConsoleCommandsHandler
|
|||||||
|
|
||||||
AddCommand("help", "Show help", "help <command>", args =>
|
AddCommand("help", "Show help", "help <command>", args =>
|
||||||
{
|
{
|
||||||
if (args[1] == "lip")
|
|
||||||
{
|
|
||||||
foreach (var tuple in Config.Plugins.InstalledPlugins)
|
|
||||||
{
|
|
||||||
Console.WriteLine(tuple.Item1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.Length <= 1)
|
if (args.Length <= 1)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Available commands:");
|
Console.WriteLine("Available commands:");
|
||||||
@@ -54,9 +44,11 @@ public class ConsoleCommandsHandler
|
|||||||
foreach (var command in commandList)
|
foreach (var command in commandList)
|
||||||
{
|
{
|
||||||
var pa = from p in command.Action.Method.GetParameters()
|
var pa = from p in command.Action.Method.GetParameters()
|
||||||
where p.Name != null select p.ParameterType.FullName;
|
where p.Name != null
|
||||||
|
select p.ParameterType.FullName;
|
||||||
items.Add(new[] { command.CommandName, command.Description, command.Usage });
|
items.Add(new[] { command.CommandName, command.Description, command.Usage });
|
||||||
}
|
}
|
||||||
|
|
||||||
items.Add(new[] { "-", "-", "-" });
|
items.Add(new[] { "-", "-", "-" });
|
||||||
Console_Utilities.FormatAndAlignTable(items);
|
Console_Utilities.FormatAndAlignTable(items);
|
||||||
}
|
}
|
||||||
@@ -75,6 +67,7 @@ public class ConsoleCommandsHandler
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
AddCommand("lp", "Load plugins", () =>
|
AddCommand("lp", "Load plugins", () =>
|
||||||
{
|
{
|
||||||
if (pluginsLoaded) return;
|
if (pluginsLoaded) return;
|
||||||
@@ -141,8 +134,8 @@ public class ConsoleCommandsHandler
|
|||||||
await ServerCom.DownloadFileAsync(info[1], path);
|
await ServerCom.DownloadFileAsync(info[1], path);
|
||||||
if (info[0] == "Command" || info[0] == "Event")
|
if (info[0] == "Command" || info[0] == "Event")
|
||||||
if (info[0] == "Event")
|
if (info[0] == "Event")
|
||||||
Config.Plugins.InstalledPlugins.Add(new(name, PluginType.Event));
|
Config.PluginConfig.InstalledPlugins.Add(new(name, PluginType.Event));
|
||||||
else if (info[0] == "Command") Config.Plugins.InstalledPlugins.Add(new(name, PluginType.Command));
|
else if (info[0] == "Command") Config.PluginConfig.InstalledPlugins.Add(new(name, PluginType.Command));
|
||||||
|
|
||||||
|
|
||||||
Console.WriteLine("\n");
|
Console.WriteLine("\n");
|
||||||
@@ -190,16 +183,6 @@ public class ConsoleCommandsHandler
|
|||||||
Console.WriteLine("\n");
|
Console.WriteLine("\n");
|
||||||
File.Delete("./" + split[1]);
|
File.Delete("./" + split[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name == "DBUI")
|
|
||||||
{
|
|
||||||
Console.WriteLine("Reload with GUI ?[y/n]");
|
|
||||||
if (Console.ReadKey().Key == ConsoleKey.Y)
|
|
||||||
{
|
|
||||||
Process.Start("./DiscordBotGUI.exe");
|
|
||||||
Environment.Exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
@@ -227,23 +210,7 @@ public class ConsoleCommandsHandler
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (Config.ContainsKey(key)) return;
|
Config.GetAndAddValueToVariable(key, value, isReadOnly);
|
||||||
if (int.TryParse(value, out var intValue))
|
|
||||||
Config.AddValueToVariables(key, intValue, isReadOnly);
|
|
||||||
else if (bool.TryParse(value, out var boolValue))
|
|
||||||
Config.AddValueToVariables(key, boolValue, isReadOnly);
|
|
||||||
else if (float.TryParse(value, out var floatValue))
|
|
||||||
Config.AddValueToVariables(key, floatValue, isReadOnly);
|
|
||||||
else if (double.TryParse(value, out var doubleValue))
|
|
||||||
Config.AddValueToVariables(key, doubleValue, isReadOnly);
|
|
||||||
else if (uint.TryParse(value, out var uintValue))
|
|
||||||
Config.AddValueToVariables(key, uintValue, isReadOnly);
|
|
||||||
else if (long.TryParse(value, out var longValue))
|
|
||||||
Config.AddValueToVariables(key, longValue, isReadOnly);
|
|
||||||
else if (byte.TryParse(value, out var byteValue))
|
|
||||||
Config.AddValueToVariables(key, byteValue, isReadOnly);
|
|
||||||
else
|
|
||||||
Config.AddValueToVariables(key, value, isReadOnly);
|
|
||||||
Console.WriteLine($"Updated config file with the following command: {args[1]} => {value}");
|
Console.WriteLine($"Updated config file with the following command: {args[1]} => {value}");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public class PluginsManager
|
|||||||
|
|
||||||
else
|
else
|
||||||
display[3] = "1";
|
display[3] = "1";
|
||||||
if (Config.Plugins.Contains(content[0]) || Config.Plugins.Contains(content[0]))
|
if (Config.PluginConfig.Contains(content[0]) || Config.PluginConfig.Contains(content[0]))
|
||||||
display[4] = "✓";
|
display[4] = "✓";
|
||||||
else
|
else
|
||||||
display[4] = "X";
|
display[4] = "X";
|
||||||
@@ -73,7 +73,7 @@ public class PluginsManager
|
|||||||
display[1] = content[1];
|
display[1] = content[1];
|
||||||
display[2] = content[2];
|
display[2] = content[2];
|
||||||
if (content.Length == 6 && (content[5] != null || content[5].Length > 2)) display[3] = ((await ServerCom.ReadTextFromFile(content[5])).Count + 1).ToString();
|
if (content.Length == 6 && (content[5] != null || content[5].Length > 2)) display[3] = ((await ServerCom.ReadTextFromFile(content[5])).Count + 1).ToString();
|
||||||
if (Config.Plugins.Contains(content[0]) || Config.Plugins.Contains(content[0]))
|
if (Config.PluginConfig.Contains(content[0]) || Config.PluginConfig.Contains(content[0]))
|
||||||
display[4] = "✓";
|
display[4] = "✓";
|
||||||
else
|
else
|
||||||
display[4] = "X";
|
display[4] = "X";
|
||||||
|
|||||||
Reference in New Issue
Block a user