This commit is contained in:
2022-06-08 18:54:58 +03:00
parent c66ff52d94
commit 531edcd3cc
55 changed files with 2253 additions and 2360 deletions

View File

@@ -1,7 +1,7 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="DiscordBotGUI.App">
<Application.Styles>
<FluentTheme Mode="Dark"/>
</Application.Styles>
</Application>
<Application.Styles>
<FluentTheme Mode="Dark" />
</Application.Styles>
</Application>

View File

@@ -1,23 +1,21 @@
using System.IO;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using PluginManager.Others;
namespace DiscordBotGUI
namespace DiscordBotGUI;
public class App : Application
{
public partial class App : Application
public override void Initialize()
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
AvaloniaXamlLoader.Load(this);
}
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { desktop.MainWindow = new AppUpdater() { Width = 300, Height = 50, WindowStartupLocation = Avalonia.Controls.WindowStartupLocation.CenterScreen }; }
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) desktop.MainWindow = new AppUpdater { Width = 300, Height = 50, WindowStartupLocation = WindowStartupLocation.CenterScreen };
base.OnFrameworkInitializationCompleted();
}
base.OnFrameworkInitializationCompleted();
}
}

View File

@@ -5,12 +5,13 @@
mc:Ignorable="d" d:DesignWidth="250" d:DesignHeight="50"
x:Class="DiscordBotGUI.AppUpdater"
Title="AppUpdater"
Background="Transparent"
TransparencyLevelHint="AcrylicBlur"
HasSystemDecorations="False">
Background="Transparent"
TransparencyLevelHint="AcrylicBlur"
SystemDecorations="BorderOnly">
<StackPanel Margin="10">
<TextBlock x:Class="DiscordBotGUI.AppUpdater" x:Name="textBox1" Text="Checking for updates..." />
<ProgressBar IsIndeterminate="True" x:Class="DiscordBotGUI.AppUpdater" x:Name="progressBar1" Foreground="Yellow" />
</StackPanel>
</Window>
<StackPanel Margin="10">
<TextBlock x:Class="DiscordBotGUI.AppUpdater" x:Name="textBox1" Text="Checking for updates..." />
<ProgressBar IsIndeterminate="True" x:Class="DiscordBotGUI.AppUpdater" x:Name="progressBar1"
Foreground="Yellow" />
</StackPanel>
</Window>

View File

