Ejemplo n.º 1
0
        public async Task Connect()
        {
            client.Log             += logger.Log;
            client.Ready           += RepeatingTimer.StartTimer;
            client.ReactionAdded   += OnReactAdded;
            client.MessageReceived += OnMessageReceived;
            client.JoinedGuild     += Client_JoinedGuild;
            client.LeftGuild       += Client_LeftGuild;
            await client.SetGameAsync(Messages.GetAlert("System.Game"), type : ActivityType.Listening);

            await client.LoginAsync(TokenType.Bot, config.GetValueFor(Constants.ConfigKeyToken));

            await client.StartAsync();

            Global.Client = client;
            ConsoleTools.ConsoleInput();
        }
Ejemplo n.º 2
0
        public static async Task ConsoleInput()
        {
            string       input = "";
            ConsoleTools obj   = new ConsoleTools();

            while (continueConsoleTools)
            {
                // Retrieves input and, if it is a command, attempts to format it to be parsed.
                input = Console.ReadLine().ToLower().Trim();
                if (!input.StartsWith(prefix) || !(input.Length > 1))
                {
                    continue;
                }
                else
                {
                    input = input.Substring(1);
                }

                // Gets parameters and methods, and attempts to invoke a method if it matches the inputted command.
                var parameters = obj.GetParams(input);
                var methods    = typeof(ConsoleTools).GetRuntimeMethods();
                foreach (MethodInfo method in methods)
                {
                    foreach (Attribute attr in method.GetCustomAttributes())
                    {
                        if (attr is CommandAttribute cmd && input.StartsWith(cmd.Name))
                        {
                            parameters = obj.ConvertParams(parameters, method);
                            try
                            {
                                method.Invoke(obj, parameters);
                                continue;
                            }
                            catch (TargetParameterCountException)
                            {
                                Console.WriteLine("Invalid paramters.");
                            }
                        }
                    }
                }
            }
        }