示例#1
0
        private static async Task EditConfigAsync()
        {
            bool exit = false;

            while (!exit)
            {
                List <string> options = new List <string>(ConfigOptions)
                {
                    [1] = $"Slow typing Animation (Current: {UserConfig.SlowTyping})"
                };
                int option = OptionSelection("Enter an option:", options);
                switch (option)
                {
                case 1:
                    string token;
                    while (true)
                    {
                        Console.Write("\nEnter the new token (Enter 'r' to return): ");
                        token = Console.ReadLine()?.Trim();
                        if (string.IsNullOrWhiteSpace(token))
                        {
                            Console.WriteLine("You must enter a token.");
                        }
                        else if (token.ToLowerInvariant() == "r")
                        {
                            break;
                        }
                        else if (!Guid.TryParse(token, out _))
                        {
                            Console.WriteLine("Invalid token.");
                        }
                        else
                        {
                            UserConfig.Token = token;
                            API = new AIDungeon(UserConfig.Token);
                            SaveConfig();
                            break;
                        }
                    }
                    break;

                case 2:
                    UserConfig.SlowTyping = !UserConfig.SlowTyping;
                    SaveConfig();
                    break;

                case 3:
                    DeleteConfig();
                    HasToken = false;
                    await LoginAsync();

                    exit = true;
                    break;

                case 4:
                    exit = true;
                    break;
                }
            }
        }
示例#2
0
 private static void LoadConfig()
 {
     if (!File.Exists(ConfigFile))
     {
         return;
     }
     try
     {
         string json = File.ReadAllText(ConfigFile);
         UserConfig = JsonConvert.DeserializeObject <Config>(json);
         API        = new AIDungeon(UserConfig.Token);
         HasToken   = true;
         Console.Write("Configuration loaded.");
     }
     catch
     {
         Console.Write("Unable to load the config.");
     }
 }
示例#3
0
        private static async Task LoginAsync()
        {
            while (!HasToken)
            {
                string email;
                string password;
                int    loginOption = OptionSelection("Enter an option to log in:", LoginOptions);
                switch (loginOption)
                {
                case 1:
                    Console.Write("\nEmail: ");
                    email = Console.ReadLine();
                    Console.Write("Username: "******"Password: "******"\nLoading...");
                    API = new AIDungeon();
                    try
                    {
                        var response = await API.RegisterAsync(email, username, password);

                        if (response.Errors != null)
                        {
                            Console.Write($"En error occurred: {response.Errors[0].Message}");
                        }
                        else
                        {
                            API.Token = response.Data.CreateAccount.AccessToken;
                            Console.Write("Registered Successfully. You should check your E-Mail to verify your account.");
                            HasToken = true;
                        }
                    }
                    catch (HttpRequestException e)
                    {
                        Console.WriteLine($"An error occurred: {e.Message}");
                    }
                    await Task.Delay(5000);

                    break;

                case 2:
                    Console.Write("\nEmail: ");
                    email = Console.ReadLine();
                    Console.Write("Password: "******"\nLogging in...");
                    API = new AIDungeon();
                    LoginResponse loginResponse;
                    try
                    {
                        loginResponse = await API.LoginAsync(email, password);
                    }
                    catch (HttpRequestException e)
                    {
                        Console.WriteLine($"An error occurred: {e.Message}");
                    }
                    await Task.Delay(5000);

                    break;

                case 3:
                    string token;
                    while (true)
                    {
                        Console.Write("\nEnter a token (Enter 'r' to return): ");
                        token = Console.ReadLine()?.Trim();
                        if (string.IsNullOrWhiteSpace(token))
                        {
                            Console.WriteLine("You must enter a token.");
                        }
                        else if (token.ToLowerInvariant() == "r")
                        {
                            break;
                        }
                        else if (!Guid.TryParse(token, out _))
                        {
                            Console.WriteLine("Invalid token.");
                        }
                        else
                        {
                            API      = new AIDungeon(token);
                            HasToken = true;
                            break;
                        }
                    }
                    break;

                case 4:
                    Environment.Exit(0);
                    break;
                }

                // Create config file
                if (HasToken)
                {
                    UserConfig = new Config(API.Token, true);
                    SaveConfig();
                }
            }
        }