2 Commits

Author SHA1 Message Date
f8de1536b2 2022-05-27 12:29:23 +03:00
c1d0155867 2022-05-27 12:28:55 +03:00
6 changed files with 35 additions and 13 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -87,7 +87,8 @@ namespace DiscordBot
while (true) while (true)
{ {
Console.ForegroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.White;
consoleCommandsHandler.HandleCommand(Console.ReadLine()); string cmd = Console.ReadLine();
consoleCommandsHandler.HandleCommand(cmd);
} }
} }

View File

@@ -5,6 +5,9 @@ using Discord.WebSocket;
using PluginManager.Others; using PluginManager.Others;
using PluginManager.Interfaces; using PluginManager.Interfaces;
using PluginManager.LanguageSystem; using PluginManager.LanguageSystem;
using PluginManager.Items;
using System;
public class LevelingSystem : DBEvent public class LevelingSystem : DBEvent
{ {
public string name => "Leveling System"; public string name => "Leveling System";
@@ -13,6 +16,13 @@ public class LevelingSystem : DBEvent
public void Start(DiscordSocketClient client) public void Start(DiscordSocketClient client)
{ {
ConsoleCommandsHandler.AddCommand("lvl", "Test command", async (args) =>
{
Console.WriteLine("Leveling system command");
});
client.MessageReceived += Client_MessageReceived; client.MessageReceived += Client_MessageReceived;
} }

View File

@@ -1,5 +1,8 @@
using PluginManager.Interfaces; using PluginManager.Interfaces;
using PluginManager.Items;
using Games.Objects; using Games.Objects;
using PluginManager.Others;
namespace Games; namespace Games;
public class Game : DBCommand public class Game : DBCommand
@@ -15,7 +18,8 @@ public class Game : DBCommand
public async void Execute(Discord.Commands.SocketCommandContext context, Discord.WebSocket.SocketMessage message, public async void Execute(Discord.Commands.SocketCommandContext context, Discord.WebSocket.SocketMessage message,
Discord.WebSocket.DiscordSocketClient client, bool isDM) Discord.WebSocket.DiscordSocketClient client, bool isDM)
{ {
string game_name = PluginManager.Others.Functions.MergeStrings(message.Content.Split(' '), 1);
string game_name = Functions.MergeStrings(message.Content.Split(' '), 1);
string game_url = await GameData.GetSteamLinkFromGame(game_name); string game_url = await GameData.GetSteamLinkFromGame(game_name);
if (game_url is null || game_url == null) if (game_url is null || game_url == null)
{ {

View File

@@ -11,6 +11,8 @@ using System.Diagnostics;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Threading; using System.Threading;
using PluginManager.LanguageSystem; using PluginManager.LanguageSystem;
using System.Linq;
using System.Reflection.Metadata.Ecma335;
namespace PluginManager.Items namespace PluginManager.Items
{ {
@@ -21,25 +23,25 @@ namespace PluginManager.Items
private static LanguageManager languageManager = new LanguageManager("https://sethdiscordbot.000webhostapp.com/Storage/Discord%20Bot/Languages"); private static LanguageManager languageManager = new LanguageManager("https://sethdiscordbot.000webhostapp.com/Storage/Discord%20Bot/Languages");
public static List<Tuple<string, string, Action<string[]>>> commandList = new List<Tuple<string, string, Action<string[]>>>(); public static List<Tuple<string, string, Action<string[]>>>? commandList = new List<Tuple<string, string, Action<string[]>>>();
private DiscordSocketClient client; private DiscordSocketClient client;
public ConsoleCommandsHandler(DiscordSocketClient client) public ConsoleCommandsHandler(DiscordSocketClient client)
{ {
this.client = client; this.client = client;
//commandList = new List<Tuple<string, string, Action<string[]>>>();
InitializeBasicCommands(); InitializeBasicCommands();
//Console.WriteLine("ConsoleCommandsHandler enabled"); Console.WriteLine("Initalized console command handeler !");
} }
private void InitializeBasicCommands() private void InitializeBasicCommands()
{ {
bool pluginsLoaded = false; bool pluginsLoaded = false;
commandList.Clear();
AddCommand("help", "Show help", (args) => 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)
@@ -51,7 +53,7 @@ namespace PluginManager.Items
{ {
foreach (var command in commandList) foreach (var command in commandList)
{ {
if (command.Item1 == args[0]) if (command.Item1 == args[1])
{ {
Console.WriteLine(command.Item2); Console.WriteLine(command.Item2);
return; return;
@@ -270,20 +272,20 @@ namespace PluginManager.Items
else Console.WriteLine("File could not be found. Please register token"); else Console.WriteLine("File could not be found. Please register token");
}); });
} }
public static void AddCommand(string command, string description, Action<string[]> action) public static void AddCommand(string command, string description, Action<string[]> action)
{ {
commandList.Add(new Tuple<string, string, Action<string[]>>(command, description, 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"); Console_Utilities.WriteColorText($"Command &r{command} &cadded to the list of commands");
} }
public static void AddCommand(string command, string description, Action action) public static void AddCommand(string command, string description, Action action)
{ {
AddCommand(command, description, (args) => AddCommand(command, description, (args) => action());
{
action();
});
/* Console.WriteLine("Added command: " + command);*/ /* Console.WriteLine("Added command: " + command);*/
} }
@@ -293,15 +295,20 @@ namespace PluginManager.Items
commandList.RemoveAll(x => x.Item1 == 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) public void HandleCommand(string command)
{ {
string[] args = command.Split(' '); string[] args = command.Split(' ');
foreach (var item in commandList) foreach (var item in commandList.ToList())
{ {
if (item.Item1 == args[0]) if (item.Item1 == args[0])
{ {
item.Item3(args); item.Item3(args);
return; //Console.WriteLine($"Executing: {args[0]} with the following parameters: {args.MergeStrings(1)}");
} }
} }
} }