patch
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -1,48 +1,42 @@
|
|||||||
using System;
|
using Discord;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Discord;
|
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
using PluginManager;
|
using PluginManager;
|
||||||
using PluginManager.Interfaces;
|
using PluginManager.Interfaces;
|
||||||
using PluginManager.Others;
|
using PluginManager.Others;
|
||||||
|
|
||||||
namespace CMD_LevelingSystem
|
namespace CMD_LevelingSystem;
|
||||||
|
|
||||||
|
internal class Level : DBCommand
|
||||||
{
|
{
|
||||||
internal class Level : DBCommand
|
public string Command => "level";
|
||||||
|
|
||||||
|
public string Description => "Display tour current level";
|
||||||
|
|
||||||
|
public string Usage => "level";
|
||||||
|
|
||||||
|
public bool canUseDM => false;
|
||||||
|
|
||||||
|
public bool canUseServer => true;
|
||||||
|
|
||||||
|
public bool requireAdmin => false;
|
||||||
|
|
||||||
|
public async void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
||||||
{
|
{
|
||||||
public string Command => "level";
|
var user = await Functions.ConvertFromJson<User>(Config.GetValue<string>("LevelingSystemPath") + $"/{message.Author.Id}.dat");
|
||||||
|
if (user == null)
|
||||||
public string Description => "Display tour current level";
|
|
||||||
|
|
||||||
public string Usage => "level";
|
|
||||||
|
|
||||||
public bool canUseDM => false;
|
|
||||||
|
|
||||||
public bool canUseServer => true;
|
|
||||||
|
|
||||||
public bool requireAdmin => false;
|
|
||||||
|
|
||||||
public async void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
|
||||||
{
|
{
|
||||||
User user = await Functions.ConvertFromJson<User>(Config.GetValue("LevelingSystemPath") + $"/{message.Author.Id}.dat");
|
await context.Channel.SendMessageAsync("You are now unranked !");
|
||||||
if (user == null)
|
return;
|
||||||
{
|
|
||||||
await context.Channel.SendMessageAsync("You are now unranked !");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var builder = new EmbedBuilder();
|
|
||||||
Random r = new Random();
|
|
||||||
builder.WithColor(r.Next(256), r.Next(256), r.Next(256));
|
|
||||||
builder.AddField("Current Level", user.CurrentLevel, true)
|
|
||||||
.AddField("Current EXP", user.CurrentEXP, true)
|
|
||||||
.AddField("Required Exp", user.RequiredEXPToLevelUp, true);
|
|
||||||
builder.WithTimestamp(DateTimeOffset.Now);
|
|
||||||
await context.Channel.SendMessageAsync(embed: builder.Build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var builder = new EmbedBuilder();
|
||||||
|
var r = new Random();
|
||||||
|
builder.WithColor(r.Next(256), r.Next(256), r.Next(256));
|
||||||
|
builder.AddField("Current Level", user.CurrentLevel, true)
|
||||||
|
.AddField("Current EXP", user.CurrentEXP, true)
|
||||||
|
.AddField("Required Exp", user.RequiredEXPToLevelUp, true);
|
||||||
|
builder.WithTimestamp(DateTimeOffset.Now);
|
||||||
|
await context.Channel.SendMessageAsync(embed: builder.Build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,9 @@
|
|||||||
using System;
|
namespace CMD_LevelingSystem;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace CMD_LevelingSystem
|
public class User
|
||||||
{
|
{
|
||||||
public class User
|
public string userID { get; set; }
|
||||||
{
|
public int CurrentLevel { get; set; }
|
||||||
public string userID { get; set; }
|
public long CurrentEXP { get; set; }
|
||||||
public int CurrentLevel { get; set; }
|
public long RequiredEXPToLevelUp { get; set; }
|
||||||
public Int64 CurrentEXP { get; set; }
|
|
||||||
public Int64 RequiredEXPToLevelUp { get; set; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
|
||||||
using PluginManager.Interfaces;
|
using PluginManager.Interfaces;
|
||||||
|
|
||||||
internal class Echo : DBCommand
|
internal class Echo : DBCommand
|
||||||
@@ -11,14 +10,14 @@ internal class Echo : DBCommand
|
|||||||
|
|
||||||
public string Usage => "echo [message]";
|
public string Usage => "echo [message]";
|
||||||
|
|
||||||
public bool canUseDM => true;
|
public bool canUseDM => true;
|
||||||
public bool canUseServer => true;
|
public bool canUseServer => true;
|
||||||
|
|
||||||
public bool requireAdmin => false;
|
public bool requireAdmin => false;
|
||||||
|
|
||||||
public async void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
public async void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
||||||
{
|
{
|
||||||
string m = message.Content.Substring(6);
|
var m = message.Content.Substring(6);
|
||||||
await message.Channel.SendMessageAsync(m);
|
await message.Channel.SendMessageAsync(m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +1,30 @@
|
|||||||
using System;
|
using Discord.Commands;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
using Discord.Commands;
|
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
|
||||||
using PluginManager.Interfaces;
|
using PluginManager.Interfaces;
|
||||||
|
|
||||||
namespace CMD_Utils
|
namespace CMD_Utils;
|
||||||
|
|
||||||
|
internal class FlipCoin : DBCommand
|
||||||
{
|
{
|
||||||
class FlipCoin : DBCommand
|
public string Command => "flip";
|
||||||
|
|
||||||
|
public string Description => "Flip a coin";
|
||||||
|
|
||||||
|
public string Usage => "flip";
|
||||||
|
|
||||||
|
public bool canUseDM => true;
|
||||||
|
|
||||||
|
public bool canUseServer => true;
|
||||||
|
|
||||||
|
public bool requireAdmin => false;
|
||||||
|
|
||||||
|
public async void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
||||||
{
|
{
|
||||||
public string Command => "flip";
|
var random = new System.Random();
|
||||||
|
var r = random.Next(1, 3);
|
||||||
public string Description => "Flip a coin";
|
if (r == 1)
|
||||||
|
await message.Channel.SendMessageAsync("Heads");
|
||||||
public string Usage => "flip";
|
else
|
||||||
|
await message.Channel.SendMessageAsync("Tails");
|
||||||
public bool canUseDM => true;
|
|
||||||
|
|
||||||
public bool canUseServer => true;
|
|
||||||
|
|
||||||
public bool requireAdmin => false;
|
|
||||||
|
|
||||||
public async void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
|
||||||
{
|
|
||||||
System.Random random = new System.Random();
|
|
||||||
int r = random.Next(1, 3);
|
|
||||||
if (r == 1)
|
|
||||||
await message.Channel.SendMessageAsync("Heads");
|
|
||||||
else await message.Channel.SendMessageAsync("Tails");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,53 +1,45 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
|
||||||
using PluginManager.Interfaces;
|
using PluginManager.Interfaces;
|
||||||
|
using PluginManager.Others;
|
||||||
|
|
||||||
namespace CMD_Utils
|
namespace CMD_Utils;
|
||||||
|
|
||||||
|
public class Poll : DBCommand
|
||||||
{
|
{
|
||||||
public class Poll : DBCommand
|
public string Command => "poll";
|
||||||
|
|
||||||
|
public string Description => "Create a poll with options";
|
||||||
|
|
||||||
|
public string Usage => "poll [This-is-question] [This-is-answer-1] [This-is-answer-2] ... ";
|
||||||
|
|
||||||
|
public bool canUseDM => false;
|
||||||
|
|
||||||
|
public bool canUseServer => true;
|
||||||
|
|
||||||
|
public bool requireAdmin => true;
|
||||||
|
|
||||||
|
public async void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
||||||
{
|
{
|
||||||
public string Command => "poll";
|
if (isDM) return;
|
||||||
|
var question = message.Content.Split(' ')[1].Replace('-', ' ');
|
||||||
|
var answers = Functions.MergeStrings(message.Content.Split(' '), 2).Split(' ');
|
||||||
|
var embedBuilder = new EmbedBuilder();
|
||||||
|
embedBuilder.Title = question;
|
||||||
|
var len = answers.Length;
|
||||||
|
for (var i = 0; i < len; i++) embedBuilder.AddField($"Answer {i + 1}", answers[i].Replace('-', ' '), true);
|
||||||
|
var msg = await context.Channel.SendMessageAsync(embed: embedBuilder.Build());
|
||||||
|
|
||||||
public string Description => "Create a poll with options";
|
var emotes = new List<IEmote>();
|
||||||
|
emotes.Add(Emoji.Parse(":one:"));
|
||||||
|
emotes.Add(Emoji.Parse(":two:"));
|
||||||
|
emotes.Add(Emoji.Parse(":three:"));
|
||||||
|
emotes.Add(Emoji.Parse(":four:"));
|
||||||
|
emotes.Add(Emoji.Parse(":five:"));
|
||||||
|
emotes.Add(Emoji.Parse(":six:"));
|
||||||
|
|
||||||
public string Usage => "poll [This-is-question] [This-is-answer-1] [This-is-answer-2] ... ";
|
for (var i = 0; i < len; i++) await msg.AddReactionAsync(emotes[i]);
|
||||||
|
|
||||||
public bool canUseDM => false;
|
|
||||||
|
|
||||||
public bool canUseServer => true;
|
|
||||||
|
|
||||||
public bool requireAdmin => true;
|
|
||||||
|
|
||||||
public async void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
|
||||||
{
|
|
||||||
if (isDM) return;
|
|
||||||
string question = message.Content.Split(' ')[1].Replace('-', ' ');
|
|
||||||
string[] answers = PluginManager.Others.Functions.MergeStrings(message.Content.Split(' '), 2).Split(' ');
|
|
||||||
EmbedBuilder embedBuilder = new EmbedBuilder();
|
|
||||||
embedBuilder.Title = question;
|
|
||||||
int len = answers.Length;
|
|
||||||
for (int i = 0; i < len; i++)
|
|
||||||
embedBuilder.AddField($"Answer {i + 1}", answers[i].Replace('-', ' '), true);
|
|
||||||
var msg = await context.Channel.SendMessageAsync(embed: embedBuilder.Build());
|
|
||||||
|
|
||||||
List<IEmote> emotes = new List<IEmote>();
|
|
||||||
emotes.Add(Emoji.Parse(":one:"));
|
|
||||||
emotes.Add(Emoji.Parse(":two:"));
|
|
||||||
emotes.Add(Emoji.Parse(":three:"));
|
|
||||||
emotes.Add(Emoji.Parse(":four:"));
|
|
||||||
emotes.Add(Emoji.Parse(":five:"));
|
|
||||||
emotes.Add(Emoji.Parse(":six:"));
|
|
||||||
|
|
||||||
for (int i = 0; i < len; i++)
|
|
||||||
await msg.AddReactionAsync(emotes[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
|
||||||
using PluginManager.Interfaces;
|
using PluginManager.Interfaces;
|
||||||
|
|
||||||
public class Random : DBCommand
|
public class Random : DBCommand
|
||||||
@@ -11,7 +10,7 @@ public class Random : DBCommand
|
|||||||
|
|
||||||
public string Usage => "random [number1] [number2]";
|
public string Usage => "random [number1] [number2]";
|
||||||
|
|
||||||
public bool canUseDM => true;
|
public bool canUseDM => true;
|
||||||
public bool canUseServer => true;
|
public bool canUseServer => true;
|
||||||
public bool requireAdmin => false;
|
public bool requireAdmin => false;
|
||||||
|
|
||||||
@@ -19,19 +18,18 @@ public class Random : DBCommand
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string msg = message.Content;
|
var msg = message.Content;
|
||||||
int a = int.Parse(msg.Split(' ')[1]);
|
var a = int.Parse(msg.Split(' ')[1]);
|
||||||
int b = int.Parse(msg.Split(' ')[2]);
|
var b = int.Parse(msg.Split(' ')[2]);
|
||||||
|
|
||||||
if (a > b)
|
if (a > b)
|
||||||
{
|
{
|
||||||
int x = a;
|
var x = a;
|
||||||
a = b;
|
a = b;
|
||||||
b = x;
|
b = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
await message.Channel.SendMessageAsync("Your random generated number is " + new System.Random().Next(a, b));
|
await message.Channel.SendMessageAsync("Your random generated number is " + new System.Random().Next(a, b));
|
||||||
|
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
<dependentAssembly>
|
<dependentAssembly>
|
||||||
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
|
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="4.0.0.0"/>
|
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="4.0.0.0" />
|
||||||
</dependentAssembly>
|
</dependentAssembly>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,106 +1,100 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
|
||||||
using PluginManager.Loaders;
|
|
||||||
using PluginManager.Interfaces;
|
using PluginManager.Interfaces;
|
||||||
using PluginManager.Others.Permissions;
|
using PluginManager.Loaders;
|
||||||
using PluginManager.Others;
|
using PluginManager.Others;
|
||||||
|
|
||||||
using System.Collections.Generic;
|
namespace DiscordBot.Discord.Commands;
|
||||||
|
|
||||||
namespace DiscordBot.Discord.Commands
|
/// <summary>
|
||||||
|
/// The help command
|
||||||
|
/// </summary>
|
||||||
|
internal class Help : DBCommand
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The help command
|
/// Command name
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class Help : DBCommand
|
public string Command => "help";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Command Description
|
||||||
|
/// </summary>
|
||||||
|
public string Description => "This command allows you to check all loadded commands";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Command usage
|
||||||
|
/// </summary>
|
||||||
|
public string Usage => "help";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if the command can be used <inheritdoca DM <see cref="IChannel" />/>
|
||||||
|
/// </summary>
|
||||||
|
public bool canUseDM => true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if the command can be used in a server
|
||||||
|
/// </summary>
|
||||||
|
public bool canUseServer => true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if the command require administrator to be executed
|
||||||
|
/// </summary>
|
||||||
|
public bool requireAdmin => false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The main body of the command
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context">The command context</param>
|
||||||
|
/// <param name="message">The command message</param>
|
||||||
|
/// <param name="client">The discord bot client</param>
|
||||||
|
/// <param name="isDM">True if the message was sent from a DM channel, false otherwise</param>
|
||||||
|
public void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
||||||
{
|
{
|
||||||
/// <summary>
|
var args = Functions.GetArguments(message);
|
||||||
/// Command name
|
if (args.Count != 0)
|
||||||
/// </summary>
|
|
||||||
public string Command => "help";
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Command Description
|
|
||||||
/// </summary>
|
|
||||||
public string Description => "This command allows you to check all loadded commands";
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Command usage
|
|
||||||
/// </summary>
|
|
||||||
public string Usage => "help";
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check if the command can be used <inheritdoca DM <see cref="IChannel"/>/>
|
|
||||||
/// </summary>
|
|
||||||
public bool canUseDM => true;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check if the command can be used in a server
|
|
||||||
/// </summary>
|
|
||||||
public bool canUseServer => true;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check if the command require administrator to be executed
|
|
||||||
/// </summary>
|
|
||||||
public bool requireAdmin => false;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The main body of the command
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context">The command context</param>
|
|
||||||
/// <param name="message">The command message</param>
|
|
||||||
/// <param name="client">The discord bot client</param>
|
|
||||||
/// <param name="isDM">True if the message was sent from a DM channel, false otherwise</param>
|
|
||||||
public void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
|
||||||
{
|
{
|
||||||
List<string> args = Functions.GetArguments(message);
|
foreach (var item in args)
|
||||||
if (args.Count != 0)
|
|
||||||
{
|
{
|
||||||
|
var e = GenerateHelpCommand(item);
|
||||||
foreach (var item in args)
|
if (e != null)
|
||||||
{
|
context.Channel.SendMessageAsync(embed: e.Build());
|
||||||
var e = GenerateHelpCommand(item);
|
else
|
||||||
if (e != null)
|
context.Channel.SendMessageAsync("Unknown Command " + item);
|
||||||
context.Channel.SendMessageAsync(embed: e.Build());
|
|
||||||
else
|
|
||||||
context.Channel.SendMessageAsync("Unknown Command " + item);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
EmbedBuilder embedBuilder = new EmbedBuilder();
|
|
||||||
|
|
||||||
string adminCommands = "";
|
|
||||||
string normalCommands = "";
|
|
||||||
string DMCommands = "";
|
|
||||||
|
|
||||||
foreach (var cmd in PluginLoader.Commands!)
|
|
||||||
{
|
|
||||||
if (cmd.canUseDM) DMCommands += cmd.Command + " ";
|
|
||||||
if (cmd.requireAdmin)
|
|
||||||
adminCommands += cmd.Command + " ";
|
|
||||||
else if (cmd.canUseServer) normalCommands += cmd.Command + " ";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
embedBuilder.AddField("Admin Commands", adminCommands);
|
return;
|
||||||
embedBuilder.AddField("Normal Commands", normalCommands);
|
|
||||||
embedBuilder.AddField("DM Commands", DMCommands);
|
|
||||||
context.Channel.SendMessageAsync(embed: embedBuilder.Build());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private EmbedBuilder GenerateHelpCommand(string command)
|
var embedBuilder = new EmbedBuilder();
|
||||||
|
|
||||||
|
var adminCommands = "";
|
||||||
|
var normalCommands = "";
|
||||||
|
var DMCommands = "";
|
||||||
|
|
||||||
|
foreach (var cmd in PluginLoader.Commands!)
|
||||||
{
|
{
|
||||||
EmbedBuilder embedBuilder = new EmbedBuilder();
|
if (cmd.canUseDM) DMCommands += cmd.Command + " ";
|
||||||
DBCommand cmd = PluginLoader.Commands.Find(p => p.Command == command);
|
if (cmd.requireAdmin)
|
||||||
if (cmd == null)
|
adminCommands += cmd.Command + " ";
|
||||||
return null;
|
else if (cmd.canUseServer) normalCommands += cmd.Command + " ";
|
||||||
|
|
||||||
embedBuilder.AddField("Usage", cmd.Usage);
|
|
||||||
embedBuilder.AddField("Description", cmd.Description);
|
|
||||||
|
|
||||||
return embedBuilder;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
embedBuilder.AddField("Admin Commands", adminCommands);
|
||||||
|
embedBuilder.AddField("Normal Commands", normalCommands);
|
||||||
|
embedBuilder.AddField("DM Commands", DMCommands);
|
||||||
|
context.Channel.SendMessageAsync(embed: embedBuilder.Build());
|
||||||
|
}
|
||||||
|
|
||||||
|
private EmbedBuilder GenerateHelpCommand(string command)
|
||||||
|
{
|
||||||
|
var embedBuilder = new EmbedBuilder();
|
||||||
|
var cmd = PluginLoader.Commands.Find(p => p.Command == command);
|
||||||
|
if (cmd == null) return null;
|
||||||
|
|
||||||
|
embedBuilder.AddField("Usage", cmd.Usage);
|
||||||
|
embedBuilder.AddField("Description", cmd.Description);
|
||||||
|
|
||||||
|
return embedBuilder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,114 +1,113 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
using PluginManager.Interfaces;
|
||||||
|
using PluginManager.Others;
|
||||||
|
using PluginManager.Others.Permissions;
|
||||||
using DiscordLibCommands = Discord.Commands;
|
using DiscordLibCommands = Discord.Commands;
|
||||||
using DiscordLib = Discord;
|
using DiscordLib = Discord;
|
||||||
|
using OperatingSystem = PluginManager.Others.OperatingSystem;
|
||||||
|
|
||||||
using PluginManager.Interfaces;
|
namespace DiscordBot.Discord.Commands;
|
||||||
using PluginManager.Others.Permissions;
|
|
||||||
using PluginManager.Others;
|
|
||||||
|
|
||||||
namespace DiscordBot.Discord.Commands
|
internal class Restart : DBCommand
|
||||||
{
|
{
|
||||||
internal class Restart : DBCommand
|
/// <summary>
|
||||||
|
/// Command name
|
||||||
|
/// </summary>
|
||||||
|
public string Command => "restart";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Command Description
|
||||||
|
/// </summary>
|
||||||
|
public string Description => "Restart the bot";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Command usage
|
||||||
|
/// </summary>
|
||||||
|
public string Usage => "restart [-p | -c | -args | -cmd] <args>";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if the command can be used <inheritdoca DM <see cref="IChannel" />/>
|
||||||
|
/// </summary>
|
||||||
|
public bool canUseDM => false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if the command can be used in a server
|
||||||
|
/// </summary>
|
||||||
|
public bool canUseServer => true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if the command require administrator to be executed
|
||||||
|
/// </summary>
|
||||||
|
public bool requireAdmin => false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The main body of the command
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context">The command context</param>
|
||||||
|
/// <param name="message">The command message</param>
|
||||||
|
/// <param name="client">The discord bot client</param>
|
||||||
|
/// <param name="isDM">True if the message was sent from a DM channel, false otherwise</param>
|
||||||
|
public async void Execute(DiscordLibCommands.SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
||||||
{
|
{
|
||||||
/// <summary>
|
if (!(message.Author as SocketGuildUser).hasPermission(DiscordLib.GuildPermission.Administrator)) return;
|
||||||
/// Command name
|
var args = Functions.GetArguments(message);
|
||||||
/// </summary>
|
var OS = Functions.GetOperatingSystem();
|
||||||
public string Command => "restart";
|
if (args.Count == 0)
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Command Description
|
|
||||||
/// </summary>
|
|
||||||
public string Description => "Restart the bot";
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Command usage
|
|
||||||
/// </summary>
|
|
||||||
public string Usage => "restart [-p | -c | -args | -cmd] <args>";
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check if the command can be used <inheritdoca DM <see cref="IChannel"/>/>
|
|
||||||
/// </summary>
|
|
||||||
public bool canUseDM => false;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check if the command can be used in a server
|
|
||||||
/// </summary>
|
|
||||||
public bool canUseServer => true;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check if the command require administrator to be executed
|
|
||||||
/// </summary>
|
|
||||||
public bool requireAdmin => false;
|
|
||||||
/// <summary>
|
|
||||||
/// The main body of the command
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context">The command context</param>
|
|
||||||
/// <param name="message">The command message</param>
|
|
||||||
/// <param name="client">The discord bot client</param>
|
|
||||||
/// <param name="isDM">True if the message was sent from a DM channel, false otherwise</param>
|
|
||||||
public async void Execute(DiscordLibCommands.SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
|
||||||
{
|
{
|
||||||
if (!DiscordPermissions.hasPermission(message.Author as SocketGuildUser, DiscordLib.GuildPermission.Administrator)) return;
|
switch (OS)
|
||||||
var args = Functions.GetArguments(message);
|
|
||||||
var OS = Functions.GetOperatingSystem();
|
|
||||||
if (args.Count == 0)
|
|
||||||
{
|
{
|
||||||
|
case OperatingSystem.WINDOWS:
|
||||||
|
Process.Start("./DiscordBot.exe");
|
||||||
|
break;
|
||||||
|
case OperatingSystem.LINUX:
|
||||||
|
case OperatingSystem.MAC_OS:
|
||||||
|
Process.Start("./DiscordBot");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (args[0])
|
||||||
|
{
|
||||||
|
case "-p":
|
||||||
|
case "-poweroff":
|
||||||
|
case "-c":
|
||||||
|
case "-close":
|
||||||
|
Environment.Exit(0);
|
||||||
|
break;
|
||||||
|
case "-cmd":
|
||||||
|
case "-args":
|
||||||
|
var cmd = "--args";
|
||||||
|
|
||||||
|
if (args.Count > 1)
|
||||||
|
for (var i = 1; i < args.Count; i++)
|
||||||
|
cmd += $" {args[i]}";
|
||||||
|
|
||||||
|
|
||||||
switch (OS)
|
switch (OS)
|
||||||
{
|
{
|
||||||
case PluginManager.Others.OperatingSystem.WINDOWS:
|
case OperatingSystem.WINDOWS:
|
||||||
Process.Start("./DiscordBot.exe");
|
Functions.WriteLogFile("Restarting the bot with the following arguments: \"" + cmd + "\"");
|
||||||
|
Process.Start("./DiscordBot.exe", cmd);
|
||||||
break;
|
break;
|
||||||
case PluginManager.Others.OperatingSystem.LINUX:
|
case OperatingSystem.LINUX:
|
||||||
case PluginManager.Others.OperatingSystem.MAC_OS:
|
//case PluginManager.Others.OperatingSystem.MAC_OS: ?? - not tested
|
||||||
Process.Start("./DiscordBot");
|
Process.Start("./DiscordBot", cmd);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
switch (args[0])
|
|
||||||
{
|
|
||||||
case "-p":
|
|
||||||
case "-poweroff":
|
|
||||||
case "-c":
|
|
||||||
case "-close":
|
|
||||||
Environment.Exit(0);
|
|
||||||
break;
|
|
||||||
case "-cmd":
|
|
||||||
case "-args":
|
|
||||||
string cmd = "--args";
|
|
||||||
|
|
||||||
if (args.Count > 1)
|
|
||||||
for (int i = 1; i < args.Count; i++)
|
|
||||||
cmd += $" {args[i]}";
|
|
||||||
|
|
||||||
|
|
||||||
switch (OS)
|
|
||||||
{
|
|
||||||
case PluginManager.Others.OperatingSystem.WINDOWS:
|
|
||||||
Functions.WriteLogFile("Restarting the bot with the following arguments: \"" + cmd + "\"");
|
|
||||||
Process.Start("./DiscordBot.exe", cmd);
|
|
||||||
break;
|
|
||||||
case PluginManager.Others.OperatingSystem.LINUX:
|
|
||||||
//case PluginManager.Others.OperatingSystem.MAC_OS: ?? - not tested
|
|
||||||
Process.Start("./DiscordBot", cmd);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Environment.Exit(0);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
await context.Channel.SendMessageAsync("Invalid argument. Use `help restart` to see the usage.");
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Environment.Exit(0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
await context.Channel.SendMessageAsync("Invalid argument. Use `help restart` to see the usage.");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,107 +1,97 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
using DiscordBot.Discord.Core;
|
|
||||||
using PluginManager;
|
using PluginManager;
|
||||||
using PluginManager.Interfaces;
|
using PluginManager.Interfaces;
|
||||||
using PluginManager.Others;
|
|
||||||
using PluginManager.Others.Permissions;
|
|
||||||
|
|
||||||
namespace DiscordBot.Discord.Commands
|
namespace DiscordBot.Discord.Commands;
|
||||||
|
|
||||||
|
internal class Settings : DBCommand
|
||||||
{
|
{
|
||||||
class Settings : DBCommand
|
/// <summary>
|
||||||
|
/// Command name
|
||||||
|
/// </summary>
|
||||||
|
public string Command => "set";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Command Description
|
||||||
|
/// </summary>
|
||||||
|
public string Description => "This command allows you change all settings. Use \"set help\" to show details";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Command usage
|
||||||
|
/// </summary>
|
||||||
|
public string Usage => "set [keyword] [new Value]";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if the command can be used <inheritdoca DM <see cref="IChannel" />/>
|
||||||
|
/// </summary>
|
||||||
|
public bool canUseDM => true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if the command can be used in a server
|
||||||
|
/// </summary>
|
||||||
|
public bool canUseServer => true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if the command require administrator to be executed
|
||||||
|
/// </summary>
|
||||||
|
public bool requireAdmin => true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The main body of the command
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context">The command context</param>
|
||||||
|
/// <param name="message">The command message</param>
|
||||||
|
/// <param name="client">The discord bot client</param>
|
||||||
|
/// <param name="isDM">True if the message was sent from a DM channel, false otherwise</param>
|
||||||
|
public async void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
||||||
{
|
{
|
||||||
|
var channel = message.Channel;
|
||||||
/// <summary>
|
try
|
||||||
/// Command name
|
|
||||||
/// </summary>
|
|
||||||
public string Command => "set";
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Command Description
|
|
||||||
/// </summary>
|
|
||||||
public string Description => "This command allows you change all settings. Use \"set help\" to show details";
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Command usage
|
|
||||||
/// </summary>
|
|
||||||
public string Usage => "set [keyword] [new Value]";
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check if the command can be used <inheritdoca DM <see cref="IChannel"/>/>
|
|
||||||
/// </summary>
|
|
||||||
public bool canUseDM => true;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check if the command can be used in a server
|
|
||||||
/// </summary>
|
|
||||||
public bool canUseServer => true;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check if the command require administrator to be executed
|
|
||||||
/// </summary>
|
|
||||||
public bool requireAdmin => true;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The main body of the command
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context">The command context</param>
|
|
||||||
/// <param name="message">The command message</param>
|
|
||||||
/// <param name="client">The discord bot client</param>
|
|
||||||
/// <param name="isDM">True if the message was sent from a DM channel, false otherwise</param>
|
|
||||||
public async void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
|
||||||
{
|
{
|
||||||
var channel = message.Channel;
|
var content = message.Content;
|
||||||
try
|
var data = content.Split(' ');
|
||||||
|
var keyword = data[1];
|
||||||
|
if (keyword.ToLower() == "help")
|
||||||
{
|
{
|
||||||
string content = message.Content;
|
await channel.SendMessageAsync("set token [new value] -- set the value of the new token (require restart)");
|
||||||
string[] data = content.Split(' ');
|
await channel.SendMessageAsync("set prefix [new value] -- set the value of the new preifx (require restart)");
|
||||||
string keyword = data[1];
|
|
||||||
if (keyword.ToLower() == "help")
|
|
||||||
{
|
|
||||||
await channel.SendMessageAsync("set token [new value] -- set the value of the new token (require restart)");
|
|
||||||
await channel.SendMessageAsync("set prefix [new value] -- set the value of the new preifx (require restart)");
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (keyword.ToLower())
|
switch (keyword.ToLower())
|
||||||
{
|
{
|
||||||
case "token":
|
case "token":
|
||||||
if (data.Length != 3)
|
if (data.Length != 3)
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("Invalid token !");
|
await channel.SendMessageAsync("Invalid token !");
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Config.SetValue("token", data[2]);
|
|
||||||
break;
|
|
||||||
case "prefix":
|
|
||||||
if (data.Length != 3)
|
|
||||||
{
|
|
||||||
await channel.SendMessageAsync("Invalid token !");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Config.SetValue("token", data[2]);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await channel.SendMessageAsync("Restart required ...");
|
Config.SetValue("token", data[2]);
|
||||||
}
|
break;
|
||||||
catch (Exception ex)
|
case "prefix":
|
||||||
{
|
if (data.Length != 3)
|
||||||
Console.WriteLine(ex.Message);
|
{
|
||||||
await channel.SendMessageAsync("Unknown usage to this command !\nUsage: " + Usage);
|
await channel.SendMessageAsync("Invalid token !");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Config.SetValue("token", data[2]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await channel.SendMessageAsync("Restart required ...");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
await channel.SendMessageAsync("Unknown usage to this command !\nUsage: " + Usage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,150 +1,149 @@
|
|||||||
using Discord;
|
using System;
|
||||||
using Discord.Commands;
|
|
||||||
using Discord.WebSocket;
|
|
||||||
using System;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Discord;
|
||||||
|
using Discord.Commands;
|
||||||
|
using Discord.WebSocket;
|
||||||
using PluginManager;
|
using PluginManager;
|
||||||
using static PluginManager.Others.Functions;
|
using static PluginManager.Others.Functions;
|
||||||
|
|
||||||
namespace DiscordBot.Discord.Core
|
namespace DiscordBot.Discord.Core;
|
||||||
|
|
||||||
|
internal class Boot
|
||||||
{
|
{
|
||||||
internal class Boot
|
/// <summary>
|
||||||
|
/// The bot prefix
|
||||||
|
/// </summary>
|
||||||
|
public readonly string botPrefix;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The bot token
|
||||||
|
/// </summary>
|
||||||
|
public readonly string botToken;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The bot client
|
||||||
|
/// </summary>
|
||||||
|
public DiscordSocketClient client;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The bot command handler
|
||||||
|
/// </summary>
|
||||||
|
private CommandHandler commandServiceHandler;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The command service
|
||||||
|
/// </summary>
|
||||||
|
private CommandService service;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The main Boot constructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="botToken">The bot token</param>
|
||||||
|
/// <param name="botPrefix">The bot prefix</param>
|
||||||
|
public Boot(string botToken, string botPrefix)
|
||||||
{
|
{
|
||||||
/// <summary>
|
this.botPrefix = botPrefix;
|
||||||
/// The bot prefix
|
this.botToken = botToken;
|
||||||
/// </summary>
|
}
|
||||||
public readonly string botPrefix;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The bot token
|
|
||||||
/// </summary>
|
|
||||||
public readonly string botToken;
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if the bot is ready
|
/// Checks if the bot is ready
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value> true if the bot is ready, othwerwise false </value>
|
/// <value> true if the bot is ready, othwerwise false </value>
|
||||||
public bool isReady { get; private set; } = false;
|
public bool isReady { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The bot client
|
/// The start method for the bot. This method is used to load the bot
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DiscordSocketClient client;
|
/// <returns>Task</returns>
|
||||||
|
public async Task Awake()
|
||||||
|
{
|
||||||
|
client = new DiscordSocketClient();
|
||||||
|
service = new CommandService();
|
||||||
|
|
||||||
/// <summary>
|
CommonTasks();
|
||||||
/// The bot command handler
|
|
||||||
/// </summary>
|
|
||||||
private CommandHandler commandServiceHandler;
|
|
||||||
|
|
||||||
/// <summary>
|
await client.LoginAsync(TokenType.Bot, botToken);
|
||||||
/// The command service
|
await client.StartAsync();
|
||||||
/// </summary>
|
|
||||||
private CommandService service;
|
|
||||||
|
|
||||||
/// <summary>
|
commandServiceHandler = new CommandHandler(client, service, botPrefix);
|
||||||
/// The main Boot constructor
|
await commandServiceHandler.InstallCommandsAsync();
|
||||||
/// </summary>
|
|
||||||
/// <param name="botToken">The bot token</param>
|
|
||||||
/// <param name="botPrefix">The bot prefix</param>
|
|
||||||
public Boot(string botToken, string botPrefix)
|
|
||||||
{
|
|
||||||
this.botPrefix = botPrefix;
|
|
||||||
this.botToken = botToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
await Task.Delay(2000);
|
||||||
/// The start method for the bot. This method is used to load the bot
|
while (!isReady) ;
|
||||||
/// </summary>
|
}
|
||||||
/// <returns>Task</returns>
|
|
||||||
public async Task Awake()
|
|
||||||
{
|
|
||||||
client = new DiscordSocketClient();
|
|
||||||
service = new CommandService();
|
|
||||||
|
|
||||||
CommonTasks();
|
private void CommonTasks()
|
||||||
|
{
|
||||||
|
if (client == null) return;
|
||||||
|
client.LoggedOut += Client_LoggedOut;
|
||||||
|
client.Log += Log;
|
||||||
|
client.LoggedIn += LoggedIn;
|
||||||
|
client.Ready += Ready;
|
||||||
|
}
|
||||||
|
|
||||||
await client.LoginAsync(TokenType.Bot, botToken);
|
private Task Client_LoggedOut()
|
||||||
await client.StartAsync();
|
{
|
||||||
|
WriteLogFile("Successfully Logged Out");
|
||||||
|
Log(new LogMessage(LogSeverity.Info, "Boot", "Successfully logged out from discord !"));
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
commandServiceHandler = new CommandHandler(client, service, botPrefix);
|
private Task Ready()
|
||||||
await commandServiceHandler.InstallCommandsAsync();
|
{
|
||||||
|
Console.Title = "ONLINE";
|
||||||
|
isReady = true;
|
||||||
|
|
||||||
await Task.Delay(2000);
|
new Thread(async () =>
|
||||||
while (!isReady) ;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CommonTasks()
|
|
||||||
{
|
|
||||||
if (client == null) return;
|
|
||||||
client.LoggedOut += Client_LoggedOut;
|
|
||||||
client.Log += Log;
|
|
||||||
client.LoggedIn += LoggedIn;
|
|
||||||
client.Ready += Ready;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Task Client_LoggedOut()
|
|
||||||
{
|
|
||||||
WriteLogFile("Successfully Logged Out");
|
|
||||||
Log(new LogMessage(LogSeverity.Info, "Boot", "Successfully logged out from discord !"));
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Task Ready()
|
|
||||||
{
|
|
||||||
Console.Title = "ONLINE";
|
|
||||||
isReady = true;
|
|
||||||
|
|
||||||
new Thread(async () =>
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
Config.SaveConfig();
|
|
||||||
Thread.Sleep(10000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
).Start();
|
|
||||||
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Task LoggedIn()
|
|
||||||
{
|
|
||||||
Console.Title = "CONNECTED";
|
|
||||||
WriteLogFile("The bot has been logged in at " + DateTime.Now.ToShortDateString() + " (" +
|
|
||||||
DateTime.Now.ToShortTimeString() + ")");
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Task Log(LogMessage message)
|
|
||||||
{
|
|
||||||
switch (message.Severity)
|
|
||||||
{
|
{
|
||||||
case LogSeverity.Error:
|
while (true)
|
||||||
case LogSeverity.Critical:
|
{
|
||||||
WriteErrFile(message.Message);
|
Config.SaveConfig();
|
||||||
|
Thread.Sleep(10000);
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
}
|
||||||
Console.WriteLine("[ERROR] " + message.Message);
|
|
||||||
Console.ForegroundColor = ConsoleColor.White;
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LogSeverity.Info:
|
|
||||||
case LogSeverity.Debug:
|
|
||||||
WriteLogFile(message.Message);
|
|
||||||
|
|
||||||
Console.ForegroundColor = ConsoleColor.Cyan;
|
|
||||||
Console.WriteLine("[INFO] " + message.Message);
|
|
||||||
Console.ForegroundColor = ConsoleColor.White;
|
|
||||||
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
).Start();
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task LoggedIn()
|
||||||
|
{
|
||||||
|
Console.Title = "CONNECTED";
|
||||||
|
WriteLogFile("The bot has been logged in at " + DateTime.Now.ToShortDateString() + " (" +
|
||||||
|
DateTime.Now.ToShortTimeString() + ")"
|
||||||
|
);
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task Log(LogMessage message)
|
||||||
|
{
|
||||||
|
switch (message.Severity)
|
||||||
|
{
|
||||||
|
case LogSeverity.Error:
|
||||||
|
case LogSeverity.Critical:
|
||||||
|
WriteErrFile(message.Message);
|
||||||
|
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Console.WriteLine("[ERROR] " + message.Message);
|
||||||
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LogSeverity.Info:
|
||||||
|
case LogSeverity.Debug:
|
||||||
|
WriteLogFile(message.Message);
|
||||||
|
|
||||||
|
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||||
|
Console.WriteLine("[INFO] " + message.Message);
|
||||||
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
|
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,136 +1,132 @@
|
|||||||
using Discord.Commands;
|
using System.Linq;
|
||||||
using Discord.WebSocket;
|
|
||||||
|
|
||||||
using PluginManager.Interfaces;
|
|
||||||
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Discord.Commands;
|
||||||
|
using Discord.WebSocket;
|
||||||
|
using PluginManager.Loaders;
|
||||||
using PluginManager.Others;
|
using PluginManager.Others;
|
||||||
using PluginManager.Others.Permissions;
|
using PluginManager.Others.Permissions;
|
||||||
using PluginManager.Loaders;
|
|
||||||
|
|
||||||
using System.Threading.Tasks;
|
namespace DiscordBot.Discord.Core;
|
||||||
using System.Linq;
|
|
||||||
using Discord;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace DiscordBot.Discord.Core
|
internal class CommandHandler
|
||||||
{
|
{
|
||||||
internal class CommandHandler
|
private readonly string botPrefix;
|
||||||
|
private readonly DiscordSocketClient client;
|
||||||
|
private readonly CommandService commandService;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Command handler constructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client">The discord bot client</param>
|
||||||
|
/// <param name="commandService">The discord bot command service</param>
|
||||||
|
/// <param name="botPrefix">The prefix to watch for</param>
|
||||||
|
public CommandHandler(DiscordSocketClient client, CommandService commandService, string botPrefix)
|
||||||
{
|
{
|
||||||
private readonly DiscordSocketClient client;
|
this.client = client;
|
||||||
private readonly CommandService commandService;
|
this.commandService = commandService;
|
||||||
private readonly string botPrefix;
|
this.botPrefix = botPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Command handler constructor
|
/// The method to initialize all commands
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="client">The discord bot client</param>
|
/// <returns></returns>
|
||||||
/// <param name="commandService">The discord bot command service</param>
|
public async Task InstallCommandsAsync()
|
||||||
/// <param name="botPrefix">The prefix to watch for</param>
|
{
|
||||||
public CommandHandler(DiscordSocketClient client, CommandService commandService, string botPrefix)
|
client.MessageReceived += MessageHandler;
|
||||||
{
|
await commandService.AddModulesAsync(Assembly.GetEntryAssembly(), null);
|
||||||
this.client = client;
|
}
|
||||||
this.commandService = commandService;
|
|
||||||
this.botPrefix = botPrefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The method to initialize all commands
|
/// The message handler for the bot
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <param name="Message">The message got from the user in discord chat</param>
|
||||||
public async Task InstallCommandsAsync()
|
/// <returns></returns>
|
||||||
|
private async Task MessageHandler(SocketMessage Message)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
client.MessageReceived += MessageHandler;
|
if (Message as SocketUserMessage == null) return;
|
||||||
await commandService.AddModulesAsync(assembly: Assembly.GetEntryAssembly(), services: null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
var message = Message as SocketUserMessage;
|
||||||
/// The message handler for the bot
|
|
||||||
/// </summary>
|
if (message == null) return;
|
||||||
/// <param name="Message">The message got from the user in discord chat</param>
|
|
||||||
/// <returns></returns>
|
if (!message.Content.StartsWith(botPrefix)) return;
|
||||||
private async Task MessageHandler(SocketMessage Message)
|
|
||||||
{
|
var argPos = 0;
|
||||||
try
|
|
||||||
|
if (message.HasMentionPrefix(client.CurrentUser, ref argPos))
|
||||||
{
|
{
|
||||||
if (Message as SocketUserMessage == null)
|
await message.Channel.SendMessageAsync("Can not exec mentioned commands !");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var message = Message as SocketUserMessage;
|
if (message.Author.IsBot) return;
|
||||||
|
|
||||||
if (message == null) return;
|
var context = new SocketCommandContext(client, message);
|
||||||
|
|
||||||
if (!message.Content.StartsWith(botPrefix)) return;
|
await commandService.ExecuteAsync(
|
||||||
|
context,
|
||||||
|
argPos,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
int argPos = 0;
|
var plugin = PluginLoader.Commands!.Where(p => p.Command == message.Content.Split(' ')[0].Substring(botPrefix.Length)).FirstOrDefault();
|
||||||
|
|
||||||
if (message.HasMentionPrefix(client.CurrentUser, ref argPos))
|
|
||||||
|
if (plugin != null)
|
||||||
|
{
|
||||||
|
if (message.Channel == await message.Author.CreateDMChannelAsync())
|
||||||
{
|
{
|
||||||
await message.Channel.SendMessageAsync("Can not exec mentioned commands !");
|
if (plugin.canUseDM)
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (message.Author.IsBot) return;
|
|
||||||
|
|
||||||
var context = new SocketCommandContext(client, message);
|
|
||||||
|
|
||||||
await commandService.ExecuteAsync(
|
|
||||||
context: context,
|
|
||||||
argPos: argPos,
|
|
||||||
services: null
|
|
||||||
);
|
|
||||||
|
|
||||||
DBCommand plugin = PluginLoader.Commands!.Where(p => p.Command == (message.Content.Split(' ')[0]).Substring(botPrefix.Length)).FirstOrDefault();
|
|
||||||
|
|
||||||
|
|
||||||
if (plugin != null)
|
|
||||||
{
|
|
||||||
if (message.Channel == await message.Author.CreateDMChannelAsync())
|
|
||||||
{
|
|
||||||
if (plugin.canUseDM)
|
|
||||||
{
|
|
||||||
if (plugin.requireAdmin)
|
|
||||||
{
|
|
||||||
if (message.Author.isAdmin())
|
|
||||||
{
|
|
||||||
plugin.Execute(context, message, client, true);
|
|
||||||
Functions.WriteLogFile($"[{message.Author.Id}] Executed command (DM) : " + plugin.Command);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await message.Channel.SendMessageAsync("This command is for administrators only !");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
plugin.Execute(context, message, client, true);
|
|
||||||
Functions.WriteLogFile($"[{message.Author.Id}] Executed command (DM) : " + plugin.Command);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await message.Channel.SendMessageAsync("This command is not for DMs");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (plugin.canUseServer)
|
|
||||||
{
|
{
|
||||||
if (plugin.requireAdmin)
|
if (plugin.requireAdmin)
|
||||||
{
|
{
|
||||||
if (message.Author.isAdmin())
|
if (message.Author.isAdmin())
|
||||||
{
|
{
|
||||||
plugin.Execute(context, message, client, false);
|
plugin.Execute(context, message, client, true);
|
||||||
Functions.WriteLogFile($"[{message.Author.Id}] Executed command : " + plugin.Command);
|
Functions.WriteLogFile($"[{message.Author.Id}] Executed command (DM) : " + plugin.Command);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await message.Channel.SendMessageAsync("This command is for administrators only !");
|
await message.Channel.SendMessageAsync("This command is for administrators only !");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
plugin.Execute(context, message, client, false);
|
|
||||||
Functions.WriteLogFile($"[{message.Author.Id}] Executed command : " + plugin.Command);
|
plugin.Execute(context, message, client, true);
|
||||||
|
Functions.WriteLogFile($"[{message.Author.Id}] Executed command (DM) : " + plugin.Command);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
|
|
||||||
|
await message.Channel.SendMessageAsync("This command is not for DMs");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (plugin.canUseServer)
|
||||||
|
{
|
||||||
|
if (plugin.requireAdmin)
|
||||||
|
{
|
||||||
|
if (message.Author.isAdmin())
|
||||||
|
{
|
||||||
|
plugin.Execute(context, message, client, false);
|
||||||
|
Functions.WriteLogFile($"[{message.Author.Id}] Executed command : " + plugin.Command);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await message.Channel.SendMessageAsync("This command is for administrators only !");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.Execute(context, message, client, false);
|
||||||
|
Functions.WriteLogFile($"[{message.Author.Id}] Executed command : " + plugin.Command);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch { }
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,15 +6,14 @@ using System;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using PluginManager.Online;
|
||||||
|
|
||||||
namespace DiscordBot
|
namespace DiscordBot
|
||||||
{
|
{
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
private static bool loadPluginsOnStartup = false;
|
private static bool loadPluginsOnStartup = false;
|
||||||
private static bool listPluginsAtStartup = false;
|
private static bool listPluginsAtStartup = false;
|
||||||
|
|
||||||
private static bool listLanguagAtStartup = false;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main entry point for the application.
|
/// The main entry point for the application.
|
||||||
@@ -27,13 +26,7 @@ namespace DiscordBot
|
|||||||
Directory.CreateDirectory("./Data/Languages");
|
Directory.CreateDirectory("./Data/Languages");
|
||||||
Directory.CreateDirectory("./Data/Plugins/Commands");
|
Directory.CreateDirectory("./Data/Plugins/Commands");
|
||||||
Directory.CreateDirectory("./Data/Plugins/Events");
|
Directory.CreateDirectory("./Data/Plugins/Events");
|
||||||
Config.LoadConfig().Wait();
|
PreLoadComponents();
|
||||||
|
|
||||||
if (Config.ContainsKey("DeleteLogsAtStartup"))
|
|
||||||
if (Config.GetValue<bool>("DeleteLogsAtStartup"))
|
|
||||||
foreach (string file in Directory.GetFiles("./Output/Logs/"))
|
|
||||||
File.Delete(file);
|
|
||||||
|
|
||||||
|
|
||||||
if (!Config.ContainsKey("token") || Config.GetValue<string>("token") == null || Config.GetValue<string>("token")?.Length != 70)
|
if (!Config.ContainsKey("token") || Config.GetValue<string>("token") == null || Config.GetValue<string>("token")?.Length != 70)
|
||||||
{
|
{
|
||||||
@@ -84,7 +77,6 @@ namespace DiscordBot
|
|||||||
ConsoleCommandsHandler consoleCommandsHandler = new ConsoleCommandsHandler(discordbooter.client);
|
ConsoleCommandsHandler 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");
|
||||||
if (listLanguagAtStartup) consoleCommandsHandler.HandleCommand("listlang");
|
|
||||||
Config.SaveConfig();
|
Config.SaveConfig();
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
@@ -165,12 +157,20 @@ namespace DiscordBot
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (len == 3 && args[0] == "/download")
|
||||||
|
{
|
||||||
|
string url = args[1];
|
||||||
|
string location = args[2];
|
||||||
|
|
||||||
|
await ServerCom.DownloadFileAsync(url, location);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (len > 0 && (args.Contains("--cmd") || args.Contains("--args") || args.Contains("--nomessage")))
|
if (len > 0 && (args.Contains("--cmd") || args.Contains("--args") || args.Contains("--nomessage")))
|
||||||
{
|
{
|
||||||
if (args.Contains("lp") || args.Contains("loadplugins")) loadPluginsOnStartup = true;
|
if (args.Contains("lp") || args.Contains("loadplugins")) loadPluginsOnStartup = true;
|
||||||
if (args.Contains("listplugs")) listPluginsAtStartup = true;
|
if (args.Contains("listplugs")) listPluginsAtStartup = true;
|
||||||
if (args.Contains("listlang")) listLanguagAtStartup = true;
|
|
||||||
//if (args.Contains("--nomessage")) ShowStartupMessage = false;
|
|
||||||
len = 0;
|
len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,6 +182,7 @@ namespace DiscordBot
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Console.ForegroundColor = ConsoleColor.DarkYellow;
|
Console.ForegroundColor = ConsoleColor.DarkYellow;
|
||||||
Console.WriteLine("Execute command interface noGUI\n\n");
|
Console.WriteLine("Execute command interface noGUI\n\n");
|
||||||
Console.WriteLine(
|
Console.WriteLine(
|
||||||
@@ -240,11 +241,22 @@ namespace DiscordBot
|
|||||||
Boot booter = await StartNoGUI();
|
Boot booter = await StartNoGUI();
|
||||||
await NoGUI(booter);
|
await NoGUI(booter);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Console.WriteLine("Failed to execute command " + message[0]);
|
Console.WriteLine("Failed to execute command " + message[0]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static async Task PreLoadComponents()
|
||||||
|
{
|
||||||
|
Config.LoadConfig().Wait();
|
||||||
|
|
||||||
|
if (Config.ContainsKey("DeleteLogsAtStartup"))
|
||||||
|
if (Config.GetValue<bool>("DeleteLogsAtStartup"))
|
||||||
|
foreach (string file in Directory.GetFiles("./Output/Logs/"))
|
||||||
|
File.Delete(file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<Application xmlns="https://github.com/avaloniaui"
|
<Application xmlns="https://github.com/avaloniaui"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
x:Class="DiscordBotGUI.App">
|
x:Class="DiscordBotGUI.App">
|
||||||
<Application.Styles>
|
<Application.Styles>
|
||||||
<FluentTheme Mode="Dark"/>
|
<FluentTheme Mode="Dark" />
|
||||||
</Application.Styles>
|
</Application.Styles>
|
||||||
</Application>
|
</Application>
|
||||||
@@ -1,23 +1,21 @@
|
|||||||
using System.IO;
|
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
using Avalonia.Controls.ApplicationLifetimes;
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
using Avalonia.Markup.Xaml;
|
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()
|
public override void OnFrameworkInitializationCompleted()
|
||||||
{
|
{
|
||||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { desktop.MainWindow = new AppUpdater() { Width = 300, Height = 50, WindowStartupLocation = Avalonia.Controls.WindowStartupLocation.CenterScreen }; }
|
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) desktop.MainWindow = new AppUpdater { Width = 300, Height = 50, WindowStartupLocation = WindowStartupLocation.CenterScreen };
|
||||||
|
|
||||||
base.OnFrameworkInitializationCompleted();
|
base.OnFrameworkInitializationCompleted();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,13 @@
|
|||||||
mc:Ignorable="d" d:DesignWidth="250" d:DesignHeight="50"
|
mc:Ignorable="d" d:DesignWidth="250" d:DesignHeight="50"
|
||||||
x:Class="DiscordBotGUI.AppUpdater"
|
x:Class="DiscordBotGUI.AppUpdater"
|
||||||
Title="AppUpdater"
|
Title="AppUpdater"
|
||||||
Background="Transparent"
|
Background="Transparent"
|
||||||
TransparencyLevelHint="AcrylicBlur"
|
TransparencyLevelHint="AcrylicBlur"
|
||||||
HasSystemDecorations="False">
|
SystemDecorations="BorderOnly">
|
||||||
|
|
||||||
<StackPanel Margin="10">
|
<StackPanel Margin="10">
|
||||||
<TextBlock x:Class="DiscordBotGUI.AppUpdater" x:Name="textBox1" Text="Checking for updates..." />
|
<TextBlock x:Class="DiscordBotGUI.AppUpdater" x:Name="textBox1" Text="Checking for updates..." />
|
||||||
<ProgressBar IsIndeterminate="True" x:Class="DiscordBotGUI.AppUpdater" x:Name="progressBar1" Foreground="Yellow" />
|
<ProgressBar IsIndeterminate="True" x:Class="DiscordBotGUI.AppUpdater" x:Name="progressBar1"
|
||||||
</StackPanel>
|
Foreground="Yellow" />
|
||||||
|
</StackPanel>
|
||||||
</Window>
|
</Window>
|
||||||
@@ -11,7 +11,7 @@ namespace DiscordBotGUI
|
|||||||
{
|
{
|
||||||
public partial class AppUpdater : Window
|
public partial class AppUpdater : Window
|
||||||
{
|
{
|
||||||
private string _version;
|
private string _version = "";
|
||||||
|
|
||||||
public AppUpdater()
|
public AppUpdater()
|
||||||
{
|
{
|
||||||
@@ -149,7 +149,7 @@ namespace DiscordBotGUI
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string current_version = Config.GetValue("Version");
|
string current_version = Config.GetValue<string>("Version");
|
||||||
if (current_version == null)
|
if (current_version == null)
|
||||||
if (!Config.SetValue("Version", "0"))
|
if (!Config.SetValue("Version", "0"))
|
||||||
Config.AddValueToVariables("Version", "0", false);
|
Config.AddValueToVariables("Version", "0", false);
|
||||||
|
|||||||
@@ -5,32 +5,35 @@
|
|||||||
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="425"
|
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="425"
|
||||||
x:Class="DiscordBotGUI.MainWindow"
|
x:Class="DiscordBotGUI.MainWindow"
|
||||||
Title="DiscordBotGUI"
|
Title="DiscordBotGUI"
|
||||||
Background="Transparent"
|
Background="Transparent"
|
||||||
TransparencyLevelHint="AcrylicBlur"
|
TransparencyLevelHint="AcrylicBlur"
|
||||||
ExtendClientAreaToDecorationsHint="True" >
|
ExtendClientAreaToDecorationsHint="True">
|
||||||
|
|
||||||
<StackPanel Margin="20">
|
<StackPanel Margin="20">
|
||||||
<Menu>
|
<Menu>
|
||||||
<MenuItem Header="Plugins">
|
<MenuItem Header="Plugins">
|
||||||
<MenuItem Header="Commands" x:Class="DiscordBotGUI.MainWindow" x:Name="commandsSettingMenuItem" />
|
<MenuItem Header="Commands" x:Class="DiscordBotGUI.MainWindow" x:Name="commandsSettingMenuItem" />
|
||||||
<MenuItem Header="Events" x:Class="DiscordBotGUI.MainWindow" x:Name="eventsSettingMenuItem" />
|
<MenuItem Header="Events" x:Class="DiscordBotGUI.MainWindow" x:Name="eventsSettingMenuItem" />
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem Header="Application Variables" x:Class="DiscordBotGUI.MainWindow" x:Name="applicationVariablesMenuItem"/>
|
<MenuItem Header="Application Variables" x:Class="DiscordBotGUI.MainWindow"
|
||||||
</Menu>
|
x:Name="applicationVariablesMenuItem" />
|
||||||
<Label x:Class="DiscordBotGUI.MainWindow" x:Name="label1" Content="Discord Token" />
|
</Menu>
|
||||||
<TextBox x:Class="DiscordBotGUI.MainWindow" x:Name="textBox1" IsReadOnly="True" TextAlignment="Center" Text=""/>
|
<Label x:Class="DiscordBotGUI.MainWindow" x:Name="label1" Content="Discord Token" />
|
||||||
<Label x:Class="DiscordBotGUI.MainWindow" x:Name="label2" Content="Bot Prefix" />
|
<TextBox x:Class="DiscordBotGUI.MainWindow" x:Name="textBox1" IsReadOnly="True" TextAlignment="Center" Text="" />
|
||||||
<TextBox x:Class="DiscordBotGUI.MainWindow" x:Name="textBox2" TextAlignment="Center" HorizontalAlignment="Left" IsReadOnly="True" Text=""/>
|
<Label x:Class="DiscordBotGUI.MainWindow" x:Name="label2" Content="Bot Prefix" />
|
||||||
<Border Background="Black" Padding="0.5" Margin="25"/>
|
<TextBox x:Class="DiscordBotGUI.MainWindow" x:Name="textBox2" TextAlignment="Center" HorizontalAlignment="Left"
|
||||||
<Label x:Class="DiscordBotGUI.MainWindow" x:Name="label3" Content="Start Arguments: " />
|
IsReadOnly="True" Text="" />
|
||||||
<TextBox x:Class="DiscordBotGUI.MainWindow" x:Name="textBox3" Width="250" TextAlignment="Center" HorizontalAlignment="Left" IsReadOnly="False" Text=""/>
|
<Border Background="Black" Padding="0.5" Margin="25" />
|
||||||
<Label x:Class="DiscordBotGUI.MainWindow" x:Name="label4" Content="" Foreground="Red" Margin="10"/>
|
<Label x:Class="DiscordBotGUI.MainWindow" x:Name="label3" Content="Start Arguments: " />
|
||||||
<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" />
|
<TextBox x:Class="DiscordBotGUI.MainWindow" x:Name="textBox3" Width="250" TextAlignment="Center"
|
||||||
<Label x:Class="DiscordBotGUI.MainWindow" x:Name="label5" Content="" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="0,0,0,0"/>
|
HorizontalAlignment="Left" IsReadOnly="False" Text="" />
|
||||||
</StackPanel>
|
<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>
|
||||||
@@ -1,99 +1,86 @@
|
|||||||
using Avalonia.Controls;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using PluginManager.Others;
|
|
||||||
using System.IO;
|
|
||||||
using System;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Avalonia.Controls;
|
||||||
using DiscordBotGUI.Settings;
|
using DiscordBotGUI.Settings;
|
||||||
using Avalonia.Themes.Fluent;
|
|
||||||
using PluginManager;
|
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();
|
if (!((token.Length == 70 || token.Length == 59) && prefix.Length == 1))
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void LoadElements()
|
|
||||||
{
|
|
||||||
textBox3.Watermark = "Insert start arguments";
|
|
||||||
if (File.Exists("./Version.txt")) label5.Content = Config.GetValue("Version");
|
|
||||||
button1.Click += async (sender, e) =>
|
|
||||||
{
|
{
|
||||||
|
label4.Content = "Invalid Token or Prefix.\n(Prefix must be 1 character long and token must be 59 or 79 characters long)";
|
||||||
string token = textBox1.Text;
|
await Task.Delay(5000);
|
||||||
string prefix = textBox2.Text;
|
label4.Content = "";
|
||||||
string args = "--nomessage " + textBox3.Text;
|
return;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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;
|
textBox1.IsReadOnly = false;
|
||||||
textBox2.IsReadOnly = false;
|
textBox2.IsReadOnly = false;
|
||||||
textBox1.Watermark = "Insert Bot Token Here";
|
textBox1.Watermark = "Insert Bot Token Here";
|
||||||
textBox2.Watermark = "Insert Bot Prefix Here";
|
textBox2.Watermark = "Insert Bot Prefix Here";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
textBox1.Text = botToken;
|
||||||
|
textBox2.Text = botPrefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
catch
|
||||||
|
|
||||||
private void RunDiscordBot(string args)
|
|
||||||
{
|
{
|
||||||
var os = Functions.GetOperatingSystem();
|
textBox1.IsReadOnly = false;
|
||||||
if (os == PluginManager.Others.OperatingSystem.WINDOWS)
|
textBox2.IsReadOnly = false;
|
||||||
Process.Start("./DiscordBot.exe", args);
|
textBox1.Watermark = "Insert Bot Token Here";
|
||||||
else if (os == PluginManager.Others.OperatingSystem.LINUX)
|
textBox2.Watermark = "Insert Bot Prefix Here";
|
||||||
Process.Start("./DiscordBot", args);
|
|
||||||
else if (os == PluginManager.Others.OperatingSystem.MAC_OS)
|
|
||||||
Process.Start("./DiscordBot.app/Contents/MacOS/DiscordBot", args);
|
|
||||||
Close();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,25 @@
|
|||||||
using Avalonia;
|
|
||||||
using Avalonia.Controls;
|
|
||||||
using Avalonia.Controls.ApplicationLifetimes;
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using Avalonia;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
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
|
BuildAvaloniaApp()
|
||||||
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
|
.StartWithClassicDesktopLifetime(args);
|
||||||
// yet and stuff might break.
|
}
|
||||||
[STAThread]
|
|
||||||
public static void Main(string[] args)
|
|
||||||
{
|
|
||||||
BuildAvaloniaApp()
|
|
||||||
.StartWithClassicDesktopLifetime(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Avalonia configuration, don't remove; also used by visual designer.
|
// Avalonia configuration, don't remove; also used by visual designer.
|
||||||
public static AppBuilder BuildAvaloniaApp()
|
public static AppBuilder BuildAvaloniaApp()
|
||||||
=> AppBuilder.Configure<App>()
|
{
|
||||||
.UsePlatformDetect()
|
return AppBuilder.Configure<App>()
|
||||||
.LogToTrace();
|
.UsePlatformDetect()
|
||||||
|
.LogToTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,19 +5,19 @@
|
|||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="DiscordBotGUI.Settings.ApplicationVariables"
|
x:Class="DiscordBotGUI.Settings.ApplicationVariables"
|
||||||
Title="ApplicationVariables">
|
Title="ApplicationVariables">
|
||||||
<StackPanel>
|
<StackPanel>
|
||||||
<Label Content="Available commands"/>
|
<Label Content="Available commands" />
|
||||||
<TextBox x:Name="textBox1" x:Class="DiscordBotGUI.Settings.ApplicationVariables"/>
|
<TextBox x:Name="textBox1" x:Class="DiscordBotGUI.Settings.ApplicationVariables" />
|
||||||
<Label Content="Insert a new variable"/>
|
<Label Content="Insert a new variable" />
|
||||||
<Border Background="White" BorderThickness="3" Margin="10"/>
|
<Border Background="White" BorderThickness="3" Margin="10" />
|
||||||
<Label Content="New Variable Name"/>
|
<Label Content="New Variable Name" />
|
||||||
<TextBox x:Name="textBox2" x:Class="DiscordBotGUI.Settings.ApplicationVariables"/>
|
<TextBox x:Name="textBox2" x:Class="DiscordBotGUI.Settings.ApplicationVariables" />
|
||||||
<Label Content="New Variable Value"/>
|
<Label Content="New Variable Value" />
|
||||||
<TextBox x:Name="textBox3" x:Class="DiscordBotGUI.Settings.ApplicationVariables"/>
|
<TextBox x:Name="textBox3" x:Class="DiscordBotGUI.Settings.ApplicationVariables" />
|
||||||
<Label Content="New Variable IsReadOnly"/>
|
<Label Content="New Variable IsReadOnly" />
|
||||||
<CheckBox x:Class="DiscordBotGUI.Settings.ApplicationVariables" x:Name="checkBox1"/>
|
<CheckBox x:Class="DiscordBotGUI.Settings.ApplicationVariables" x:Name="checkBox1" />
|
||||||
<Button Content="Add command" x:Class="DiscordBotGUI.Settings.ApplicationVariables" x:Name="button1"/>
|
<Button Content="Add command" x:Class="DiscordBotGUI.Settings.ApplicationVariables" x:Name="button1" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
|
|
||||||
</Window>
|
</Window>
|
||||||
@@ -1,44 +1,41 @@
|
|||||||
using Avalonia;
|
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Markup.Xaml;
|
|
||||||
using PluginManager;
|
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();
|
var key = textBox2.Text;
|
||||||
button1.Click += (sedner, e) =>
|
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();
|
ClearEverything();
|
||||||
};
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClearEverything()
|
var value = textBox3.Text;
|
||||||
{
|
Config.AddValueToVariables(key, value, checkBox1.IsChecked!.Value);
|
||||||
textBox1.Text = "";
|
ClearEverything();
|
||||||
textBox2.Text = "";
|
};
|
||||||
textBox3.Text = "";
|
}
|
||||||
checkBox1.IsChecked = false;
|
|
||||||
var allvars = Config.GetAllVariables();
|
private void ClearEverything()
|
||||||
foreach (var kvp in allvars) textBox1.Text += kvp.Key + " => " + kvp.Value + "\n";
|
{
|
||||||
}
|
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";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,17 +5,20 @@
|
|||||||
mc:Ignorable="d" d:DesignWidth="550" d:DesignHeight="200"
|
mc:Ignorable="d" d:DesignWidth="550" d:DesignHeight="200"
|
||||||
x:Class="DiscordBotGUI.Settings.Commands"
|
x:Class="DiscordBotGUI.Settings.Commands"
|
||||||
Title="Commands"
|
Title="Commands"
|
||||||
Background="Transparent"
|
Background="Transparent"
|
||||||
TransparencyLevelHint="AcrylicBlur"
|
TransparencyLevelHint="AcrylicBlur"
|
||||||
ExtendClientAreaToDecorationsHint="True">
|
ExtendClientAreaToDecorationsHint="True">
|
||||||
<StackPanel x:Class="DiscordBotGUI.Settings.Commands" x:Name="stackpanel1" Margin="10">
|
<StackPanel x:Class="DiscordBotGUI.Settings.Commands" x:Name="stackpanel1" Margin="10">
|
||||||
<Label Content="Installed Commands" />
|
<Label Content="Installed Commands" />
|
||||||
<TextBox x:Class="DiscordBotGUI.Settings.Commands" x:Name="textbox1" TextAlignment="Left" IsReadOnly="True" />
|
<TextBox x:Class="DiscordBotGUI.Settings.Commands" x:Name="textbox1" TextAlignment="Left" IsReadOnly="True" />
|
||||||
<Label Content="Install another command" />
|
<Label Content="Install another command" />
|
||||||
<ComboBox x:Class="DiscordBotGUI.Settings.Commands" x:Name="comboBox1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,10" Padding="200,0" />
|
<ComboBox x:Class="DiscordBotGUI.Settings.Commands" x:Name="comboBox1" HorizontalAlignment="Left"
|
||||||
<Button x:Class="DiscordBotGUI.Settings.Commands" x:Name="button1" HorizontalAlignment="Left" Content="Install" />
|
VerticalAlignment="Top" Margin="0,10" Padding="200,0" />
|
||||||
<ProgressBar x:Class="DiscordBotGUI.Settings.Commands" x:Name="progressBar1" HorizontalAlignment="Left" Margin="0,10" Foreground="Yellow" />
|
<Button x:Class="DiscordBotGUI.Settings.Commands" x:Name="button1" HorizontalAlignment="Left" Content="Install" />
|
||||||
<Label x:Class="DiscordBotGUI.Settings.Commands" x:Name="label1" Content="" HorizontalAlignment="Left" Margin="0,10" />
|
<ProgressBar x:Class="DiscordBotGUI.Settings.Commands" x:Name="progressBar1" HorizontalAlignment="Left"
|
||||||
</StackPanel>
|
Margin="0,10" Foreground="Yellow" />
|
||||||
|
<Label x:Class="DiscordBotGUI.Settings.Commands" x:Name="label1" Content="" HorizontalAlignment="Left"
|
||||||
|
Margin="0,10" />
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
</Window>
|
</Window>
|
||||||
@@ -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;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
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>();
|
InitializeComponent();
|
||||||
public Commands()
|
LoadData();
|
||||||
{
|
LoadComboBox();
|
||||||
InitializeComponent();
|
|
||||||
LoadData();
|
|
||||||
LoadComboBox();
|
|
||||||
|
|
||||||
button1.Click += async (sender, e) =>
|
button1.Click += async (sender, e) => { await Download(); };
|
||||||
{
|
}
|
||||||
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";
|
||||||
}
|
}
|
||||||
|
catch
|
||||||
|
|
||||||
private void LoadData()
|
|
||||||
{
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
try
|
||||||
{
|
{
|
||||||
textbox1.Text = "";
|
if (Directory.EnumerateFiles("./Data/Plugins/Commands/").Any(x => x.EndsWith(info[0] + ".dll"))) continue;
|
||||||
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";
|
|
||||||
}
|
}
|
||||||
catch { }
|
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++)
|
|
||||||
{
|
{
|
||||||
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]}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
comboBox1.Items = data;
|
||||||
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;
|
|
||||||
|
|
||||||
|
|
||||||
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)}%";
|
label1.Content = $"Downloading {pluginName} {MathF.Round(value, 2)}%";
|
||||||
if (value == 1f)
|
if (value == 1f)
|
||||||
@@ -101,38 +99,38 @@ namespace DiscordBotGUI.Settings
|
|||||||
await Task.Delay(5000);
|
await Task.Delay(5000);
|
||||||
label1.Content = "";
|
label1.Content = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
progressBar1.Value = value;
|
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);
|
await ServerCom.DownloadFileAsync(URL, "./Data/Plugins/Commands/" + pluginName + ".dll", progress);
|
||||||
label1.Content = "Downloaded";
|
var requirements = (from s in commands
|
||||||
progressBar1.Value = 100;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,16 +5,19 @@
|
|||||||
mc:Ignorable="d" d:DesignWidth="550" d:DesignHeight="200"
|
mc:Ignorable="d" d:DesignWidth="550" d:DesignHeight="200"
|
||||||
x:Class="DiscordBotGUI.Settings.Events"
|
x:Class="DiscordBotGUI.Settings.Events"
|
||||||
Title="Events"
|
Title="Events"
|
||||||
Background="Transparent"
|
Background="Transparent"
|
||||||
TransparencyLevelHint="AcrylicBlur"
|
TransparencyLevelHint="AcrylicBlur"
|
||||||
ExtendClientAreaToDecorationsHint="True">
|
ExtendClientAreaToDecorationsHint="True">
|
||||||
<StackPanel Margin="10">
|
<StackPanel Margin="10">
|
||||||
<Label Content="Installed Events" />
|
<Label Content="Installed Events" />
|
||||||
<TextBox x:Class="DiscordBotGUI.Settings.Events" x:Name="textbox1" TextAlignment="Left" IsReadOnly="True" />
|
<TextBox x:Class="DiscordBotGUI.Settings.Events" x:Name="textbox1" TextAlignment="Left" IsReadOnly="True" />
|
||||||
<Label Content="Install another Events" />
|
<Label Content="Install another Events" />
|
||||||
<ComboBox x:Class="DiscordBotGUI.Settings.Events" x:Name="comboBox1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,10" Padding="200,0" />
|
<ComboBox x:Class="DiscordBotGUI.Settings.Events" x:Name="comboBox1" HorizontalAlignment="Left"
|
||||||
<Button x:Class="DiscordBotGUI.Settings.Events" x:Name="button1" HorizontalAlignment="Left" Content="Install" />
|
VerticalAlignment="Top" Margin="0,10" Padding="200,0" />
|
||||||
<ProgressBar x:Class="DiscordBotGUI.Settings.Events" x:Name="progressBar1" HorizontalAlignment="Left" Margin="0,10" Foreground="Yellow" />
|
<Button x:Class="DiscordBotGUI.Settings.Events" x:Name="button1" HorizontalAlignment="Left" Content="Install" />
|
||||||
<Label x:Class="DiscordBotGUI.Settings.Events" x:Name="label1" Content="" HorizontalAlignment="Left" Margin="0,10" />
|
<ProgressBar x:Class="DiscordBotGUI.Settings.Events" x:Name="progressBar1" HorizontalAlignment="Left"
|
||||||
</StackPanel>
|
Margin="0,10" Foreground="Yellow" />
|
||||||
|
<Label x:Class="DiscordBotGUI.Settings.Events" x:Name="label1" Content="" HorizontalAlignment="Left"
|
||||||
|
Margin="0,10" />
|
||||||
|
</StackPanel>
|
||||||
</Window>
|
</Window>
|
||||||
@@ -1,97 +1,94 @@
|
|||||||
using Avalonia;
|
|
||||||
using Avalonia.Controls;
|
|
||||||
using Avalonia.Markup.Xaml;
|
|
||||||
|
|
||||||
using PluginManager.Others;
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Collections.Generic;
|
||||||
using System.Reflection.Emit;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
using static PluginManager.Others.Console_Utilities;
|
|
||||||
using System.IO;
|
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>();
|
InitializeComponent();
|
||||||
public Events()
|
LoadData();
|
||||||
{
|
LoadComboBox();
|
||||||
InitializeComponent();
|
button1.Click += async (sender, e) => { await Download(); };
|
||||||
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";
|
||||||
}
|
}
|
||||||
|
catch
|
||||||
private void LoadData()
|
|
||||||
{
|
{
|
||||||
//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
|
try
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory("./Data/Plugins/Events/");
|
if (Directory.EnumerateFiles("./Data/Plugins/Events/").Any(x => x.EndsWith(info[0] + ".dll"))) continue;
|
||||||
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";
|
|
||||||
}
|
}
|
||||||
catch { }
|
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++)
|
|
||||||
{
|
{
|
||||||
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;
|
comboBox1.Items = data;
|
||||||
string? URL = (from s in events
|
}
|
||||||
where s.StartsWith(pluginName)
|
|
||||||
select s.Split(',')[3].Trim()).FirstOrDefault();
|
|
||||||
|
|
||||||
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)}%";
|
label1.Content = $"Downloading {pluginName} {MathF.Round(value, 2)}%";
|
||||||
if (value == 1f)
|
if (value == 1f)
|
||||||
@@ -103,37 +100,36 @@ namespace DiscordBotGUI.Settings
|
|||||||
await Task.Delay(5000);
|
await Task.Delay(5000);
|
||||||
label1.Content = "";
|
label1.Content = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
progressBar1.Value = value;
|
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 = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ namespace EVE_LevelingSystem
|
|||||||
Config.AddValueToVariables("LevelingSystemPath", "./Data/Resources/LevelingSystem", true);
|
Config.AddValueToVariables("LevelingSystemPath", "./Data/Resources/LevelingSystem", true);
|
||||||
Config.AddValueToVariables("LevelingSystemSettingsFile", "./Data/Resources/LevelingSystemSettings.txt", true);
|
Config.AddValueToVariables("LevelingSystemSettingsFile", "./Data/Resources/LevelingSystemSettings.txt", true);
|
||||||
|
|
||||||
if (!File.Exists(Config.GetValue("LevelingSystemSettingsFile")))
|
if (!File.Exists(Config.GetValue<string>("LevelingSystemSettingsFile")))
|
||||||
{
|
{
|
||||||
globalSettings = new Settings { TimeToWaitBetweenMessages = 5 };
|
globalSettings = new Settings { TimeToWaitBetweenMessages = 5 };
|
||||||
await Functions.SaveToJsonFile<Settings>(Config.GetValue("LevelingSystemSettingsFile"), globalSettings);
|
await Functions.SaveToJsonFile<Settings>(Config.GetValue<string>("LevelingSystemSettingsFile"), globalSettings);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
globalSettings = await Functions.ConvertFromJson<Settings>(Config.GetValue("LevelingSystemSettingsFile"));
|
globalSettings = await Functions.ConvertFromJson<Settings>(Config.GetValue<string>("LevelingSystemSettingsFile"));
|
||||||
|
|
||||||
// Console.WriteLine(globalSettings.TimeToWaitBetweenMessages);
|
// Console.WriteLine(globalSettings.TimeToWaitBetweenMessages);
|
||||||
client.MessageReceived += ClientOnMessageReceived;
|
client.MessageReceived += ClientOnMessageReceived;
|
||||||
@@ -33,21 +33,21 @@ namespace EVE_LevelingSystem
|
|||||||
|
|
||||||
private async Task ClientOnMessageReceived(SocketMessage arg)
|
private async Task ClientOnMessageReceived(SocketMessage arg)
|
||||||
{
|
{
|
||||||
if (arg.Author.IsBot || arg.IsTTS || arg.Content.StartsWith(Config.GetValue("prefix"))) return;
|
if (arg.Author.IsBot || arg.IsTTS || arg.Content.StartsWith(Config.GetValue<string>("prefix"))) return;
|
||||||
string userID = arg.Author.Id.ToString();
|
string userID = arg.Author.Id.ToString();
|
||||||
User user;
|
User user;
|
||||||
if (File.Exists($"{Config.GetValue("LevelingSystemPath")}/{userID}.dat"))
|
if (File.Exists($"{Config.GetValue<string>("LevelingSystemPath")}/{userID}.dat"))
|
||||||
{
|
{
|
||||||
user = await Functions.ConvertFromJson<User>(Config.GetValue("LevelingSystemPath")! + $"/{userID}.dat");
|
user = await Functions.ConvertFromJson<User>(Config.GetValue<string>("LevelingSystemPath")! + $"/{userID}.dat");
|
||||||
// Console.WriteLine(Config.GetValue("LevelingSystemPath"));
|
// Console.WriteLine(Config.GetValue("LevelingSystemPath"));
|
||||||
if (user.AddEXP()) await arg.Channel.SendMessageAsync($"{arg.Author.Mention} is now level {user.CurrentLevel}");
|
if (user.AddEXP()) await arg.Channel.SendMessageAsync($"{arg.Author.Mention} is now level {user.CurrentLevel}");
|
||||||
await Functions.SaveToJsonFile(Config.GetValue("LevelingSystemPath") + $"/{userID}.dat", user);
|
await Functions.SaveToJsonFile(Config.GetValue<string>("LevelingSystemPath") + $"/{userID}.dat", user);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
user = new User() { CurrentEXP = 0, CurrentLevel = 1, RequiredEXPToLevelUp = LevelCalculator.GetNextLevelRequiredEXP(1), userID = userID };
|
user = new User() { CurrentEXP = 0, CurrentLevel = 1, RequiredEXPToLevelUp = LevelCalculator.GetNextLevelRequiredEXP(1), userID = userID };
|
||||||
if (user.AddEXP()) await arg.Channel.SendMessageAsync($"{arg.Author.Mention} is now level {user.CurrentLevel}");
|
if (user.AddEXP()) await arg.Channel.SendMessageAsync($"{arg.Author.Mention} is now level {user.CurrentLevel}");
|
||||||
await Functions.SaveToJsonFile($"{Config.GetValue("LevelingSystemPath")}/{userID}.dat", user);
|
await Functions.SaveToJsonFile($"{Config.GetValue<string>("LevelingSystemPath")}/{userID}.dat", user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,9 @@
|
|||||||
using System;
|
namespace EVE_LevelingSystem.LevelingSystemCore;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace EVE_LevelingSystem.LevelingSystemCore
|
public class User
|
||||||
{
|
{
|
||||||
public class User
|
public string userID { get; set; }
|
||||||
{
|
public int CurrentLevel { get; set; }
|
||||||
public string userID { get; set; }
|
public long CurrentEXP { get; set; }
|
||||||
public int CurrentLevel { get; set; }
|
public long RequiredEXPToLevelUp { get; set; }
|
||||||
public Int64 CurrentEXP { get; set; }
|
|
||||||
public Int64 RequiredEXPToLevelUp { get; set; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Audio;
|
using Discord.Audio;
|
||||||
|
|
||||||
using MusicCommands;
|
using MusicCommands;
|
||||||
|
|
||||||
namespace CMD_Utils.Music
|
namespace CMD_Utils.Music;
|
||||||
{
|
|
||||||
internal static class Data
|
|
||||||
{
|
|
||||||
internal static IAudioClient audioClient = null;
|
|
||||||
internal static IVoiceChannel voiceChannel = null;
|
|
||||||
|
|
||||||
internal static MusicPlayer CurrentlyRunning = null;
|
internal static class Data
|
||||||
}
|
{
|
||||||
|
internal static IAudioClient audioClient = null;
|
||||||
|
internal static IVoiceChannel voiceChannel = null;
|
||||||
|
|
||||||
|
internal static MusicPlayer CurrentlyRunning = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,39 +1,31 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
|
||||||
using PluginManager.Interfaces;
|
using PluginManager.Interfaces;
|
||||||
|
|
||||||
using System;
|
namespace CMD_Utils.Music;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace CMD_Utils.Music
|
internal class Leave : DBCommand
|
||||||
{
|
{
|
||||||
class Leave : DBCommand
|
public string Command => "leave";
|
||||||
|
|
||||||
|
public string Description => "Leave the voice channel";
|
||||||
|
|
||||||
|
public string Usage => "leave";
|
||||||
|
|
||||||
|
public bool canUseDM => false;
|
||||||
|
|
||||||
|
public bool canUseServer => true;
|
||||||
|
|
||||||
|
public bool requireAdmin => false;
|
||||||
|
|
||||||
|
public async void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
||||||
{
|
{
|
||||||
public string Command => "leave";
|
if (Data.audioClient is not null && Data.voiceChannel is not null)
|
||||||
|
|
||||||
public string Description => "Leave the voice channel";
|
|
||||||
|
|
||||||
public string Usage => "leave";
|
|
||||||
|
|
||||||
public bool canUseDM => false;
|
|
||||||
|
|
||||||
public bool canUseServer => true;
|
|
||||||
|
|
||||||
public bool requireAdmin => false;
|
|
||||||
|
|
||||||
public async void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
|
||||||
{
|
{
|
||||||
if (Data.audioClient is not null && Data.voiceChannel is not null)
|
Data.CurrentlyRunning.Stop();
|
||||||
{
|
Data.CurrentlyRunning = null;
|
||||||
Data.CurrentlyRunning.Stop();
|
await Data.audioClient.StopAsync();
|
||||||
Data.CurrentlyRunning = null;
|
await Data.voiceChannel.DisconnectAsync();
|
||||||
await Data.audioClient.StopAsync();
|
|
||||||
await Data.voiceChannel.DisconnectAsync();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,121 +1,118 @@
|
|||||||
using CMD_Utils.Music;
|
using System;
|
||||||
|
|
||||||
using PluginManager.Others;
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Net.Http.Headers;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using CMD_Utils.Music;
|
||||||
|
using PluginManager.Others;
|
||||||
|
|
||||||
namespace MusicCommands
|
namespace MusicCommands;
|
||||||
|
|
||||||
|
internal class MusicPlayer
|
||||||
{
|
{
|
||||||
class MusicPlayer
|
public MusicPlayer(Stream input, Stream output)
|
||||||
{
|
{
|
||||||
public Stream inputStream { get; private set; } // from FFMPEG
|
inputStream = input;
|
||||||
public Stream outputStream { get; private set; } // to Voice Channel
|
outputStream = output;
|
||||||
public MusicPlayer(Stream input, Stream output)
|
}
|
||||||
{
|
|
||||||
inputStream = input;
|
|
||||||
outputStream = output;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MusicPlayer(Stream output)
|
public MusicPlayer(Stream output)
|
||||||
{
|
{
|
||||||
inputStream = null;
|
inputStream = null;
|
||||||
outputStream = output;
|
outputStream = output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Paused { get; set; }
|
public Stream inputStream { get; } // from FFMPEG
|
||||||
private bool _stop { get; set; }
|
public Stream outputStream { get; } // to Voice Channel
|
||||||
public void Stop()
|
|
||||||
{
|
|
||||||
_stop = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task StartSendAudioFromLink(string URL)
|
public bool Paused { get; set; }
|
||||||
{
|
private bool _stop { get; set; }
|
||||||
|
|
||||||
/* using (HttpClient client = new HttpClient())
|
public void Stop()
|
||||||
using (HttpResponseMessage response = await client.GetAsync(URL))
|
{
|
||||||
using (var content = response.Content)
|
_stop = true;
|
||||||
{
|
}
|
||||||
await (await content.ReadAsStreamAsync()).CopyToAsync(outputStream);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
public async Task StartSendAudioFromLink(string URL)
|
||||||
Stream ms = new MemoryStream();
|
{
|
||||||
int bsize = 512;
|
/* using (HttpClient client = new HttpClient())
|
||||||
new Thread(async delegate (object o)
|
using (HttpResponseMessage response = await client.GetAsync(URL))
|
||||||
|
using (var content = response.Content)
|
||||||
{
|
{
|
||||||
var response = await new HttpClient().GetAsync(URL);
|
await (await content.ReadAsStreamAsync()).CopyToAsync(outputStream);
|
||||||
using (var stream = await response.Content.ReadAsStreamAsync())
|
}*/
|
||||||
{
|
|
||||||
byte[] buffer = new byte[bsize];
|
|
||||||
int read;
|
Stream ms = new MemoryStream();
|
||||||
while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
|
var bsize = 512;
|
||||||
{
|
new Thread(async delegate(object o)
|
||||||
var pos = ms.Position;
|
|
||||||
ms.Position = ms.Length;
|
|
||||||
ms.Write(buffer, 0, read);
|
|
||||||
ms.Position = pos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).Start();
|
|
||||||
Console.Write("Reading data: ");
|
|
||||||
while (ms.Length < bsize * 10)
|
|
||||||
{
|
{
|
||||||
await Task.Delay(1000);
|
var response = await new HttpClient().GetAsync(URL);
|
||||||
Console.Title = "Reading data: " + ms.Length + " bytes read of " + bsize * 10;
|
using (var stream = await response.Content.ReadAsStreamAsync())
|
||||||
Console.Write(".");
|
{
|
||||||
|
var buffer = new byte[bsize];
|
||||||
|
int read;
|
||||||
|
while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
|
||||||
|
{
|
||||||
|
var pos = ms.Position;
|
||||||
|
ms.Position = ms.Length;
|
||||||
|
ms.Write(buffer, 0, read);
|
||||||
|
ms.Position = pos;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Console.WriteLine("\nDone");
|
).Start();
|
||||||
ms.Position = 0;
|
Console.Write("Reading data: ");
|
||||||
|
while (ms.Length < bsize * 10)
|
||||||
_stop = false;
|
{
|
||||||
Paused = false;
|
await Task.Delay(1000);
|
||||||
|
Console.Title = "Reading data: " + ms.Length + " bytes read of " + bsize * 10;
|
||||||
while (!_stop)
|
Console.Write(".");
|
||||||
{
|
|
||||||
if (Paused) continue;
|
|
||||||
byte[] buffer = new byte[bsize];
|
|
||||||
int read = await ms.ReadAsync(buffer, 0, buffer.Length);
|
|
||||||
if (read > 0)
|
|
||||||
await outputStream.WriteAsync(buffer, 0, read);
|
|
||||||
else break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task StartSendAudio()
|
Console.WriteLine("\nDone");
|
||||||
{
|
ms.Position = 0;
|
||||||
Paused = false;
|
|
||||||
_stop = false;
|
|
||||||
while (!_stop)
|
|
||||||
{
|
|
||||||
if (Paused) continue;
|
|
||||||
int bsize = 512;
|
|
||||||
byte[] buffer = new byte[bsize];
|
|
||||||
var bcount = await inputStream.ReadAsync(buffer, 0, bsize);
|
|
||||||
if (bcount <= 0)
|
|
||||||
{
|
|
||||||
Stop();
|
|
||||||
Data.CurrentlyRunning = null;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await outputStream.WriteAsync(buffer, 0, bcount);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
await outputStream.FlushAsync();
|
|
||||||
Functions.WriteLogFile(ex.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
_stop = false;
|
||||||
|
Paused = false;
|
||||||
|
|
||||||
|
while (!_stop)
|
||||||
|
{
|
||||||
|
if (Paused) continue;
|
||||||
|
var buffer = new byte[bsize];
|
||||||
|
var read = await ms.ReadAsync(buffer, 0, buffer.Length);
|
||||||
|
if (read > 0)
|
||||||
|
await outputStream.WriteAsync(buffer, 0, read);
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task StartSendAudio()
|
||||||
|
{
|
||||||
|
Paused = false;
|
||||||
|
_stop = false;
|
||||||
|
while (!_stop)
|
||||||
|
{
|
||||||
|
if (Paused) continue;
|
||||||
|
var bsize = 512;
|
||||||
|
var buffer = new byte[bsize];
|
||||||
|
var bcount = await inputStream.ReadAsync(buffer, 0, bsize);
|
||||||
|
if (bcount <= 0)
|
||||||
|
{
|
||||||
|
Stop();
|
||||||
|
Data.CurrentlyRunning = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await outputStream.WriteAsync(buffer, 0, bcount);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
await outputStream.FlushAsync();
|
||||||
|
Functions.WriteLogFile(ex.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,25 @@
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
|
||||||
using PluginManager.Interfaces;
|
using PluginManager.Interfaces;
|
||||||
|
|
||||||
namespace CMD_Utils.Music
|
namespace CMD_Utils.Music;
|
||||||
|
|
||||||
|
internal class Pause : DBCommand
|
||||||
{
|
{
|
||||||
class Pause : DBCommand
|
public string Command => "pause";
|
||||||
|
|
||||||
|
public string Description => "Pause the music";
|
||||||
|
|
||||||
|
public string Usage => "pause";
|
||||||
|
|
||||||
|
public bool canUseDM => false;
|
||||||
|
|
||||||
|
public bool canUseServer => true;
|
||||||
|
|
||||||
|
public bool requireAdmin => false;
|
||||||
|
|
||||||
|
public void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
||||||
{
|
{
|
||||||
public string Command => "pause";
|
Data.CurrentlyRunning.Paused = true;
|
||||||
|
|
||||||
public string Description => "Pause the music";
|
|
||||||
|
|
||||||
public string Usage => "pause";
|
|
||||||
|
|
||||||
public bool canUseDM => false;
|
|
||||||
|
|
||||||
public bool canUseServer => true;
|
|
||||||
|
|
||||||
public bool requireAdmin => false;
|
|
||||||
|
|
||||||
public void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
|
||||||
{
|
|
||||||
Data.CurrentlyRunning.Paused = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,70 +1,63 @@
|
|||||||
using Discord;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using Discord;
|
||||||
using Discord.Audio;
|
using Discord.Audio;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
|
||||||
using MusicCommands;
|
using MusicCommands;
|
||||||
|
|
||||||
using PluginManager.Interfaces;
|
using PluginManager.Interfaces;
|
||||||
using PluginManager.Others;
|
using PluginManager.Others;
|
||||||
|
|
||||||
using System;
|
namespace CMD_Utils.Music;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace CMD_Utils.Music
|
internal class Play : DBCommand
|
||||||
{
|
{
|
||||||
class Play : DBCommand
|
public string Command => "fplay";
|
||||||
|
|
||||||
|
public string Description => "Play music from a file";
|
||||||
|
|
||||||
|
public string Usage => "fplay [name]";
|
||||||
|
|
||||||
|
public bool canUseDM => false;
|
||||||
|
|
||||||
|
public bool canUseServer => true;
|
||||||
|
|
||||||
|
public bool requireAdmin => false;
|
||||||
|
|
||||||
|
public async void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
||||||
{
|
{
|
||||||
public string Command => "fplay";
|
var path = "./Music";
|
||||||
|
var FileName = Functions.GetArguments(message).ToArray().MergeStrings(0);
|
||||||
public string Description => "Play music from a file";
|
path += "/" + FileName + ".mp3";
|
||||||
|
if (!File.Exists(path))
|
||||||
public string Usage => "fplay [name]";
|
|
||||||
|
|
||||||
public bool canUseDM => false;
|
|
||||||
|
|
||||||
public bool canUseServer => true;
|
|
||||||
|
|
||||||
public bool requireAdmin => false;
|
|
||||||
|
|
||||||
public async void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
|
||||||
{
|
{
|
||||||
string path = "./Music";
|
Console.WriteLine("Unknown path " + path);
|
||||||
string FileName = Functions.GetArguments(message).ToArray().MergeStrings(0);
|
return;
|
||||||
path += "/" + FileName + ".mp3";
|
|
||||||
if (!File.Exists(path))
|
|
||||||
{
|
|
||||||
Console.WriteLine("Unknown path " + path);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Data.voiceChannel = (context.User as IGuildUser)?.VoiceChannel;
|
|
||||||
if (Data.voiceChannel == null) { await context.Channel.SendMessageAsync("User must be in a voice channel, or a voice channel must be passed as an argument."); return; }
|
|
||||||
|
|
||||||
Data.audioClient = await Data.voiceChannel.ConnectAsync();
|
|
||||||
|
|
||||||
using (var ffmpeg = CreateStream(path))
|
|
||||||
using (var output = ffmpeg.StandardOutput.BaseStream)
|
|
||||||
using (var discord = Data.audioClient.CreatePCMStream(AudioApplication.Mixed))
|
|
||||||
{
|
|
||||||
if (Data.CurrentlyRunning != null)
|
|
||||||
Data.CurrentlyRunning.Stop();
|
|
||||||
Data.CurrentlyRunning = new MusicPlayer(output, discord);
|
|
||||||
await Data.CurrentlyRunning.StartSendAudio();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Process CreateStream(string path)
|
|
||||||
|
Data.voiceChannel = (context.User as IGuildUser)?.VoiceChannel;
|
||||||
|
if (Data.voiceChannel == null)
|
||||||
{
|
{
|
||||||
return Process.Start(new ProcessStartInfo
|
await context.Channel.SendMessageAsync("User must be in a voice channel, or a voice channel must be passed as an argument.");
|
||||||
{
|
return;
|
||||||
FileName = "ffmpeg",
|
}
|
||||||
Arguments = $"-hide_banner -loglevel panic -i \"{path}\" -ac 2 -f s16le -ar 48000 pipe:1",
|
|
||||||
UseShellExecute = false,
|
Data.audioClient = await Data.voiceChannel.ConnectAsync();
|
||||||
RedirectStandardOutput = true,
|
|
||||||
});
|
using (var ffmpeg = CreateStream(path))
|
||||||
|
using (var output = ffmpeg.StandardOutput.BaseStream)
|
||||||
|
using (var discord = Data.audioClient.CreatePCMStream(AudioApplication.Mixed))
|
||||||
|
{
|
||||||
|
if (Data.CurrentlyRunning != null) Data.CurrentlyRunning.Stop();
|
||||||
|
Data.CurrentlyRunning = new MusicPlayer(output, discord);
|
||||||
|
await Data.CurrentlyRunning.StartSendAudio();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Process CreateStream(string path)
|
||||||
|
{
|
||||||
|
return Process.Start(new ProcessStartInfo { FileName = "ffmpeg", Arguments = $"-hide_banner -loglevel panic -i \"{path}\" -ac 2 -f s16le -ar 48000 pipe:1", UseShellExecute = false, RedirectStandardOutput = true });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +1,26 @@
|
|||||||
using CMD_Utils.Music;
|
using CMD_Utils.Music;
|
||||||
|
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
|
||||||
using PluginManager.Interfaces;
|
using PluginManager.Interfaces;
|
||||||
|
|
||||||
using System;
|
namespace MusicCommands;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace MusicCommands
|
internal class Unpause : DBCommand
|
||||||
{
|
{
|
||||||
class Unpause : DBCommand
|
public string Command => "unpause";
|
||||||
|
|
||||||
|
public string Description => "Unpause the music";
|
||||||
|
|
||||||
|
public string Usage => "unpause";
|
||||||
|
|
||||||
|
public bool canUseDM => false;
|
||||||
|
|
||||||
|
public bool canUseServer => true;
|
||||||
|
|
||||||
|
public bool requireAdmin => false;
|
||||||
|
|
||||||
|
public void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
||||||
{
|
{
|
||||||
public string Command => "unpause";
|
Data.CurrentlyRunning.Paused = false;
|
||||||
|
|
||||||
public string Description => "Unpause the music";
|
|
||||||
|
|
||||||
public string Usage => "unpause";
|
|
||||||
|
|
||||||
public bool canUseDM => false;
|
|
||||||
|
|
||||||
public bool canUseServer => true;
|
|
||||||
|
|
||||||
public bool requireAdmin => false;
|
|
||||||
|
|
||||||
public void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
|
||||||
{
|
|
||||||
Data.CurrentlyRunning.Paused = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,52 +1,50 @@
|
|||||||
using CMD_Utils.Music;
|
using CMD_Utils.Music;
|
||||||
|
using Discord;
|
||||||
using Discord.Audio;
|
using Discord.Audio;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
using Discord;
|
|
||||||
|
|
||||||
using PluginManager.Interfaces;
|
using PluginManager.Interfaces;
|
||||||
|
|
||||||
namespace MusicCommands
|
namespace MusicCommands;
|
||||||
|
|
||||||
|
internal class lplay : DBCommand
|
||||||
{
|
{
|
||||||
class lplay : DBCommand
|
public string Command => "lplay";
|
||||||
|
|
||||||
|
public string Description => "Play music from a link";
|
||||||
|
|
||||||
|
public string Usage => "lplay [url]";
|
||||||
|
|
||||||
|
public bool canUseDM => false;
|
||||||
|
|
||||||
|
public bool canUseServer => false;
|
||||||
|
|
||||||
|
public bool requireAdmin => false;
|
||||||
|
|
||||||
|
public async void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
||||||
{
|
{
|
||||||
public string Command => "lplay";
|
var URL = message.Content.Split(' ')[1];
|
||||||
|
if (!URL.EndsWith(".mp3") && !URL.EndsWith(".wav") && !URL.EndsWith(".flac") && !URL.EndsWith(".ogg"))
|
||||||
public string Description => "Play music from a link";
|
|
||||||
|
|
||||||
public string Usage => "lplay [url]";
|
|
||||||
|
|
||||||
public bool canUseDM => false;
|
|
||||||
|
|
||||||
public bool canUseServer => false;
|
|
||||||
|
|
||||||
public bool requireAdmin => false;
|
|
||||||
|
|
||||||
public async void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
|
||||||
{
|
{
|
||||||
string URL = message.Content.Split(' ')[1];
|
await message.Channel.SendMessageAsync("Invalid URL");
|
||||||
if (!URL.EndsWith(".mp3") && !URL.EndsWith(".wav") && !URL.EndsWith(".flac") && !URL.EndsWith(".ogg"))
|
return;
|
||||||
{
|
|
||||||
await message.Channel.SendMessageAsync("Invalid URL");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Data.voiceChannel = (context.User as IGuildUser)?.VoiceChannel;
|
|
||||||
if (Data.voiceChannel == null) { await context.Channel.SendMessageAsync("User must be in a voice channel, or a voice channel must be passed as an argument."); return; }
|
|
||||||
|
|
||||||
Data.audioClient = await Data.voiceChannel.ConnectAsync();
|
|
||||||
|
|
||||||
using (var discord = Data.audioClient.CreatePCMStream(AudioApplication.Mixed))
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
await message.Channel.SendMessageAsync("Loading...");
|
|
||||||
|
|
||||||
Data.CurrentlyRunning = new MusicPlayer(discord);
|
|
||||||
await Data.CurrentlyRunning.StartSendAudioFromLink(URL);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Data.voiceChannel = (context.User as IGuildUser)?.VoiceChannel;
|
||||||
|
if (Data.voiceChannel == null)
|
||||||
|
{
|
||||||
|
await context.Channel.SendMessageAsync("User must be in a voice channel, or a voice channel must be passed as an argument.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Data.audioClient = await Data.voiceChannel.ConnectAsync();
|
||||||
|
|
||||||
|
using (var discord = Data.audioClient.CreatePCMStream(AudioApplication.Mixed))
|
||||||
|
{
|
||||||
|
await message.Channel.SendMessageAsync("Loading...");
|
||||||
|
|
||||||
|
Data.CurrentlyRunning = new MusicPlayer(discord);
|
||||||
|
await Data.CurrentlyRunning.StartSendAudioFromLink(URL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace PluginManager
|
|||||||
|
|
||||||
public static class Config
|
public static class Config
|
||||||
{
|
{
|
||||||
private static AppConfig appConfig = null;
|
private static AppConfig appConfig;
|
||||||
|
|
||||||
public static bool AddValueToVariables<T>(string key, T value, bool isProtected)
|
public static bool AddValueToVariables<T>(string key, T value, bool isProtected)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,49 +1,51 @@
|
|||||||
namespace PluginManager.Interfaces
|
using Discord.Commands;
|
||||||
|
using Discord.WebSocket;
|
||||||
|
|
||||||
|
namespace PluginManager.Interfaces;
|
||||||
|
|
||||||
|
public interface DBCommand
|
||||||
{
|
{
|
||||||
public interface DBCommand
|
/// <summary>
|
||||||
{
|
/// Command to be executed
|
||||||
/// <summary>
|
/// It's CaSe SeNsItIvE
|
||||||
/// Command to be executed
|
/// </summary>
|
||||||
/// It's CaSe SeNsItIvE
|
string Command { get; }
|
||||||
/// </summary>
|
|
||||||
string Command { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Command description
|
/// Command description
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string Description { get; }
|
string Description { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The usage for your command.
|
/// The usage for your command.
|
||||||
/// It will be displayed when users type help
|
/// It will be displayed when users type help
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string Usage { get; }
|
string Usage { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// true if the command can be used in a DM channel, otherwise false
|
/// true if the command can be used in a DM channel, otherwise false
|
||||||
/// </summary>
|
/// </summary>
|
||||||
bool canUseDM { get; }
|
bool canUseDM { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// true if the command can be used in a server, otherwise false
|
/// true if the command can be used in a server, otherwise false
|
||||||
/// </summary>
|
/// </summary>
|
||||||
bool canUseServer { get; }
|
bool canUseServer { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// true if the command requre admin, otherwise false
|
/// true if the command requre admin, otherwise false
|
||||||
/// </summary>
|
/// </summary>
|
||||||
bool requireAdmin { get; }
|
bool requireAdmin { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main body of the command. This is what is executed when user calls the command
|
/// The main body of the command. This is what is executed when user calls the command
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="context">The disocrd Context</param>
|
/// <param name="context">The disocrd Context</param>
|
||||||
/// <param name="message">The message that the user types</param>
|
/// <param name="message">The message that the user types</param>
|
||||||
/// <param name="client">The discord client of the bot</param>
|
/// <param name="client">The discord client of the bot</param>
|
||||||
/// <param name="isDM">true if the message was sent from DM, otherwise false. It is always false if canUseDM is false</param>
|
/// <param name="isDM">true if the message was sent from DM, otherwise false. It is always false if canUseDM is false</param>
|
||||||
void Execute(Discord.Commands.SocketCommandContext context,
|
void Execute(SocketCommandContext context,
|
||||||
Discord.WebSocket.SocketMessage message,
|
SocketMessage message,
|
||||||
Discord.WebSocket.DiscordSocketClient client,
|
DiscordSocketClient client,
|
||||||
bool isDM);
|
bool isDM);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,23 +1,22 @@
|
|||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
|
||||||
namespace PluginManager.Interfaces
|
namespace PluginManager.Interfaces;
|
||||||
|
|
||||||
|
public interface DBEvent
|
||||||
{
|
{
|
||||||
public interface DBEvent
|
/// <summary>
|
||||||
{
|
/// The name of the event
|
||||||
/// <summary>
|
/// </summary>
|
||||||
/// The name of the event
|
string name { get; }
|
||||||
/// </summary>
|
|
||||||
string name { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The description of the event
|
/// The description of the event
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string description { get; }
|
string description { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The method that is invoked when the event is loaded into memory
|
/// The method that is invoked when the event is loaded into memory
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="client">The discord bot client</param>
|
/// <param name="client">The discord bot client</param>
|
||||||
void Start(DiscordSocketClient client);
|
void Start(DiscordSocketClient client);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,51 +1,44 @@
|
|||||||
using Discord.WebSocket;
|
using System.Collections.Generic;
|
||||||
|
using Discord.WebSocket;
|
||||||
using PluginManager.Loaders;
|
|
||||||
using PluginManager.Others;
|
using PluginManager.Others;
|
||||||
|
|
||||||
using System;
|
namespace PluginManager.Items;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace PluginManager.Items
|
internal class Command
|
||||||
{
|
{
|
||||||
internal class Command
|
/// <summary>
|
||||||
|
/// The author of the command
|
||||||
|
/// </summary>
|
||||||
|
public SocketUser? Author;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Command class contructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">The message that was sent</param>
|
||||||
|
public Command(SocketMessage message)
|
||||||
{
|
{
|
||||||
/// <summary>
|
Author = message.Author;
|
||||||
/// The author of the command
|
var data = message.Content.Split(' ');
|
||||||
/// </summary>
|
if (data.Length > 1)
|
||||||
public SocketUser? Author;
|
Arguments = new List<string>(data.MergeStrings(1).Split(' '));
|
||||||
|
else
|
||||||
/// <summary>
|
Arguments = new List<string>();
|
||||||
/// The list of arguments
|
CommandName = data[0].Substring(1);
|
||||||
/// </summary>
|
PrefixUsed = data[0][0];
|
||||||
public List<string> Arguments { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The command that is executed
|
|
||||||
/// </summary>
|
|
||||||
public string CommandName { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The prefix that is used for the command
|
|
||||||
/// </summary>
|
|
||||||
public char PrefixUsed { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The Command class contructor
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message">The message that was sent</param>
|
|
||||||
public Command(SocketMessage message)
|
|
||||||
{
|
|
||||||
this.Author = message.Author;
|
|
||||||
string[] data = message.Content.Split(' ');
|
|
||||||
if (data.Length > 1)
|
|
||||||
this.Arguments = new List<string>(data.MergeStrings(1).Split(' '));
|
|
||||||
else this.Arguments = new List<string>();
|
|
||||||
this.CommandName = data[0].Substring(1);
|
|
||||||
this.PrefixUsed = data[0][0];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The list of arguments
|
||||||
|
/// </summary>
|
||||||
|
public List<string> Arguments { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The command that is executed
|
||||||
|
/// </summary>
|
||||||
|
public string CommandName { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The prefix that is used for the command
|
||||||
|
/// </summary>
|
||||||
|
public char PrefixUsed { get; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,98 +1,89 @@
|
|||||||
using Discord.WebSocket;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Discord.WebSocket;
|
||||||
using PluginManager.Loaders;
|
using PluginManager.Loaders;
|
||||||
using PluginManager.Online;
|
using PluginManager.Online;
|
||||||
using PluginManager.Others;
|
using PluginManager.Others;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection.Metadata.Ecma335;
|
|
||||||
using Newtonsoft.Json.Converters;
|
|
||||||
|
|
||||||
namespace PluginManager.Items
|
namespace PluginManager.Items;
|
||||||
|
|
||||||
|
public class ConsoleCommandsHandler
|
||||||
{
|
{
|
||||||
public class ConsoleCommandsHandler
|
private static readonly PluginsManager manager = new("https://sethdiscordbot.000webhostapp.com/Storage/Discord%20Bot/Plugins");
|
||||||
|
|
||||||
|
public static List<Tuple<string, string, Action<string[]>>> commandList = new();
|
||||||
|
private readonly DiscordSocketClient? client;
|
||||||
|
|
||||||
|
public ConsoleCommandsHandler(DiscordSocketClient client)
|
||||||
{
|
{
|
||||||
private static PluginsManager manager = new("https://sethdiscordbot.000webhostapp.com/Storage/Discord%20Bot/Plugins");
|
this.client = client;
|
||||||
|
InitializeBasicCommands();
|
||||||
|
Console.WriteLine("Initalized console command handeler !");
|
||||||
|
}
|
||||||
|
|
||||||
public static List<Tuple<string, string, Action<string[]>>>? commandList = new List<Tuple<string, string, Action<string[]>>>();
|
private void InitializeBasicCommands()
|
||||||
private DiscordSocketClient client;
|
{
|
||||||
|
var pluginsLoaded = false;
|
||||||
|
commandList.Clear();
|
||||||
|
|
||||||
public ConsoleCommandsHandler(DiscordSocketClient client)
|
AddCommand("help", "Show help", args =>
|
||||||
{
|
|
||||||
this.client = client;
|
|
||||||
InitializeBasicCommands();
|
|
||||||
Console.WriteLine("Initalized console command handeler !");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void InitializeBasicCommands()
|
|
||||||
{
|
|
||||||
|
|
||||||
bool pluginsLoaded = false;
|
|
||||||
commandList.Clear();
|
|
||||||
|
|
||||||
AddCommand("help", "Show help", (args) =>
|
|
||||||
{
|
{
|
||||||
if (args.Length <= 1)
|
if (args.Length <= 1)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Available commands:");
|
Console.WriteLine("Available commands:");
|
||||||
foreach (var command in commandList)
|
foreach (var command in commandList) Console.WriteLine("\t" + command.Item1 + " - " + command.Item2);
|
||||||
{
|
|
||||||
Console.WriteLine("\t" + command.Item1 + " - " + command.Item2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach (var command in commandList)
|
foreach (var command in commandList)
|
||||||
{
|
|
||||||
if (command.Item1 == args[1])
|
if (command.Item1 == args[1])
|
||||||
{
|
{
|
||||||
Console.WriteLine(command.Item2);
|
Console.WriteLine(command.Item2);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Console.WriteLine("Command not found");
|
Console.WriteLine("Command not found");
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
AddCommand("lp", "Load plugins", () =>
|
AddCommand("lp", "Load plugins", () =>
|
||||||
{
|
{
|
||||||
if (pluginsLoaded) return;
|
if (pluginsLoaded) return;
|
||||||
var loader = new PluginLoader(client);
|
var loader = new PluginLoader(client);
|
||||||
loader.onCMDLoad += (name, typeName, success, exception) =>
|
loader.onCMDLoad += (name, typeName, success, exception) =>
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
if (name == null || name.Length < 2)
|
if (name == null || name.Length < 2) name = typeName;
|
||||||
name = typeName;
|
|
||||||
if (success)
|
if (success)
|
||||||
Console.WriteLine("[CMD] Successfully loaded command : " + name);
|
Console.WriteLine("[CMD] Successfully loaded command : " + name);
|
||||||
else
|
else
|
||||||
Console.WriteLine("[CMD] Failed to load command : " + name + " because " + exception.Message);
|
Console.WriteLine("[CMD] Failed to load command : " + name + " because " + exception!.Message);
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
};
|
};
|
||||||
loader.onEVELoad += (name, typeName, success, exception) =>
|
loader.onEVELoad += (name, typeName, success, exception) =>
|
||||||
{
|
{
|
||||||
if (name == null || name.Length < 2)
|
if (name == null || name.Length < 2) name = typeName;
|
||||||
name = typeName;
|
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
if (success)
|
if (success)
|
||||||
Console.WriteLine("[EVENT] Successfully loaded event : " + name);
|
Console.WriteLine("[EVENT] Successfully loaded event : " + name);
|
||||||
else
|
else
|
||||||
Console.WriteLine("[EVENT] Failed to load event : " + name + " because " + exception.Message);
|
Console.WriteLine("[EVENT] Failed to load event : " + name + " because " + exception!.Message);
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
};
|
};
|
||||||
loader.LoadPlugins();
|
loader.LoadPlugins();
|
||||||
pluginsLoaded = true;
|
pluginsLoaded = true;
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
AddCommand("listplugs", "list available plugins", async () =>
|
AddCommand("listplugs", "list available plugins", async () => { await manager.ListAvailablePlugins(); });
|
||||||
{
|
|
||||||
await manager.ListAvailablePlugins();
|
|
||||||
});
|
|
||||||
|
|
||||||
AddCommand("dwplug", "download plugin", async (args) =>
|
AddCommand("dwplug", "download plugin", async args =>
|
||||||
{
|
{
|
||||||
if (args.Length == 1)
|
if (args.Length == 1)
|
||||||
{
|
{
|
||||||
@@ -100,27 +91,30 @@ namespace PluginManager.Items
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string name = args.MergeStrings(1);
|
var name = args.MergeStrings(1);
|
||||||
// info[0] = plugin type
|
// info[0] = plugin type
|
||||||
// info[1] = plugin link
|
// info[1] = plugin link
|
||||||
// info[2] = if others are required, or string.Empty if none
|
// info[2] = if others are required, or string.Empty if none
|
||||||
string[] info = await manager.GetPluginLinkByName(name);
|
var info = await manager.GetPluginLinkByName(name);
|
||||||
if (info[1] == null) // link is null
|
if (info[1] == null) // link is null
|
||||||
{
|
{
|
||||||
if (name == "")
|
if (name == "")
|
||||||
{
|
{
|
||||||
Console_Utilities.WriteColorText($"Name is invalid");
|
Console_Utilities.WriteColorText("Name is invalid");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Console_Utilities.WriteColorText($"Failed to find plugin &b{name} &c!" +
|
|
||||||
$" Use &glistplugs &ccommand to display all available plugins !");
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
Console_Utilities.WriteColorText($"Failed to find plugin &b{name} &c!" +
|
||||||
|
" Use &glistplugs &ccommand to display all available plugins !"
|
||||||
|
);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string path;
|
string path;
|
||||||
if (info[0] == "Command" || info[0] == "Event")
|
if (info[0] == "Command" || info[0] == "Event")
|
||||||
path = "./Data/Plugins/" + info[0] + "s/" + name + ".dll";
|
path = "./Data/Plugins/" + info[0] + "s/" + name + ".dll";
|
||||||
else path = $"./{info[1].Split('/')[info[1].Split('/').Length - 1]}";
|
else
|
||||||
|
path = $"./{info[1].Split('/')[info[1].Split('/').Length - 1]}";
|
||||||
await ServerCom.DownloadFileAsync(info[1], path);
|
await ServerCom.DownloadFileAsync(info[1], path);
|
||||||
Console.WriteLine("\n");
|
Console.WriteLine("\n");
|
||||||
|
|
||||||
@@ -130,47 +124,41 @@ namespace PluginManager.Items
|
|||||||
{
|
{
|
||||||
Console.WriteLine($"Downloading requirements for plugin : {name}");
|
Console.WriteLine($"Downloading requirements for plugin : {name}");
|
||||||
|
|
||||||
List<string> lines = await ServerCom.ReadTextFromFile(info[2]);
|
var lines = await ServerCom.ReadTextFromFile(info[2]);
|
||||||
|
|
||||||
foreach (var line in lines)
|
foreach (var line in lines)
|
||||||
{
|
{
|
||||||
string[] split = line.Split(',');
|
var split = line.Split(',');
|
||||||
Console.WriteLine($"\nDownloading item: {split[1]}");
|
Console.WriteLine($"\nDownloading item: {split[1]}");
|
||||||
await ServerCom.DownloadFileAsync(split[0], "./" + split[1]);
|
await ServerCom.DownloadFileAsync(split[0], "./" + split[1]);
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
|
|
||||||
if (split[0].EndsWith(".zip"))
|
if (split[0].EndsWith(".zip"))
|
||||||
{
|
{
|
||||||
|
|
||||||
Console.WriteLine($"Extracting {split[1]}");
|
Console.WriteLine($"Extracting {split[1]}");
|
||||||
double proc = 0d;
|
var proc = 0d;
|
||||||
bool isExtracting = true;
|
var isExtracting = true;
|
||||||
Console_Utilities.ProgressBar bar = new Console_Utilities.ProgressBar(100, "");
|
var bar = new Console_Utilities.ProgressBar { Max = 100, Color = ConsoleColor.Green };
|
||||||
|
|
||||||
IProgress<float> extractProgress = new Progress<float>(value =>
|
IProgress<float> extractProgress = new Progress<float>(value => { proc = value; });
|
||||||
{
|
|
||||||
proc = value;
|
|
||||||
});
|
|
||||||
new Thread(new Task(() =>
|
new Thread(new Task(() =>
|
||||||
{
|
{
|
||||||
while (isExtracting)
|
while (isExtracting)
|
||||||
{
|
{
|
||||||
bar.Update((int)proc);
|
bar.Update((int)proc);
|
||||||
if (proc >= 99.9f)
|
if (proc >= 99.9f) break;
|
||||||
break;
|
Thread.Sleep(500);
|
||||||
Thread.Sleep(500);
|
}
|
||||||
}
|
}
|
||||||
}).Start).Start();
|
).Start
|
||||||
|
).Start();
|
||||||
await Functions.ExtractArchive("./" + split[1], "./", extractProgress);
|
await Functions.ExtractArchive("./" + split[1], "./", extractProgress);
|
||||||
bar.Update(100);
|
bar.Update(100);
|
||||||
isExtracting = false;
|
isExtracting = false;
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000);
|
||||||
bar.Update(100);
|
bar.Update(100);
|
||||||
Console.WriteLine("\n");
|
Console.WriteLine("\n");
|
||||||
System.IO.File.Delete("./" + split[1]);
|
File.Delete("./" + split[1]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name == "DBUI")
|
if (name == "DBUI")
|
||||||
@@ -183,121 +171,122 @@ namespace PluginManager.Items
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
|
|
||||||
AddCommand("value", "read value from VariableStack", (args) =>
|
AddCommand("value", "read value from VariableStack", args =>
|
||||||
{
|
|
||||||
if (args.Length != 2) return;
|
|
||||||
if (!Config.ContainsKey(args[1])) return;
|
|
||||||
|
|
||||||
string data = Config.GetValue<string>(args[1]);
|
|
||||||
Console.WriteLine($"{args[1]} => {data}");
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
AddCommand("add", "add variable to the system variables\nadd [key] [value] [isReadOnly=true/false]", async (args) =>
|
|
||||||
{
|
|
||||||
if (args.Length < 4) return;
|
|
||||||
string key = args[1];
|
|
||||||
string value = args[2];
|
|
||||||
bool isReadOnly = args[3].Equals("true", StringComparison.CurrentCultureIgnoreCase);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (Config.ContainsKey(key)) return;
|
|
||||||
if (int.TryParse(value, out int intValue))
|
|
||||||
Config.AddValueToVariables(key, intValue, isReadOnly);
|
|
||||||
else if (bool.TryParse(value, out bool boolValue))
|
|
||||||
Config.AddValueToVariables(key, boolValue, isReadOnly);
|
|
||||||
else if (float.TryParse(value, out float floatValue))
|
|
||||||
Config.AddValueToVariables(key, floatValue, isReadOnly);
|
|
||||||
else if (double.TryParse(value, out double doubleValue))
|
|
||||||
Config.AddValueToVariables(key, doubleValue, isReadOnly);
|
|
||||||
else if (uint.TryParse(value, out uint uintValue))
|
|
||||||
Config.AddValueToVariables(key, uintValue, isReadOnly);
|
|
||||||
else if (long.TryParse(value, out long longValue))
|
|
||||||
Config.AddValueToVariables(key, longValue, isReadOnly);
|
|
||||||
else if (byte.TryParse(value, out byte byteValue))
|
|
||||||
Config.AddValueToVariables(key, byteValue, isReadOnly);
|
|
||||||
else
|
|
||||||
Config.AddValueToVariables(key, value, isReadOnly);
|
|
||||||
Console.WriteLine($"Updated config file with the following command: {args[1]} => {value}");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine(ex.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
AddCommand("remv", "remove variable from system variables", (args) =>
|
|
||||||
{
|
|
||||||
if (args.Length < 2) return;
|
|
||||||
Config.RemoveKey(args[1]);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
AddCommand("vars", "Display all variables", () =>
|
|
||||||
{
|
|
||||||
var d = Config.GetAllVariables();
|
|
||||||
List<string[]> data = new List<string[]>();
|
|
||||||
data.Add(new string[] { "-", "-" });
|
|
||||||
data.Add(new string[] { "Key", "Value" });
|
|
||||||
data.Add(new string[] { "-", "-" });
|
|
||||||
foreach (var kvp in d) data.Add(new string[] { kvp.Key, kvp.Value.ToString() });
|
|
||||||
data.Add(new string[] { "-", "-" });
|
|
||||||
Console_Utilities.FormatAndAlignTable(data);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
AddCommand("sd", "Shuts down the discord bot", async () =>
|
|
||||||
{
|
|
||||||
await client.StopAsync();
|
|
||||||
await client.DisposeAsync();
|
|
||||||
Config.SaveConfig();
|
|
||||||
Environment.Exit(0);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AddCommand(string command, string description, Action<string[]> action)
|
|
||||||
{
|
|
||||||
commandList.Add(new Tuple<string, string, Action<string[]>>(command, description, action));
|
|
||||||
Console.ForegroundColor = ConsoleColor.White;
|
|
||||||
Console_Utilities.WriteColorText($"Command &r{command} &cadded to the list of commands");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AddCommand(string command, string description, Action action)
|
|
||||||
{
|
|
||||||
AddCommand(command, description, (args) => action());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemoveCommand(string command)
|
|
||||||
{
|
|
||||||
commandList.RemoveAll(x => x.Item1 == command);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Tuple<string, string, Action<string[]>>? SearchCommand(string command)
|
|
||||||
{
|
|
||||||
return commandList.FirstOrDefault(t => t.Item1 == command);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void HandleCommand(string command)
|
|
||||||
{
|
|
||||||
string[] args = command.Split(' ');
|
|
||||||
foreach (var item in commandList.ToList())
|
|
||||||
{
|
{
|
||||||
if (item.Item1 == args[0])
|
if (args.Length != 2) return;
|
||||||
|
if (!Config.ContainsKey(args[1])) return;
|
||||||
|
|
||||||
|
var data = Config.GetValue<string>(args[1]);
|
||||||
|
Console.WriteLine($"{args[1]} => {data}");
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
AddCommand("add", "add variable to the system variables\nadd [key] [value] [isReadOnly=true/false]", async args =>
|
||||||
|
{
|
||||||
|
if (args.Length < 4) return;
|
||||||
|
var key = args[1];
|
||||||
|
var value = args[2];
|
||||||
|
var isReadOnly = args[3].Equals("true", StringComparison.CurrentCultureIgnoreCase);
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
item.Item3(args);
|
if (Config.ContainsKey(key)) return;
|
||||||
//Console.WriteLine($"Executing: {args[0]} with the following parameters: {args.MergeStrings(1)}");
|
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}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
);
|
||||||
|
|
||||||
|
AddCommand("remv", "remove variable from system variables", args =>
|
||||||
|
{
|
||||||
|
if (args.Length < 2) return;
|
||||||
|
Config.RemoveKey(args[1]);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
AddCommand("vars", "Display all variables", () =>
|
||||||
|
{
|
||||||
|
var d = Config.GetAllVariables();
|
||||||
|
var data = new List<string[]>();
|
||||||
|
data.Add(new[] { "-", "-" });
|
||||||
|
data.Add(new[] { "Key", "Value" });
|
||||||
|
data.Add(new[] { "-", "-" });
|
||||||
|
foreach (var kvp in d) data.Add(new[] { kvp.Key, kvp.Value.ToString() });
|
||||||
|
data.Add(new[] { "-", "-" });
|
||||||
|
Console_Utilities.FormatAndAlignTable(data);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
AddCommand("sd", "Shuts down the discord bot", async () =>
|
||||||
|
{
|
||||||
|
if (client is null) return;
|
||||||
|
await client.StopAsync();
|
||||||
|
await client.DisposeAsync();
|
||||||
|
Config.SaveConfig();
|
||||||
|
Environment.Exit(0);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddCommand(string command, string description, Action<string[]> action)
|
||||||
|
{
|
||||||
|
commandList.Add(new Tuple<string, string, Action<string[]>>(command, description, action));
|
||||||
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
|
Console_Utilities.WriteColorText($"Command &r{command} &cadded to the list of commands");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddCommand(string command, string description, Action action)
|
||||||
|
{
|
||||||
|
AddCommand(command, description, args => action());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemoveCommand(string command)
|
||||||
|
{
|
||||||
|
commandList.RemoveAll(x => x.Item1 == command);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool CommandExists(string command)
|
||||||
|
{
|
||||||
|
return !(GetCommand(command) is null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Tuple<string, string, Action<string[]>>? GetCommand(string command)
|
||||||
|
{
|
||||||
|
return commandList.FirstOrDefault(t => t.Item1 == command);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void HandleCommand(string command)
|
||||||
|
{
|
||||||
|
var args = command.Split(' ');
|
||||||
|
foreach (var item in commandList.ToList())
|
||||||
|
if (item.Item1 == args[0])
|
||||||
|
item.Item3(args);
|
||||||
|
//Console.WriteLine($"Executing: {args[0]} with the following parameters: {args.MergeStrings(1)}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,54 +1,62 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using PluginManager.Others.Exceptions;
|
||||||
|
|
||||||
namespace PluginManager.Items
|
namespace PluginManager.Items;
|
||||||
|
|
||||||
|
public class Spinner
|
||||||
{
|
{
|
||||||
public class Spinner
|
/// <summary>
|
||||||
|
/// True if active, false otherwise
|
||||||
|
/// </summary>
|
||||||
|
public bool isSpinning;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Spinner constructor
|
||||||
|
/// </summary>
|
||||||
|
public Spinner()
|
||||||
{
|
{
|
||||||
/// <summary>
|
isSpinning = false;
|
||||||
/// True if active, false otherwise
|
}
|
||||||
/// </summary>
|
|
||||||
public bool isSpinning;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Spinner constructor
|
/// The method that is called to start spinning the spinner
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Spinner()
|
public async void Start()
|
||||||
|
{
|
||||||
|
isSpinning = true;
|
||||||
|
var cnt = 0;
|
||||||
|
|
||||||
|
while (isSpinning)
|
||||||
{
|
{
|
||||||
isSpinning = false;
|
cnt++;
|
||||||
}
|
switch (cnt % 4)
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The method that is called to start spinning the spinner
|
|
||||||
/// </summary>
|
|
||||||
public async void Start()
|
|
||||||
{
|
|
||||||
isSpinning = true;
|
|
||||||
int cnt = 0;
|
|
||||||
|
|
||||||
while (isSpinning)
|
|
||||||
{
|
{
|
||||||
cnt++;
|
case 0:
|
||||||
switch (cnt % 4)
|
Console.Write("/");
|
||||||
{
|
break;
|
||||||
case 0: Console.Write("/"); break;
|
case 1:
|
||||||
case 1: Console.Write("-"); break;
|
Console.Write("-");
|
||||||
case 2: Console.Write("\\"); break;
|
break;
|
||||||
case 3: Console.Write("|"); break;
|
case 2:
|
||||||
}
|
Console.Write("\\");
|
||||||
Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
|
break;
|
||||||
await Task.Delay(250);
|
case 3:
|
||||||
|
Console.Write("|");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
|
||||||
/// The method that is called to stop the spinner from spinning
|
await Task.Delay(250);
|
||||||
/// </summary>
|
|
||||||
public void Stop()
|
|
||||||
{
|
|
||||||
if (!isSpinning)
|
|
||||||
throw new Others.Exceptions.APIException("Spinner was not spinning", GetType());
|
|
||||||
isSpinning = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The method that is called to stop the spinner from spinning
|
||||||
|
/// </summary>
|
||||||
|
public void Stop()
|
||||||
|
{
|
||||||
|
if (!isSpinning) throw new APIException("Spinner was not spinning", GetType());
|
||||||
|
isSpinning = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -3,116 +3,105 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using PluginManager.Interfaces;
|
|
||||||
using PluginManager.Others;
|
using PluginManager.Others;
|
||||||
|
|
||||||
namespace PluginManager.Loaders
|
namespace PluginManager.Loaders;
|
||||||
|
|
||||||
|
internal class LoaderArgs : EventArgs
|
||||||
{
|
{
|
||||||
internal class LoaderArgs : EventArgs
|
internal string? PluginName { get; init; }
|
||||||
{
|
internal string? TypeName { get; init; }
|
||||||
internal string? PluginName { get; init; }
|
internal bool IsLoaded { get; init; }
|
||||||
internal string? TypeName { get; init; }
|
internal Exception? Exception { get; init; }
|
||||||
internal bool IsLoaded { get; init; }
|
internal object? Plugin { get; init; }
|
||||||
internal Exception? Exception { get; init; }
|
}
|
||||||
internal object? Plugin { get; init; }
|
|
||||||
}
|
internal class Loader<T>
|
||||||
|
{
|
||||||
internal class Loader<T>
|
internal Loader(string path, string extension)
|
||||||
{
|
{
|
||||||
internal delegate void FileLoadedEventHandler(LoaderArgs args);
|
this.path = path;
|
||||||
|
this.extension = extension;
|
||||||
internal event FileLoadedEventHandler? FileLoaded;
|
}
|
||||||
|
|
||||||
internal delegate void PluginLoadedEventHandler(LoaderArgs args);
|
|
||||||
|
private string path { get; }
|
||||||
internal event PluginLoadedEventHandler? PluginLoaded;
|
private string extension { get; }
|
||||||
|
|
||||||
|
internal event FileLoadedEventHandler? FileLoaded;
|
||||||
private string path { get; }
|
|
||||||
private string extension { get; }
|
internal event PluginLoadedEventHandler? PluginLoaded;
|
||||||
|
|
||||||
|
internal List<T>? Load()
|
||||||
internal Loader(string path, string extension)
|
{
|
||||||
{
|
var list = new List<T>();
|
||||||
this.path = path;
|
if (!Directory.Exists(path))
|
||||||
this.extension = extension;
|
{
|
||||||
}
|
Directory.CreateDirectory(path);
|
||||||
|
return null;
|
||||||
internal List<T>? Load()
|
}
|
||||||
{
|
|
||||||
List<T> list = new List<T>();
|
var files = Directory.GetFiles(path, $"*.{extension}", SearchOption.AllDirectories);
|
||||||
if (!Directory.Exists(path))
|
foreach (var file in files)
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(path);
|
Assembly.LoadFrom(file);
|
||||||
return null;
|
if (FileLoaded != null)
|
||||||
}
|
{
|
||||||
|
var args = new LoaderArgs
|
||||||
string[] files = Directory.GetFiles(path, $"*.{extension}", SearchOption.AllDirectories);
|
{
|
||||||
foreach (var file in files)
|
Exception = null,
|
||||||
{
|
TypeName = nameof(T),
|
||||||
Assembly.LoadFrom(file);
|
IsLoaded = false,
|
||||||
if (FileLoaded != null)
|
PluginName = file,
|
||||||
{
|
Plugin = null
|
||||||
LoaderArgs args = new LoaderArgs()
|
};
|
||||||
{
|
FileLoaded.Invoke(args);
|
||||||
Exception = null,
|
}
|
||||||
TypeName = nameof(T),
|
}
|
||||||
IsLoaded = false,
|
|
||||||
PluginName = file,
|
try
|
||||||
Plugin = null
|
{
|
||||||
};
|
var interfaceType = typeof(T);
|
||||||
FileLoaded.Invoke(args);
|
var types = AppDomain.CurrentDomain.GetAssemblies()
|
||||||
}
|
.SelectMany(a => a.GetTypes())
|
||||||
}
|
.Where(p => interfaceType.IsAssignableFrom(p) && p.IsClass)
|
||||||
|
.ToArray();
|
||||||
try
|
|
||||||
{
|
|
||||||
Type interfaceType = typeof(T);
|
list.Clear();
|
||||||
Type[] types = AppDomain.CurrentDomain.GetAssemblies()
|
foreach (var type in types)
|
||||||
.SelectMany(a => a.GetTypes())
|
try
|
||||||
.Where(p => interfaceType.IsAssignableFrom(p) && p.IsClass)
|
{
|
||||||
.ToArray();
|
var plugin = (T)Activator.CreateInstance(type)!;
|
||||||
|
list.Add(plugin);
|
||||||
|
|
||||||
list.Clear();
|
|
||||||
foreach (Type type in types)
|
if (PluginLoaded != null)
|
||||||
{
|
PluginLoaded.Invoke(new LoaderArgs
|
||||||
try
|
{
|
||||||
{
|
Exception = null,
|
||||||
T plugin = (T)(Activator.CreateInstance(type)!);
|
IsLoaded = true,
|
||||||
list.Add(plugin);
|
PluginName = type.FullName,
|
||||||
|
TypeName = nameof(T),
|
||||||
|
Plugin = plugin
|
||||||
if (PluginLoaded != null)
|
}
|
||||||
{
|
);
|
||||||
PluginLoaded.Invoke(new()
|
}
|
||||||
{
|
catch (Exception ex)
|
||||||
Exception = null,
|
{
|
||||||
IsLoaded = true,
|
if (PluginLoaded != null) PluginLoaded.Invoke(new LoaderArgs { Exception = ex, IsLoaded = false, PluginName = type.FullName, TypeName = nameof(T) });
|
||||||
PluginName = type.FullName,
|
}
|
||||||
TypeName = nameof(T),
|
}
|
||||||
Plugin = plugin
|
catch (Exception ex)
|
||||||
}
|
{
|
||||||
);
|
Functions.WriteErrFile(ex.ToString());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
return list;
|
||||||
if (PluginLoaded != null)
|
}
|
||||||
{
|
|
||||||
PluginLoaded.Invoke(new() { Exception = ex, IsLoaded = false, PluginName = type.FullName, TypeName = nameof(T) });
|
internal delegate void FileLoadedEventHandler(LoaderArgs args);
|
||||||
}
|
|
||||||
}
|
internal delegate void PluginLoadedEventHandler(LoaderArgs args);
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Functions.WriteErrFile(ex.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,97 +1,97 @@
|
|||||||
using Discord.WebSocket;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Discord.WebSocket;
|
||||||
using PluginManager.Interfaces;
|
using PluginManager.Interfaces;
|
||||||
using PluginManager.Others;
|
using PluginManager.Others;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace PluginManager.Loaders
|
namespace PluginManager.Loaders;
|
||||||
|
|
||||||
|
public class PluginLoader
|
||||||
{
|
{
|
||||||
public class PluginLoader
|
public delegate void CMDLoaded(string name, string typeName, bool success, Exception? e = null);
|
||||||
|
|
||||||
|
public delegate void EVELoaded(string name, string typeName, bool success, Exception? e = null);
|
||||||
|
|
||||||
|
private const string pluginCMDFolder = @"./Data/Plugins/Commands/";
|
||||||
|
private const string pluginEVEFolder = @"./Data/Plugins/Events/";
|
||||||
|
|
||||||
|
private const string pluginCMDExtension = "dll";
|
||||||
|
private const string pluginEVEExtension = "dll";
|
||||||
|
private readonly DiscordSocketClient _client;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event that is fired when a <see cref="DBCommand" /> is successfully loaded into commands list
|
||||||
|
/// </summary>
|
||||||
|
public CMDLoaded? onCMDLoad;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event that is fired when a <see cref="DBEvent" /> is successfully loaded into events list
|
||||||
|
/// </summary>
|
||||||
|
public EVELoaded? onEVELoad;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Plugin Loader constructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="discordSocketClient">The discord bot client where the plugins will pe attached to</param>
|
||||||
|
public PluginLoader(DiscordSocketClient discordSocketClient)
|
||||||
{
|
{
|
||||||
private readonly DiscordSocketClient _client;
|
_client = discordSocketClient;
|
||||||
|
}
|
||||||
/// <summary>
|
|
||||||
/// The Plugin Loader constructor
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="discordSocketClient">The discord bot client where the plugins will pe attached to</param>
|
|
||||||
public PluginLoader(DiscordSocketClient discordSocketClient) { this._client = discordSocketClient; }
|
|
||||||
|
|
||||||
private const string pluginCMDFolder = @"./Data/Plugins/Commands/";
|
|
||||||
private const string pluginEVEFolder = @"./Data/Plugins/Events/";
|
|
||||||
|
|
||||||
private const string pluginCMDExtension = "dll";
|
|
||||||
private const string pluginEVEExtension = "dll";
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A list of <see cref="DBCommand"/> commands
|
/// A list of <see cref="DBCommand" /> commands
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static List<DBCommand>? Commands { get; set; }
|
public static List<DBCommand>? Commands { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A list of <see cref="DBEvent"/> commands
|
/// A list of <see cref="DBEvent" /> commands
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static List<DBEvent>? Events { get; set; }
|
public static List<DBEvent>? Events { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The main mathod that is called to load all events
|
||||||
|
/// </summary>
|
||||||
|
public void LoadPlugins()
|
||||||
|
{
|
||||||
|
Commands = new List<DBCommand>();
|
||||||
|
Events = new List<DBEvent>();
|
||||||
|
|
||||||
public delegate void CMDLoaded(string name, string typeName, bool success, Exception? e = null);
|
Functions.WriteLogFile("Starting plugin loader ... Client: " + _client.CurrentUser.Username);
|
||||||
|
Console.WriteLine("Loading plugins");
|
||||||
|
|
||||||
public delegate void EVELoaded(string name, string typeName, bool success, Exception? e = null);
|
var commandsLoader = new Loader<DBCommand>(pluginCMDFolder, pluginCMDExtension);
|
||||||
|
var eventsLoader = new Loader<DBEvent>(pluginEVEFolder, pluginEVEExtension);
|
||||||
|
|
||||||
/// <summary>
|
commandsLoader.FileLoaded += OnCommandFileLoaded;
|
||||||
/// Event that is fired when a <see cref="DBCommand"/> is successfully loaded into commands list
|
commandsLoader.PluginLoaded += OnCommandLoaded;
|
||||||
/// </summary>
|
|
||||||
public CMDLoaded? onCMDLoad;
|
|
||||||
|
|
||||||
/// <summary>
|
eventsLoader.FileLoaded += EventFileLoaded;
|
||||||
/// Event that is fired when a <see cref="DBEvent"/> is successfully loaded into events list
|
eventsLoader.PluginLoaded += OnEventLoaded;
|
||||||
/// </summary>
|
|
||||||
public EVELoaded? onEVELoad;
|
|
||||||
|
|
||||||
/// <summary>
|
Commands = commandsLoader.Load();
|
||||||
/// The main mathod that is called to load all events
|
Events = eventsLoader.Load();
|
||||||
/// </summary>
|
}
|
||||||
public void LoadPlugins()
|
|
||||||
{
|
|
||||||
Commands = new List<DBCommand>();
|
|
||||||
Events = new List<DBEvent>();
|
|
||||||
|
|
||||||
Functions.WriteLogFile("Starting plugin loader ... Client: " + _client.CurrentUser.Username);
|
private void EventFileLoaded(LoaderArgs e)
|
||||||
Console.WriteLine("Loading plugins");
|
{
|
||||||
|
if (e.IsLoaded) Functions.WriteLogFile($"[EVENT] Event from file [{e.PluginName}] has been successfully created !");
|
||||||
|
}
|
||||||
|
|
||||||
Loader<DBCommand> commandsLoader = new Loader<DBCommand>(pluginCMDFolder, pluginCMDExtension);
|
private void OnCommandFileLoaded(LoaderArgs e)
|
||||||
Loader<DBEvent> eventsLoader = new Loader<DBEvent>(pluginEVEFolder, pluginEVEExtension);
|
{
|
||||||
|
if (e.IsLoaded) Functions.WriteLogFile($"[CMD] Command from file [{e.PluginName}] has been successfully loaded !");
|
||||||
|
}
|
||||||
|
|
||||||
commandsLoader.FileLoaded += OnCommandFileLoaded;
|
private void OnEventLoaded(LoaderArgs e)
|
||||||
commandsLoader.PluginLoaded += OnCommandLoaded;
|
{
|
||||||
|
if (e.IsLoaded) ((DBEvent)e.Plugin!).Start(_client);
|
||||||
|
|
||||||
eventsLoader.FileLoaded += EventFileLoaded;
|
if (onEVELoad != null) onEVELoad.Invoke(((DBEvent)e.Plugin!).name, e.TypeName!, e.IsLoaded, e.Exception);
|
||||||
eventsLoader.PluginLoaded += OnEventLoaded;
|
}
|
||||||
|
|
||||||
Commands = commandsLoader.Load();
|
private void OnCommandLoaded(LoaderArgs e)
|
||||||
Events = eventsLoader.Load();
|
{
|
||||||
}
|
if (onCMDLoad != null) onCMDLoad.Invoke(((DBCommand)e.Plugin!).Command, e.TypeName!, e.IsLoaded, e.Exception);
|
||||||
|
|
||||||
private void EventFileLoaded(LoaderArgs e)
|
|
||||||
{
|
|
||||||
if (e.IsLoaded) Functions.WriteLogFile($"[EVENT] Event from file [{e.PluginName}] has been successfully created !");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnCommandFileLoaded(LoaderArgs e)
|
|
||||||
{
|
|
||||||
if (e.IsLoaded) Functions.WriteLogFile($"[CMD] Command from file [{e.PluginName}] has been successfully loaded !");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnEventLoaded(LoaderArgs e)
|
|
||||||
{
|
|
||||||
if (e.IsLoaded) { ((DBEvent)e.Plugin!).Start(_client); }
|
|
||||||
|
|
||||||
if (onEVELoad != null) onEVELoad.Invoke(((DBEvent)e.Plugin!).name, e.TypeName!, e.IsLoaded, e.Exception);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnCommandLoaded(LoaderArgs e)
|
|
||||||
{
|
|
||||||
if (onCMDLoad != null) onCMDLoad.Invoke(((DBCommand)e.Plugin!).Command, e.TypeName!, e.IsLoaded, e.Exception);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,86 +1,82 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Net;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using PluginManager.Others;
|
using PluginManager.Others;
|
||||||
|
|
||||||
namespace PluginManager.Online
|
namespace PluginManager.Online;
|
||||||
|
|
||||||
|
public class LanguageManager
|
||||||
{
|
{
|
||||||
public class LanguageManager
|
private readonly string link;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Language Manager constructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="link">The link to where all the languages for the bot are stored</param>
|
||||||
|
public LanguageManager(string link)
|
||||||
{
|
{
|
||||||
private string link;
|
this.link = link;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Language Manager constructor
|
/// The method to list all languages
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="link">The link to where all the languages for the bot are stored</param>
|
/// <returns></returns>
|
||||||
public LanguageManager(string link) => this.link = link;
|
public async Task ListAllLanguages()
|
||||||
|
{
|
||||||
/// <summary>
|
try
|
||||||
/// The method to list all languages
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task ListAllLanguages()
|
|
||||||
{
|
{
|
||||||
|
var list = await ServerCom.ReadTextFromFile(link);
|
||||||
|
var lines = list.ToArray();
|
||||||
|
|
||||||
try
|
var info = new List<string[]>();
|
||||||
|
info.Add(new[] { "-", "-" });
|
||||||
|
info.Add(new[] { "Language Name", "File Size" });
|
||||||
|
info.Add(new[] { "-", "-" });
|
||||||
|
foreach (var line in lines)
|
||||||
{
|
{
|
||||||
List<string> list = await ServerCom.ReadTextFromFile(link);
|
if (line.Length <= 2) continue;
|
||||||
string[] lines = list.ToArray();
|
var d = line.Split(',');
|
||||||
|
if (d[3].Contains("cp") || d[3].Contains("CrossPlatform")) info.Add(new[] { d[0], d[1] });
|
||||||
List<string[]> info = new List<string[]>();
|
|
||||||
info.Add(new string[] { "-", "-" });
|
|
||||||
info.Add(new string[] { "Language Name", "File Size" });
|
|
||||||
info.Add(new string[] { "-", "-" });
|
|
||||||
foreach (var line in lines)
|
|
||||||
{
|
|
||||||
if (line.Length <= 2) continue;
|
|
||||||
string[] d = line.Split(',');
|
|
||||||
if (d[3].Contains("cp") || d[3].Contains("CrossPlatform"))
|
|
||||||
info.Add(new string[] { d[0], d[1] });
|
|
||||||
}
|
|
||||||
info.Add(new string[] { "-", "-" });
|
|
||||||
Console_Utilities.FormatAndAlignTable(info);
|
|
||||||
}
|
|
||||||
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Failed to execute command: listlang\nReason: " + exception.Message);
|
|
||||||
Others.Functions.WriteErrFile(exception.ToString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
info.Add(new[] { "-", "-" });
|
||||||
|
Console_Utilities.FormatAndAlignTable(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
catch (Exception exception)
|
||||||
/// A function that gets the download link for specified language
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="langName">The name of the language</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task<string[]?> GetDownloadLink(string langName)
|
|
||||||
{
|
{
|
||||||
try
|
Console.WriteLine("Failed to execute command: listlang\nReason: " + exception.Message);
|
||||||
{
|
Functions.WriteErrFile(exception.ToString());
|
||||||
List<string> list = await ServerCom.ReadTextFromFile(link);
|
|
||||||
string[] lines = list.ToArray();
|
|
||||||
|
|
||||||
foreach (var line in lines)
|
|
||||||
{
|
|
||||||
if (line.Length <= 2) continue;
|
|
||||||
string[] d = line.Split(',');
|
|
||||||
if (d[0].Equals(langName) && (d[3].Contains("cp") || d[3].Contains("CrossPlatform")))
|
|
||||||
return new string[] { d[2], d[3] };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Failed to execute command: listlang\nReason: " + exception.Message);
|
|
||||||
Others.Functions.WriteErrFile(exception.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A function that gets the download link for specified language
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="langName">The name of the language</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<string[]?> GetDownloadLink(string langName)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = await ServerCom.ReadTextFromFile(link);
|
||||||
|
var lines = list.ToArray();
|
||||||
|
|
||||||
|
foreach (var line in lines)
|
||||||
|
{
|
||||||
|
if (line.Length <= 2) continue;
|
||||||
|
var d = line.Split(',');
|
||||||
|
if (d[0].Equals(langName) && (d[3].Contains("cp") || d[3].Contains("CrossPlatform"))) return new[] { d[2], d[3] };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Failed to execute command: listlang\nReason: " + exception.Message);
|
||||||
|
Functions.WriteErrFile(exception.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,128 +1,118 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using PluginManager.Others;
|
using PluginManager.Others;
|
||||||
|
using OperatingSystem = PluginManager.Others.OperatingSystem;
|
||||||
|
|
||||||
namespace PluginManager.Online
|
namespace PluginManager.Online;
|
||||||
|
|
||||||
|
public class PluginsManager
|
||||||
{
|
{
|
||||||
public class PluginsManager
|
/// <summary>
|
||||||
|
/// The Plugin Manager constructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="link">The link to the file where all plugins are stored</param>
|
||||||
|
public PluginsManager(string link)
|
||||||
{
|
{
|
||||||
/// <summary>
|
PluginsLink = link;
|
||||||
/// The URL of the server
|
}
|
||||||
/// </summary>
|
|
||||||
public string PluginsLink { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Plugin Manager constructor
|
/// The URL of the server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="link">The link to the file where all plugins are stored</param>
|
public string PluginsLink { get; }
|
||||||
public PluginsManager(string link)
|
|
||||||
{
|
|
||||||
PluginsLink = link;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The method to load all plugins
|
/// The method to load all plugins
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task ListAvailablePlugins()
|
public async Task ListAvailablePlugins()
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
try
|
var list = await ServerCom.ReadTextFromFile(PluginsLink);
|
||||||
|
var lines = list.ToArray();
|
||||||
|
|
||||||
|
var data = new List<string[]>();
|
||||||
|
var op = Functions.GetOperatingSystem();
|
||||||
|
|
||||||
|
var len = lines.Length;
|
||||||
|
string[] titles = { "Name", "Description", "Plugin Type", "Libraries" };
|
||||||
|
data.Add(new[] { "-", "-", "-", "-" });
|
||||||
|
data.Add(titles);
|
||||||
|
data.Add(new[] { "-", "-", "-", "-" });
|
||||||
|
for (var i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
List<string> list = await ServerCom.ReadTextFromFile(PluginsLink);
|
if (lines[i].Length <= 2) continue;
|
||||||
string[] lines = list.ToArray();
|
var content = lines[i].Split(',');
|
||||||
|
var display = new string[4];
|
||||||
List<string[]> data = new List<string[]>();
|
if (op == OperatingSystem.WINDOWS)
|
||||||
var op = Functions.GetOperatingSystem();
|
|
||||||
|
|
||||||
int len = lines.Length;
|
|
||||||
string[] titles = { "Name", "Description", "Plugin Type", "Libraries" };
|
|
||||||
data.Add(new string[] { "-", "-", "-", "-" });
|
|
||||||
data.Add(titles);
|
|
||||||
data.Add(new string[] { "-", "-", "-", "-" });
|
|
||||||
for (int i = 0; i < len; i++)
|
|
||||||
{
|
{
|
||||||
if (lines[i].Length <= 2) continue;
|
if (content[4].Contains("Windows"))
|
||||||
string[] content = lines[i].Split(',');
|
|
||||||
string[] display = new string[4];
|
|
||||||
if (op == Others.OperatingSystem.WINDOWS)
|
|
||||||
{
|
{
|
||||||
if (content[4].Contains("Windows"))
|
display[0] = content[0];
|
||||||
{
|
display[1] = content[1];
|
||||||
display[0] = content[0];
|
display[2] = content[2];
|
||||||
display[1] = content[1];
|
if (content.Length == 6 && (content[5] != null || content[5].Length > 2))
|
||||||
display[2] = content[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();
|
|
||||||
|
|
||||||
else display[3] = "1";
|
else
|
||||||
data.Add(display);
|
display[3] = "1";
|
||||||
continue;
|
data.Add(display);
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (op == Others.OperatingSystem.LINUX)
|
|
||||||
{
|
|
||||||
if (content[4].Contains("Linux"))
|
|
||||||
{
|
|
||||||
display[0] = content[0];
|
|
||||||
display[1] = content[1];
|
|
||||||
display[2] = content[2];
|
|
||||||
data.Add(display);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (op == OperatingSystem.LINUX)
|
||||||
data.Add(new string[] { "-", "-", "-", "-" });
|
|
||||||
|
|
||||||
Console_Utilities.FormatAndAlignTable(data);
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Failed to execute command: listlang\nReason: " + exception.Message);
|
|
||||||
Others.Functions.WriteErrFile(exception.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The method to get plugin information by its name
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">The plugin name</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task<string[]> GetPluginLinkByName(string name)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
List<string> list = await ServerCom.ReadTextFromFile(PluginsLink);
|
|
||||||
string[] lines = list.ToArray();
|
|
||||||
int len = lines.Length;
|
|
||||||
for (int i = 0; i < len; i++)
|
|
||||||
{
|
{
|
||||||
string[] contents = lines[i].Split(',');
|
if (content[4].Contains("Linux"))
|
||||||
if (contents[0] == name)
|
|
||||||
{
|
{
|
||||||
if (contents.Length == 6)
|
display[0] = content[0];
|
||||||
return new string[] { contents[2], contents[3], contents[5] };
|
display[1] = content[1];
|
||||||
else if (contents.Length == 5)
|
display[2] = content[2];
|
||||||
return new string[] { contents[2], contents[3], string.Empty };
|
data.Add(display);
|
||||||
else throw new Exception("Failed to download plugin. Invalid Argument Length");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Failed to execute command: listplugs\nReason: " + exception.Message);
|
|
||||||
Others.Functions.WriteErrFile(exception.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return new string[] { null!, null!, null! };
|
data.Add(new[] { "-", "-", "-", "-" });
|
||||||
|
|
||||||
|
Console_Utilities.FormatAndAlignTable(data);
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Failed to execute command: listlang\nReason: " + exception.Message);
|
||||||
|
Functions.WriteErrFile(exception.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The method to get plugin information by its name
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The plugin name</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<string[]> GetPluginLinkByName(string name)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = await ServerCom.ReadTextFromFile(PluginsLink);
|
||||||
|
var lines = list.ToArray();
|
||||||
|
var len = lines.Length;
|
||||||
|
for (var i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
var contents = lines[i].Split(',');
|
||||||
|
if (contents[0] == name)
|
||||||
|
{
|
||||||
|
if (contents.Length == 6) return new[] { contents[2], contents[3], contents[5] };
|
||||||
|
if (contents.Length == 5) return new[] { contents[2], contents[3], string.Empty };
|
||||||
|
throw new Exception("Failed to download plugin. Invalid Argument Length");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Failed to execute command: listplugs\nReason: " + exception.Message);
|
||||||
|
Functions.WriteErrFile(exception.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new string[] { null!, null!, null! };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
using PluginManager.Online.Helpers;
|
using PluginManager.Online.Helpers;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using PluginManager.Others;
|
||||||
|
|
||||||
namespace PluginManager.Online
|
namespace PluginManager.Online
|
||||||
{
|
{
|
||||||
@@ -51,37 +52,35 @@ namespace PluginManager.Online
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static async Task DownloadFileAsync(string URL, string location)
|
public static async Task DownloadFileAsync(string URL, string location)
|
||||||
{
|
{
|
||||||
bool isDownloading = true;
|
bool isDownloading = true;
|
||||||
int c_progress = 0;
|
int c_progress = 0;
|
||||||
|
|
||||||
Others.Console_Utilities.ProgressBar pbar = new Others.Console_Utilities.ProgressBar(100, "");
|
Console_Utilities.ProgressBar pbar = new Console_Utilities.ProgressBar { Max = 100, NoColor = true };
|
||||||
|
|
||||||
IProgress<float> progress = new Progress<float>(percent =>
|
IProgress<float> progress = new Progress<float>(percent =>
|
||||||
{
|
{
|
||||||
c_progress = (int)percent;
|
c_progress = (int)percent;
|
||||||
});
|
});
|
||||||
|
|
||||||
Task updateProgressBarTask = new Task(() =>
|
|
||||||
{
|
|
||||||
while (isDownloading)
|
|
||||||
{
|
|
||||||
pbar.Update(c_progress);
|
|
||||||
if (c_progress == 100)
|
|
||||||
break;
|
|
||||||
System.Threading.Thread.Sleep(500);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
new System.Threading.Thread(updateProgressBarTask.Start).Start();
|
Task updateProgressBarTask = new Task(() =>
|
||||||
|
{
|
||||||
|
while (isDownloading)
|
||||||
|
{
|
||||||
|
pbar.Update(c_progress);
|
||||||
|
if (c_progress == 100) break;
|
||||||
|
Thread.Sleep(500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
new Thread(updateProgressBarTask.Start).Start();
|
||||||
await DownloadFileAsync(URL, location, progress);
|
await DownloadFileAsync(URL, location, progress);
|
||||||
|
|
||||||
|
|
||||||
c_progress = 100;
|
c_progress = 100;
|
||||||
pbar.Update(100);
|
pbar.Update(100);
|
||||||
isDownloading = false;
|
isDownloading = false;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,42 +1,60 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
using Discord;
|
using Discord;
|
||||||
|
|
||||||
using System.Threading.Tasks;
|
namespace PluginManager.Others;
|
||||||
|
|
||||||
namespace PluginManager.Others
|
/// <summary>
|
||||||
|
/// A class that handles the sending of messages to the user.
|
||||||
|
/// </summary>
|
||||||
|
public static class ChannelManagement
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A class that handles the sending of messages to the user.
|
/// Get the text channel by name from server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class ChannelManagement
|
/// <param name="server">The server</param>
|
||||||
|
/// <param name="name">The channel name</param>
|
||||||
|
/// <returns>
|
||||||
|
/// <see cref="IGuildChannel" />
|
||||||
|
/// </returns>
|
||||||
|
public static IGuildChannel GetTextChannel(this IGuild server, string name)
|
||||||
{
|
{
|
||||||
/// <summary>
|
return server.GetTextChannel(name);
|
||||||
/// Get the text channel by name from server
|
}
|
||||||
/// </summary>
|
|
||||||
/// <param name="server">The server</param>
|
|
||||||
/// <param name="name">The channel name</param>
|
|
||||||
/// <returns><see cref="IGuildChannel"/></returns>
|
|
||||||
public static IGuildChannel GetTextChannel(this IGuild server, string name) => server.GetTextChannel(name);
|
|
||||||
/// <summary>
|
|
||||||
/// Get the voice channel by name from server
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="server">The server</param>
|
|
||||||
/// <param name="name">The channel name</param>
|
|
||||||
/// <returns><see cref="IGuildChannel"/></returns>
|
|
||||||
public static IGuildChannel GetVoiceChannel(this IGuild server, string name) => server.GetVoiceChannel(name);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the DM channel between <see cref="Discord.WebSocket.DiscordSocketClient"/> and <see cref="IGuildUser"/>
|
/// Get the voice channel by name from server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="user"></param>
|
/// <param name="server">The server</param>
|
||||||
/// <returns><see cref="IDMChannel"/></returns>
|
/// <param name="name">The channel name</param>
|
||||||
public static async Task<IDMChannel> GetDMChannel(IGuildUser user) => await user.CreateDMChannelAsync();
|
/// <returns>
|
||||||
|
/// <see cref="IGuildChannel" />
|
||||||
|
/// </returns>
|
||||||
|
public static IGuildChannel GetVoiceChannel(this IGuild server, string name)
|
||||||
|
{
|
||||||
|
return server.GetVoiceChannel(name);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the channel where the message was sent
|
/// Get the DM channel between <see cref="Discord.WebSocket.DiscordSocketClient" /> and <see cref="IGuildUser" />
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message</param>
|
/// <param name="user"></param>
|
||||||
/// <returns><see cref="IChannel"/></returns>
|
/// <returns>
|
||||||
public static IChannel GetChannel(IMessage message) => message.Channel;
|
/// <see cref="IDMChannel" />
|
||||||
|
/// </returns>
|
||||||
|
public static async Task<IDMChannel> GetDMChannel(IGuildUser user)
|
||||||
|
{
|
||||||
|
return await user.CreateDMChannelAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the channel where the message was sent
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">The message</param>
|
||||||
|
/// <returns>
|
||||||
|
/// <see cref="IChannel" />
|
||||||
|
/// </returns>
|
||||||
|
public static IChannel GetChannel(IMessage message)
|
||||||
|
{
|
||||||
|
return message.Channel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,23 +10,13 @@ namespace PluginManager.Others
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ProgressBar
|
public class ProgressBar
|
||||||
{
|
{
|
||||||
public int Max { get; set; }
|
public int Max { get; init; }
|
||||||
public string Message { get; set; }
|
|
||||||
public ConsoleColor Color { get; init; }
|
public ConsoleColor Color { get; init; }
|
||||||
|
public bool NoColor { get; init; }
|
||||||
|
|
||||||
|
|
||||||
public ProgressBar(int max, string message)
|
|
||||||
{
|
|
||||||
Max = max;
|
|
||||||
Message = message;
|
|
||||||
var consoleColors = Enum.GetValues(typeof(ConsoleColor));
|
|
||||||
while ((Color = (ConsoleColor)consoleColors.GetValue(new Random().Next(consoleColors.Length))!) == ConsoleColor.White && Color != ConsoleColor.Black) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Update(int progress, double speed = -1, string? unit = null)
|
public void Update(int progress, double speed = -1, string? unit = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
//progress bar
|
|
||||||
Console.CursorLeft = 0;
|
Console.CursorLeft = 0;
|
||||||
Console.Write("[");
|
Console.Write("[");
|
||||||
Console.CursorLeft = 32;
|
Console.CursorLeft = 32;
|
||||||
@@ -38,15 +28,21 @@ namespace PluginManager.Others
|
|||||||
|
|
||||||
for (int i = 0; i < onechunk * progress; i++)
|
for (int i = 0; i < onechunk * progress; i++)
|
||||||
{
|
{
|
||||||
Console.BackgroundColor = this.Color;
|
if (NoColor)
|
||||||
|
Console.BackgroundColor = ConsoleColor.Black; //this.Color
|
||||||
|
else
|
||||||
|
Console.BackgroundColor = this.Color;
|
||||||
Console.CursorLeft = position++;
|
Console.CursorLeft = position++;
|
||||||
Console.Write(" ");
|
Console.Write("#");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = position; i <= 31; i++)
|
for (int i = position; i <= 31; i++)
|
||||||
{
|
{
|
||||||
Console.BackgroundColor = ConsoleColor.Gray;
|
if (NoColor)
|
||||||
Console.CursorLeft = position++;
|
Console.BackgroundColor = ConsoleColor.Black; // background of empty bar
|
||||||
|
else
|
||||||
|
Console.BackgroundColor = ConsoleColor.DarkGray;
|
||||||
|
Console.CursorLeft = position++;
|
||||||
Console.Write(" ");
|
Console.Write(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,91 +1,88 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace PluginManager.Others
|
namespace PluginManager.Others;
|
||||||
|
|
||||||
|
public class Cryptography
|
||||||
{
|
{
|
||||||
public class Cryptography
|
/// <summary>
|
||||||
|
/// Translate hex to string
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="hexString">The encrypted string</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string FromHexToString(string hexString)
|
||||||
{
|
{
|
||||||
|
var bytes = new byte[hexString.Length / 2];
|
||||||
|
for (var i = 0; i < bytes.Length; i++) bytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
|
||||||
|
|
||||||
/// <summary>
|
return Encoding.Unicode.GetString(bytes);
|
||||||
/// Translate hex to string
|
}
|
||||||
/// </summary>
|
|
||||||
/// <param name="hexString">The encrypted string</param>
|
/// <summary>
|
||||||
/// <returns></returns>
|
/// Translate string to hex
|
||||||
public static string FromHexToString(string hexString)
|
/// </summary>
|
||||||
|
/// <param name="str">The string to encrypt</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string ToHexString(string str)
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
|
||||||
|
var bytes = Encoding.Unicode.GetBytes(str);
|
||||||
|
foreach (var t in bytes) sb.Append(t.ToString("X2"));
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create MD5 hash
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text">The text to encrypt</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async Task<string> CreateMD5(string text)
|
||||||
|
{
|
||||||
|
var output = "";
|
||||||
|
using (var md5 = MD5.Create())
|
||||||
{
|
{
|
||||||
var bytes = new byte[hexString.Length / 2];
|
using (var s = GenerateStreamFromString(text))
|
||||||
for (var i = 0; i < bytes.Length; i++)
|
|
||||||
{
|
{
|
||||||
bytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
|
var t = await md5.ComputeHashAsync(s);
|
||||||
|
output = Convert.ToBase64String(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
return System.Text.Encoding.Unicode.GetString(bytes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
return output;
|
||||||
/// Translate string to hex
|
}
|
||||||
/// </summary>
|
|
||||||
/// <param name="str">The string to encrypt</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static string ToHexString(string str)
|
|
||||||
{
|
|
||||||
var sb = new System.Text.StringBuilder();
|
|
||||||
|
|
||||||
var bytes = System.Text.Encoding.Unicode.GetBytes(str);
|
/// <summary>
|
||||||
foreach (var t in bytes)
|
/// Create SHA256 hash
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text">The text to encrypt</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async Task<string> CreateSHA256(string text)
|
||||||
|
{
|
||||||
|
var output = "";
|
||||||
|
using (var sha = SHA256.Create())
|
||||||
|
{
|
||||||
|
using (var s = GenerateStreamFromString(text))
|
||||||
{
|
{
|
||||||
sb.Append(t.ToString("X2"));
|
var t = await sha.ComputeHashAsync(s);
|
||||||
|
output = Convert.ToBase64String(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
return output;
|
||||||
/// Create MD5 hash
|
}
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">The text to encrypt</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static async System.Threading.Tasks.Task<string> CreateMD5(string text)
|
|
||||||
{
|
|
||||||
string output = "";
|
|
||||||
using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
|
|
||||||
{
|
|
||||||
using (var s = GenerateStreamFromString(text))
|
|
||||||
{
|
|
||||||
byte[] t = await md5.ComputeHashAsync(s);
|
|
||||||
output = System.Convert.ToBase64String(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return output;
|
private static Stream GenerateStreamFromString(string s)
|
||||||
}
|
{
|
||||||
|
var stream = new MemoryStream();
|
||||||
/// <summary>
|
var writer = new StreamWriter(stream);
|
||||||
/// Create SHA256 hash
|
writer.Write(s);
|
||||||
/// </summary>
|
writer.Flush();
|
||||||
/// <param name="text">The text to encrypt</param>
|
stream.Position = 0;
|
||||||
/// <returns></returns>
|
return stream;
|
||||||
public static async System.Threading.Tasks.Task<string> CreateSHA256(string text)
|
|
||||||
{
|
|
||||||
string output = "";
|
|
||||||
using (System.Security.Cryptography.SHA256 sha = System.Security.Cryptography.SHA256.Create())
|
|
||||||
{
|
|
||||||
using (var s = GenerateStreamFromString(text))
|
|
||||||
{
|
|
||||||
byte[] t = await sha.ComputeHashAsync(s);
|
|
||||||
output = System.Convert.ToBase64String(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static System.IO.Stream GenerateStreamFromString(string s)
|
|
||||||
{
|
|
||||||
var stream = new System.IO.MemoryStream();
|
|
||||||
var writer = new System.IO.StreamWriter(stream);
|
|
||||||
writer.Write(s);
|
|
||||||
writer.Flush();
|
|
||||||
stream.Position = 0;
|
|
||||||
return stream;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,20 +1,22 @@
|
|||||||
namespace PluginManager.Others
|
namespace PluginManager.Others;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A list of operating systems
|
||||||
|
/// </summary>
|
||||||
|
public enum OperatingSystem
|
||||||
{
|
{
|
||||||
|
WINDOWS, LINUX, MAC_OS, UNKNOWN
|
||||||
/// <summary>
|
|
||||||
/// A list of operating systems
|
|
||||||
/// </summary>
|
|
||||||
public enum OperatingSystem
|
|
||||||
{ WINDOWS, LINUX, MAC_OS, UNKNOWN }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A list with all errors
|
|
||||||
/// </summary>
|
|
||||||
public enum Error
|
|
||||||
{ UNKNOWN_ERROR, GUILD_NOT_FOUND, STREAM_NOT_FOUND, INVALID_USER, INVALID_CHANNEL, INVALID_PERMISSIONS }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The output log type
|
|
||||||
/// </summary>
|
|
||||||
public enum OutputLogLevel { NONE, INFO, WARNING, ERROR, CRITICAL }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A list with all errors
|
||||||
|
/// </summary>
|
||||||
|
public enum Error
|
||||||
|
{
|
||||||
|
UNKNOWN_ERROR, GUILD_NOT_FOUND, STREAM_NOT_FOUND, INVALID_USER, INVALID_CHANNEL, INVALID_PERMISSIONS
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The output log type
|
||||||
|
/// </summary>
|
||||||
|
public enum OutputLogLevel { NONE, INFO, WARNING, ERROR, CRITICAL }
|
||||||
|
|||||||
@@ -1,94 +1,91 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace PluginManager.Others.Exceptions
|
namespace PluginManager.Others.Exceptions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Custom Exception for PluginManager
|
||||||
|
/// </summary>
|
||||||
|
[Serializable]
|
||||||
|
public class APIException : Exception
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Custom Exception for PluginManager
|
/// The APIException contructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable]
|
/// <param name="message">The error message</param>
|
||||||
|
/// <param name="function">The function where the message was triggered</param>
|
||||||
public class APIException : Exception
|
/// <param name="possible_cause">The possible cause of the error</param>
|
||||||
|
/// <param name="error">The error code</param>
|
||||||
|
public APIException(string message, string? function, string possible_cause, Error error) : base(message)
|
||||||
{
|
{
|
||||||
/// <summary>
|
ErrorCode = error;
|
||||||
/// The function where the error occurred
|
Function = function;
|
||||||
/// </summary>
|
PossibleCause = possible_cause;
|
||||||
public string? Function { get; } = "not specified";
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The error code
|
|
||||||
/// </summary>
|
|
||||||
public Error? ErrorCode { get; } = Error.UNKNOWN_ERROR;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The possible cause that determined the error
|
|
||||||
/// </summary>
|
|
||||||
public string? PossibleCause { get; } = "not specified";
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The APIException contructor
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message">The error message</param>
|
|
||||||
/// <param name="function">The function where the message was triggered</param>
|
|
||||||
/// <param name="possible_cause">The possible cause of the error</param>
|
|
||||||
/// <param name="error">The error code</param>
|
|
||||||
public APIException(string message, string? function, string possible_cause, Error error) : base(message)
|
|
||||||
{
|
|
||||||
ErrorCode = error;
|
|
||||||
Function = function;
|
|
||||||
PossibleCause = possible_cause;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The APIException contructor
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message">The error message</param>
|
|
||||||
/// <param name="function">The function where the message was triggered</param>
|
|
||||||
/// <param name="errorCode">The error code</param>
|
|
||||||
public APIException(string message, string? function, Error? errorCode) : base(message)
|
|
||||||
{
|
|
||||||
ErrorCode = errorCode;
|
|
||||||
Function = function;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// The APIException contructor
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message">The error message</param>
|
|
||||||
/// <param name="function">The function where the message was triggered</param>
|
|
||||||
public APIException(string message, string? function) : base(message)
|
|
||||||
{
|
|
||||||
Function = function;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// The APIException contructor
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message">The error message</param>
|
|
||||||
public APIException(string message) : base(message)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The APIException constructor
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message">The error message</param>
|
|
||||||
/// <param name="errorLocation">The class where the error was thrown</param>
|
|
||||||
public APIException(string message, Type errorLocation) : base(message)
|
|
||||||
{
|
|
||||||
Function = errorLocation.FullName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Method to print the error to <see cref="Console"/>
|
|
||||||
/// </summary>
|
|
||||||
public void Print()
|
|
||||||
{
|
|
||||||
Console.WriteLine("Message Content: " + Message);
|
|
||||||
Console.WriteLine("Function: " + Function);
|
|
||||||
Console.WriteLine("Error Code: " + ErrorCode.ToString());
|
|
||||||
Console.WriteLine("Possible cause: " + PossibleCause);
|
|
||||||
if (this.StackTrace != null)
|
|
||||||
Functions.WriteErrFile(this.StackTrace);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The APIException contructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">The error message</param>
|
||||||
|
/// <param name="function">The function where the message was triggered</param>
|
||||||
|
/// <param name="errorCode">The error code</param>
|
||||||
|
public APIException(string message, string? function, Error? errorCode) : base(message)
|
||||||
|
{
|
||||||
|
ErrorCode = errorCode;
|
||||||
|
Function = function;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The APIException contructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">The error message</param>
|
||||||
|
/// <param name="function">The function where the message was triggered</param>
|
||||||
|
public APIException(string message, string? function) : base(message)
|
||||||
|
{
|
||||||
|
Function = function;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The APIException contructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">The error message</param>
|
||||||
|
public APIException(string message) : base(message)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The APIException constructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">The error message</param>
|
||||||
|
/// <param name="errorLocation">The class where the error was thrown</param>
|
||||||
|
public APIException(string message, Type errorLocation) : base(message)
|
||||||
|
{
|
||||||
|
Function = errorLocation.FullName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The function where the error occurred
|
||||||
|
/// </summary>
|
||||||
|
public string? Function { get; } = "not specified";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The error code
|
||||||
|
/// </summary>
|
||||||
|
public Error? ErrorCode { get; } = Error.UNKNOWN_ERROR;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The possible cause that determined the error
|
||||||
|
/// </summary>
|
||||||
|
public string? PossibleCause { get; } = "not specified";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Method to print the error to <see cref="Console" />
|
||||||
|
/// </summary>
|
||||||
|
public void Print()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Message Content: " + Message);
|
||||||
|
Console.WriteLine("Function: " + Function);
|
||||||
|
Console.WriteLine("Error Code: " + ErrorCode);
|
||||||
|
Console.WriteLine("Possible cause: " + PossibleCause);
|
||||||
|
if (StackTrace != null) Functions.WriteErrFile(StackTrace);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -212,11 +212,22 @@ namespace PluginManager.Others
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static (double, string) ConvertBytes(long bytes)
|
public static (double, string) ConvertBytes(long bytes)
|
||||||
{
|
{
|
||||||
if (bytes < 1024) return (bytes, "B");
|
List<string> units = new List<string>()
|
||||||
if (bytes < 1024 * 1024) return (bytes / 1024.0, "KB");
|
{
|
||||||
if (bytes < 1024 * 1024 * 1024) return (bytes / 1024.0 / 1024.0, "MB");
|
"B",
|
||||||
return (bytes / 1024.0 / 1024.0 / 1024.0, "GB");
|
"KB",
|
||||||
|
"MB",
|
||||||
|
"GB",
|
||||||
|
"TB"
|
||||||
|
};
|
||||||
|
int i = 0;
|
||||||
|
while (bytes >= 1024)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
bytes /= 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (bytes, units[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,55 +1,64 @@
|
|||||||
using Discord;
|
using System.Linq;
|
||||||
|
using Discord;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
|
||||||
using System.Linq;
|
namespace PluginManager.Others.Permissions;
|
||||||
|
|
||||||
namespace PluginManager.Others.Permissions
|
/// <summary>
|
||||||
|
/// A class whith all discord permissions
|
||||||
|
/// </summary>
|
||||||
|
public static class DiscordPermissions
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A class whith all discord permissions
|
/// Checks if the role has the specified permission
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class DiscordPermissions
|
/// <param name="role">The role</param>
|
||||||
|
/// <param name="permission">The permission</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool hasPermission(this IRole role, GuildPermission permission)
|
||||||
{
|
{
|
||||||
/// <summary>
|
return role.Permissions.Has(permission);
|
||||||
/// Checks if the role has the specified permission
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="role">The role</param>
|
|
||||||
/// <param name="permission">The permission</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static bool hasPermission(this IRole role, GuildPermission permission) => role.Permissions.Has(permission);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check if user has the specified role
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="user">The user</param>
|
|
||||||
/// <param name="role">The role</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static bool hasRole(this SocketGuildUser user, IRole role) => user.Roles.Contains(role);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check if user has the specified permission
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="user">The user</param>
|
|
||||||
/// <param name="permission">The permission</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static bool hasPermission(this SocketGuildUser user, GuildPermission permission)
|
|
||||||
=> user.Roles.Where(role => role.hasPermission(permission)).Any() || user.Guild.Owner == user;
|
|
||||||
/// <summary>
|
|
||||||
/// Check if user is administrator of server
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="user">The user</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static bool isAdmin(this SocketGuildUser user) => user.hasPermission(GuildPermission.Administrator);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check if user is administrator of server
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="user">The user</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static bool isAdmin(this SocketUser user) => isAdmin((SocketGuildUser)user);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if user has the specified role
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user">The user</param>
|
||||||
|
/// <param name="role">The role</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool hasRole(this SocketGuildUser user, IRole role)
|
||||||
|
{
|
||||||
|
return user.Roles.Contains(role);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if user has the specified permission
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user">The user</param>
|
||||||
|
/// <param name="permission">The permission</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool hasPermission(this SocketGuildUser user, GuildPermission permission)
|
||||||
|
{
|
||||||
|
return user.Roles.Where(role => role.hasPermission(permission)).Any() || user.Guild.Owner == user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if user is administrator of server
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user">The user</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool isAdmin(this SocketGuildUser user)
|
||||||
|
{
|
||||||
|
return user.hasPermission(GuildPermission.Administrator);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if user is administrator of server
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user">The user</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool isAdmin(this SocketUser user)
|
||||||
|
{
|
||||||
|
return isAdmin((SocketGuildUser)user);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user