Checkup for internet connection
This commit is contained in:
@@ -9,13 +9,10 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordBotCore.Others.Exceptions;
|
||||
using DiscordBotCore.Loaders;
|
||||
using DiscordBotCore.Interfaces.Modules;
|
||||
using DiscordBotCore.Interfaces.Logger;
|
||||
using DiscordBotCore.Modules;
|
||||
using System.Linq;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics;
|
||||
using DiscordBotCore.Online.Helpers;
|
||||
|
||||
|
||||
namespace DiscordBotCore
|
||||
@@ -40,7 +37,6 @@ namespace DiscordBotCore
|
||||
|
||||
public string ServerID => ApplicationEnvironmentVariables["ServerID"];
|
||||
public string PluginDatabase => ApplicationEnvironmentVariables["PluginDatabase"] ?? _PluginsDatabaseFile;
|
||||
public string LogFile => $"{ApplicationEnvironmentVariables["LogFolder"]}/{DateTime.Now.ToLongDateString().Replace(" / ", "")}.log";
|
||||
|
||||
private ModuleManager _ModuleManager;
|
||||
|
||||
@@ -74,11 +70,20 @@ namespace DiscordBotCore
|
||||
|
||||
public static async Task CreateApplication()
|
||||
{
|
||||
|
||||
if (!await OnlineFunctions.IsInternetConnected())
|
||||
{
|
||||
Console.WriteLine("No internet connection detected. Exiting ...");
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
if (CurrentApplication is not null)
|
||||
return;
|
||||
|
||||
CurrentApplication = new Application();
|
||||
|
||||
|
||||
|
||||
Directory.CreateDirectory(_ResourcesFolder);
|
||||
Directory.CreateDirectory(_PluginsFolder);
|
||||
Directory.CreateDirectory(_ArchivesFolder);
|
||||
|
||||
@@ -107,4 +107,21 @@ internal static class OnlineFunctions
|
||||
using var client = new HttpClient();
|
||||
return await client.GetStringAsync(url, cancellation);
|
||||
}
|
||||
|
||||
internal static async Task<bool> IsInternetConnected()
|
||||
{
|
||||
bool result = false;
|
||||
try
|
||||
{
|
||||
using var client = new HttpClient();
|
||||
await client.GetStringAsync("https://www.google.com");
|
||||
result = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user