This commit is contained in:
2022-04-08 18:47:39 +03:00
parent 74c1fcede8
commit b57e132912
12 changed files with 145 additions and 54 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -5,11 +5,13 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>E:\DiscordBot\BUILDS\</OutputPath> <OutputPath>..\BUILDS\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<DebugType>none</DebugType> <DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols> <DebugSymbols>false</DebugSymbols>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<WarningsAsErrors />
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@@ -5,7 +5,7 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>E:\DiscordBot\BUILDS\</OutputPath> <OutputPath>..\BUILDS\</OutputPath>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@@ -1,9 +1,13 @@
using Discord.Commands; using Discord;
using Discord.Commands;
using Discord.WebSocket; using Discord.WebSocket;
using PluginManager.Loaders; using PluginManager.Loaders;
using PluginManager.Interfaces; using PluginManager.Interfaces;
using PluginManager.Others.Permissions; using PluginManager.Others.Permissions;
using PluginManager.Others;
using System.Collections.Generic;
namespace PluginManager.Commands namespace PluginManager.Commands
{ {
@@ -22,43 +26,59 @@ namespace PluginManager.Commands
public void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM) public void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
{ {
List<string> args = Functions.GetArguments(message);
if (args.Count != 0)
{
foreach (var item in args)
{
bool commandExists = false;
var e = GenerateHelpCommand(item);
if (e != null)
{
commandExists = true;
context.Channel.SendMessageAsync(embed: e.Build());
}
if (!commandExists)
context.Channel.SendMessageAsync("Unknown Command " + item);
}
return;
}
bool isAdmin = ((SocketGuildUser)message.Author).isAdmin(); bool isAdmin = ((SocketGuildUser)message.Author).isAdmin();
if (isAdmin) Discord.EmbedBuilder embedBuilder = new Discord.EmbedBuilder();
string adminCommands = "";
string normalCommands = "";
string DMCommands = "";
foreach (var cmd in PluginLoader.Plugins!)
{ {
if (isDM) if (cmd.canUseDM)
{ DMCommands += cmd.Command + " ";
foreach (DBCommand p in PluginLoader.Plugins!) if (cmd.requireAdmin)
if (p.canUseDM) adminCommands += cmd.Command + " ";
if (p.requireAdmin) else normalCommands += cmd.Command + " ";
context.Channel.SendMessageAsync("[ADMIN] " + p.Usage + "\t" + p.Description);
else context.Channel.SendMessageAsync(p.Usage + "\t" + p.Description);
}
else
{
foreach (DBCommand p in PluginLoader.Plugins!)
if (p.canUseServer)
if (p.requireAdmin)
context.Channel.SendMessageAsync("[ADMIN] " + p.Usage + "\t" + p.Description);
else context.Channel.SendMessageAsync(p.Usage + "\t" + p.Description);
}
}
else
{
if (isDM)
{
foreach (DBCommand p in PluginLoader.Plugins!)
if (p.canUseDM && !p.requireAdmin)
context.Channel.SendMessageAsync(p.Usage + "\t" + p.Description);
}
else
{
foreach (DBCommand p in PluginLoader.Plugins!)
if (p.canUseServer && !p.requireAdmin)
context.Channel.SendMessageAsync(p.Usage + "\t" + p.Description);
}
} }
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)
{
EmbedBuilder embedBuilder = new EmbedBuilder();
DBCommand cmd = PluginLoader.Plugins.Find(p => p.Command == command);
if (cmd == null)
return null;
embedBuilder.AddField("Usage", cmd.Usage);
embedBuilder.AddField("Description", cmd.Description);
return embedBuilder;
}
} }
} }

View File

