private static void CreateGoogleConfigFiles() { if (!File.Exists(GoogleConfFile)) { GoogleData = new GoogleConfig { RolesStartAfter = 1, RolesEndBefore = 1, DiscordIDField = 0, NicknameField = -1 }; // Default values for GoogleData string googleJson = JsonConvert.SerializeObject(GoogleData, Formatting.Indented); File.WriteAllText(GoogleConfFile, googleJson); Console.WriteLine("Google Sheets data not found or corrupt."); } else { string googleJson = File.ReadAllText(GoogleConfFile); try { GoogleData = JsonConvert.DeserializeObject <GoogleConfig>(googleJson); } catch { File.Delete(GoogleConfFile); CreateGoogleConfigFiles(); } } }
public static void WriteToGoogleConfig(string apiKey, string spreadsheetID, string range, int rolesStartAfter, int rolesEndBefore, int discordID, int nickname) { GoogleData = new GoogleConfig() { APIKey = apiKey, SheetsID = spreadsheetID, Range = range, RolesStartAfter = rolesStartAfter, RolesEndBefore = rolesEndBefore, DiscordIDField = discordID, NicknameField = nickname, }; string botJson = JsonConvert.SerializeObject(GoogleData, Formatting.Indented); File.WriteAllText(GoogleConfFile, botJson); }