This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -5,11 +5,13 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<OutputPath>E:\DiscordBot\BUILDS\</OutputPath>
|
||||
<OutputPath>..\BUILDS\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<DebugType>none</DebugType>
|
||||
<DebugSymbols>false</DebugSymbols>
|
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||
<WarningsAsErrors />
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<OutputPath>E:\DiscordBot\BUILDS\</OutputPath>
|
||||
<OutputPath>..\BUILDS\</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
using Discord.Commands;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
|
||||
using PluginManager.Loaders;
|
||||
using PluginManager.Interfaces;
|
||||
using PluginManager.Others.Permissions;
|
||||
using PluginManager.Others;
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PluginManager.Commands
|
||||
{
|
||||
@@ -22,43 +26,59 @@ namespace PluginManager.Commands
|
||||
|
||||
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();
|
||||
if (isAdmin)
|
||||
Discord.EmbedBuilder embedBuilder = new Discord.EmbedBuilder();
|
||||
|
||||
string adminCommands = "";
|
||||
string normalCommands = "";
|
||||
string DMCommands = "";
|
||||
|
||||
foreach (var cmd in PluginLoader.Plugins!)
|
||||
{
|
||||
if (isDM)
|
||||
{
|
||||
foreach (DBCommand p in PluginLoader.Plugins!)
|
||||
if (p.canUseDM)
|
||||
if (p.requireAdmin)
|
||||
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);
|
||||
}
|
||||
if (cmd.canUseDM)
|
||||
DMCommands += cmd.Command + " ";
|
||||
if (cmd.requireAdmin)
|
||||
adminCommands += cmd.Command + " ";
|
||||
else normalCommands += cmd.Command + " ";
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,8 @@ namespace PluginManager.Core
|
||||
{
|
||||
internal class Boot
|
||||
{
|
||||
private readonly string botPrefix;
|
||||
private readonly string botToken;
|
||||
public readonly string botPrefix;
|
||||
public readonly string botToken;
|
||||
|
||||
private bool isReady = false;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<Nullable>disable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Discord;
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
@@ -8,6 +9,7 @@ using PluginManager.Others;
|
||||
using PluginManager.Loaders;
|
||||
using PluginManager.LanguageSystem;
|
||||
using PluginManager.Online;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace DiscordBot
|
||||
{
|
||||
@@ -37,12 +39,12 @@ namespace DiscordBot
|
||||
{
|
||||
Console.WriteLine("Please insert your token: ");
|
||||
Console.Write("TOKEN: ");
|
||||
string? botToken = Console.ReadLine();
|
||||
string botToken = Console.ReadLine();
|
||||
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');
|
||||
if (prefix == String.Empty || prefix == null)
|
||||
if (prefix == string.Empty || prefix == null)
|
||||
prefix = "!";
|
||||
File.WriteAllText("./Data/Resources/DiscordBotCore.data", $"BOT_TOKEN\t{botToken}\nBOT_PREFIX\t{prefix}\n");
|
||||
break;
|
||||
@@ -71,12 +73,14 @@ namespace DiscordBot
|
||||
private static async Task NoGUI(Boot discordbooter)
|
||||
{
|
||||
LoadLanguage();
|
||||
if (loadPluginsOnStartup) LoadPlugins(discordbooter);
|
||||
if (loadPluginsOnStartup)
|
||||
LoadPlugins(discordbooter);
|
||||
while (true)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Console.Write('$');
|
||||
Functions.WriteColorText("&mConsole > &c", false);
|
||||
string[] data = Console.ReadLine().Split(' ');
|
||||
|
||||
if (data[0].Length < 2) continue;
|
||||
switch (data[0])
|
||||
{
|
||||
@@ -85,7 +89,17 @@ namespace DiscordBot
|
||||
if (discordbooter.client.ConnectionState == ConnectionState.Connected)
|
||||
await discordbooter.ShutDown().ContinueWith(t => { Environment.Exit(0); });
|
||||
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":
|
||||
await manager.ListAvailablePlugins();
|
||||
break;
|
||||
@@ -121,7 +135,7 @@ namespace DiscordBot
|
||||
break;
|
||||
case "dwlang":
|
||||
string Lname = data.MergeStrings(1);
|
||||
string?[] link = await languageManager.GetDownloadLink(Lname);
|
||||
string[] link = await languageManager.GetDownloadLink(Lname);
|
||||
try
|
||||
{
|
||||
if (link[0] is null || link is null)
|
||||
@@ -180,6 +194,7 @@ namespace DiscordBot
|
||||
default:
|
||||
goto case "help";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,10 +371,11 @@ namespace DiscordBot
|
||||
return;
|
||||
}
|
||||
|
||||
if (len == 2 && args[0] == "--encrypt")
|
||||
if (len >= 2 && args[0] == "--encrypt")
|
||||
{
|
||||
Console.WriteLine("MD5: " + await Cryptography.CreateMD5(args[1]));
|
||||
System.Console.WriteLine("SHA356: " + await Cryptography.CreateSHA256(args[1]));
|
||||
string s2e = args.MergeStrings(1);
|
||||
Console.WriteLine("MD5: " + await Cryptography.CreateMD5(s2e));
|
||||
Console.WriteLine("SHA356: " + await Cryptography.CreateSHA256(s2e));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<OutputPath>E:\DiscordBot\BUILDS\</OutputPath>
|
||||
<OutputPath>..\BUILDS\</OutputPath>
|
||||
<DebugType>none</DebugType>
|
||||
<DebugSymbols>false</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
|
||||
43
PluginManager/Items/Command.cs
Normal file
43
PluginManager/Items/Command.cs
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,8 @@ using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Discord.WebSocket;
|
||||
using PluginManager.Items;
|
||||
|
||||
namespace PluginManager.Others
|
||||
{
|
||||
@@ -167,6 +168,12 @@ namespace PluginManager.Others
|
||||
return OperatingSystem.UNKNOWN;
|
||||
}
|
||||
|
||||
public static List<string> GetArguments(SocketMessage message)
|
||||
{
|
||||
Command command = new Command(message);
|
||||
return command.Arguments;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A way to create a table based on input data
|
||||
/// EpicWings (Pasca Robert) este cel mai bun
|
||||
@@ -223,9 +230,10 @@ namespace PluginManager.Others
|
||||
|
||||
/// <summary>
|
||||
/// Write the text using color options( &g-green; &b-blue; &r-red; &c-clear; )
|
||||
///
|
||||
/// </summary>
|
||||
/// <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(' ');
|
||||
Dictionary<string, ConsoleColor> colors = new Dictionary<string, ConsoleColor>()
|
||||
@@ -233,6 +241,7 @@ namespace PluginManager.Others
|
||||
{"&g", ConsoleColor.Green },
|
||||
{"&b", ConsoleColor.Blue },
|
||||
{"&r", ConsoleColor.Red },
|
||||
{"&m", ConsoleColor.Magenta },
|
||||
{"&c", Console.ForegroundColor }
|
||||
};
|
||||
foreach (string word in words)
|
||||
@@ -244,9 +253,10 @@ namespace PluginManager.Others
|
||||
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 + " ");
|
||||
}
|
||||
if (appendNewLine)
|
||||
Console.Write('\n');
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<OutputPath>E:\DiscordBot\BUILDS\</OutputPath>
|
||||
<OutputPath>..\BUILDS\</OutputPath>
|
||||
<DebugType>none</DebugType>
|
||||
<DebugSymbols>false</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
|
||||
Reference in New Issue
Block a user