@@ -11,7 +11,7 @@ namespace DiscordBotGUI
{
public partial class AppUpdater : Window
{
private string _version;
private string _version = "";
public AppUpdater()
{
@@ -149,7 +149,7 @@ namespace DiscordBotGUI
{
try
{
string current_version = Config.GetValue("Version");
string current_version = Config.GetValue<string>("Version");
if (current_version == null)
if (!Config.SetValue("Version", "0"))
Config.AddValueToVariables("Version", "0", false);

View File

@@ -5,32 +5,35 @@
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="425"
x:Class="DiscordBotGUI.MainWindow"
Title="DiscordBotGUI"
Background="Transparent"
TransparencyLevelHint="AcrylicBlur"
ExtendClientAreaToDecorationsHint="True" >
Background="Transparent"
TransparencyLevelHint="AcrylicBlur"
ExtendClientAreaToDecorationsHint="True">
<StackPanel Margin="20">
<Menu>
<MenuItem Header="Plugins">
<MenuItem Header="Commands" x:Class="DiscordBotGUI.MainWindow" x:Name="commandsSettingMenuItem" />
<MenuItem Header="Events" x:Class="DiscordBotGUI.MainWindow" x:Name="eventsSettingMenuItem" />
<StackPanel Margin="20">
<Menu>
<MenuItem Header="Plugins">
<MenuItem Header="Commands" x:Class="DiscordBotGUI.MainWindow" x:Name="commandsSettingMenuItem" />
<MenuItem Header="Events" x:Class="DiscordBotGUI.MainWindow" x:Name="eventsSettingMenuItem" />
</MenuItem>
<MenuItem Header="Application Variables" x:Class="DiscordBotGUI.MainWindow" x:Name="applicationVariablesMenuItem"/>
</Menu>
<Label x:Class="DiscordBotGUI.MainWindow" x:Name="label1" Content="Discord Token" />
<TextBox x:Class="DiscordBotGUI.MainWindow" x:Name="textBox1" IsReadOnly="True" TextAlignment="Center" Text=""/>
<Label x:Class="DiscordBotGUI.MainWindow" x:Name="label2" Content="Bot Prefix" />
<TextBox x:Class="DiscordBotGUI.MainWindow" x:Name="textBox2" TextAlignment="Center" HorizontalAlignment="Left" IsReadOnly="True" Text=""/>
<Border Background="Black" Padding="0.5" Margin="25"/>
<Label x:Class="DiscordBotGUI.MainWindow" x:Name="label3" Content="Start Arguments: " />
<TextBox x:Class="DiscordBotGUI.MainWindow" x:Name="textBox3" Width="250" TextAlignment="Center" HorizontalAlignment="Left" IsReadOnly="False" Text=""/>
<Label x:Class="DiscordBotGUI.MainWindow" x:Name="label4" Content="" Foreground="Red" Margin="10"/>
<Button x:Class="DiscordBotGUI.MainWindow" x:Name="button1" HorizontalAlignment="Center" VerticalAlignment="Bottom" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Width="200" Content="Start Bot" Margin="0,75,0,0" />
<Label x:Class="DiscordBotGUI.MainWindow" x:Name="label5" Content="" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="0,0,0,0"/>
</StackPanel>
<MenuItem Header="Application Variables" x:Class="DiscordBotGUI.MainWindow"
x:Name="applicationVariablesMenuItem" />
</Menu>
<Label x:Class="DiscordBotGUI.MainWindow" x:Name="label1" Content="Discord Token" />
<TextBox x:Class="DiscordBotGUI.MainWindow" x:Name="textBox1" IsReadOnly="True" TextAlignment="Center" Text="" />
<Label x:Class="DiscordBotGUI.MainWindow" x:Name="label2" Content="Bot Prefix" />
<TextBox x:Class="DiscordBotGUI.MainWindow" x:Name="textBox2" TextAlignment="Center" HorizontalAlignment="Left"
IsReadOnly="True" Text="" />
<Border Background="Black" Padding="0.5" Margin="25" />
<Label x:Class="DiscordBotGUI.MainWindow" x:Name="label3" Content="Start Arguments: " />
<TextBox x:Class="DiscordBotGUI.MainWindow" x:Name="textBox3" Width="250" TextAlignment="Center"
HorizontalAlignment="Left" IsReadOnly="False" Text="" />
<Label x:Class="DiscordBotGUI.MainWindow" x:Name="label4" Content="" Foreground="Red" Margin="10" />
<Button x:Class="DiscordBotGUI.MainWindow" x:Name="button1" HorizontalAlignment="Center"
VerticalAlignment="Bottom" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
Width="200" Content="Start Bot" Margin="0,75,0,0" />
<Label x:Class="DiscordBotGUI.MainWindow" x:Name="label5" Content="" VerticalAlignment="Bottom"
HorizontalAlignment="Right" Margin="0,0,0,0" />
</StackPanel>
</Window>
</Window>

View File

@@ -1,99 +1,86 @@
using Avalonia.Controls;
using System.Threading.Tasks;
using PluginManager.Others;
using System.IO;
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using Avalonia.Controls;
using DiscordBotGUI.Settings;
using Avalonia.Themes.Fluent;
using PluginManager;
using PluginManager.Others;
namespace DiscordBotGUI
namespace DiscordBotGUI;
public partial class MainWindow : Window
{
public partial class MainWindow : Window
public MainWindow()
{
public MainWindow()
InitializeComponent();
LoadElements();
}
private void LoadElements()
{
textBox3.Watermark = "Insert start arguments";
if (File.Exists("./Version.txt")) label5.Content = Config.GetValue<string>("Version");
button1.Click += async (sender, e) =>
{
InitializeComponent();
var token = textBox1.Text;
var prefix = textBox2.Text;
var args = "--nomessage " + textBox3.Text;
LoadElements();
}
private void LoadElements()
{
textBox3.Watermark = "Insert start arguments";
if (File.Exists("./Version.txt")) label5.Content = Config.GetValue("Version");
button1.Click += async (sender, e) =>
if (!((token.Length == 70 || token.Length == 59) && prefix.Length == 1))
{
string token = textBox1.Text;
string prefix = textBox2.Text;
string args = "--nomessage " + textBox3.Text;
if (!((token.Length == 70 || token.Length == 59) && prefix.Length == 1))
{
label4.Content = "Invalid Token or Prefix.\n(Prefix must be 1 character long and token must be 59 or 79 characters long)";
await Task.Delay(5000);
label4.Content = "";
return;
}
Config.SetValue("token", token);
Config.SetValue("prefix", prefix);
RunDiscordBot(args);
};
commandsSettingMenuItem.Click += (sender, e) => new Commands() /*{ Height = 200, Width = 550 }*/.ShowDialog(this);
eventsSettingMenuItem.Click += (sender, e) => new Events() /*{ Height = 200, Width = 550 }*/.ShowDialog(this);
applicationVariablesMenuItem.Click += (sender, e) => new ApplicationVariables().ShowDialog(this);
string folder = $"{Functions.dataFolder}DiscordBotCore.data";
Directory.CreateDirectory(Functions.dataFolder);
try
{
string? botToken = Config.GetValue("token") as string;
string? botPrefix = Config.GetValue("prefix") as string;
if (botToken == null || botPrefix == null)
{
textBox1.IsReadOnly = false;
textBox2.IsReadOnly = false;
textBox1.Watermark = "Insert Bot Token Here";
textBox2.Watermark = "Insert Bot Prefix Here";
}
else
{
textBox1.Text = botToken;
textBox2.Text = botPrefix;
}
label4.Content = "Invalid Token or Prefix.\n(Prefix must be 1 character long and token must be 59 or 79 characters long)";
await Task.Delay(5000);
label4.Content = "";
return;
}
catch
Config.SetValue("token", token);
Config.SetValue("prefix", prefix);
RunDiscordBot(args);
};
commandsSettingMenuItem.Click += (sender, e) => new Commands() /*{ Height = 200, Width = 550 }*/.ShowDialog(this);
eventsSettingMenuItem.Click += (sender, e) => new Events() /*{ Height = 200, Width = 550 }*/.ShowDialog(this);
applicationVariablesMenuItem.Click += (sender, e) => new ApplicationVariables().ShowDialog(this);
var folder = $"{Functions.dataFolder}DiscordBotCore.data";
Directory.CreateDirectory(Functions.dataFolder);
try
{
var botToken = Config.GetValue<string>("token");
var botPrefix = Config.GetValue<string>("prefix");
if (botToken == null || botPrefix == null)
{
textBox1.IsReadOnly = false;
textBox2.IsReadOnly = false;
textBox1.Watermark = "Insert Bot Token Here";
textBox2.Watermark = "Insert Bot Prefix Here";
textBox1.Watermark = "Insert Bot Token Here";
textBox2.Watermark = "Insert Bot Prefix Here";
}
else
{
textBox1.Text = botToken;
textBox2.Text = botPrefix;
}
}
private void RunDiscordBot(string args)
catch
{
var os = Functions.GetOperatingSystem();
if (os == PluginManager.Others.OperatingSystem.WINDOWS)
Process.Start("./DiscordBot.exe", args);
else if (os == PluginManager.Others.OperatingSystem.LINUX)
Process.Start("./DiscordBot", args);
else if (os == PluginManager.Others.OperatingSystem.MAC_OS)
Process.Start("./DiscordBot.app/Contents/MacOS/DiscordBot", args);
Close();
return;
textBox1.IsReadOnly = false;
textBox2.IsReadOnly = false;
textBox1.Watermark = "Insert Bot Token Here";
textBox2.Watermark = "Insert Bot Prefix Here";
}
}
private void RunDiscordBot(string args)
{
var os = Functions.GetOperatingSystem();
if (os == OperatingSystem.WINDOWS)
Process.Start("./DiscordBot.exe", args);
else if (os == OperatingSystem.LINUX)
Process.Start("./DiscordBot", args);
else if (os == OperatingSystem.MAC_OS) Process.Start("./DiscordBot.app/Contents/MacOS/DiscordBot", args);
Close();
}
}

View File

@@ -1,29 +1,25 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using System;
using System.IO;
using System.Threading.Tasks;
using Avalonia;
namespace DiscordBotGUI
namespace DiscordBotGUI;
internal class Program
{
internal class Program
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args)
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args)
{
BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
}
BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
}
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace();
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
{
return AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace();
}
}

View File

@@ -5,19 +5,19 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="DiscordBotGUI.Settings.ApplicationVariables"
Title="ApplicationVariables">
<StackPanel>
<Label Content="Available commands"/>
<TextBox x:Name="textBox1" x:Class="DiscordBotGUI.Settings.ApplicationVariables"/>
<Label Content="Insert a new variable"/>
<Border Background="White" BorderThickness="3" Margin="10"/>
<Label Content="New Variable Name"/>
<TextBox x:Name="textBox2" x:Class="DiscordBotGUI.Settings.ApplicationVariables"/>
<Label Content="New Variable Value"/>
<TextBox x:Name="textBox3" x:Class="DiscordBotGUI.Settings.ApplicationVariables"/>
<Label Content="New Variable IsReadOnly"/>
<CheckBox x:Class="DiscordBotGUI.Settings.ApplicationVariables" x:Name="checkBox1"/>
<Button Content="Add command" x:Class="DiscordBotGUI.Settings.ApplicationVariables" x:Name="button1"/>
</StackPanel>
<StackPanel>
<Label Content="Available commands" />
<TextBox x:Name="textBox1" x:Class="DiscordBotGUI.Settings.ApplicationVariables" />
<Label Content="Insert a new variable" />
<Border Background="White" BorderThickness="3" Margin="10" />
<Label Content="New Variable Name" />
<TextBox x:Name="textBox2" x:Class="DiscordBotGUI.Settings.ApplicationVariables" />
<Label Content="New Variable Value" />
<TextBox x:Name="textBox3" x:Class="DiscordBotGUI.Settings.ApplicationVariables" />
<Label Content="New Variable IsReadOnly" />
<CheckBox x:Class="DiscordBotGUI.Settings.ApplicationVariables" x:Name="checkBox1" />
<Button Content="Add command" x:Class="DiscordBotGUI.Settings.ApplicationVariables" x:Name="button1" />
</StackPanel>
</Window>
</Window>

View File

@@ -1,44 +1,41 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using PluginManager;
namespace DiscordBotGUI.Settings
namespace DiscordBotGUI.Settings;
public partial class ApplicationVariables : Window
{
public partial class ApplicationVariables : Window
public ApplicationVariables()
{
public ApplicationVariables()
{
InitializeComponent();
Load();
}
InitializeComponent();
Load();
}
private void Load()
private void Load()
{
ClearEverything();
button1.Click += (sedner, e) =>
{
ClearEverything();
button1.Click += (sedner, e) =>
var key = textBox2.Text;
if (Config.ContainsKey(key))
{
string key = textBox2.Text;
if (Config.ContainsKey(key))
{
ClearEverything();
return;
}
string value = textBox3.Text;
Config.AddValueToVariables(key, value, checkBox1.IsChecked!.Value);
ClearEverything();
};
}
return;
}
private void ClearEverything()
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
checkBox1.IsChecked = false;
var allvars = Config.GetAllVariables();
foreach (var kvp in allvars) textBox1.Text += kvp.Key + " => " + kvp.Value + "\n";
}
var value = textBox3.Text;
Config.AddValueToVariables(key, value, checkBox1.IsChecked!.Value);
ClearEverything();
};
}
private void ClearEverything()
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
checkBox1.IsChecked = false;
var allvars = Config.GetAllVariables();
foreach (var kvp in allvars) textBox1.Text += kvp.Key + " => " + kvp.Value + "\n";
}
}