@@ -11,8 +11,8 @@ namespace PluginManager.Core
{ {
internal class Boot internal class Boot
{ {
private readonly string botPrefix; public readonly string botPrefix;
private readonly string botToken; public readonly string botToken;
private bool isReady = false; private bool isReady = false;

View File

@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable> <Nullable>disable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@@ -1,4 +1,5 @@
using Discord; using Discord;
using System; using System;
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -8,6 +9,7 @@ using PluginManager.Others;
using PluginManager.Loaders; using PluginManager.Loaders;
using PluginManager.LanguageSystem; using PluginManager.LanguageSystem;
using PluginManager.Online; using PluginManager.Online;
using System.Diagnostics;
namespace DiscordBot namespace DiscordBot
{ {
@@ -37,12 +39,12 @@ namespace DiscordBot
{ {
Console.WriteLine("Please insert your token: "); Console.WriteLine("Please insert your token: ");
Console.Write("TOKEN: "); Console.Write("TOKEN: ");
string? botToken = Console.ReadLine(); string botToken = Console.ReadLine();
if (botToken.Length == 59) if (botToken.Length == 59)
{ {
string? prefix = Functions.readCodeFromFile("./Data/Resources/DiscordBotCore.data", "BOT_PREFIX", string prefix = Functions.readCodeFromFile("./Data/Resources/DiscordBotCore.data", "BOT_PREFIX",
'\t'); '\t');
if (prefix == String.Empty || prefix == null) if (prefix == string.Empty || prefix == null)
prefix = "!"; prefix = "!";
File.WriteAllText("./Data/Resources/DiscordBotCore.data", $"BOT_TOKEN\t{botToken}\nBOT_PREFIX\t{prefix}\n"); File.WriteAllText("./Data/Resources/DiscordBotCore.data", $"BOT_TOKEN\t{botToken}\nBOT_PREFIX\t{prefix}\n");
break; break;
@@ -71,12 +73,14 @@ namespace DiscordBot
private static async Task NoGUI(Boot discordbooter) private static async Task NoGUI(Boot discordbooter)
{ {
LoadLanguage(); LoadLanguage();
if (loadPluginsOnStartup) LoadPlugins(discordbooter); if (loadPluginsOnStartup)
LoadPlugins(discordbooter);
while (true) while (true)
{ {
Console.ForegroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.White;
Console.Write('$'); Functions.WriteColorText("&mConsole > &c", false);
string[] data = Console.ReadLine().Split(' '); string[] data = Console.ReadLine().Split(' ');
if (data[0].Length < 2) continue; if (data[0].Length < 2) continue;
switch (data[0]) switch (data[0])
{ {
@@ -85,7 +89,17 @@ namespace DiscordBot
if (discordbooter.client.ConnectionState == ConnectionState.Connected) if (discordbooter.client.ConnectionState == ConnectionState.Connected)
await discordbooter.ShutDown().ContinueWith(t => { Environment.Exit(0); }); await discordbooter.ShutDown().ContinueWith(t => { Environment.Exit(0); });
break; break;
case "reload":
case "rl":
if (Environment.OSVersion.Platform != PlatformID.Win32NT)
{
Console.WriteLine("This command is for windows users ONLY");
break;
}
if (discordbooter.client.ConnectionState == ConnectionState.Connected)
await discordbooter.ShutDown();
Process.Start("./DiscordBot", "--execute:lp");
break;
case "listplugs": case "listplugs":
await manager.ListAvailablePlugins(); await manager.ListAvailablePlugins();
break; break;
@@ -121,7 +135,7 @@ namespace DiscordBot
break; break;
case "dwlang": case "dwlang":
string Lname = data.MergeStrings(1); string Lname = data.MergeStrings(1);
string?[] link = await languageManager.GetDownloadLink(Lname); string[] link = await languageManager.GetDownloadLink(Lname);
try try
{ {
if (link[0] is null || link is null) if (link[0] is null || link is null)
@@ -180,6 +194,7 @@ namespace DiscordBot
default: default:
goto case "help"; goto case "help";
} }
} }
} }
@@ -356,10 +371,11 @@ namespace DiscordBot
return; return;
} }
if (len == 2 && args[0] == "--encrypt") if (len >= 2 && args[0] == "--encrypt")
{ {
Console.WriteLine("MD5: " + await Cryptography.CreateMD5(args[1])); string s2e = args.MergeStrings(1);
System.Console.WriteLine("SHA356: " + await Cryptography.CreateSHA256(args[1])); Console.WriteLine("MD5: " + await Cryptography.CreateMD5(s2e));
Console.WriteLine("SHA356: " + await Cryptography.CreateSHA256(s2e));
return; return;
} }

View File

@@ -5,7 +5,7 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>E:\DiscordBot\BUILDS\</OutputPath> <OutputPath>..\BUILDS\</OutputPath>
<DebugType>none</DebugType> <DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols> <DebugSymbols>false</DebugSymbols>
</PropertyGroup> </PropertyGroup>

View File

@@ -0,0 +1,43 @@
using Discord.WebSocket;
using PluginManager.Loaders;
using PluginManager.Others;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PluginManager.Items
{
internal class Command
{
public SocketUser Author;
public List<string> Arguments { get; private set; }
public string CommandName { get; private set; }
public char PrefixUsed { get; private set; }
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];
}
public Command(string message, bool hasPrefix)
{
string[] data = message.Split(' ');
this.Author = null;
this.Arguments = new List<string>(data.MergeStrings(1).Split(' '));
this.CommandName = data[0].Substring(1);
if (hasPrefix)
this.PrefixUsed = data[0][0];
else this.PrefixUsed = '\0'; //null
}
}
}

View File

@@ -4,7 +4,8 @@ using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Linq; using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using Discord.WebSocket;
using PluginManager.Items;
namespace PluginManager.Others namespace PluginManager.Others
{ {
@@ -167,6 +168,12 @@ namespace PluginManager.Others
return OperatingSystem.UNKNOWN; return OperatingSystem.UNKNOWN;
} }
public static List<string> GetArguments(SocketMessage message)
{
Command command = new Command(message);
return command.Arguments;
}
/// <summary> /// <summary>
/// A way to create a table based on input data /// A way to create a table based on input data
/// EpicWings (Pasca Robert) este cel mai bun /// EpicWings (Pasca Robert) este cel mai bun
@@ -223,9 +230,10 @@ namespace PluginManager.Others
/// <summary> /// <summary>
/// Write the text using color options( &g-green; &b-blue; &r-red; &c-clear; ) /// Write the text using color options( &g-green; &b-blue; &r-red; &c-clear; )
///
/// </summary> /// </summary>
/// <param name="text">The text</param> /// <param name="text">The text</param>
public static void WriteColorText(string text) public static void WriteColorText(string text, bool appendNewLine = true)
{ {
string[] words = text.Split(' '); string[] words = text.Split(' ');
Dictionary<string, ConsoleColor> colors = new Dictionary<string, ConsoleColor>() Dictionary<string, ConsoleColor> colors = new Dictionary<string, ConsoleColor>()
@@ -233,6 +241,7 @@ namespace PluginManager.Others
{"&g", ConsoleColor.Green }, {"&g", ConsoleColor.Green },
{"&b", ConsoleColor.Blue }, {"&b", ConsoleColor.Blue },
{"&r", ConsoleColor.Red }, {"&r", ConsoleColor.Red },
{"&m", ConsoleColor.Magenta },
{"&c", Console.ForegroundColor } {"&c", Console.ForegroundColor }
}; };
foreach (string word in words) foreach (string word in words)
@@ -244,9 +253,10 @@ namespace PluginManager.Others
Console.ForegroundColor = colors[prefix]; Console.ForegroundColor = colors[prefix];
} }
string m = word.Replace("&g", "").Replace("&b", "").Replace("&r", "").Replace("&c", ""); string m = word.Replace("&g", "").Replace("&b", "").Replace("&r", "").Replace("&c", "").Replace("&m", "");
Console.Write(m + " "); Console.Write(m + " ");
} }
if (appendNewLine)
Console.Write('\n'); Console.Write('\n');
} }

View File

@@ -5,7 +5,7 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>E:\DiscordBot\BUILDS\</OutputPath> <OutputPath>..\BUILDS\</OutputPath>
<DebugType>none</DebugType> <DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols> <DebugSymbols>false</DebugSymbols>
</PropertyGroup> </PropertyGroup>