Updated Logger and message handler. Updated to latest Discord.Net version

This commit is contained in:
2023-01-01 21:55:29 +02:00
parent 4a5e0ef2f3
commit 69d99b4189
11 changed files with 108 additions and 65 deletions

View File

@@ -66,7 +66,9 @@ internal class Boot
AlwaysDownloadUsers = true,
//Disable system clock checkup (for responses at slash commands)
UseInteractionSnowflakeDate = false
UseInteractionSnowflakeDate = false,
GatewayIntents = GatewayIntents.All
};
client = new DiscordSocketClient(config);

View File

@@ -30,6 +30,7 @@ internal class CommandHandler
this.client = client;
this.commandService = commandService;
this.botPrefix = botPrefix;
}
/// <summary>
@@ -76,12 +77,13 @@ internal class CommandHandler
{
try
{
if (Message.Author.IsBot) return;
if (Message as SocketUserMessage == null)
return;
var message = Message as SocketUserMessage;
if (message == null)
if (message is null)
return;
if (!message.Content.StartsWith(botPrefix))
@@ -95,9 +97,6 @@ internal class CommandHandler
return;
}
if (message.Author.IsBot)
return;
var context = new SocketCommandContext(client, message);
await commandService.ExecuteAsync(context, argPos, null);

View File

@@ -38,7 +38,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Discord.Net" Version="3.7.2" />
<PackageReference Include="Discord.Net" Version="3.8.1" />
</ItemGroup>
<ItemGroup>

View File

@@ -33,7 +33,6 @@ public class Program
[STAThread]
public static void Startup(string[] args)
{
PreLoadComponents().Wait();
if (!Config.Variables.Exists("ServerID") || !Config.Variables.Exists("token") ||
@@ -56,9 +55,9 @@ public class Program
top.Add(win);
var labelInfo = new Label(
"Configuration file not found or invalid. " +
"Please fill the following fields to create a new configuration file."
)
"Configuration file not found or invalid. " +
"Please fill the following fields to create a new configuration file."
)
{
X = Pos.Center(),
Y = 2
@@ -251,12 +250,7 @@ public class Program
{
string token = "";
#if DEBUG
if (await Settings.sqlDatabase.TableExistsAsync("BetaTest"))
{
Logger.WriteLine("Starting in DEBUG MODE");
token = await Settings.sqlDatabase.GetValueAsync("BetaTest", "VariableName", "Token", "Value");
}
if (File.Exists("./Data/Resources/token.txt")) token = File.ReadAllText("./Data/Resources/token.txt");
else token = Config.Variables.GetValue("token");
#else
token = Config.Variables.GetValue("token");
@@ -307,8 +301,8 @@ public class Program
{
if (Config.Variables.Exists("LaunchMessage"))
Config.Variables.Add("LaunchMessage",
"An error occured while closing the bot last time. Please consider closing the bot using the &rsd&c method !\nThere is a risk of losing all data or corruption of the save file, which in some cases requires to reinstall the bot !",
false);
"An error occured while closing the bot last time. Please consider closing the bot using the &rsd&c method !\nThere is a risk of losing all data or corruption of the save file, which in some cases requires to reinstall the bot !",
false);
Logger.WriteErrFile(ex.ToString());
}
}
@@ -318,7 +312,7 @@ public class Program
private static async Task PreLoadComponents()
{
Settings.sqlDatabase = new SqlDatabase(Functions.dataFolder + "SetDB.dat");
Settings.sqlDatabase = new SqlDatabase("SetDB.dat");
await Settings.sqlDatabase.Open();
await Config.Initialize();
@@ -326,10 +320,7 @@ public class Program
ArchiveManager.Initialize();
Logger.LogEvent += (message) =>
{
Console.Write(message);
};
Logger.LogEvent += (message) => { Console.Write(message); };
Logger.WriteLine("Loading resources ...");
var main = new Utilities.ProgressBar(ProgressBarType.NO_END);
@@ -348,9 +339,11 @@ public class Program
if (!await Config.Variables.ExistsAsync("Version"))
await Config.Variables.AddAsync("Version", Assembly.GetExecutingAssembly().GetName().Version.ToString(), false);
await Config.Variables.AddAsync("Version", Assembly.GetExecutingAssembly().GetName().Version.ToString(),
false);
else
await Config.Variables.SetValueAsync("Version", Assembly.GetExecutingAssembly().GetName().Version.ToString());
await Config.Variables.SetValueAsync(
"Version", Assembly.GetExecutingAssembly().GetName().Version.ToString());
foreach (var key in OnlineDefaultKeys)
@@ -397,21 +390,21 @@ public class Program
Console.ForegroundColor = ConsoleColor.Red;
Logger.WriteLine("A new version of the bot is available !");
Console.ForegroundColor = ConsoleColor.Yellow;
Logger.WriteLine("Current version : " + Assembly.GetExecutingAssembly().GetName().Version.ToString());
Logger.WriteLine("Current version : " +
Assembly.GetExecutingAssembly().GetName().Version.ToString());
Console.ForegroundColor = ConsoleColor.Green;
Logger.WriteLine("New version : " + newVersion);
Console.ForegroundColor = ConsoleColor.White;
Logger.WriteLine("Changelog :");
List<string> changeLog = await ServerCom.ReadTextFromURL("https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/VersionData/DiscordBot");
List<string> changeLog = await ServerCom.ReadTextFromURL(
"https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/VersionData/DiscordBot");
foreach (var item in changeLog)
Utilities.WriteColorText(item);
Logger.WriteLine("Do you want to update the bot ? (y/n)");
if (Console.ReadKey().Key == ConsoleKey.Y)
{
if (Functions.GetOperatingSystem() == OperatingSystem.WINDOWS)
{
var url =
@@ -453,7 +446,7 @@ public class Program
"https://github.com/Wizzy69/installer/releases/download/release-1-discordbot/Updater.zip",
"./Updater.zip");
await ArchiveManager.ExtractArchive("./Updater.zip", "./", null,
UnzipProgressType.PercentageFromTotalSize);
UnzipProgressType.PercentageFromTotalSize);
await Config.Variables.SetValueAsync("UpdaterVersion", updaternewversion);
File.Delete("Updater.zip");
bar.Stop("Updater has been updated !");
@@ -463,6 +456,7 @@ public class Program
break;
}
}
Console.Clear();
}
}