View File

@@ -5,17 +5,20 @@
mc:Ignorable="d" d:DesignWidth="550" d:DesignHeight="200"
x:Class="DiscordBotGUI.Settings.Commands"
Title="Commands"
Background="Transparent"
TransparencyLevelHint="AcrylicBlur"
ExtendClientAreaToDecorationsHint="True">
<StackPanel x:Class="DiscordBotGUI.Settings.Commands" x:Name="stackpanel1" Margin="10">
<Label Content="Installed Commands" />
<TextBox x:Class="DiscordBotGUI.Settings.Commands" x:Name="textbox1" TextAlignment="Left" IsReadOnly="True" />
<Label Content="Install another command" />
<ComboBox x:Class="DiscordBotGUI.Settings.Commands" x:Name="comboBox1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,10" Padding="200,0" />
<Button x:Class="DiscordBotGUI.Settings.Commands" x:Name="button1" HorizontalAlignment="Left" Content="Install" />
<ProgressBar x:Class="DiscordBotGUI.Settings.Commands" x:Name="progressBar1" HorizontalAlignment="Left" Margin="0,10" Foreground="Yellow" />
<Label x:Class="DiscordBotGUI.Settings.Commands" x:Name="label1" Content="" HorizontalAlignment="Left" Margin="0,10" />
</StackPanel>
Background="Transparent"
TransparencyLevelHint="AcrylicBlur"
ExtendClientAreaToDecorationsHint="True">
<StackPanel x:Class="DiscordBotGUI.Settings.Commands" x:Name="stackpanel1" Margin="10">
<Label Content="Installed Commands" />
<TextBox x:Class="DiscordBotGUI.Settings.Commands" x:Name="textbox1" TextAlignment="Left" IsReadOnly="True" />
<Label Content="Install another command" />
<ComboBox x:Class="DiscordBotGUI.Settings.Commands" x:Name="comboBox1" HorizontalAlignment="Left"
VerticalAlignment="Top" Margin="0,10" Padding="200,0" />
<Button x:Class="DiscordBotGUI.Settings.Commands" x:Name="button1" HorizontalAlignment="Left" Content="Install" />
<ProgressBar x:Class="DiscordBotGUI.Settings.Commands" x:Name="progressBar1" HorizontalAlignment="Left"
Margin="0,10" Foreground="Yellow" />
<Label x:Class="DiscordBotGUI.Settings.Commands" x:Name="label1" Content="" HorizontalAlignment="Left"
Margin="0,10" />
</StackPanel>
</Window>
</Window>

