Exemple #1
0
        static void IniModules() //! Get all modules
        {
            Modules.Module.ModulesList = (from module in Assembly.GetEntryAssembly().GetTypes()
                                          where module.GetInterfaces().Contains(typeof(IModule)) && !module.IsInterface
                                          select Activator.CreateInstance(module) as IModule).ToList();

            //? Modules config directory
            string modulespath = Path.Combine(AppContext.BaseDirectory, "Modules");

            try
            {
                if (!Directory.Exists(modulespath))
                {
                    Directory.CreateDirectory(Path.Combine(AppContext.BaseDirectory, "Modules"));
                }
            }
            catch (Exception e)
            {
                Shell.WriteLineError("Can't create Modules config directory.");
                Shell.WriteLineError(e.Message);
            }

            //? Auto activated Modules
            ConfigurationFile modules = new ConfigurationFile(Misc.GetFilePath("modules.config"));

            foreach (IModule mod in Modules.Module.ModulesList)
            {
                string name = mod.GetType().Name;

                if (modules[name] == null)
                {
                    modules.Add(name, "false");
                    modules.Save();
                    continue;
                }
                if (modules[name].Value == "true")
                {
                    mod.Activate();
                    mod.IsActivated = true;
                    Shell.Write(ConsoleColor.DarkCyan, "[Autostart] ");
                    Shell.WriteLine(ConsoleColor.Cyan, name);
                    //x Log.SendLog("[Autostart] " + name);
                }
            }

            Shell.Write();
        }
Exemple #2
0
        static async Task Connect(string input) // Connect Command
        {
            string[]  cmd   = input.Split(' ');
            string    token = null;
            TokenType type  = TokenType.Bearer;

            if (cmd.Length < 2)
            {
                Shell.WriteLine("Invalid arguments, please try with \"connect bot/user token\"");
                return;
            }

            if (int.TryParse(cmd[1], out int i))
            {
                if (i <= Program.ClientAccount.Accounts.Count)
                {
                    token = Program.ClientAccount.Accounts[i - 1].Token;
                    type  = Program.ClientAccount.Accounts[i - 1].Type;
                }
            }
            else if (cmd.Length > 2)
            {
                token = cmd[2];
                if (cmd[1].Equals("bot", StringComparison.OrdinalIgnoreCase))
                {
                    type = TokenType.Bot;
                }
                else if (cmd[1].Equals("user", StringComparison.OrdinalIgnoreCase))
                {
                    type = TokenType.User;
                }
            }


            if (token == null || type == TokenType.Bearer)
            {
                Shell.WriteLineError("Invalid arguments, please try with \"connect bot/user token\"");
                return;
            }

            try
            {
                await Program.Client.StartAsync();

                await Program.Client.LoginAsync(type, token);
            }
            catch (Exception e)
            {
                Shell.WriteLineError("Error during connection...");
                Shell.WriteLineError(e.Message);
                return;
            }


            Shell.Write(ConsoleColor.Yellow, "Connecting to server...");

            int timeout = 0;

            while (!Program.ClientAccount.IsConnected)
            {
                if (timeout > 20)
                {
                    Shell.WriteLineError("Error during connection...");
                    await Disconnect();

                    return;
                }

                Shell.Write(ConsoleColor.Yellow, ".");
                System.Threading.Thread.Sleep(500);
                timeout++;
            }
            Shell.Write();
            Shell.WriteLine(ConsoleColor.Green, "Connected to Discord server !");

            ConfigurationFile accounts = new ConfigurationFile(Path.Combine(AppContext.BaseDirectory, "accounts.config"));

            accounts.Add(Program.Client.CurrentUser.Username, type + ";" + token);
            accounts.Save();

            // Set playing game
            await PlayInit();
        }