/// <summary> /// Queries the input of users chat and retrieves the command, flag and flag parameters /// </summary> /// <param name="message"></param> public static void parseInput(DoggoDiscordAssistant bot, Server server, Discord.Channel channel, Discord.User user, string message) { string command; string parameter; Dictionary <string, string> flags = new Dictionary <string, string>(); //Discard command symbol and split the message into a list message = message.Remove(0, 1); splitMessage = message.Split(' ').ToList <string>(); //Grab the command and discard it from the list command = splitMessage[0]; splitMessage.RemoveAt(0); /*If command matches a registered command identifier, continue parsing for the parameter, * flags and flag parameter, and then execute the command*/ foreach (Command rcommand in server.AvailableCommands.ToList()) { if (command == rcommand.Identifier) { parameter = parseParameter(); flags = parseFlags(); if (bot.Debug) { Logging.consoleLog(user.Name + " has executed a command! " + Environment.NewLine + "Command: " + command + Environment.NewLine + "Parameter: " + parameter, Logging.logType.Debug); foreach (KeyValuePair <string, string> flag in flags) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Flag: " + flag.Key + " Parameter: " + flag.Value, Logging.logType.Debug); Console.ForegroundColor = ConsoleColor.White; } } rcommand.Execute(server, channel, user, parameter, flags); } } }
public static void parseAdminInput(string message, DoggoDiscordAssistant bot) { //Check to see that input has correct symbol if (message.Length > 0 && message[0] == '/') { string filteredMessage = message.Remove(0, 1).ToLower(); string[] command = filteredMessage.Split(' '); switch (command[0]) { case "debug": bot.Debug = !bot.Debug; if (bot.Debug) { Console.WriteLine("Debug ON!"); } else { Console.WriteLine("Debug OFF!"); } break; case "servers": Console.WriteLine("Currently in " + bot.servers.Count + " servers!"); foreach (Server server in bot.servers) { Console.WriteLine(server.ServerAPI.Name); } break; } Console.WriteLine(); } }
static void Main(string[] args) { string botToken = null; while (botToken == null) { Console.WriteLine("Would you like to run the offical client or the test client?"); Console.WriteLine("1. Doggo Discord Assistant"); Console.WriteLine("2. Doggo Test Assistant"); string input = Console.ReadLine(); if (input == "1") { Console.WriteLine("Official Client Selected!"); botToken = Token.getBotToken; } else if (input == "2") { Console.WriteLine("Test Client Selected!"); botToken = Token.getTestToken; } else { Console.WriteLine("Please type either a 1 or 2 and try again"); } Console.WriteLine(); } System.Threading.Thread.Sleep(3000); Console.Clear(); DoggoDiscordAssistant doggodiscordassistant = new DoggoDiscordAssistant(botToken, metadata => { metadata.AppName = "DogGo Discord Assistant"; metadata.AppVersion = "0.1.0"; metadata.AppUrl = "https://github.com/KevinMech/DogGo-Discord-Assistant"; metadata.LogLevel = LogSeverity.Error; metadata.LogHandler += Logging.APIErrorLogHandling; }); }