View File

@@ -1,95 +1,93 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using PluginManager.Others;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Avalonia.Controls;
using PluginManager.Online;
using PluginManager.Others;
using OperatingSystem = PluginManager.Others.OperatingSystem;
namespace DiscordBotGUI.Settings
namespace DiscordBotGUI.Settings;
public partial class Commands : Window
{
public partial class Commands : Window
private List<string> commands = new();
public Commands()
{
List<string> commands = new List<string>();
public Commands()
{
InitializeComponent();
LoadData();
LoadComboBox();
InitializeComponent();
LoadData();
LoadComboBox();
button1.Click += async (sender, e) =>
{
await Download();
};
button1.Click += async (sender, e) => { await Download(); };
}
private void LoadData()
{
try
{
textbox1.Text = "";
Directory.CreateDirectory("./Data/Plugins/Commands/");
var files = Directory.EnumerateFiles("./Data/Plugins/Commands/");
if (files == null || files.Count() < 1) return;
foreach (var file in files) textbox1.Text += file.Split('/')[file.Split('/').Length - 1] + "\n";
}
private void LoadData()
catch
{
}
}
private async void LoadComboBox()
{
comboBox1.Items = null;
commands = await ServerCom.ReadTextFromFile("https://sethdiscordbot.000webhostapp.com/Storage/Discord%20Bot/Plugins");
if (commands == null) return;
var plugins = commands.ToArray();
string OS;
var OSG = Functions.GetOperatingSystem();
if (OSG == OperatingSystem.WINDOWS)
OS = "Windows";
else if (OSG == OperatingSystem.LINUX)
OS = "Linux";
else
OS = "MAC_OS";
var data = new List<string>();
for (var i = 0; i < plugins.Length; i++)
{
if (!plugins[i].Contains(OS) || !plugins[i].Contains("Commands")) continue;
var info = plugins[i].Split(',');
try
{
textbox1.Text = "";
Directory.CreateDirectory("./Data/Plugins/Commands/");
var files = System.IO.Directory.EnumerateFiles("./Data/Plugins/Commands/");
if (files == null || files.Count() < 1) return;
foreach (var file in files)
textbox1.Text += file.Split('/')[file.Split('/').Length - 1] + "\n";
if (Directory.EnumerateFiles("./Data/Plugins/Commands/").Any(x => x.EndsWith(info[0] + ".dll"))) continue;
}
catch { }
}
private async void LoadComboBox()
{
comboBox1.Items = null;
commands = await PluginManager.Online.ServerCom.ReadTextFromFile("https://sethdiscordbot.000webhostapp.com/Storage/Discord%20Bot/Plugins");
if (commands == null) return;
string[] plugins = commands.ToArray();
string OS;
var OSG = Functions.GetOperatingSystem();
if (OSG == PluginManager.Others.OperatingSystem.WINDOWS) OS = "Windows";
else if (OSG == PluginManager.Others.OperatingSystem.LINUX) OS = "Linux";
else OS = "MAC_OS";
List<string> data = new List<string>();
for (int i = 0; i < plugins.Length; i++)
catch
{
if (!plugins[i].Contains(OS) || !plugins[i].Contains("Commands"))
continue;
string[] info = plugins[i].Split(',');
try
{
if (System.IO.Directory.EnumerateFiles("./Data/Plugins/Commands/").Any(x => x.EndsWith(info[0] + ".dll")))
continue;
}
catch { }
data.Add($"{info[0]} - {info[1]} - {info[2]}");
}
comboBox1.Items = data;
data.Add($"{info[0]} - {info[1]} - {info[2]}");
}
private async Task Download()
{
if (comboBox1 == null || comboBox1.SelectedIndex == -1 || comboBox1.SelectedItem == null)
return;
string? pluginName = comboBox1?.SelectedItem?.ToString()?.Split('-')[0].Trim();
if (pluginName == null) return;
string? URL = (from s in commands
where s.StartsWith(pluginName)
select s.Split(',')[3].Trim()).FirstOrDefault();
if (URL == null) return;
comboBox1.Items = data;
}
IProgress<float> progress = new Progress<float>(async value =>
private async Task Download()
{
if (comboBox1 == null || comboBox1.SelectedIndex == -1 || comboBox1.SelectedItem == null) return;
var pluginName = comboBox1?.SelectedItem?.ToString()?.Split('-')[0].Trim();
if (pluginName == null) return;
var URL = (from s in commands
where s.StartsWith(pluginName)
select s.Split(',')[3].Trim()).FirstOrDefault();
if (URL == null) return;
IProgress<float> progress = new Progress<float>(async value =>
{
label1.Content = $"Downloading {pluginName} {MathF.Round(value, 2)}%";
if (value == 1f)
@@ -101,38 +99,38 @@ namespace DiscordBotGUI.Settings
await Task.Delay(5000);
label1.Content = "";
}
progressBar1.Value = value;
});
await PluginManager.Online.ServerCom.DownloadFileAsync(URL, "./Data/Plugins/Commands/" + pluginName + ".dll", progress);
string? requirements = (from s in commands
where s.StartsWith(pluginName) && s.Split(',').Length == 6
select s.Split(',')[5].Trim()).FirstOrDefault();
if (requirements == null) return;
List<string> req = await PluginManager.Online.ServerCom.ReadTextFromFile(requirements);
if (req == null) return;
foreach (var requirement in req)
{
string[] info = requirement.Split(',');
pluginName = info[1];
progress.Report(0);
await PluginManager.Online.ServerCom.DownloadFileAsync(info[0], $"./{info[1]}", progress);
await Task.Delay(1000);
if (info[0].EndsWith(".zip"))
{
await Functions.ExtractArchive("./" + info[1], "./", progress);
await Task.Delay(1000);
}
}
);
progress.Report(100f);
label1.Content = "Downloaded";
progressBar1.Value = 100;
await ServerCom.DownloadFileAsync(URL, "./Data/Plugins/Commands/" + pluginName + ".dll", progress);
var requirements = (from s in commands
where s.StartsWith(pluginName) && s.Split(',').Length == 6
select s.Split(',')[5].Trim()).FirstOrDefault();
if (requirements == null) return;
var req = await ServerCom.ReadTextFromFile(requirements);
if (req == null) return;
foreach (var requirement in req)
{
var info = requirement.Split(',');
pluginName = info[1];
progress.Report(0);
await ServerCom.DownloadFileAsync(info[0], $"./{info[1]}", progress);
await Task.Delay(1000);
if (info[0].EndsWith(".zip"))
{
await Functions.ExtractArchive("./" + info[1], "./", progress);
await Task.Delay(1000);
}
}
progress.Report(100f);
label1.Content = "Downloaded";
progressBar1.Value = 100;
}
}

View File

@@ -5,16 +5,19 @@
mc:Ignorable="d" d:DesignWidth="550" d:DesignHeight="200"
x:Class="DiscordBotGUI.Settings.Events"
Title="Events"
Background="Transparent"
TransparencyLevelHint="AcrylicBlur"
ExtendClientAreaToDecorationsHint="True">
<StackPanel Margin="10">
<Label Content="Installed Events" />
<TextBox x:Class="DiscordBotGUI.Settings.Events" x:Name="textbox1" TextAlignment="Left" IsReadOnly="True" />
<Label Content="Install another Events" />
<ComboBox x:Class="DiscordBotGUI.Settings.Events" x:Name="comboBox1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,10" Padding="200,0" />
<Button x:Class="DiscordBotGUI.Settings.Events" x:Name="button1" HorizontalAlignment="Left" Content="Install" />
<ProgressBar x:Class="DiscordBotGUI.Settings.Events" x:Name="progressBar1" HorizontalAlignment="Left" Margin="0,10" Foreground="Yellow" />
<Label x:Class="DiscordBotGUI.Settings.Events" x:Name="label1" Content="" HorizontalAlignment="Left" Margin="0,10" />
</StackPanel>
</Window>
Background="Transparent"
TransparencyLevelHint="AcrylicBlur"
ExtendClientAreaToDecorationsHint="True">
<StackPanel Margin="10">
<Label Content="Installed Events" />
<TextBox x:Class="DiscordBotGUI.Settings.Events" x:Name="textbox1" TextAlignment="Left" IsReadOnly="True" />
<Label Content="Install another Events" />
<ComboBox x:Class="DiscordBotGUI.Settings.Events" x:Name="comboBox1" HorizontalAlignment="Left"
VerticalAlignment="Top" Margin="0,10" Padding="200,0" />
<Button x:Class="DiscordBotGUI.Settings.Events" x:Name="button1" HorizontalAlignment="Left" Content="Install" />
<ProgressBar x:Class="DiscordBotGUI.Settings.Events" x:Name="progressBar1" HorizontalAlignment="Left"
Margin="0,10" Foreground="Yellow" />
<Label x:Class="DiscordBotGUI.Settings.Events" x:Name="label1" Content="" HorizontalAlignment="Left"
Margin="0,10" />
</StackPanel>
</Window>

View File

@@ -1,97 +1,94 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using PluginManager.Others;
using System.Collections.Generic;
using System;
using System.Linq;
using System.Reflection.Emit;
using System.Threading.Tasks;
using static PluginManager.Others.Console_Utilities;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Avalonia.Controls;
using PluginManager.Online;
using PluginManager.Others;
using OperatingSystem = PluginManager.Others.OperatingSystem;
namespace DiscordBotGUI.Settings
namespace DiscordBotGUI.Settings;
public partial class Events : Window
{
public partial class Events : Window
private List<string> events = new();
public Events()
{
List<string> events = new List<string>();
public Events()
{
InitializeComponent();
LoadData();
LoadComboBox();
button1.Click += async (sender, e) =>
{
await Download();
InitializeComponent();
LoadData();
LoadComboBox();
button1.Click += async (sender, e) => { await Download(); };
}
};
private void LoadData()
{
//Read components from Commands Folder:
//textbox1 = new TextBox();
try
{
Directory.CreateDirectory("./Data/Plugins/Events/");
textbox1.IsReadOnly = false;
textbox1.Text = "";
var files = Directory.EnumerateFiles("./Data/Plugins/Events/");
if (files == null || files.Count() < 1) return;
foreach (var file in files) textbox1.Text += file.Split('/')[file.Split('/').Length - 1] + "\n";
}
private void LoadData()
catch
{
//Read components from Commands Folder:
//textbox1 = new TextBox();
}
}
private async void LoadComboBox()
{
comboBox1.Items = null;
events = await ServerCom.ReadTextFromFile("https://sethdiscordbot.000webhostapp.com/Storage/Discord%20Bot/Plugins");
if (events == null) return;
var plugins = events.ToArray();
string OS;
var OSG = Functions.GetOperatingSystem();
if (OSG == OperatingSystem.WINDOWS)
OS = "Windows";
else if (OSG == OperatingSystem.LINUX)
OS = "Linux";
else
OS = "MAC_OS";
var data = new List<string>();
for (var i = 0; i < plugins.Length; i++)
{
if (!plugins[i].Contains(OS) || !plugins[i].Contains("Event")) continue;
var info = plugins[i].Split(',');
try
{
Directory.CreateDirectory("./Data/Plugins/Events/");
textbox1.IsReadOnly = false;
textbox1.Text = "";
var files = System.IO.Directory.EnumerateFiles("./Data/Plugins/Events/");
if (files == null || files.Count() < 1) return;
foreach (var file in files)
textbox1.Text += file.Split('/')[file.Split('/').Length - 1] + "\n";
if (Directory.EnumerateFiles("./Data/Plugins/Events/").Any(x => x.EndsWith(info[0] + ".dll"))) continue;
}
catch { }
}
private async void LoadComboBox()
{
comboBox1.Items = null;
events = await PluginManager.Online.ServerCom.ReadTextFromFile("https://sethdiscordbot.000webhostapp.com/Storage/Discord%20Bot/Plugins");
if (events == null) return;
string[] plugins = events.ToArray();
string OS;
var OSG = Functions.GetOperatingSystem();
if (OSG == PluginManager.Others.OperatingSystem.WINDOWS) OS = "Windows";
else if (OSG == PluginManager.Others.OperatingSystem.LINUX) OS = "Linux";
else OS = "MAC_OS";
List<string> data = new List<string>();
for (int i = 0; i < plugins.Length; i++)
catch
{
if (!plugins[i].Contains(OS) || !plugins[i].Contains("Event"))
continue;
string[] info = plugins[i].Split(',');
try
{
if (System.IO.Directory.EnumerateFiles("./Data/Plugins/Events/").Any(x => x.EndsWith(info[0] + ".dll")))
continue;
}
catch { }
data.Add($"{info[0]} - {info[1]} - {info[2]}");
}
comboBox1.Items = data;
data.Add($"{info[0]} - {info[1]} - {info[2]}");
}
private async Task Download()
{
if (comboBox1 == null || comboBox1.SelectedIndex == -1 || comboBox1.SelectedItem == null)
return;
string? pluginName = comboBox1?.SelectedItem?.ToString()?.Split('-')[0].Trim();
if (pluginName == null) return;
string? URL = (from s in events
where s.StartsWith(pluginName)
select s.Split(',')[3].Trim()).FirstOrDefault();
comboBox1.Items = data;
}
if (URL == null) return;
private async Task Download()
{
if (comboBox1 == null || comboBox1.SelectedIndex == -1 || comboBox1.SelectedItem == null) return;
var pluginName = comboBox1?.SelectedItem?.ToString()?.Split('-')[0].Trim();
if (pluginName == null) return;
var URL = (from s in events
where s.StartsWith(pluginName)
select s.Split(',')[3].Trim()).FirstOrDefault();
if (URL == null) return;
IProgress<float> progress = new Progress<float>(async value =>
IProgress<float> progress = new Progress<float>(async value =>
{
label1.Content = $"Downloading {pluginName} {MathF.Round(value, 2)}%";
if (value == 1f)
@@ -103,37 +100,36 @@ namespace DiscordBotGUI.Settings
await Task.Delay(5000);
label1.Content = "";
}
progressBar1.Value = value;
});
await PluginManager.Online.ServerCom.DownloadFileAsync(URL, "./Data/Plugins/Events/" + pluginName + ".dll", progress);
string? requirements = (from s in events
where s.StartsWith(pluginName) && s.Split(',').Length == 6
select s.Split(',')[5].Trim()).FirstOrDefault();
if (requirements == null) return;
List<string> req = await PluginManager.Online.ServerCom.ReadTextFromFile(requirements);
if (req == null) return;
foreach (var requirement in req)
{
string[] info = requirement.Split(',');
pluginName = info[1];
progress.Report(0);
await PluginManager.Online.ServerCom.DownloadFileAsync(info[0], $"./{info[1]}", progress);
await Task.Delay(1000);
if (info[0].EndsWith(".zip"))
{
await Functions.ExtractArchive("./" + info[1], "./", progress);
await Task.Delay(1000);
}
}
);
label1.Content = "";
await ServerCom.DownloadFileAsync(URL, "./Data/Plugins/Events/" + pluginName + ".dll", progress);
var requirements = (from s in events
where s.StartsWith(pluginName) && s.Split(',').Length == 6
select s.Split(',')[5].Trim()).FirstOrDefault();
if (requirements == null) return;
var req = await ServerCom.ReadTextFromFile(requirements);
if (req == null) return;
foreach (var requirement in req)
{
var info = requirement.Split(',');
pluginName = info[1];
progress.Report(0);
await ServerCom.DownloadFileAsync(info[0], $"./{info[1]}", progress);
await Task.Delay(1000);
if (info[0].EndsWith(".zip"))
{
await Functions.ExtractArchive("./" + info[1], "./", progress);
await Task.Delay(1000);
}
}
label1.Content = "";
}
}